[pypy-svn] r73433 - in pypy/branch/cpython-extension/pypy/module/cpyext: . include

xoraxax at codespeak.net xoraxax at codespeak.net
Tue Apr 6 02:09:03 CEST 2010


Author: xoraxax
Date: Tue Apr  6 02:09:01 2010
New Revision: 73433

Modified:
   pypy/branch/cpython-extension/pypy/module/cpyext/include/object.h
   pypy/branch/cpython-extension/pypy/module/cpyext/object.py
   pypy/branch/cpython-extension/pypy/module/cpyext/pyobject.py
Log:
Implement missing function in object.py, disable the corresponding macros. Add a hack to accept also un-readied typeobjects.

Modified: pypy/branch/cpython-extension/pypy/module/cpyext/include/object.h
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/include/object.h	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/include/object.h	Tue Apr  6 02:09:01 2010
@@ -410,15 +410,20 @@
 #define PyObject_INIT_VAR(op, typeobj, size) \
 	( Py_SIZE(op) = (size), PyObject_INIT((op), (typeobj)) )
 
+/*
 #define PyObject_NEW(type, typeobj) \
 ( (type *) PyObject_Init( \
 	(PyObject *) PyObject_MALLOC( _PyObject_SIZE(typeobj) ), (typeobj)) )
+*/
+#define PyObject_NEW PyObject_New
+#define PyObject_NEW_VAR PyObject_NewVar
 
+/*
 #define PyObject_NEW_VAR(type, typeobj, n) \
 ( (type *) PyObject_InitVar( \
       (PyVarObject *) PyObject_MALLOC(_PyObject_VAR_SIZE((typeobj),(n)) ),\
       (typeobj), (n)) )
-
+*/
 
 /* PyPy internal ----------------------------------- */
 int PyPyType_Register(PyTypeObject *);

Modified: pypy/branch/cpython-extension/pypy/module/cpyext/object.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/object.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/object.py	Tue Apr  6 02:09:01 2010
@@ -11,12 +11,20 @@
 import pypy.module.__builtin__.operation as operation
 
 
- at cpython_api([PyObject], PyObject)
-def _PyObject_New(space, w_type):
+ at cpython_api([PyTypeObjectPtr], PyObject)
+def _PyObject_New(space, type):
+    try:
+        w_type = from_ref(space, rffi.cast(PyObject, type))
+    except:
+        import pdb; pdb.set_trace()
     if isinstance(w_type, W_PyCTypeObject):
         w_obj = space.allocate_instance(W_ObjectObject, w_type)
         return w_obj
-    assert False, "Please add more cases in get_cls_for_type_object!"
+    assert False, "Please add more cases in _PyObject_New"
+
+ at cpython_api([PyTypeObjectPtr, Py_ssize_t], PyObject)
+def _PyObject_NewVar(space, type, size): # XXX use size!
+    return _PyObject_New(space, type)
 
 @cpython_api([rffi.VOIDP_real], lltype.Void)
 def PyObject_Del(space, obj):

Modified: pypy/branch/cpython-extension/pypy/module/cpyext/pyobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/pyobject.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/pyobject.py	Tue Apr  6 02:09:01 2010
@@ -123,6 +123,7 @@
 
 
 def from_ref(space, ref):
+    from pypy.module.cpyext.typeobject import PyPyType_Ready
     assert lltype.typeOf(ref) == PyObject
     if not ref:
         return None
@@ -132,13 +133,20 @@
         w_obj = state.py_objects_r2w[ptr]
     except KeyError:
         ref_type = rffi.cast(PyObject, ref.c_ob_type)
-        if ref != ref_type and space.is_w(from_ref(space, ref_type), space.w_str):
-            return force_string(space, ref)
+        if ref != ref_type:
+            w_type = from_ref(space, ref_type)
+            if space.is_w(w_type, space.w_str):
+                return force_string(space, ref)
+            elif space.is_w(w_type, space.w_type):
+                PyPyType_Ready(space, rffi.cast(PyTypeObjectPtr, ref), None)
+                return from_ref(space, ref)
+            else:
+                msg = ""
+                if not we_are_translated():
+                    msg = "Got invalid reference to a PyObject: %r" % (ref, )
+                raise InvalidPointerException(msg)
         else:
-            msg = ""
-            if not we_are_translated():
-                msg = "Got invalid reference to a PyObject: %r" % (ref, )
-            raise InvalidPointerException(msg)
+            raise InvalidPointerException("This should never happen")
     return w_obj
 
 



More information about the Pypy-commit mailing list