[pypy-svn] r72606 - pypy/branch/cpython-extension/pypy/module/cpyext
xoraxax at codespeak.net
xoraxax at codespeak.net
Tue Mar 23 02:23:27 CET 2010
Author: xoraxax
Date: Tue Mar 23 02:23:26 2010
New Revision: 72606
Modified:
pypy/branch/cpython-extension/pypy/module/cpyext/api.py
Log:
Fill the type field. Unfortunately, we cannot easily fill it lazily because Py_TYPE needs to remain a macro. Maybe the macro could force the type obj? But then refcounting is hard.
Modified: pypy/branch/cpython-extension/pypy/module/cpyext/api.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/api.py (original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/api.py Tue Mar 23 02:23:26 2010
@@ -132,8 +132,13 @@
if py_obj is None:
from pypy.module.cpyext.typeobject import allocate_type_obj,\
W_PyCTypeObject, W_PyCObject
- if space.is_w(space.type(w_obj), space.w_type):
+ w_type = space.type(w_obj)
+ if space.is_w(w_type, space.w_type):
py_obj = allocate_type_obj(space, w_obj)
+ if space.is_w(w_type, w_obj):
+ pto = py_obj
+ else:
+ pto = make_ref(space, w_type)
elif isinstance(w_obj, W_PyCObject):
w_type = space.type(w_obj)
assert isinstance(w_type, W_PyCTypeObject)
@@ -143,6 +148,8 @@
py_obj = lltype.malloc(T, None, flavor="raw")
else:
py_obj = lltype.malloc(PyObject.TO, None, flavor="raw")
+ pto = make_ref(space, space.type(w_obj))
+ py_obj.c_obj_type = rffi.cast(PyObject, pto)
py_obj.c_obj_refcnt = 1
ctypes_obj = ll2ctypes.lltype2ctypes(py_obj)
ptr = ctypes.cast(ctypes_obj, ctypes.c_void_p).value
More information about the Pypy-commit
mailing list