Comments (11)
Thanks! Will apply these.
I wonder if we need to do anything else to handle recursion correctly in all cases - will your fix handle cases where the substitution is slightly different, such as #define sched_priority (sched_priority)
?
from panda3d.
I've just tested with this:
/* Backward compatibility. */
#define sched_priority sched_priority
#define __sched_priority (sched_priority)
int __sched_priority = 0;
and found that my patch doesn't fix this case.
from panda3d.
OK, I'll try to have a go at this - I think every iteration needs to make a blacklist of macros not to expand for the next iteration, or something of the sort.
from panda3d.
I've just went through it again with gdb
and changed the fix (notice it includes fix for the two bugs) and it does work with both cases now:
------------------ dtool/src/cppparser/cppPreprocessor.cxx -------------------
index 878e1c6..443f127 100644
@@ -821,7 +821,7 @@ expand_manifests(const string &input_expr, bool expand_undefined,
if (mi != _manifests.end()) {
const CPPManifest *manifest = (*mi).second;
expand_manifest_inline(expr, q, p, manifest);
- manifest_found = true;
+ manifest_found = expr != input_expr; //stop if we didn't changed anything
} else if (ident == "__FILE__") {
// Special case: this is a dynamic definition.
@@ -1455,7 +1455,7 @@ int CPPPreprocessor::
get_preprocessor_args(int c, string &args) {
// Following the command, the rest of the line, as well as any text on
// successive lines, is part of the arguments to the command.
-
+ c = skip_comment(c); //Check for comments first
while (c != EOF && c != '\n') {
if (c == '\\') {
int next_c = get();
from panda3d.
Another problem that I'm looking now is with <math.h>
:
cppparser-nb -v -D__PANDA_CC__ -D__builtin_va_list=void* -Dwchar_t=pccwchar_t -S/usr/include -S/usr/lib/gcc/x86_64-linux-gnu/9/include /usr/include/math.h
Predefining __PANDA_CC__ as
Predefining __builtin_va_list as void*
Predefining wchar_t as pccwchar_t
Reading /usr/include/math.h
...
Reading /usr/include/x86_64-linux-gnu/bits/flt-eval-method.h
Reading /usr/include/x86_64-linux-gnu/bits/fp-logb.h
Reading /usr/include/x86_64-linux-gnu/bits/fp-fast.h
Reading /usr/include/x86_64-linux-gnu/bits/mathcalls-helper-functions.h
Reading /usr/include/x86_64-linux-gnu/bits/mathcalls.h
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:62:38: error: syntax error, unexpected IDENTIFIER
__MATHCALL_VEC (cos,, (_Mdouble_ __x));
^
Error in parsing.
from panda3d.
Here is the minimum example that shows the problem with <math.h>
:
#define __CONCAT(x,y) x ## y
int __CONCAT(a, __CONCAT(b, c));
gcc output:
gcc -E -P test.c
int a__CONCAT(b, c);
cppparser output:
cppparser-nb -v -D__PANDA_CC__ -D__builtin_va_list=void* -Dwchar_t=pccwchar_t -S/usr/include -S/usr/lib/gcc/x86_64-linux-gnu/9/include test.c
Predefining __PANDA_CC__ as
Predefining __builtin_va_list as void*
Predefining wchar_t as pccwchar_t
Reading test.c
Finished parsing.
int a__CONCAT;
from panda3d.
I think Panda and gcc are parsing those examples similarly; they're both invalid code, Panda just shows the invalid code differently. GCC will show an error if you try to compile it, and parse_file will handle it correctly if you replaced b
and c
with int b
and int c
.
As for your other fix, it was still not handling this correctly:
#define A A B C
#define B B C A
#define C C A B
I just checked in a change that handles this correctly by implementing it recursively, with keeping track of already-substituted manifests.
I will close this issue, please open new (individual) issues for other problems you encounter.
Thanks!
from panda3d.
A simpler version of what's happening in math.h:
#define __CONCAT(x, y) x ## y
#define __SIMD_DECL(function) __CONCAT(__DECL_SIMD_, function)
#define __MATHCALL_VEC(function, suffix) __SIMD_DECL(__CONCAT(function, suffix))
int __SIMD_DECL(__CONCAT(a, b));
gcc output:
int __DECL_SIMD_ab;
parse_file output:
int __DECL_SIMD___CONCAT;
With CPP_VERBOSE_LEX
defined you can see that it's actually being parsed as:
int __DECL_SIMD___CONCAT(a, b);
It should probably be doing expansion on the arguments before passing them into CPPManifest::expand()
.
from panda3d.
After all the latest fixes to the preprocessor while trying to parse sqlite3.c
I found another macro that result in an endless loop:
#define GLOBAL(t,v) v
#define vfsList GLOBAL(sqlite3_vfs *, vfsList)
int pVfs = vfsList;
gcc output:
gcc -E -P test.c
int pVfs = vfsList;
cppparser output:
cppparser-nb -v -D__PANDA_CC__ -D__builtin_va_list=void* -Dwchar_t=pccwchar_t -S/usr/include -S/usr/lib/gcc/x86_64-linux-gnu/9/include test.c
Predefining __PANDA_CC__ as
Predefining __builtin_va_list as void*
Predefining wchar_t as pccwchar_t
Reading test.c
0. START_CPP
#define GLOBAL(t,v) v
#define vfsList GLOBAL(sqlite3_vfs *, vfsList)
Pushing to string "vfsList"
0. START_CONST_EXPR
End of input stream, restoring to previous input
1. IDENTIFIER vfsList
2. token 0
1. KW_INT
2. IDENTIFIER pVfs
3. '='
Pushing to expansion " GLOBAL(sqlite3_vfs *, vfsList) "
Expanding vfsList to GLOBAL(sqlite3_vfs *, vfsList)
Pushing to expansion " GLOBAL(sqlite3_vfs *, vfsList) "
Expanding GLOBAL to GLOBAL(sqlite3_vfs *, vfsList)
Pushing to expansion " GLOBAL(sqlite3_vfs *, vfsList) "
Expanding GLOBAL to GLOBAL(sqlite3_vfs *, vfsList)
...
from panda3d.
Yeah, got it, forgot to make sure it's not expanding manifests it's already in the process of expanding in this situation. Fix incoming.
from panda3d.
Fixed in 38a3048, keep it coming!
from panda3d.
Related Issues (20)
- Reimplement core functionality of DIRECT in C++ codebase HOT 1
- Cppparser preprocessor do not expand macros with arguments correctly HOT 94
- bam_model_extensions changes external path references in distributions
- FSM object has no attribute 'notifier' in requestNext/requestPrev
- Importing Pyrender with Panda3D results in the code not processing HOT 1
- Triangulator running out of memory HOT 1
- Interrogate limitations
- PandAI website link in the manual is broken, navmesh converter source "BlenderMeshGen.py" is lost. HOT 1
- DirectEntry with both backgroundFocus=1 and overflow=1 leave hanging events after being destroyed, causing a segmentation fault HOT 2
- Generated interrogate wrapper is not deterministic on macOS HOT 1
- PNMImage.flip() documentation doesn't match method, can't transpose with x/y mirror HOT 2
- Type Definition for functions and methods HOT 2
- Actor Animation Problem HOT 2
- Bam cache should remember loader used
- PStats: Scrubbing Through Flame-Charts
- Implement Khronos' reference PBR tone mapping operator HOT 3
- `Python 3.12.3`: No found distribution for panda3d HOT 3
- More Filters in Common Filters
- Issues using makewheel with CMake
- Is this license a BSD one or a different one? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from panda3d.