xmlsec / python-xmlsec

Python bindings for the XML Security Library.
MIT License
95 stars 99 forks source link

Compilation failure when building C extension standalone #267

Closed chrisnovakovic closed 9 months ago

chrisnovakovic commented 1 year ago

Building the extension code under src outside of setup.py results in the following compilation error:

src/main.c, line 457, column 1: error: pasting formed 'PyInit_"xmlsec"', an invalid preprocessing token
PYENTRY_FUNC_NAME(void)
^
src/main.c, line 453, column 27: note: expanded from macro 'PYENTRY_FUNC_NAME'
#define PYENTRY_FUNC_NAME JOIN(PyInit_, MODULE_NAME)
                          ^
src/common.h, line 19, column 19: note: expanded from macro 'JOIN'
#define JOIN(X,Y) DO_JOIN1(X,Y)
                  ^
src/common.h, line 20, column 23: note: expanded from macro 'DO_JOIN1'
#define DO_JOIN1(X,Y) DO_JOIN2(X,Y)
                      ^
src/common.h, line 21, column 24: note: expanded from macro 'DO_JOIN2'
#define DO_JOIN2(X,Y) X##Y
                       ^
src/main.c, line 457, column 1: error: expected ';' after top level declarator
src/main.c, line 453, column 41: note: expanded from macro 'PYENTRY_FUNC_NAME'
#define PYENTRY_FUNC_NAME JOIN(PyInit_, MODULE_NAME)
                                        ^
src/common.h, line 16, column 21: note: expanded from macro 'MODULE_NAME'
#define MODULE_NAME "xmlsec"

The source of the problem is the definition of MODULE_NAME in src/common.h, which is set to "xmlsec" by the preprocessor if it isn't already defined:

https://github.com/xmlsec/python-xmlsec/blob/156394743a0c712e6638fe6e7e300c2f24b4fb12/src/common.h#L15-L17

This should be xmlsec rather than "xmlsec", since the macro value is used in contexts where a string literal isn't appropriate. This is masked when building the extension code from setup.py, which correctly sets the macro's value to xmlsec (without the quotes):

https://github.com/xmlsec/python-xmlsec/blob/156394743a0c712e6638fe6e7e300c2f24b4fb12/setup.py#L131-L133