Coder Social home page Coder Social logo

Multi-line macro fails about ctypeslib HOT 2 CLOSED

trolldbois avatar trolldbois commented on June 15, 2024
Multi-line macro fails

from ctypeslib.

Comments (2)

trolldbois avatar trolldbois commented on June 15, 2024

Not really,
the clang preprocessor should be doing it, not ctypeslib.

from ctypeslib.

jmw182 avatar jmw182 commented on June 15, 2024

Okay. Just to make sure I described my issue clearly, I am only encountering a problem when I use the -k m option to include macros in the ctypeslib output. I am passing in a .h file to define constants and structure typedefs. If I include a multi-line macro in the .h file containing part of a structure definition, I can use that macro within structure typedefs in the .h file, and ctypeslib will process the macro correctly as long as I do not use the -k m option (I am guessing this is because the clang preprocessor is handling the macros in this case). If I use the -k m option I get the following error:

$ python3 "ctypeslib\clang2py.py" -c -k cdefmstu -o message_defs.py message_defs.h
Traceback (most recent call last):
  File "ctypeslib\clang2py.py", line 311, in <module>
    main()
  File "ctypeslib\clang2py.py", line 306, in main
    flags=clang_opts)
  File "ctypeslib\codegen\codegenerator.py", line 888, in generate_code
    parser.parse(srcfile)
  File "ctypeslib\codegen\clangparser.py", line 120, in parse
    self.startElement(node)
  File "ctypeslib\codegen\clangparser.py", line 159, in startElement
    stop_recurse = self.parse_cursor(node)
  File "ctypeslib\codegen\clangparser.py", line 273, in parse_cursor
    return self.cursorkind_handler.parse_cursor(cursor)
  File "ctypeslib\codegen\cursorhandler.py", line 37, in parse_cursor
    return mth(cursor)
  File "ctypeslib\codegen\util.py", line 119, in fn
    return func(*args, **kwargs)
  File "ctypeslib\codegen\cursorhandler.py", line 1041, in MACRO_DEFINITION
    tokens = self._literal_handling(cursor)
  File "ctypeslib\codegen\util.py", line 119, in fn
    return func(*args, **kwargs)
  File "ctypeslib\codegen\cursorhandler.py", line 528, in _literal_handling
    value = self.get_registered(value).body
  File "ctypeslib\codegen\handler.py", line 47, in get_registered
    return self.parser.get_registered(name)
  File "ctypeslib\codegen\clangparser.py", line 188, in get_registered
    return self.all[name]
KeyError: 'msg_type'

Here is the example message_defs.h file that causes this error:

#define MT_REQUEST_TEST_DATA 101
#define MT_TEST_DATA 102

#define RTMA_MSG_HEADER_FIELDS \
	int	msg_type; \
	int	msg_count; \
	double	send_time; \
	double	recv_time

typedef struct 
{ 
    RTMA_MSG_HEADER_FIELDS;
    int a; 
    int b; 
    double x; 
} MDF_TEST_DATA;

I had been assuming the issue was related to reading in one line at a time, but I tried redefining the macro on a single line like this, and got the same error: #define RTMA_MSG_HEADER_FIELDS int msg_type; int msg_count; double send_time; double recv_time

Does the -k m option rely on the clang preprocessor in the same way as when -k m is not specified?
Thanks.

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.