[pypy-issue] Issue #3022: pypy3 fails to deepcopy nested ctype structures (pypy/pypy)

Jan at bitbucket.org Jan at bitbucket.org
Tue Jun 4 19:35:24 EDT 2019


New issue 3022: pypy3 fails to deepcopy nested ctype structures
https://bitbucket.org/pypy/pypy/issues/3022/pypy3-fails-to-deepcopy-nested-ctype

Jan Vesely:

```python
import ctypes, copy

class struct_a(ctypes.Structure):
    pass
    
class struct_b(ctypes.Structure):
    pass
    
struct_a._fields_ = [('first',struct_b)]

a = struct_a()
b = copy.deepcopy(a)
```

results in:

```
$ pypy3 ctype-struct.py 
Traceback (most recent call last):
  File "ctype-struct.py", line 12, in <module>
    b = copy.deepcopy(a)
  File "/usr/lib/pypy3.6/lib-python/3/copy.py", line 180, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "/usr/lib/pypy3.6/lib-python/3/copy.py", line 280, in _reconstruct
    state = deepcopy(state, memo)
  File "/usr/lib/pypy3.6/lib-python/3/copy.py", line 150, in deepcopy
    y = copier(x, memo)
  File "/usr/lib/pypy3.6/lib-python/3/copy.py", line 240, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/lib/pypy3.6/lib-python/3/copy.py", line 180, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "/usr/lib/pypy3.6/lib-python/3/copy.py", line 274, in _reconstruct
    y = func(*args)
  File "/usr/lib/pypy3.6/lib-python/3/copyreg.py", line 88, in __newobj__
    return cls.__new__(cls, *args)
TypeError: object.__new__(StructureInstanceAutoFree) is not safe, use StructureInstanceAutoFree.__new__()
```




More information about the pypy-issue mailing list