[pypy-commit] pypy cpyext-avoid-roundtrip: (antocuni, arigo): move these two api functions to C
antocuni
pypy.commits at gmail.com
Mon Oct 2 09:36:51 EDT 2017
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: cpyext-avoid-roundtrip
Changeset: r92557:63bf91dc13e5
Date: 2017-10-02 15:36 +0200
http://bitbucket.org/pypy/pypy/changeset/63bf91dc13e5/
Log: (antocuni, arigo): move these two api functions to C
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',
+ 'Py_IncRef', 'Py_DecRef', 'PyObject_Free', 'PyObject_GC_Del',
]
TYPES = {}
FORWARD_DECLS = []
@@ -1073,12 +1073,17 @@
add_fork_hook('child', reinit_tls)
-def attach_c_functions(space, eci):
+def attach_c_functions(space, eci, prefix):
state = space.fromcache(State)
state.C._Py_Dealloc = rffi.llexternal('_Py_Dealloc',
[PyObject], lltype.Void,
compilation_info=eci,
_nowrapper=True)
+ state.C.PyObject_Free = rffi.llexternal(
+ mangle_name(prefix, 'PyObject_Free'),
+ [rffi.VOIDP], lltype.Void,
+ 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')
@@ -1158,7 +1163,7 @@
space.fromcache(State).install_dll(eci)
modulename = py.path.local(eci.libraries[-1])
- attach_c_functions(space, eci)
+ attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# load the bridge, and init structure
@@ -1498,7 +1503,7 @@
eci = build_eci(code, use_micronumpy, translating=True)
space.fromcache(State).install_dll(eci)
- attach_c_functions(space, eci)
+ attach_c_functions(space, eci, prefix)
run_bootstrap_functions(space)
# emit uninitialized static data
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
@@ -323,6 +323,11 @@
PyAPI_FUNC(int) PyObject_AsWriteBuffer(PyObject *, void **, Py_ssize_t *);
PyAPI_FUNC(int) PyObject_CheckReadBuffer(PyObject *);
+/* on CPython, these are in objimpl.h */
+
+PyAPI_FUNC(void) PyObject_Free(void *);
+PyAPI_FUNC(void) PyObject_GC_Del(void *);
+
#define PyObject_MALLOC PyObject_Malloc
#define PyObject_REALLOC PyObject_Realloc
#define PyObject_FREE PyObject_Free
@@ -330,7 +335,6 @@
#define PyObject_DEL PyObject_Free
-
/* PyPy internal ----------------------------------- */
PyAPI_FUNC(int) PyPyType_Register(PyTypeObject *);
#define PyObject_Length PyObject_Size
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
@@ -32,10 +32,6 @@
# XXX FIXME
return realloc(ptr, size)
- at cpython_api([rffi.VOIDP], lltype.Void)
-def PyObject_Free(space, ptr):
- lltype.free(ptr, flavor='raw')
-
@cpython_api([PyTypeObjectPtr], PyObject, result_is_ll=True)
def _PyObject_New(space, type):
return _PyObject_NewVar(space, type, 0)
@@ -68,10 +64,6 @@
def _PyObject_GC_New(space, type):
return _PyObject_New(space, type)
- at cpython_api([rffi.VOIDP], lltype.Void)
-def PyObject_GC_Del(space, obj):
- PyObject_Free(space, obj)
-
@cpython_api([PyObject], PyObjectP, error=CANNOT_FAIL)
def _PyObject_GetDictPtr(space, op):
return lltype.nullptr(PyObjectP.TO)
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
@@ -35,3 +35,15 @@
if (pto->tp_flags & Py_TPFLAGS_HEAPTYPE)
Py_DECREF(pto);
}
+
+void
+PyObject_Free(void *obj)
+{
+ free(obj);
+}
+
+void
+PyObject_GC_Del(void *obj)
+{
+ free(obj);
+}
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
@@ -686,8 +686,6 @@
"""
Fills a newly allocated PyTypeObject from an existing type.
"""
- from pypy.module.cpyext.object import PyObject_Free
-
assert isinstance(w_type, W_TypeObject)
pto = rffi.cast(PyTypeObjectPtr, py_obj)
@@ -701,9 +699,10 @@
# buffer protocol
setup_buffer_procs(space, w_type, pto)
- pto.c_tp_free = llslot(space, PyObject_Free)
+ state = space.fromcache(State)
+ pto.c_tp_free = state.C.PyObject_Free
pto.c_tp_alloc = llslot(space, PyType_GenericAlloc)
- builder = space.fromcache(State).builder
+ builder = state.builder
if ((pto.c_tp_flags & Py_TPFLAGS_HEAPTYPE) != 0
and builder.cpyext_type_init is None):
# this ^^^ is not None only during startup of cpyext. At that
@@ -734,7 +733,6 @@
pto.c_tp_dealloc = pto.c_tp_base.c_tp_dealloc
if not pto.c_tp_dealloc:
# strange, but happens (ABCMeta)
- state = space.fromcache(State)
pto.c_tp_dealloc = state.C._PyPy_subtype_dealloc
if builder.cpyext_type_init is not None:
More information about the pypy-commit
mailing list