[pypy-svn] r73922 - pypy/branch/cpython-extension/pypy/module/cpyext

afa at codespeak.net afa at codespeak.net
Wed Apr 21 00:07:08 CEST 2010


Author: afa
Date: Wed Apr 21 00:07:07 2010
New Revision: 73922

Modified:
   pypy/branch/cpython-extension/pypy/module/cpyext/api.py
Log:
For tests, allow automatic conversion from wrapped objects to pointers like PyUnicodeObject.
This fixes tests for PyUnicode_AsWideChar


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	Wed Apr 21 00:07:07 2010
@@ -175,16 +175,17 @@
                 to_decref = []
                 for i, (ARG, is_wrapped) in types_names_enum_ui:
                     input_arg = args[i]
-                    if ARG is PyObject and not is_wrapped:
+                    if is_PyObject(ARG) and not is_wrapped:
                         # build a reference
                         if input_arg is None:
                             arg = lltype.nullptr(PyObject.TO)
                         elif isinstance(input_arg, W_Root):
-                            arg = make_ref(space, input_arg)
-                            to_decref.append(arg)
+                            ref = make_ref(space, input_arg)
+                            to_decref.append(ref)
+                            arg = rffi.cast(ARG, ref)
                         else:
                             arg = input_arg
-                    elif ARG is PyObject and is_wrapped:
+                    elif is_PyObject(ARG) and is_wrapped:
                         # convert to a wrapped object
                         if input_arg is None:
                             arg = input_arg
@@ -322,6 +323,11 @@
 PyVarObjectStruct = cpython_struct("PyVarObject", PyVarObjectFields)
 PyVarObject = lltype.Ptr(PyVarObjectStruct)
 
+def is_PyObject(TYPE):
+    if not isinstance(TYPE, lltype.Ptr):
+        return False
+    return hasattr(TYPE.TO, 'c_ob_refcnt') and hasattr(TYPE.TO, 'c_ob_type')
+
 # a pointer to PyObject
 PyObjectP = rffi.CArrayPtr(PyObject)
 



More information about the Pypy-commit mailing list