[Python-Dev] ob_refcnt access
Guido van Rossum
guido at CNRI.Reston.VA.US
Thu Jun 24 17:30:45 CEST 1999
> How about introducing internal macros for explicit ob_refcnt accesses
> in the core?
What problem does this solve?
> 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))
Why the cast? It loses some type-safety, e.g. _Py_GETREF(0) will now
cause a core dump instead of a compile-time error.
> Comments?
I don't see how it's cleaner or saves typing:
op->ob_refcnt
_Py_GETREF(op)
op->ob_refcnt = 1
_Py_SETREF(op, 1)
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-Dev
mailing list