Comments (8)
Ah, I think I understand, you mean you would like
- To not have a type declaration for an anonymous union, that is an un-named field (union_s_0)
- A type declaration for an anonymous union, that is named field should carry the name of the field (union_s_1 -> union_s_u)
is that what you were asking ?
from ctypeslib.
FWIW I'm using the following command:
clang2py -v --validate 1 -k mcdefstua --clang-args "-I/dir/includes -std=c11 " target_header.h
from ctypeslib.
Another note, after digging through the logs, the interesting thing is that I can see the actual name of the struct being detected as a field FIELD_DECL, where the expected name in this edited log snippet is bar
.
`
2023-03-26 09:38:37,157:DEBUG:clangparser:Unregister foo_0_3
2023-03-26 09:38:37,157:DEBUG:clangparser:register: foo_0_3
2023-03-26 09:38:37,157:DEBUG:cursorhandler:creating FIELD_DECL for FIELD_DECL/bar
2023-03-26 09:38:37,157:DEBUG:cursorhandler:FIELD_DECL: field offset is 0
2023-03-26 09:38:37,157:DEBUG:cursorhandler:FIELD_DECL: field is 80 bits
2023-03-26 09:38:37,157:DEBUG:cursorhandler:FIELD_DECL: we now look for the declaration name.kind CursorKind.STRUCT_DECL`
from ctypeslib.
The following is a simple test showcasing the behavior I'm seeing as well an accompanying c file with the desired use of the struct I would need in my python code.
example.zip
from ctypeslib.
@RobertHerreraEECS can you confirm this is fixed in the main branch ?
from ctypeslib.
Thanks for getting this ticket first off!
This seems like a partial fix but definitely much better results. Unfortunately, it seems like the current patch and tests only account for the only 'fields' inheriting the TYPEDECL
name and not propagating that into the class namespace as well.
For instance I would expect the following in test case
self.assertNotIn('union_s_0', self.namespace) self.assertIn('union_s_u', self.namespace)
Let me know if this doesn't fit within the scope of functionality ^. If it doesn't, feel free to close the ticket.
Thanks again.
from ctypeslib.
@RobertHerreraEECS I'm sorry I do not understand the test case you are proposing.
Could you write python code you see failing / are not happy with, and the C headers ?
from ctypeslib.
Yes exactly! "A type declaration for an anonymous union, that is named field should carry the name of the field (union_s_1 -> union_s_u)".
Let me know what you think. I think its quite portable for most use cases. From a C standpoint if I see a structure that is both named and typedef usually the code base resorts to only using the typdef alias.
So my proposition would be if it the structure was unnamed (cursor.type.get_declaration().spelling == ''
) BUT cursor.spelling != ''
(the typedef alias), then just use the typedef name rather using a numeric index.
from ctypeslib.
Related Issues (20)
- Parsing a variadic macro makes clang2py crash HOT 1
- Define with parenthesis not parsed HOT 1
- clang2py not installed in "/usr/bin" HOT 1
- define didn't convert to python HOT 1
- Add if Windows 32bit use WinDLL instead CDLL HOT 1
- Use of "-r" option makes clang2py crash HOT 2
- do not support enum without name HOT 3
- No output from clang2py even for simple headers - CLANG compatibility issues HOT 6
- ctypeslib2 gives following error on any anaconda environment whenever installed with pip. HOT 3
- AttributeError: 'Output' object has no attribute 'options' HOT 1
- clang dependecy issue in version 2.3.2 (ubuntu 20.04) HOT 6
- Macro values with parenthesis are not converted HOT 2
- File format has no dynamic symbol table HOT 1
- get_version() access violation on clang 17.0.2 HOT 2
- C++ interface HOT 1
- Add __slots__ to structs HOT 1
- macOS quirks HOT 1
- as_dict() is broken for arrays of Structures
- anonymous union got incorrect name
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 ctypeslib.