Author: Armin Rigo <[email protected]>
Branch: cpyext-avoid-roundtrip
Changeset: r92674:22870e1d5f60
Date: 2017-10-09 12:12 +0200
http://bitbucket.org/pypy/pypy/changeset/22870e1d5f60/

Log:    (antocuni, arigo)

        Yay. We are seemingly managing to remove _type_alloc() now.

diff --git a/pypy/module/cpyext/pyobject.py b/pypy/module/cpyext/pyobject.py
--- a/pypy/module/cpyext/pyobject.py
+++ b/pypy/module/cpyext/pyobject.py
@@ -99,6 +99,7 @@
     assert not kw, "Extra arguments to make_typedescr"
 
     null_dealloc = lltype.nullptr(lltype.FuncType([PyObject], lltype.Void))
+    assert not isinstance(tp_basestruct, lltype.Ptr), "should pass .TO"
 
     class CpyTypedescr(BaseCpyTypedescr):
         basestruct = tp_basestruct
diff --git a/pypy/module/cpyext/src/object.c b/pypy/module/cpyext/src/object.c
--- a/pypy/module/cpyext/src/object.c
+++ b/pypy/module/cpyext/src/object.c
@@ -70,25 +70,6 @@
 
 
 static PyObject *
-_type_alloc(PyTypeObject *metatype)
-{
-    PyHeapTypeObject *heaptype = 
(PyHeapTypeObject*)_PyPy_Malloc(sizeof(PyHeapTypeObject));
-    PyTypeObject *pto = &heaptype->ht_type;
-
-    pto->ob_refcnt = 1;
-    pto->ob_pypy_link = 0;
-    pto->ob_type = metatype;
-    pto->tp_flags |= Py_TPFLAGS_HEAPTYPE;
-    pto->tp_as_number = &heaptype->as_number;
-    pto->tp_as_sequence = &heaptype->as_sequence;
-    pto->tp_as_mapping = &heaptype->as_mapping;
-    pto->tp_as_buffer = &heaptype->as_buffer;
-    pto->tp_basicsize = -1; /* hopefully this makes malloc bail out */
-    pto->tp_itemsize = 0;
-    return (PyObject*)heaptype;
-}
-
-static PyObject *
 _generic_alloc(PyTypeObject *type, Py_ssize_t nitems)
 {
     if (type->tp_flags & Py_TPFLAGS_HEAPTYPE)
@@ -99,7 +80,9 @@
         size += nitems * type->tp_itemsize;
 
     PyObject *pyobj = (PyObject*)_PyPy_Malloc(size);
-    
+    if (pyobj == NULL)
+        return NULL;
+
     if (type->tp_itemsize)
         ((PyVarObject*)pyobj)->ob_size = nitems;
 
@@ -117,12 +100,7 @@
        current cpyext logic here, and fix it when the migration to C is
        completed
     */
-    PyObject *py_obj;
-    if (type == &PyType_Type)
-        py_obj = _type_alloc(type);
-    else
-        py_obj = _generic_alloc(type, nitems);
-
+    PyObject *py_obj = _generic_alloc(type, nitems);
     if (!py_obj)
         return (PyVarObject*)PyErr_NoMemory();
     
diff --git a/pypy/module/cpyext/typeobject.py b/pypy/module/cpyext/typeobject.py
--- a/pypy/module/cpyext/typeobject.py
+++ b/pypy/module/cpyext/typeobject.py
@@ -523,7 +523,7 @@
 @bootstrap_function
 def init_typeobject(space):
     make_typedescr(space.w_type.layout.typedef,
-                   basestruct=PyTypeObject,
+                   basestruct=PyHeapTypeObject.TO,
                    alloc=type_alloc,
                    attach=type_attach,
                    realize=type_realize,
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to