Fixes arbitrary selection of regex implementation #8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes Issue #7.
Here's the issue. In
ftlRegex.F90
you have declared interfaces to C functionsregexec
and others. When you link your program with-lpcre -lpcreposix
, the linker has two implementations ofregexec
available to it: one from the standard C library, which is linked automatically, and another one fromlibpcreposix
. Which one does it bind to? I wasn't able to find any rules that regulate this, so I assume that this is undefined and implementation dependent.This is exactly what happened to me in Issue #7: I have compiled the library with USE_PCRE=true (default) and linked with
-lpcre -lpcreposix
, but the linker still chose to bind to the implementation from<regex.h>
and everything crashed.Here's what I propose to fix it: instead of binding directly to the library function
regexec
and leaving it up to the linker to decide which one, let's create our own dummy C interface and bind to it. This way we can have full control over what implementation is used by conditionally including either<regex.h>
or<pcreposix.h>
. This is what I implemented in the fileftlRegex_c.c
. Theexternal "C"
block is necessary for successful binding, since it prevents name mangling in case this file is compiled as a c++ file. The functions in that file have the same names as Fortran interfaces to them, so simply removing thename
attribute inftlRegex.F90
is sufficient to select them as binding targets. Finally, I have also modifiedmakefile
to include compilation of the new C file.