lxml icon indicating copy to clipboard operation
lxml copied to clipboard

multiple declarations of constant: XML_ATTRIBUTE_IDREF

Open Julian opened this issue 10 years ago • 5 comments

I get a CFFI exception when trying to either install HEAD via pip or when trying to just directly import lxml.etree from a source checkout:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "lxml/../lxml-cffi/etree.py", line 43, in <module>
    _initThreadLogging()
  File "lxml/../lxml-cffi/xmlerror.py", line 162, in _initThreadLogging
    connectErrorLog(None)
  File "lxml/../lxml-cffi/xmlerror.py", line 165, in connectErrorLog
    from .includes import xslt
  File "lxml/includes/../../lxml-cffi/includes/xslt.py", line 6, in <module>
    ffi.include(xpath.ffi)
  File "/usr/local/Cellar/pypy/2.4.0_2/libexec/lib_pypy/cffi/api.py", line 379, in include
    self._parser.include(ffi_to_include._parser)
  File "/usr/local/Cellar/pypy/2.4.0_2/libexec/lib_pypy/cffi/cparser.py", line 584, in include
    self._add_constants(k, v)
  File "/usr/local/Cellar/pypy/2.4.0_2/libexec/lib_pypy/cffi/cparser.py", line 213, in _add_constants
    "multiple declarations of constant: %s" % (key,))
FFIError: multiple declarations of constant: XML_ATTRIBUTE_IDREF

Obviously I can provide whatever other info is necessary to help debug, but I can't figure out just what would be helpful yet myself :)

Julian avatar Nov 16 '14 14:11 Julian

This is strange. Can you check whether XML_ATTRIBUTE_IDREF appears multiple times in your copy of the src/lxml-cffi directory?

amauryfa avatar Nov 17 '14 09:11 amauryfa

The string appears in:

⊙  ag XML_ATTRIBUTE_IDREF                                                                                                                                                                        Julian@Air
src/lxml/dtd.pxi
126:           elif type == tree.XML_ATTRIBUTE_IDREF:
128:           elif type == tree.XML_ATTRIBUTE_IDREFS:

src/lxml/includes/tree.pxd
132:        XML_ATTRIBUTE_IDREF=       3
133:        XML_ATTRIBUTE_IDREFS=      4

src/lxml-cffi/dtd.py
119:       elif type == tree.XML_ATTRIBUTE_IDREF:
121:       elif type == tree.XML_ATTRIBUTE_IDREFS:

src/lxml-cffi/includes/tree.py
260:        XML_ATTRIBUTE_IDREF ,
261:        XML_ATTRIBUTE_IDREFS,

Which looks like just once to me in where that would complain, right?

Julian avatar Nov 17 '14 13:11 Julian

@amauryfa It seems to abuse ffi.include() quite a lot. In this format, every module in the includes subpackage compile its own .so that has got functions to call all the functions that it includes. You get multiple definition errors because some constants appear in more than one file, or one file's ffi is included more than once (directly or indirectly) in another file's ffi. I have no clue how it could ever have worked, btw. All I say is that you should probably not use ffi.include() in this situation.

arigo avatar Nov 17 '14 16:11 arigo

This is not what I saw. With pypy-c-jit-70319-c77678f05b18-linux-64 (cffi 0.8.2), XML_ATTRIBUTE_IDREF is present in only one .c file. And I don't get any warning.

amauryfa avatar Nov 17 '14 18:11 amauryfa

I cloned https://github.com/amauryfa/lxml, switched to branch cffi, then cd src and pypy -c "import lxml.xslt" with PyPy 2.4.0... I get the XML_ATTRIBUTE_IDREF error.

arigo avatar Nov 17 '14 18:11 arigo