[pypy-commit] cffi default: Found a simpler way to implement the in-line ffi.gc() on top of the
arigo
noreply at buildbot.pypy.org
Mon Jul 6 11:07:11 CEST 2015
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r2211:88b59dfa8176
Date: 2015-07-06 11:07 +0200
http://bitbucket.org/cffi/cffi/changeset/88b59dfa8176/
Log: Found a simpler way to implement the in-line ffi.gc() on top of the
out-of-line one
diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -5554,9 +5554,6 @@
(PyObject *)&CTypeDescr_Type);
}
-/* forward: implemented in ffi_obj.c */
-static PyObject *b_gcp(PyObject *self, PyObject *args);
-
/************************************************************/
static char _testfunc0(char a, char b)
@@ -5862,7 +5859,6 @@
{"newp_handle", b_newp_handle, METH_VARARGS},
{"from_handle", b_from_handle, METH_O},
{"from_buffer", b_from_buffer, METH_VARARGS},
- {"gcp", b_gcp, METH_VARARGS},
#ifdef MS_WIN32
{"getwinerror", (PyCFunction)b_getwinerror, METH_VARARGS | METH_KEYWORDS},
#endif
diff --git a/c/ffi_obj.c b/c/ffi_obj.c
--- a/c/ffi_obj.c
+++ b/c/ffi_obj.c
@@ -680,19 +680,6 @@
return gc_weakrefs_build(self, cd, destructor);
}
-static PyObject *b_gcp(PyObject *self, PyObject *args)
-{
- /* for in-line mode */
- static FFIObject *ffi1 = NULL;
-
- if (ffi1 == NULL) {
- ffi1 = ffi_internal_new(&FFI_Type, NULL);
- if (ffi1 == NULL)
- return NULL;
- }
- return ffi_gc(ffi1, args, NULL);
-}
-
PyDoc_STRVAR(ffi_callback_doc,
"Return a callback object or a decorator making such a callback object.\n"
"'cdecl' must name a C function pointer type. The callback invokes the\n"
diff --git a/cffi/api.py b/cffi/api.py
--- a/cffi/api.py
+++ b/cffi/api.py
@@ -72,6 +72,7 @@
self._cdefsources = []
self._included_ffis = []
self._windows_unicode = None
+ self._gcp = None
if hasattr(backend, 'set_ffi'):
backend.set_ffi(self)
for name in backend.__dict__:
@@ -328,13 +329,14 @@
data. Later, when this new cdata object is garbage-collected,
'destructor(old_cdata_object)' will be called.
"""
- try:
- gcp = self._backend.gcp
- except AttributeError:
- pass
- else:
- return gcp(cdata, destructor)
+ if self._gcp is not None:
+ return self._gcp(cdata, destructor)
+ if hasattr(self._backend, 'FFI'):
+ compiled_ffi = self._backend.FFI()
+ self._gcp = compiled_ffi.gc
+ return self._gcp(cdata, destructor)
#
+ # the rest is for the ctypes backend only
with self._lock:
try:
gc_weakrefs = self.gc_weakrefs
More information about the pypy-commit
mailing list