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

Parser: Flex Prefix #1615

Merged
merged 5 commits into from
Jan 12, 2021
Merged

Parser: Flex Prefix #1615

merged 5 commits into from
Jan 12, 2021

Conversation

ax3l
Copy link
Member

@ax3l ax3l commented Jan 11, 2021

Add a prefix to all flex symbols in the parser. This ensures that in builds with complex dependencies, which might also use flex for their own purposes, no symbol collisions occur.

Pro-active prevents issues such as: ornladios/ADIOS2#2576

@ax3l ax3l added enhancement New feature or request component: core Core WarpX functionality labels Jan 11, 2021
Add a prefix to all flex symbols in the parser.
This ensures that in builds with complex dependencies, which might
also use flex for their own purposes, no symbol collisions occur.
@ax3l
Copy link
Member Author

ax3l commented Jan 11, 2021

I called make but it looks like wp_parser.tab.cpp needs to be updated, too. Is this file generated?

/usr/bin/ld: Source/Parser/wp_parser.tab.cpp.o: in function `yyparse()':
Source/Parser/wp_parser.tab.cpp:1294: undefined reference to `yylex()'
collect2: error: ld returned 1 exit status

@WeiqunZhang
Copy link
Member

WeiqunZhang commented Jan 11, 2021

diff --git a/Source/Parser/wp_parser.y b/Source/Parser/wp_parser.y
index 809dbfa..7366eb4 100644
--- a/Source/Parser/wp_parser.y
+++ b/Source/Parser/wp_parser.y
@@ -4,7 +4,7 @@
     #include <stdlib.h>
     #include <math.h>
     #include "wp_parser_y.h"
-    int yylex (void);
+    int wxparserlex (void);
 %}
 
 /* We do not need to make this reentrant safe, because we use flex and
@@ -12,6 +12,7 @@
    thread safe.
 */
 /*%define api.pure full */
+%define api.prefix {wxparser}
 
 /* This is the type returned by functions wp_new* declared in
    wp_parser_y.h.  See also bison rules at the end of this file.

Could you apply this patch and rerun make?

@WeiqunZhang
Copy link
Member

We also need

--- a/Source/Parser/wp_parser_c.cpp
+++ b/Source/Parser/wp_parser_c.cpp
@@ -6,7 +6,7 @@ struct wp_parser*
 wp_c_parser_new (char const* body)
 {
     YY_BUFFER_STATE buffer = wxparser_scan_string(body);
-    yyparse();
+    wxparserparse();
     struct wp_parser* parser = wp_parser_new();
     wxparser_delete_buffer(buffer);
     return parser;

@WeiqunZhang
Copy link
Member

Can I push to your branch? I have a few other fixes.

@ax3l
Copy link
Member Author

ax3l commented Jan 11, 2021

Yes, will do those!

Does wp_parser.tab.cpp need updates as well or is that file unused?

@WeiqunZhang
Copy link
Member

wp_parser.tab.cpp is auto generated. The yy there is fine because of macros like

#define yyerror         wxparsererror

at the beginning of the file.

@WeiqunZhang
Copy link
Member

I have a working version now. I will push the changes in a minute.

@WeiqunZhang
Copy link
Member

@ax3l Could rerun make to generate wp_parser.lex.cpp, wp_parser.lex.h, wp_parser.tab.cpp, and wp_parser.tab.h? My versions of flex and bison are very old. It would result in too many changes.

@ax3l
Copy link
Member Author

ax3l commented Jan 11, 2021

Thank you, push incoming 🦅

Copy link
Member

@lucafedeli88 lucafedeli88 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR!

@ax3l ax3l merged commit 3f20f88 into ECP-WarpX:development Jan 12, 2021
@ax3l ax3l deleted the topic-parserPrefixFlex branch January 12, 2021 19:42
dpgrote pushed a commit to dpgrote/WarpX that referenced this pull request Jan 14, 2021
* Parser: Flex Prefix

Add a prefix to all flex symbols in the parser.
This ensures that in builds with complex dependencies, which might
also use flex for their own purposes, no symbol collisions occur.

* Parser: Flex Rebuild

* Flex Prefix: Update Parser Usage

* Parser: Fix prefixes

* Parser: Flex Rebuild

Co-authored-by: Weiqun Zhang <weiqunzhang@lbl.gov>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: core Core WarpX functionality enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants