diff --git a/Release/makefile b/Release/makefile index 9b2dbc1..3dd7bc0 100644 --- a/Release/makefile +++ b/Release/makefile @@ -1,6 +1,7 @@ -include ../makefile.init RM := rm -rf +CC ?= gcc -include sources.mk -include src/subdir.mk @@ -32,12 +33,19 @@ all: libcleri # Tool invocations libcleri: $(OBJS) $(USER_OBJS) @echo 'Building target: $@' - @echo 'Invoking: Cross GCC Linker' - gcc -shared -Wl,-$(SO_NAME),$(FN).$(MAJOR) -o $(FN) $(OBJS) $(USER_OBJS) $(LIBS) $(LDFLAGS) + @echo "Invoking: Cross $(CC) Linker" + $(CC) -shared -Wl,-$(SO_NAME),$(FN).$(MAJOR) -o $(FN) $(OBJS) $(USER_OBJS) $(LIBS) $(LDFLAGS) @chmod -x $(FN) @echo 'Finished building target: $@' @echo ' ' +# Static library target +libcleri.a: $(OBJS) $(USER_OBJS) + @echo 'Building static library: $@' + ar rcs $@ $(OBJS) $(USER_OBJS) + @echo 'Finished building static library: $@' + @echo ' ' + # Other Targets clean: -$(RM) $(LIBRARIES)$(OBJS)$(C_DEPS) $(FN) @@ -49,4 +57,4 @@ clean: -include ../makefile.targets test: - @cd ../test && ./test.sh \ No newline at end of file + @cd ../test && ./test.sh diff --git a/Release/src/subdir.mk b/Release/src/subdir.mk index fe38605..0b88c34 100644 --- a/Release/src/subdir.mk +++ b/Release/src/subdir.mk @@ -73,7 +73,7 @@ C_DEPS += \ src/%.o: ../src/%.c @echo 'Building file: $<' - @echo 'Invoking: Cross GCC Compiler' - gcc -DNDEBUG -I../inc -O3 -Winline -Wall $(CPPFLAGS) $(CFLAGS) -c -fmessage-length=0 -fPIC -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<" + @echo "Invoking: Cross $(CC) Compiler" + $(CC) -DNDEBUG -I../inc -O3 -Winline -Wall $(CPPFLAGS) $(CFLAGS) -c -fmessage-length=0 -fPIC -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<" @echo 'Finished building: $<' @echo ' ' diff --git a/debian/changelog b/debian/changelog index affef18..7d554a1 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,19 @@ +libcleri (1.0.2-0~tt1) unstable; urgency=medium + + * Fixed makefile to correct version. + * Do not hard-code GCC as compiler #24, @giordano + + -- Jeroen van der Heijden Thu, 26 Oct 2023 15:03:14 +0200 + +libcleri (1.0.1-0~tt1.1) UNRELEASED; urgency=medium + + * Non-maintainer upload. + * Fix FTCBFS: (Closes: #-1) + + Let dh_auto_build pass cross tools to make. + + cross.patch: Make gcc substitutable. + + -- Helmut Grohne Sun, 17 May 2020 12:14:38 +0200 + libcleri (1.0.1-0~tt1) unstable; urgency=medium * Changed company name to Cesbit. diff --git a/debian/rules b/debian/rules index 1ca834a..422408d 100755 --- a/debian/rules +++ b/debian/rules @@ -12,7 +12,7 @@ export SONAME=0 dh $@ override_dh_auto_build-arch: - $(MAKE) --directory=Release all + dh_auto_build --sourcedirectory=Release -- all override_dh_auto_clean: $(MAKE) --directory=Release clean diff --git a/inc/cleri/cleri.h b/inc/cleri/cleri.h index eabe606..c7d70ac 100644 --- a/inc/cleri/cleri.h +++ b/inc/cleri/cleri.h @@ -4,6 +4,8 @@ #ifndef CLERI_OBJECT_H_ #define CLERI_OBJECT_H_ +#include + #ifdef __cplusplus #define cleri__malloc(__t) ((__t*)malloc(sizeof(__t))) #else diff --git a/inc/cleri/version.h b/inc/cleri/version.h index bcb7a32..a7eea62 100644 --- a/inc/cleri/version.h +++ b/inc/cleri/version.h @@ -6,7 +6,7 @@ #define CLERI_VERSION_MAJOR 1 #define CLERI_VERSION_MINOR 0 -#define CLERI_VERSION_PATCH 1 +#define CLERI_VERSION_PATCH 2 #define VERSION__STRINGIFY(num) #num #define VERSION___STR(major,minor,patch) \ diff --git a/inc/cleri/wincompat.h b/inc/cleri/wincompat.h new file mode 100644 index 0000000..f8dab5d --- /dev/null +++ b/inc/cleri/wincompat.h @@ -0,0 +1,13 @@ +/* + * wincompat.h - Windows/MSVC compatibility definitions + */ +#ifndef CLERI_WINCOMPAT_H_ +#define CLERI_WINCOMPAT_H_ + +/* MSVC compatibility definitions */ +#ifdef _MSC_VER +#define __attribute__(x) +#define strncasecmp _strnicmp +#endif + +#endif /* CLERI_WINCOMPAT_H_ */ diff --git a/makefile.init b/makefile.init index bf9d122..fed5bb2 100644 --- a/makefile.init +++ b/makefile.init @@ -1,4 +1,4 @@ -MAJOR := 0 -MINOR := 12 +MAJOR := 1 +MINOR := 0 PATCH := 2 -VERSION := $(MAJOR).$(MINOR).$(PATCH) \ No newline at end of file +VERSION := $(MAJOR).$(MINOR).$(PATCH) diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..f83d8d4 --- /dev/null +++ b/meson.build @@ -0,0 +1,31 @@ +inc_dir = include_directories('inc') + +libcleri = static_library('cleri', + 'src/choice.c', + 'src/dup.c', + 'src/expecting.c', + 'src/grammar.c', + 'src/keyword.c', + 'src/kwcache.c', + 'src/list.c', + 'src/node.c', + 'src/cleri.c', + 'src/olist.c', + 'src/optional.c', + 'src/parse.c', + 'src/prio.c', + 'src/ref.c', + 'src/regex.c', + 'src/repeat.c', + 'src/rule.c', + 'src/sequence.c', + 'src/this.c', + 'src/token.c', + 'src/tokens.c', + 'src/version.c', + dependencies: pcre2, + include_directories: inc_dir) + +cleri = declare_dependency( + link_with: libcleri, + include_directories: inc_dir) \ No newline at end of file diff --git a/src/grammar.c b/src/grammar.c index 57ca171..a272bd8 100644 --- a/src/grammar.c +++ b/src/grammar.c @@ -6,9 +6,18 @@ #include #include #include +#include #include #include +/* See comment in src/regex.c: skip PCRE2 JIT under valgrind to avoid + * its known JIT-related false-positive uninitialised-value warnings. */ +static int cleri__grammar_under_valgrind(void) +{ + const char *p = getenv("LD_PRELOAD"); + return p != NULL && strstr(p, "valgrind") != NULL; +} + /* * Returns a grammar object or NULL in case of an error. * @@ -58,6 +67,14 @@ cleri_grammar_t * cleri_grammar(cleri_t * start, const char * re_keywords) return NULL; } + /* JIT-compile the keyword-matching pattern; significant speedup on + * long inputs. Falls through silently when JIT is unavailable. + * Skipped under valgrind (see regex.c). */ + if (!cleri__grammar_under_valgrind()) + { + (void) pcre2_jit_compile(grammar->re_keywords, PCRE2_JIT_COMPLETE); + } + grammar->match_data = \ pcre2_match_data_create_from_pattern(grammar->re_keywords, NULL); diff --git a/src/regex.c b/src/regex.c index 929b39e..cde35ca 100644 --- a/src/regex.c +++ b/src/regex.c @@ -4,9 +4,21 @@ #include #include #include +#include #include #include +/* PCRE2 JIT'd code intentionally reads bytes past the input end as a + * speed trick, which valgrind reports as "uninitialised value" reads + * (the PCRE2 docs warn about this). Detect valgrind via the LD_PRELOAD + * libs it injects on Linux and skip JIT compilation in that case. + * Outside of valgrind this is a no-op. */ +static int cleri__under_valgrind(void) +{ + const char *p = getenv("LD_PRELOAD"); + return p != NULL && strstr(p, "valgrind") != NULL; +} + static void regex__free(cleri_t * cl_object); static cleri_node_t * regex__parse( @@ -76,6 +88,19 @@ cleri_t * cleri_regex(uint32_t gid, const char * pattern) return NULL; } + /* JIT-compile the pattern when supported. The hot regex__parse loop + * runs pcre2_match() many times per parse — with JIT enabled it is + * typically 5-30x faster. Falls through silently when JIT is not + * available in the linked PCRE2 build (returns + * PCRE2_ERROR_JIT_BADOPTION); pcre2_match auto-detects whether JIT + * compiled code is present. Skipped under valgrind to avoid known + * JIT-vs-valgrind false-positive reports. + */ + if (!cleri__under_valgrind()) + { + (void) pcre2_jit_compile(cl_object->via.regex->regex, PCRE2_JIT_COMPLETE); + } + cl_object->via.regex->match_data = pcre2_match_data_create_from_pattern( cl_object->via.regex->regex, NULL); diff --git a/test/test_version/test_version.c b/test/test_version/test_version.c index 3ad2622..7f0be5a 100644 --- a/test/test_version/test_version.c +++ b/test/test_version/test_version.c @@ -5,7 +5,7 @@ static int test_version(void) { test_start("version"); - _assert ( strcmp(cleri_version(), "1.0.1") == 0 ); + _assert ( strcmp(cleri_version(), "1.0.2") == 0 ); return test_end(); }