How about introducing internal macros for explicit ob_refcnt accesses
in the core? Actually, there are a number of places where one can see
"op->ob_refcnt" logic, which could be replaced with _Py_GETREF(op),
_Py_SETREF(op, n) thus decoupling completely the low level refcount
management defined in object.h:
#define _Py_GETREF(op) (((PyObject *)op)->ob_refcnt)
#define _Py_SETREF(op, n) (((PyObject *)op)->ob_refcnt = (n))
Comments?
I've contributed myself to the mess in intobject.c & floatobject.c, so
I thought that such macros would make the code cleaner.
Here's the current state of affairs:
python/dist/src>find . -name "*.[c]" -exec grep ob_refcnt {} \; -print
(void *) v, ((PyObject *) v)->ob_refcnt))
./Modules/_tkinter.c
if (self->arg->ob_refcnt > 1) { \
if (ob->ob_refcnt < 2 || self->fast)
if (args->ob_refcnt > 1) {
./Modules/cPickle.c
if (--inst->ob_refcnt > 0) {
./Objects/classobject.c
if (result->ob_refcnt == 1)
./Objects/fileobject.c
if (PyFloat_Check(p) && p->ob_refcnt != 0)
if (!PyFloat_Check(p) || p->ob_refcnt == 0) {
if (PyFloat_Check(p) && p->ob_refcnt != 0) {
p, p->ob_refcnt, buf);
./Objects/floatobject.c
if (PyInt_Check(p) && p->ob_refcnt != 0)
if (!PyInt_Check(p) || p->ob_refcnt == 0) {
if (PyInt_Check(p) && p->ob_refcnt != 0)
p, p->ob_refcnt, p->ob_ival);
./Objects/intobject.c
assert(v->ob_refcnt == 1); /* Since v will be used as accumulator! */
./Objects/longobject.c
if (op->ob_refcnt <= 0)
op->ob_refcnt, (long)op);
op->ob_refcnt = 1;
if (op->ob_refcnt < 0)
fprintf(fp, "[%d] ", op->ob_refcnt);
./Objects/object.c
if (!PyString_Check(v) || v->ob_refcnt != 1) {
if (key->ob_refcnt == 2 && key == value) {
./Objects/stringobject.c
if (!PyTuple_Check(op) || op->ob_refcnt != 1) {
if (v == NULL || !PyTuple_Check(v) || v->ob_refcnt != 1) {
./Objects/tupleobject.c
if (PyList_Check(seq) && seq->ob_refcnt == 1) {
if (args->ob_refcnt > 1) {
./Python/bltinmodule.c
if (value->ob_refcnt != 1)
./Python/import.c
return PyInt_FromLong((long) arg->ob_refcnt);
./Python/sysmodule.c
--
Vladimir MARANGOZOV | Vladimir.Marangozov@inrialpes.fr
http://sirac.inrialpes.fr/~marangoz | tel:(+33-4)76615277 fax:76615252
in the core? Actually, there are a number of places where one can see
"op->ob_refcnt" logic, which could be replaced with _Py_GETREF(op),
_Py_SETREF(op, n) thus decoupling completely the low level refcount
management defined in object.h:
#define _Py_GETREF(op) (((PyObject *)op)->ob_refcnt)
#define _Py_SETREF(op, n) (((PyObject *)op)->ob_refcnt = (n))
Comments?
I've contributed myself to the mess in intobject.c & floatobject.c, so
I thought that such macros would make the code cleaner.
Here's the current state of affairs:
python/dist/src>find . -name "*.[c]" -exec grep ob_refcnt {} \; -print
(void *) v, ((PyObject *) v)->ob_refcnt))
./Modules/_tkinter.c
if (self->arg->ob_refcnt > 1) { \
if (ob->ob_refcnt < 2 || self->fast)
if (args->ob_refcnt > 1) {
./Modules/cPickle.c
if (--inst->ob_refcnt > 0) {
./Objects/classobject.c
if (result->ob_refcnt == 1)
./Objects/fileobject.c
if (PyFloat_Check(p) && p->ob_refcnt != 0)
if (!PyFloat_Check(p) || p->ob_refcnt == 0) {
if (PyFloat_Check(p) && p->ob_refcnt != 0) {
p, p->ob_refcnt, buf);
./Objects/floatobject.c
if (PyInt_Check(p) && p->ob_refcnt != 0)
if (!PyInt_Check(p) || p->ob_refcnt == 0) {
if (PyInt_Check(p) && p->ob_refcnt != 0)
p, p->ob_refcnt, p->ob_ival);
./Objects/intobject.c
assert(v->ob_refcnt == 1); /* Since v will be used as accumulator! */
./Objects/longobject.c
if (op->ob_refcnt <= 0)
op->ob_refcnt, (long)op);
op->ob_refcnt = 1;
if (op->ob_refcnt < 0)
fprintf(fp, "[%d] ", op->ob_refcnt);
./Objects/object.c
if (!PyString_Check(v) || v->ob_refcnt != 1) {
if (key->ob_refcnt == 2 && key == value) {
./Objects/stringobject.c
if (!PyTuple_Check(op) || op->ob_refcnt != 1) {
if (v == NULL || !PyTuple_Check(v) || v->ob_refcnt != 1) {
./Objects/tupleobject.c
if (PyList_Check(seq) && seq->ob_refcnt == 1) {
if (args->ob_refcnt > 1) {
./Python/bltinmodule.c
if (value->ob_refcnt != 1)
./Python/import.c
return PyInt_FromLong((long) arg->ob_refcnt);
./Python/sysmodule.c
--
Vladimir MARANGOZOV | Vladimir.Marangozov@inrialpes.fr
http://sirac.inrialpes.fr/~marangoz | tel:(+33-4)76615277 fax:76615252