Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions Release/makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
-include ../makefile.init

RM := rm -rf
CC ?= gcc

-include sources.mk
-include src/subdir.mk
Expand Down Expand Up @@ -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)
Expand All @@ -49,4 +57,4 @@ clean:
-include ../makefile.targets

test:
@cd ../test && ./test.sh
@cd ../test && ./test.sh
4 changes: 2 additions & 2 deletions Release/src/subdir.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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 ' '
16 changes: 16 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -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 <jeroen@cesbit.com> 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 <helmut@subdivi.de> Sun, 17 May 2020 12:14:38 +0200

libcleri (1.0.1-0~tt1) unstable; urgency=medium

* Changed company name to Cesbit.
Expand Down
2 changes: 1 addition & 1 deletion debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions inc/cleri/cleri.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#ifndef CLERI_OBJECT_H_
#define CLERI_OBJECT_H_

#include <cleri/wincompat.h>

#ifdef __cplusplus
#define cleri__malloc(__t) ((__t*)malloc(sizeof(__t)))
#else
Expand Down
2 changes: 1 addition & 1 deletion inc/cleri/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down
13 changes: 13 additions & 0 deletions inc/cleri/wincompat.h
Original file line number Diff line number Diff line change
@@ -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_ */
6 changes: 3 additions & 3 deletions makefile.init
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MAJOR := 0
MINOR := 12
MAJOR := 1
MINOR := 0
PATCH := 2
VERSION := $(MAJOR).$(MINOR).$(PATCH)
VERSION := $(MAJOR).$(MINOR).$(PATCH)
31 changes: 31 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -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)
17 changes: 17 additions & 0 deletions src/grammar.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,18 @@
#include <cleri/grammar.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <pcre2.h>
#include <assert.h>

/* 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.
*
Expand Down Expand Up @@ -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);

Expand Down
25 changes: 25 additions & 0 deletions src/regex.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,21 @@
#include <cleri/regex.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

/* 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(
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/test_version/test_version.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Loading