pypxlib icon indicating copy to clipboard operation
pypxlib copied to clipboard

Import error on Python 3.8

Open alandmoore opened this issue 5 years ago • 5 comments

When importing pypxlib on Python 3.8 I get the following:

Traceback (most recent call last):
  File "/usr/lib/python3.8/ctypes/__init__.py", line 99, in CFUNCTYPE
    return _c_functype_cache[(restype, argtypes, flags)]
KeyError: (<class 'ctypes.c_void_p'>, (<class 'pypxlib.pxlib_ctypes.py3.LP_struct_px_doc'>, <class 'ctypes.c_int'>, <class 'pypxlib.pxlib_ctypes.py3.String'>, <class 'ctypes.c_void_p'>), 1)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/alanm/.local/lib/python3.8/site-packages/pypxlib/__init__.py", line 4, in <module>
    from pypxlib.pxlib_ctypes import *
  File "/home/alanm/.local/lib/python3.8/site-packages/pypxlib/pxlib_ctypes/__init__.py", line 15, in <module>
    from pypxlib.pxlib_ctypes.py3 import *
  File "/home/alanm/.local/lib/python3.8/site-packages/pypxlib/pxlib_ctypes/py3.py", line 951, in <module>
    ('errorhandler', CFUNCTYPE(UNCHECKED(None), POINTER(pxdoc_t), c_int, String, POINTER(None))),
  File "/usr/lib/python3.8/ctypes/__init__.py", line 101, in CFUNCTYPE
    class CFunctionType(_CFuncPtr):
TypeError: item 3 in _argtypes_ passes a union by value, which is unsupported.

This is on Arch Linux running Python 3.8.1. pypxlib from pypi.

alandmoore avatar Jan 09 '20 17:01 alandmoore

Interestingly, I get the same error if I install Python 3.7.6 on this computer, but I don't get it with Python 3.7.2 on Debian.

pxlib 0.6.8-1 is installed on the Arch system, pxlib 0.6.7-1 on Debian.

alandmoore avatar Jan 09 '20 18:01 alandmoore

I did attempt generating a new py3.py file using ctypesgenerator, but I end up with the exact same call to CFUNCTYPE that causes the same error.

I also, rather naively, wrapped all the String uses in CFUNCTYPE calls with a POINTER. This stopped the import error, but pretty much broke the whole library. I really know almost nothing about ctypes, so I'm just swinging wildly at this issue.

alandmoore avatar Jan 09 '20 20:01 alandmoore

Most probably related to: https://github.com/python/cpython/pull/16799

airelil avatar Jan 11 '20 20:01 airelil

@airelil Ah yes, looks like it. What a mess.

alandmoore avatar Jan 14 '20 21:01 alandmoore

Good news, they are reverting the change: https://github.com/python/cpython/pull/17960

airelil avatar Jan 15 '20 00:01 airelil