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

class struct_b(ctypes.Structure):

struct_a._fields_ = [('first',struct_b)]

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

results in:

$ pypy3 
Traceback (most recent call last):
  File "", line 12, in <module>
    b = copy.deepcopy(a)
  File "/usr/lib/pypy3.6/lib-python/3/", line 180, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "/usr/lib/pypy3.6/lib-python/3/", line 280, in _reconstruct
    state = deepcopy(state, memo)
  File "/usr/lib/pypy3.6/lib-python/3/", line 150, in deepcopy
    y = copier(x, memo)
  File "/usr/lib/pypy3.6/lib-python/3/", line 240, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/lib/pypy3.6/lib-python/3/", line 180, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "/usr/lib/pypy3.6/lib-python/3/", line 274, in _reconstruct
    y = func(*args)
  File "/usr/lib/pypy3.6/lib-python/3/", 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