GithubHelp home page GithubHelp logo

Comments (8)

trolldbois avatar trolldbois commented on July 19, 2024 1

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.

RobertHerreraEECS avatar RobertHerreraEECS commented on July 19, 2024

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.

RobertHerreraEECS avatar RobertHerreraEECS commented on July 19, 2024

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.

RobertHerreraEECS avatar RobertHerreraEECS commented on July 19, 2024

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.

trolldbois avatar trolldbois commented on July 19, 2024

@RobertHerreraEECS can you confirm this is fixed in the main branch ?

from ctypeslib.

RobertHerreraEECS avatar RobertHerreraEECS commented on July 19, 2024

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.

trolldbois avatar trolldbois commented on July 19, 2024

@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.

RobertHerreraEECS avatar RobertHerreraEECS commented on July 19, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.