amauryfa / lxml

lxml-cffi is a PyPy-friendly port of lxml, based on cffi
20 stars 10 forks source link

multiple declarations of constant: XML_ATTRIBUTE_IDREF #4

Open Julian opened 10 years ago

Julian commented 10 years ago

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 :)

amauryfa commented 10 years ago

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

Julian commented 10 years ago

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?

arigo commented 10 years ago

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

amauryfa commented 10 years ago

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.

arigo commented 10 years ago

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.