PEP 3123: Provide forward compatibility with Python 3.0, while keeping
backwards compatibility. Add Py_Refcnt, Py_Type, Py_Size, and
PyVarObject_HEAD_INIT.
diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c
index 6c5011c..b6a871b 100644
--- a/Modules/gcmodule.c
+++ b/Modules/gcmodule.c
@@ -239,7 +239,7 @@
PyGC_Head *gc = containers->gc.gc_next;
for (; gc != containers; gc = gc->gc.gc_next) {
assert(gc->gc.gc_refs == GC_REACHABLE);
- gc->gc.gc_refs = FROM_GC(gc)->ob_refcnt;
+ gc->gc.gc_refs = Py_Refcnt(FROM_GC(gc));
/* Python's cyclic gc should never see an incoming refcount
* of 0: if something decref'ed to 0, it should have been
* deallocated immediately at that time.
@@ -291,7 +291,7 @@
traverseproc traverse;
PyGC_Head *gc = containers->gc.gc_next;
for (; gc != containers; gc=gc->gc.gc_next) {
- traverse = FROM_GC(gc)->ob_type->tp_traverse;
+ traverse = Py_Type(FROM_GC(gc))->tp_traverse;
(void) traverse(FROM_GC(gc),
(visitproc)visit_decref,
NULL);
@@ -376,7 +376,7 @@
* the next object to visit.
*/
PyObject *op = FROM_GC(gc);
- traverseproc traverse = op->ob_type->tp_traverse;
+ traverseproc traverse = Py_Type(op)->tp_traverse;
assert(gc->gc.gc_refs > 0);
gc->gc.gc_refs = GC_REACHABLE;
(void) traverse(op,
@@ -472,7 +472,7 @@
PyGC_Head *gc = finalizers->gc.gc_next;
for (; gc != finalizers; gc = gc->gc.gc_next) {
/* Note that the finalizers list may grow during this. */
- traverse = FROM_GC(gc)->ob_type->tp_traverse;
+ traverse = Py_Type(FROM_GC(gc))->tp_traverse;
(void) traverse(FROM_GC(gc),
(visitproc)visit_move,
(void *)finalizers);
@@ -517,7 +517,7 @@
assert(IS_TENTATIVELY_UNREACHABLE(op));
next = gc->gc.gc_next;
- if (! PyType_SUPPORTS_WEAKREFS(op->ob_type))
+ if (! PyType_SUPPORTS_WEAKREFS(Py_Type(op)))
continue;
/* It supports weakrefs. Does it have any? */
@@ -654,7 +654,7 @@
}
else if (debug & DEBUG_OBJECTS) {
PySys_WriteStderr("gc: %.100s <%.100s %p>\n",
- msg, op->ob_type->tp_name, op);
+ msg, Py_Type(op)->tp_name, op);
}
}
@@ -708,7 +708,7 @@
PyList_Append(garbage, op);
}
else {
- if ((clear = op->ob_type->tp_clear) != NULL) {
+ if ((clear = Py_Type(op)->tp_clear) != NULL) {
Py_INCREF(op);
clear(op);
Py_DECREF(op);
@@ -1079,7 +1079,7 @@
traverseproc traverse;
for (gc = list->gc.gc_next; gc != list; gc = gc->gc.gc_next) {
obj = FROM_GC(gc);
- traverse = obj->ob_type->tp_traverse;
+ traverse = Py_Type(obj)->tp_traverse;
if (obj == objs || obj == resultlist)
continue;
if (traverse(obj, (visitproc)referrersvisit, objs)) {
@@ -1136,7 +1136,7 @@
if (! PyObject_IS_GC(obj))
continue;
- traverse = obj->ob_type->tp_traverse;
+ traverse = Py_Type(obj)->tp_traverse;
if (! traverse)
continue;
if (traverse(obj, (visitproc)referentsvisit, result)) {
@@ -1359,13 +1359,13 @@
PyVarObject *
_PyObject_GC_Resize(PyVarObject *op, Py_ssize_t nitems)
{
- const size_t basicsize = _PyObject_VAR_SIZE(op->ob_type, nitems);
+ const size_t basicsize = _PyObject_VAR_SIZE(Py_Type(op), nitems);
PyGC_Head *g = AS_GC(op);
g = (PyGC_Head *)PyObject_REALLOC(g, sizeof(PyGC_Head) + basicsize);
if (g == NULL)
return (PyVarObject *)PyErr_NoMemory();
op = (PyVarObject *) FROM_GC(g);
- op->ob_size = nitems;
+ Py_Size(op) = nitems;
return op;
}