Author: Antonio Cuni <[email protected]>
Branch: cpyext-nowrapper
Changeset: r92661:194a4564f528
Date: 2017-10-07 19:23 +0200
http://bitbucket.org/pypy/pypy/changeset/194a4564f528/

Log:    call directly ll_type_allocate from here, bypassing the space

diff --git a/pypy/module/cpyext/object.py b/pypy/module/cpyext/object.py
--- a/pypy/module/cpyext/object.py
+++ b/pypy/module/cpyext/object.py
@@ -51,12 +51,11 @@
 @cpython_api([PyTypeObjectPtr, Py_ssize_t], PyObject, result_is_ll=True)
 def _PyObject_NewVar(space, tp, nitems):
     from pypy.module.cpyext.pyobject import _allocate_generic_object
+    from pypy.module.cpyext.typeobject import ll_type_alloc
     state = space.fromcache(State)
     if tp == state.C._PyPy_get_PyType_Type():
-        w_type = from_ref(space, rffi.cast(PyObject, tp))
-        assert isinstance(w_type, W_TypeObject)
-        typedescr = get_typedescr(w_type.layout.typedef)
-        pyobj = typedescr.allocate(space, w_type, itemcount=nitems)
+        metatype = rffi.cast(PyTypeObjectPtr, tp)
+        pyobj = ll_type_alloc(metatype, nitems)
     else:
         return _allocate_generic_object(tp, nitems)
     #
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
@@ -702,7 +702,9 @@
         flags = rffi.cast(lltype.Signed, metatype.c_tp_flags)
         if not flags & Py_TPFLAGS_HEAPTYPE:
             decref_w_obj(space, w_metatype)
+    return ll_type_alloc(metatype, itemsize)
 
+def ll_type_alloc(metatype, itemsize=0):
     heaptype = lltype.malloc(PyHeapTypeObject.TO,
                              flavor='raw', zero=True,
                              add_memory_pressure=True)
@@ -717,7 +719,6 @@
     pto.c_tp_as_buffer = heaptype.c_as_buffer
     pto.c_tp_basicsize = -1 # hopefully this makes malloc bail out
     pto.c_tp_itemsize = 0
-
     return rffi.cast(PyObject, heaptype)
 
 def type_attach(space, py_obj, w_type, w_userdata=None):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to