pypy3 fails to deepcopy nested ctype structures

Create issue
Issue #3022 new
Jan Vesely created an issue
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__()

Comments (1)

  1. Log in to comment