inducer / pycparserext

Extensions for Eli Bendersky's pycparser
http://pypi.python.org/pypi/pycparserext
Other
83 stars 29 forks source link

Support complex __attribute__ involving __alignof__ #73

Open jordr opened 1 year ago

jordr commented 1 year ago

Pycparser breaks on this example:

diff --git a/test/test_pycparserext.py b/test/test_pycparserext.py
index 183769f..357061c 100644
--- a/test/test_pycparserext.py
+++ b/test/test_pycparserext.py
@@ -245,6 +245,7 @@ def test_array_attributes():
     src = """
         int x[10] __attribute__((unused));
         int y[20] __attribute((aligned(10)));
+        long long z __attribute__((aligned(__alignof__(long long))));
         """

     from pycparserext.ext_c_parser import GnuCParser

The error vanishes if I simplify the __attribute__ or replace __alignof__ by (for example) sizeof. __alignof__ is supported by GNU : https://gcc.gnu.org/onlinedocs/gcc-6.2.0/gcc/Alignment.html

I was not able to engineer a good solution so far. Can we have a generic __attribute__((whatever(foo(long long)))) solution or do we have to manually add __alignof__ keywords and the like?

inducer commented 1 year ago

Sorry, I won't be able to help in the near term. But I would be happy to consider PRs along these lines.

jordr commented 1 year ago

Thanks for the quick response, @inducer. I'll try to find a workaround.

retif commented 4 months ago

@jordr the issue here is pycparserext is not aware of __alignof__ keyword. It needs to be added to the lexer and parser in a similar way to how __typeof added here

Did you managed to solve this?

jordr commented 4 months ago

@jordr the issue here is pycparserext is not aware of __alignof__ keyword. It needs to be added to the lexer and parser in a similar way to how __typeof added here

Did you managed to solve this?

I believe I solved it the way you're describing in our fork a year ago, yes. My memory isn't that sharp though :)

retif commented 4 months ago

@jordr it would be great if you could create a PR, or just add diff here as a comment(and i will do a PR). I have stumbled on the same issue, and would be happy not to implement the fix myself to save some time :)

jordr commented 4 months ago

@jordr it would be great if you could create a PR, or just add diff here as a comment(and i will do a PR). I have stumbled on the same issue, and would be happy not to implement the fix myself to save some time :)

I don't have time for looking much into it right now, sorry. Maybe this commit will be useful to you: https://github.com/statinf-software/pycparser/commit/deacf7d9ba4ed6c4476245023266da7d1ba3d2ec