Commit 77384d83 authored by Matti Picus's avatar Matti Picus
Browse files

allow creating ctypes.py_object() on a weakref (issue 3883)

parent 5eff3deb0aff
Pipeline #60345 passed with stage
in 8 minutes and 44 seconds
......@@ -2,6 +2,7 @@ from ctypes import *
import pytest
import sys
import weakref
def test_subclass_initializer():
......@@ -214,3 +215,14 @@ def test_memoryview():
assert mv.format == 'T{>h:a:>h:b:}'
assert mv.shape == (2, 3)
assert mv.itemsize == 4
def test_weakref():
# issue 3883: py_object of weakref
class Empty():
pass
e = Empty()
r = weakref.ref(e)
pr = py_object(r)
assert pr.value is e
......@@ -51,7 +51,10 @@ class GlobalPyobjContainer(object):
def add(self, obj):
num = len(self.objs)
self.objs.append(weakref.ref(obj))
if isinstance(obj, weakref.ReferenceType):
self.objs.append(obj)
else:
self.objs.append(weakref.ref(obj))
return num
def get(self, num):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment