Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes arbitrary selection of regex implementation #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

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.

None yet

1 participant