[pypy-commit] creflect default: simplify
arigo
noreply at buildbot.pypy.org
Fri Dec 5 22:42:52 CET 2014
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r186:8bcc78765083
Date: 2014-12-05 22:43 +0100
http://bitbucket.org/cffi/creflect/changeset/8bcc78765083/
Log: simplify
diff --git a/zeffir/cgc.c b/zeffir/cgc.c
--- a/zeffir/cgc.c
+++ b/zeffir/cgc.c
@@ -2,16 +2,12 @@
/* translated to C from cffi/gc_weakref.py */
-#define GCWREF_DATA(ffi) ((ffi)->gc_wrefs[0])
-#define GCWREF_CALLBACK(ffi) ((ffi)->gc_wrefs[1])
-
-
static PyObject *zef_name_pop;
-static PyObject *gc_wref_remove(ZefFFIObject *ffi, PyObject *arg)
+static PyObject *gc_wref_remove(PyObject *ffi_wref_data, PyObject *arg)
{
PyObject *destructor, *cdata, *x;
- PyObject *res = PyObject_CallMethodObjArgs(GCWREF_DATA(ffi),
+ PyObject *res = PyObject_CallMethodObjArgs(ffi_wref_data,
zef_name_pop, arg, NULL);
if (res == NULL)
return NULL;
@@ -30,7 +26,7 @@
}
static PyMethodDef remove_callback = {
- "remove", (PyCFunction)gc_wref_remove, METH_O
+ "zef_remove", (PyCFunction)gc_wref_remove, METH_O
};
static PyObject *gc_weakrefs_build(ZefFFIObject *ffi, CDataObject *cd,
@@ -38,32 +34,29 @@
{
PyObject *new_cdata, *ref = NULL, *tup = NULL;
- if (GCWREF_DATA(ffi) == NULL) {
+ if (ffi->gc_wrefs == NULL) {
/* initialize */
- PyObject *remove, *data;
+ PyObject *data;
if (zef_name_pop == NULL) {
zef_name_pop = PyString_InternFromString("pop");
if (zef_name_pop == NULL)
return NULL;
}
- remove = PyCFunction_New(&remove_callback, (PyObject *)ffi);
- if (remove == NULL)
+ data = PyDict_New();
+ if (data == NULL)
return NULL;
- data = PyDict_New();
- if (data == NULL) {
- Py_DECREF(remove);
+ ffi->gc_wrefs = PyCFunction_New(&remove_callback, data);
+ Py_DECREF(data);
+ if (ffi->gc_wrefs == NULL)
return NULL;
- }
- GCWREF_DATA(ffi) = data;
- GCWREF_CALLBACK(ffi) = remove;
}
new_cdata = do_cast(cd->c_type, (PyObject *)cd);
if (new_cdata == NULL)
goto error;
- ref = PyWeakref_NewRef(new_cdata, GCWREF_CALLBACK(ffi));
+ ref = PyWeakref_NewRef(new_cdata, ffi->gc_wrefs);
if (ref == NULL)
goto error;
@@ -71,7 +64,8 @@
if (tup == NULL)
goto error;
- if (PyDict_SetItem(GCWREF_DATA(ffi), ref, tup) < 0)
+ /* the 'self' of the function 'gc_wrefs' is actually the data dict */
+ if (PyDict_SetItem(PyCFunction_GET_SELF(ffi->gc_wrefs), ref, tup) < 0)
goto error;
Py_DECREF(tup);
diff --git a/zeffir/ffi_obj.c b/zeffir/ffi_obj.c
--- a/zeffir/ffi_obj.c
+++ b/zeffir/ffi_obj.c
@@ -17,23 +17,21 @@
struct ZefFFIObject_s {
PyObject_HEAD
PyObject *types_dict;
- PyObject *gc_wrefs[2];
+ PyObject *gc_wrefs;
};
static void ffi_dealloc(ZefFFIObject *ffi)
{
PyObject_GC_UnTrack(ffi);
Py_DECREF(ffi->types_dict);
- Py_XDECREF(ffi->gc_wrefs[0]);
- Py_XDECREF(ffi->gc_wrefs[1]);
+ Py_XDECREF(ffi->gc_wrefs);
PyObject_GC_Del(ffi);
}
static int ffi_traverse(ZefFFIObject *ffi, visitproc visit, void *arg)
{
Py_VISIT(ffi->types_dict);
- Py_VISIT(ffi->gc_wrefs[0]);
- Py_VISIT(ffi->gc_wrefs[1]);
+ Py_VISIT(ffi->gc_wrefs);
return 0;
}
@@ -53,8 +51,7 @@
return NULL;
}
ffi->types_dict = dict;
- ffi->gc_wrefs[0] = NULL;
- ffi->gc_wrefs[1] = NULL;
+ ffi->gc_wrefs = NULL;
PyObject_GC_Track(ffi);
return (PyObject *)ffi;
More information about the pypy-commit
mailing list