New issue 2879: ctypes structure with custom __init__  which takes argument 
does not support construction by "from_buffer_copy"
https://bitbucket.org/pypy/pypy/issues/2879/ctypes-structure-with-custom-__init__

Sheng Zou:

This is another case where ctypes lib in CPython and PyPy give different result.

Code snippet run in PyPy:

/Users/local/Downloads/pypy-c-jit-95034-d2dd59afa85c-osx64/bin/pypy

Python 2.7.13 (d2dd59afa85c, Aug 29 2018, 22:00:26)

[PyPy 6.1.0-alpha0 with GCC 4.2.1 Compatible Apple LLVM 9.1.0 
(clang-902.0.39.2)] on darwin


```
#!python

>>>> from ctypes import *
>>>> class CustomStructure(Structure):
....
....     _fields_ = [("a", c_uint16)]
....
....     def __init__(self, flag):
....         if flag is True:
....             self.a = 128
....         else:
....             self.a = 0
....
>>>> x = CustomStructure(True) # This is OK, both in PyPy and CPython
>>>> x = CustomStructure() # This is NOT OK, both in PyPy and CPython
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __init__() takes exactly 2 arguments (1 given)
>>>> x = CustomStructure.from_buffer_copy(bytearray("\x01\x00")) # This is OK 
>>>> in CPython but NOT OK in PyPy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File 
"/Users/local/Downloads/pypy-c-jit-95034-d2dd59afa85c-osx64/lib_pypy/_ctypes/basics.py",
 line 123, in from_buffer_copy
    result = self()
TypeError: __init__() takes exactly 2 arguments (1 given)
```


_______________________________________________
pypy-issue mailing list
pypy-issue@python.org
https://mail.python.org/mailman/listinfo/pypy-issue

Reply via email to