-
Notifications
You must be signed in to change notification settings - Fork 83
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
Name collision in ctypegen? #146
Comments
Adding other required details related to this issue; C pre processing output: https://pastebin.com/pPMtQmcc |
@abstractor84 Thanks for an exemplary report! Sorry for replying only now. I'll see what can be done to fix this. Note, it would have worked with unnamed parameter in the prototype: // test.h
void test_api(MyStruct *); // test.c
void test_api(MyStruct *struct_arg) { |
Not only with unnamed parameter, but also with any other non-colliding name I think. However, when changing That said, I think the OP is already aware of the renaming approach
I don't think name shadowing is good practice, albeit allowed. The 3rd party may be happy to take a patch, leastways if it's open source. Also it shouldn't be a big deal to feed a patched copy of headers into ctypesgen, seeing as the param name does not affect the output, just the parsing. Footnotes
|
I have a simple C file and Header File. Where the header has 2 typedef structures and one function, where the function accepts a struct pointer parameter, this parameter can be any name as per C99 (I believe ctypesgen is based on this standard). However ctypesgen fails to parse this properly, and failed to construct an equivalent python code as this name is already used to refer another structure (alias first_struct).
Is there any workaround or fix for this issue? (The actual issue was with a large C code base, which i reproduced with this simple files)
So far, i'm able to proceed, if i change the function parameter name from some_struct to other names like some_struct_param), But I can't change the original C files as its from a 3rd party, and needs to be shipped as is.
Appreciate any help.
Failure:
ERROR: /home/test.h:12: Syntax error at 'some_struct'
Env details (reported here):
Python: Python 3.9.2
ctypegen: 1.0.2
OS: debian11
gcc: gcc12
Note: Also tested on a centos7 machine; with Python: 3.6.8, ctypesgen: 1.0.2, gcc: 4.8.5, The result is same.
My Header file:
My C prog:
When running ctypesgen with below arguments, I think I'm getting a name collision in python, so its reporting a syntax error, however as per C99 & gnu99 this is perfectly valid, and in C it works flawlessly.
Here is the output of 1) C prog compilation, 2) C prog execution, 3) C prog pre-processing, 4) ctypesgen output.
1) C prog compilation
2) C prog execution
3) C prog pre-processing
Output too large to attach, however there is no errors reported, will upload it as a file.
4) Generating shared lib
4) ctypesgen output.
The text was updated successfully, but these errors were encountered: