Skip to content

Fixes arbitrary selection of regex implementation#8

Open
GaidaiIgor wants to merge 2 commits intoSCM-NV:masterfrom
GaidaiIgor:master
Open

Fixes arbitrary selection of regex implementation#8
GaidaiIgor wants to merge 2 commits intoSCM-NV:masterfrom
GaidaiIgor:master

Conversation

@GaidaiIgor
Copy link

Fixes Issue #7.

Here's the issue. In ftlRegex.F90 you have declared interfaces to C functions regexec and others. When you link your program with -lpcre -lpcreposix, the linker has two implementations of regexec available to it: one from the standard C library, which is linked automatically, and another one from libpcreposix. 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 file ftlRegex_c.c. The external "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 the name attribute in ftlRegex.F90 is sufficient to select them as binding targets. Finally, I have also modified makefile to include compilation of the new C file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments