Author: Antonio Cuni <[email protected]>
Branch: cpyext-avoid-roundtrip
Changeset: r92558:98f6749ae4ed
Date: 2017-10-02 16:31 +0200
http://bitbucket.org/pypy/pypy/changeset/98f6749ae4ed/
Log: (antocuni, arigo): port more functions to C, and mark some others
which we would like to port
diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -597,7 +597,7 @@
'Py_DivisionWarningFlag', 'Py_DontWriteBytecodeFlag',
'Py_NoUserSiteDirectory',
'_Py_QnewFlag', 'Py_Py3kWarningFlag', 'Py_HashRandomizationFlag',
'_Py_PackageContext',
'_PyTraceMalloc_Track', '_PyTraceMalloc_Untrack', 'PyMem_Malloc',
- 'Py_IncRef', 'Py_DecRef', 'PyObject_Free', 'PyObject_GC_Del',
+ 'Py_IncRef', 'Py_DecRef', 'PyObject_Free', 'PyObject_GC_Del',
'PyType_GenericAlloc',
]
TYPES = {}
FORWARD_DECLS = []
@@ -1084,6 +1084,11 @@
[rffi.VOIDP], lltype.Void,
compilation_info=eci,
_nowrapper=True)
+ state.C.PyType_GenericAlloc = rffi.llexternal(
+ mangle_name(prefix, 'PyType_GenericAlloc'),
+ [PyTypeObjectPtr, Py_ssize_t], PyObject,
+ compilation_info=eci,
+ _nowrapper=True)
_, state.C.set_marker = rffi.CExternVariable(
Py_ssize_t, '_pypy_rawrefcount_w_marker_deallocating',
eci, _nowrapper=True, c_type='Py_ssize_t')
diff --git a/pypy/module/cpyext/include/object.h
b/pypy/module/cpyext/include/object.h
--- a/pypy/module/cpyext/include/object.h
+++ b/pypy/module/cpyext/include/object.h
@@ -262,8 +262,16 @@
) & ~(SIZEOF_VOID_P - 1) \
)
-#define PyObject_INIT PyObject_Init
-#define PyObject_INIT_VAR PyObject_InitVar
+
+#define PyObject_INIT(op, typeobj) \
+ ( Py_TYPE(op) = (typeobj), ((PyObject *)(op))->ob_refcnt = 1,\
+ ((PyObject *)(op))->ob_pypy_link = 0, (op) )
+#define PyObject_INIT_VAR(op, typeobj, size) \
+ ( Py_SIZE(op) = (size), PyObject_INIT((op), (typeobj)) )
+
+
+PyAPI_FUNC(PyObject *) PyType_GenericAlloc(PyTypeObject *, Py_ssize_t);
+
/*
#define PyObject_NEW(type, typeobj) \
( (type *) PyObject_Init( \
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
@@ -36,6 +36,7 @@
def _PyObject_New(space, type):
return _PyObject_NewVar(space, type, 0)
+# CCC port to C
@cpython_api([PyTypeObjectPtr, Py_ssize_t], PyObject, result_is_ll=True)
def _PyObject_NewVar(space, type, itemcount):
w_type = from_ref(space, rffi.cast(PyObject, type))
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
@@ -30,6 +30,7 @@
state = space.fromcache(State)
return state.C._PyPy_subtype_dealloc
+ # CCC port to C
def allocate(self, space, w_type, itemcount=0, immortal=False):
# typically called from PyType_GenericAlloc via typedescr.allocate
# this returns a PyObject with ob_refcnt == 1.
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
@@ -47,3 +47,9 @@
{
free(obj);
}
+
+PyObject *
+PyType_GenericAlloc(PyTypeObject *type, Py_ssize_t nitems)
+{
+ return _PyObject_NewVar(type, 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
@@ -657,6 +657,7 @@
_dealloc(space, obj)
+# CCC port it to C
def type_alloc(space, w_metatype, itemsize=0):
metatype = rffi.cast(PyTypeObjectPtr, make_ref(space, w_metatype))
# Don't increase refcount for non-heaptypes
@@ -701,7 +702,7 @@
state = space.fromcache(State)
pto.c_tp_free = state.C.PyObject_Free
- pto.c_tp_alloc = llslot(space, PyType_GenericAlloc)
+ pto.c_tp_alloc = state.C.PyType_GenericAlloc
builder = state.builder
if ((pto.c_tp_flags & Py_TPFLAGS_HEAPTYPE) != 0
and builder.cpyext_type_init is None):
@@ -935,11 +936,6 @@
w_type2 = from_ref(space, rffi.cast(PyObject, b))
return int(abstract_issubclass_w(space, w_type1, w_type2)) #XXX correct?
-@cpython_api([PyTypeObjectPtr, Py_ssize_t], PyObject, result_is_ll=True)
-def PyType_GenericAlloc(space, type, nitems):
- from pypy.module.cpyext.object import _PyObject_NewVar
- return _PyObject_NewVar(space, type, nitems)
-
@cpython_api([PyTypeObjectPtr, PyObject, PyObject], PyObject)
def PyType_GenericNew(space, type, w_args, w_kwds):
return generic_cpy_call(
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit