]> granicus.if.org Git - python/commitdiff
Use Py_VISIT in all tp_traverse methods, instead of traversing manually or
authorThomas Wouters <thomas@python.org>
Sat, 15 Apr 2006 21:47:09 +0000 (21:47 +0000)
committerThomas Wouters <thomas@python.org>
Sat, 15 Apr 2006 21:47:09 +0000 (21:47 +0000)
using a custom, nearly-identical macro. This probably changes how some of
these functions are compiled, which may result in fractionally slower (or
faster) execution. Considering the nature of traversal, visiting much of the
address space in unpredictable patterns, I'd argue the code readability and
maintainability is well worth it ;P

20 files changed:
Modules/_csv.c
Modules/arraymodule.c
Modules/cPickle.c
Modules/operator.c
Modules/pyexpat.c
Modules/zipimport.c
Objects/cellobject.c
Objects/classobject.c
Objects/descrobject.c
Objects/dictobject.c
Objects/enumobject.c
Objects/funcobject.c
Objects/iterobject.c
Objects/listobject.c
Objects/methodobject.c
Objects/moduleobject.c
Objects/tupleobject.c
Objects/typeobject.c
Objects/weakrefobject.c
Python/traceback.c

index 500d36e03921227ceeee672cc1aede5b8b1dd322..67d5d9f8fb00361088864ba8ba8e8f51c78090df 100644 (file)
@@ -48,7 +48,16 @@ module instead.
                }                                               \
        } while (0)
 #endif
-
+#ifndef Py_VISIT
+#define Py_VISIT(op)                                                   \
+        do {                                                           \
+                if (op) {                                              \
+                        int vret = visit((PyObject *)(op), arg);       \
+                        if (vret)                                      \
+                                return vret;                           \
+                }                                                      \
+        } while (0)
+#endif
 
 /* end 2.2 compatibility macros */
 
@@ -825,16 +834,9 @@ Reader_dealloc(ReaderObj *self)
 static int
 Reader_traverse(ReaderObj *self, visitproc visit, void *arg)
 {
-       int err;
-#define VISIT(SLOT) \
-       if (SLOT) { \
-               err = visit((PyObject *)(SLOT), arg); \
-               if (err) \
-                       return err; \
-       }
-       VISIT(self->dialect);
-       VISIT(self->input_iter);
-       VISIT(self->fields);
+       Py_VISIT(self->dialect);
+       Py_VISIT(self->input_iter);
+       Py_VISIT(self->fields);
        return 0;
 }
 
@@ -1255,15 +1257,8 @@ Writer_dealloc(WriterObj *self)
 static int
 Writer_traverse(WriterObj *self, visitproc visit, void *arg)
 {
-       int err;
-#define VISIT(SLOT) \
-       if (SLOT) { \
-               err = visit((PyObject *)(SLOT), arg); \
-               if (err) \
-                       return err; \
-       }
-       VISIT(self->dialect);
-       VISIT(self->writeline);
+       Py_VISIT(self->dialect);
+       Py_VISIT(self->writeline);
        return 0;
 }
 
index 4324f39f840ea56ede713574da2aceac1f06fce4..4551342f455bd6940a7a9920fcda8a9d01a6056b 100644 (file)
@@ -2061,8 +2061,7 @@ arrayiter_dealloc(arrayiterobject *it)
 static int
 arrayiter_traverse(arrayiterobject *it, visitproc visit, void *arg)
 {
-       if (it->ao != NULL)
-               return visit((PyObject *)(it->ao), arg);
+       Py_VISIT(it->ao);
        return 0;
 }
 
index 1d99fcb76a48fe811fcbd689a76031a015d1fc8e..18df599b9e9325e215aa90ebc0eb6ba7e9ebfa06 100644 (file)
@@ -2909,22 +2909,14 @@ Pickler_dealloc(Picklerobject *self)
 static int
 Pickler_traverse(Picklerobject *self, visitproc visit, void *arg)
 {
-       int err;
-#define VISIT(SLOT) \
-       if (SLOT) { \
-               err = visit((PyObject *)(SLOT), arg); \
-               if (err) \
-                       return err; \
-       }
-       VISIT(self->write);
-       VISIT(self->memo);
-       VISIT(self->fast_memo);
-       VISIT(self->arg);
-       VISIT(self->file);
-       VISIT(self->pers_func);
-       VISIT(self->inst_pers_func);
-       VISIT(self->dispatch_table);
-#undef VISIT
+       Py_VISIT(self->write);
+       Py_VISIT(self->memo);
+       Py_VISIT(self->fast_memo);
+       Py_VISIT(self->arg);
+       Py_VISIT(self->file);
+       Py_VISIT(self->pers_func);
+       Py_VISIT(self->inst_pers_func);
+       Py_VISIT(self->dispatch_table);
        return 0;
 }
 
@@ -5258,24 +5250,15 @@ Unpickler_dealloc(Unpicklerobject *self)
 static int
 Unpickler_traverse(Unpicklerobject *self, visitproc visit, void *arg)
 {
-       int err;
-
-#define VISIT(SLOT) \
-       if (SLOT) { \
-               err = visit((PyObject *)(SLOT), arg); \
-               if (err) \
-                       return err; \
-       }
-       VISIT(self->readline);
-       VISIT(self->read);
-       VISIT(self->file);
-       VISIT(self->memo);
-       VISIT(self->stack);
-       VISIT(self->pers_func);
-       VISIT(self->arg);
-       VISIT(self->last_string);
-       VISIT(self->find_class);
-#undef VISIT
+       Py_VISIT(self->readline);
+       Py_VISIT(self->read);
+       Py_VISIT(self->file);
+       Py_VISIT(self->memo);
+       Py_VISIT(self->stack);
+       Py_VISIT(self->pers_func);
+       Py_VISIT(self->arg);
+       Py_VISIT(self->last_string);
+       Py_VISIT(self->find_class);
        return 0;
 }
 
index 53144f164fb9881f1ef79965444b1c824e76b4de..25b399994695315f03e1e468d757342be7074136 100644 (file)
@@ -358,8 +358,7 @@ itemgetter_dealloc(itemgetterobject *ig)
 static int
 itemgetter_traverse(itemgetterobject *ig, visitproc visit, void *arg)
 {
-       if (ig->item)
-               return visit(ig->item, arg);
+       Py_VISIT(ig->item);
        return 0;
 }
 
@@ -497,8 +496,7 @@ attrgetter_dealloc(attrgetterobject *ag)
 static int
 attrgetter_traverse(attrgetterobject *ag, visitproc visit, void *arg)
 {
-       if (ag->attr)
-               return visit(ag->attr, arg);
+       Py_VISIT(ag->attr);
        return 0;
 }
 
index fbef4e14ca81f9cbaaf5fdd61c64bfe937f84177..16f01376102beb7e7a3c0d7ab023b87a3678da44 100644 (file)
@@ -1655,13 +1655,8 @@ static int
 xmlparse_traverse(xmlparseobject *op, visitproc visit, void *arg)
 {
     int i, err;
-    for (i = 0; handler_info[i].name != NULL; i++) {
-        if (!op->handlers[i])
-            continue;
-        err = visit(op->handlers[i], arg);
-        if (err)
-            return err;
-    }
+    for (i = 0; handler_info[i].name != NULL; i++)
+        Py_VISIT(op->handlers[i]);
     return 0;
 }
 
index 3e376562f3376cce005ef13e2fb319469e9043af..d59ebd804a8982617c1d8106311884435b5999f4 100644 (file)
@@ -170,13 +170,7 @@ static int
 zipimporter_traverse(PyObject *obj, visitproc visit, void *arg)
 {
        ZipImporter *self = (ZipImporter *)obj;
-       int err;
-
-       if (self->files != NULL) {
-               err = visit(self->files, arg);
-               if (err)
-                       return err;
-       }
+       Py_VISIT(self->files);
        return 0;
 }
 
index e617e5e5f3c9dc0878da8b7bab311056cfc5313d..da48dea745223b942e9594e36954df0da105691b 100644 (file)
@@ -73,8 +73,7 @@ cell_repr(PyCellObject *op)
 static int
 cell_traverse(PyCellObject *op, visitproc visit, void *arg)
 {
-       if (op->ob_ref)
-               return visit(op->ob_ref, arg);
+       Py_VISIT(op->ob_ref);
        return 0;
 }
 
index 474c666c281bdb3a5663d6c07cf69ce9a6b7d65a..a723bd60120de2283186bd875d2a462a88f43228 100644 (file)
@@ -404,37 +404,12 @@ class_str(PyClassObject *op)
 static int
 class_traverse(PyClassObject *o, visitproc visit, void *arg)
 {
-       int err;
-       if (o->cl_bases) {
-               err = visit(o->cl_bases, arg);
-               if (err)
-                       return err;
-       }
-       if (o->cl_dict) {
-               err = visit(o->cl_dict, arg);
-               if (err)
-                       return err;
-       }
-       if (o->cl_name) {
-               err = visit(o->cl_name, arg);
-               if (err)
-                       return err;
-       }
-       if (o->cl_getattr) {
-               err = visit(o->cl_getattr, arg);
-               if (err)
-                       return err;
-       }
-       if (o->cl_setattr) {
-               err = visit(o->cl_setattr, arg);
-               if (err)
-                       return err;
-       }
-       if (o->cl_delattr) {
-               err = visit(o->cl_delattr, arg);
-               if (err)
-                       return err;
-       }
+       Py_VISIT(o->cl_bases);
+       Py_VISIT(o->cl_dict);
+       Py_VISIT(o->cl_name);
+       Py_VISIT(o->cl_getattr);
+       Py_VISIT(o->cl_setattr);
+       Py_VISIT(o->cl_delattr);
        return 0;
 }
 
@@ -979,17 +954,8 @@ instance_hash(PyInstanceObject *inst)
 static int
 instance_traverse(PyInstanceObject *o, visitproc visit, void *arg)
 {
-       int err;
-       if (o->in_class) {
-               err = visit((PyObject *)(o->in_class), arg);
-               if (err)
-                       return err;
-       }
-       if (o->in_dict) {
-               err = visit(o->in_dict, arg);
-               if (err)
-                       return err;
-       }
+       Py_VISIT(o->in_class);
+       Py_VISIT(o->in_dict);
        return 0;
 }
 
@@ -2348,22 +2314,9 @@ instancemethod_hash(PyMethodObject *a)
 static int
 instancemethod_traverse(PyMethodObject *im, visitproc visit, void *arg)
 {
-       int err;
-       if (im->im_func) {
-               err = visit(im->im_func, arg);
-               if (err)
-                       return err;
-       }
-       if (im->im_self) {
-               err = visit(im->im_self, arg);
-               if (err)
-                       return err;
-       }
-       if (im->im_class) {
-               err = visit(im->im_class, arg);
-               if (err)
-                       return err;
-       }
+       Py_VISIT(im->im_func);
+       Py_VISIT(im->im_self);
+       Py_VISIT(im->im_class);
        return 0;
 }
 
index bfa25e98f6a234d6fa038afb15058d7605b32065..561ba4a5f01de955185fbd798d9d77af5f9512a0 100644 (file)
@@ -377,13 +377,7 @@ static int
 descr_traverse(PyObject *self, visitproc visit, void *arg)
 {
        PyDescrObject *descr = (PyDescrObject *)self;
-       int err;
-
-       if (descr->d_type) {
-               err = visit((PyObject *)(descr->d_type), arg);
-               if (err)
-                       return err;
-       }
+       Py_VISIT(descr->d_type);
        return 0;
 }
 
@@ -814,13 +808,7 @@ static int
 proxy_traverse(PyObject *self, visitproc visit, void *arg)
 {
        proxyobject *pp = (proxyobject *)self;
-       int err;
-
-       if (pp->dict) {
-               err = visit(pp->dict, arg);
-               if (err)
-                       return err;
-       }
+       Py_VISIT(pp->dict);
        return 0;
 }
 
@@ -999,18 +987,8 @@ static int
 wrapper_traverse(PyObject *self, visitproc visit, void *arg)
 {
        wrapperobject *wp = (wrapperobject *)self;
-       int err;
-
-       if (wp->descr) {
-               err = visit((PyObject *)(wp->descr), arg);
-               if (err)
-                       return err;
-       }
-       if (wp->self) {
-               err = visit(wp->self, arg);
-               if (err)
-                       return err;
-       }
+       Py_VISIT(wp->descr);
+       Py_VISIT(wp->self);
        return 0;
 }
 
@@ -1237,20 +1215,10 @@ static int
 property_traverse(PyObject *self, visitproc visit, void *arg)
 {
        propertyobject *pp = (propertyobject *)self;
-       int err;
-
-#define VISIT(SLOT) \
-       if (pp->SLOT) { \
-               err = visit((PyObject *)(pp->SLOT), arg); \
-               if (err) \
-                       return err; \
-       }
-
-       VISIT(prop_get);
-       VISIT(prop_set);
-       VISIT(prop_del);
-       VISIT(prop_doc);
-
+       Py_VISIT(pp->prop_get);
+       Py_VISIT(pp->prop_set);
+       Py_VISIT(pp->prop_del);
+       Py_VISIT(pp->prop_doc);
        return 0;
 }
 
index 31ef958e63af6676b735f3086ac9b7d906b8bf7f..f5799ee09ffc16917a2e3b279deb4719309879bd 100644 (file)
@@ -1732,17 +1732,12 @@ static int
 dict_traverse(PyObject *op, visitproc visit, void *arg)
 {
        Py_ssize_t i = 0;
-       int err;
        PyObject *pk;
        PyObject *pv;
 
        while (PyDict_Next(op, &i, &pk, &pv)) {
-               err = visit(pk, arg);
-               if (err)
-                       return err;
-               err = visit(pv, arg);
-               if (err)
-                       return err;
+               Py_VISIT(pk);
+               Py_VISIT(pv);
        }
        return 0;
 }
index cd31dc15d5725d1ed4f634c30a9876405bcc04b4..a8f43e07386b8464c4fe0f7b5ee9bfe75b2da056 100644 (file)
@@ -49,18 +49,8 @@ enum_dealloc(enumobject *en)
 static int
 enum_traverse(enumobject *en, visitproc visit, void *arg)
 {
-       int err;
-
-       if (en->en_sit) {
-               err = visit(en->en_sit, arg);
-               if (err)
-                       return err;
-       }
-       if (en->en_result) {
-               err = visit(en->en_result, arg);
-               if (err)
-                       return err;
-       }
+       Py_VISIT(en->en_sit);
+       Py_VISIT(en->en_result);
        return 0;
 }
 
@@ -205,8 +195,7 @@ reversed_dealloc(reversedobject *ro)
 static int
 reversed_traverse(reversedobject *ro, visitproc visit, void *arg)
 {
-       if (ro->seq)
-               return visit((PyObject *)(ro->seq), arg);
+       Py_VISIT(ro->seq);
        return 0;
 }
 
index b86319cad839cb572ef2dc7f9271fbf653ef4c64..59cb5195074804b1ab4ad2942a34f29f5a7b0ee0 100644 (file)
@@ -466,47 +466,14 @@ func_repr(PyFunctionObject *op)
 static int
 func_traverse(PyFunctionObject *f, visitproc visit, void *arg)
 {
-       int err;
-       if (f->func_code) {
-               err = visit(f->func_code, arg);
-               if (err)
-                       return err;
-       }
-       if (f->func_globals) {
-               err = visit(f->func_globals, arg);
-               if (err)
-                       return err;
-       }
-       if (f->func_module) {
-               err = visit(f->func_module, arg);
-               if (err)
-                       return err;
-       }
-       if (f->func_defaults) {
-               err = visit(f->func_defaults, arg);
-               if (err)
-                       return err;
-       }
-       if (f->func_doc) {
-               err = visit(f->func_doc, arg);
-               if (err)
-                       return err;
-       }
-       if (f->func_name) {
-               err = visit(f->func_name, arg);
-               if (err)
-                       return err;
-       }
-       if (f->func_dict) {
-               err = visit(f->func_dict, arg);
-               if (err)
-                       return err;
-       }
-       if (f->func_closure) {
-               err = visit(f->func_closure, arg);
-               if (err)
-                       return err;
-       }
+       Py_VISIT(f->func_code);
+       Py_VISIT(f->func_globals);
+       Py_VISIT(f->func_module);
+       Py_VISIT(f->func_defaults);
+       Py_VISIT(f->func_doc);
+       Py_VISIT(f->func_name);
+       Py_VISIT(f->func_dict);
+       Py_VISIT(f->func_closure);
        return 0;
 }
 
@@ -647,9 +614,8 @@ cm_dealloc(classmethod *cm)
 static int
 cm_traverse(classmethod *cm, visitproc visit, void *arg)
 {
-       if (!cm->cm_callable)
-               return 0;
-       return visit(cm->cm_callable, arg);
+       Py_VISIT(cm->cm_callable);
+       return 0;
 }
 
 static int
@@ -806,9 +772,8 @@ sm_dealloc(staticmethod *sm)
 static int
 sm_traverse(staticmethod *sm, visitproc visit, void *arg)
 {
-       if (!sm->sm_callable)
-               return 0;
-       return visit(sm->sm_callable, arg);
+       Py_VISIT(sm->sm_callable);
+       return 0;
 }
 
 static int
index 14cacc69389b40a634e6d031779d5b51ee196c24..cf839f47816d59f49c0f2a398f5c1ecaf5d49df3 100644 (file)
@@ -38,9 +38,8 @@ iter_dealloc(seqiterobject *it)
 static int
 iter_traverse(seqiterobject *it, visitproc visit, void *arg)
 {
-       if (it->it_seq == NULL)
-               return 0;
-       return visit(it->it_seq, arg);
+       Py_VISIT(it->it_seq);
+       return 0;
 }
 
 static PyObject *
@@ -162,11 +161,8 @@ calliter_dealloc(calliterobject *it)
 static int
 calliter_traverse(calliterobject *it, visitproc visit, void *arg)
 {
-       int err;
-       if (it->it_callable != NULL && (err = visit(it->it_callable, arg)))
-               return err;
-       if (it->it_sentinel != NULL && (err = visit(it->it_sentinel, arg)))
-               return err;
+       Py_VISIT(it->it_callable);
+       Py_VISIT(it->it_sentinel);
        return 0;
 }
 
index 1debd23791b2fdc08e0a4c1086128dd538f1cb87..78961f33dad1b1a32dccbba71330868b213e1697 100644 (file)
@@ -2276,14 +2276,8 @@ list_traverse(PyListObject *o, visitproc visit, void *arg)
        Py_ssize_t i;
        PyObject *x;
 
-       for (i = o->ob_size; --i >= 0; ) {
-               x = o->ob_item[i];
-               if (x != NULL) {
-                       int err = visit(x, arg);
-                       if (err)
-                               return err;
-               }
-       }
+       for (i = o->ob_size; --i >= 0; )
+               Py_VISIT(o->ob_item[i]);
        return 0;
 }
 
@@ -2779,9 +2773,8 @@ listiter_dealloc(listiterobject *it)
 static int
 listiter_traverse(listiterobject *it, visitproc visit, void *arg)
 {
-       if (it->it_seq == NULL)
-               return 0;
-       return visit((PyObject *)it->it_seq, arg);
+       Py_VISIT(it->it_seq);
+       return 0;
 }
 
 static PyObject *
@@ -2898,9 +2891,8 @@ listreviter_dealloc(listreviterobject *it)
 static int
 listreviter_traverse(listreviterobject *it, visitproc visit, void *arg)
 {
-       if (it->it_seq == NULL)
-               return 0;
-       return visit((PyObject *)it->it_seq, arg);
+       Py_VISIT(it->it_seq);
+       return 0;
 }
 
 static PyObject *
index 8e3bf867cacc0175358bef7a76d0688515ec51e8..ecc9a0ab5257e5730f12afa2d3cb93946ead9ec9 100644 (file)
@@ -149,17 +149,8 @@ meth_get__name__(PyCFunctionObject *m, void *closure)
 static int
 meth_traverse(PyCFunctionObject *m, visitproc visit, void *arg)
 {
-       int err;
-       if (m->m_self != NULL) {
-               err = visit(m->m_self, arg);
-               if (err)
-                       return err;
-       }
-       if (m->m_module != NULL) {
-               err = visit(m->m_module, arg);
-               if (err)
-                       return err;
-       }
+       Py_VISIT(m->m_self);
+       Py_VISIT(m->m_module);
        return 0;
 }
 
index 812496806be987f4beed514a6713beee6af5909e..e454fcf3210d80b4cddaebe78643e3aabfa27e62 100644 (file)
@@ -204,8 +204,7 @@ module_repr(PyModuleObject *m)
 static int
 module_traverse(PyModuleObject *m, visitproc visit, void *arg)
 {
-       if (m->md_dict != NULL)
-               return visit(m->md_dict, arg);
+       Py_VISIT(m->md_dict);
        return 0;
 }
 
index 10b7aaffbf84b9c0dac4879f839c6b31cd1aca89..2161ab9ec1088132c3da051a798c801ccfaf4e10 100644 (file)
@@ -438,16 +438,9 @@ static int
 tupletraverse(PyTupleObject *o, visitproc visit, void *arg)
 {
        Py_ssize_t i;
-       PyObject *x;
-
-       for (i = o->ob_size; --i >= 0; ) {
-               x = o->ob_item[i];
-               if (x != NULL) {
-                       int err = visit(x, arg);
-                       if (err)
-                               return err;
-               }
-       }
+
+       for (i = o->ob_size; --i >= 0; )
+               Py_VISIT(o->ob_item[i]);
        return 0;
 }
 
@@ -802,9 +795,8 @@ tupleiter_dealloc(tupleiterobject *it)
 static int
 tupleiter_traverse(tupleiterobject *it, visitproc visit, void *arg)
 {
-       if (it->it_seq == NULL)
-               return 0;
-       return visit((PyObject *)it->it_seq, arg);
+       Py_VISIT(it->it_seq);
+       return 0;
 }
 
 static PyObject *
index a0af2c9b420bb17d438602f466921e13479745d6..43f04694f9a52c49d9b217c451699f61c376194b 100644 (file)
@@ -525,21 +525,15 @@ subtype_traverse(PyObject *self, visitproc visit, void *arg)
 
        if (type->tp_dictoffset != base->tp_dictoffset) {
                PyObject **dictptr = _PyObject_GetDictPtr(self);
-               if (dictptr && *dictptr) {
-                       int err = visit(*dictptr, arg);
-                       if (err)
-                               return err;
-               }
+               if (dictptr && *dictptr)
+                       Py_VISIT(*dictptr);
        }
 
-       if (type->tp_flags & Py_TPFLAGS_HEAPTYPE) {
+       if (type->tp_flags & Py_TPFLAGS_HEAPTYPE)
                /* For a heaptype, the instances count as references
                   to the type.  Traverse the type so the collector
                   can find cycles involving this link. */
-               int err = visit((PyObject *)type, arg);
-               if (err)
-                       return err;
-       }
+               Py_VISIT(type);
 
        if (basetraverse)
                return basetraverse(self, visit, arg);
@@ -2198,32 +2192,21 @@ PyDoc_STRVAR(type_doc,
 static int
 type_traverse(PyTypeObject *type, visitproc visit, void *arg)
 {
-       int err;
-
        /* Because of type_is_gc(), the collector only calls this
           for heaptypes. */
        assert(type->tp_flags & Py_TPFLAGS_HEAPTYPE);
 
-#define VISIT(SLOT) \
-       if (SLOT) { \
-               err = visit((PyObject *)(SLOT), arg); \
-               if (err) \
-                       return err; \
-       }
-
-       VISIT(type->tp_dict);
-       VISIT(type->tp_cache);
-       VISIT(type->tp_mro);
-       VISIT(type->tp_bases);
-       VISIT(type->tp_base);
+       Py_VISIT(type->tp_dict);
+       Py_VISIT(type->tp_cache);
+       Py_VISIT(type->tp_mro);
+       Py_VISIT(type->tp_bases);
+       Py_VISIT(type->tp_base);
 
        /* There's no need to visit type->tp_subclasses or
           ((PyHeapTypeObject *)type)->ht_slots, because they can't be involved
           in cycles; tp_subclasses is a list of weak references,
           and slots is a tuple of strings. */
 
-#undef VISIT
-
        return 0;
 }
 
@@ -5805,20 +5788,10 @@ static int
 super_traverse(PyObject *self, visitproc visit, void *arg)
 {
        superobject *su = (superobject *)self;
-       int err;
-
-#define VISIT(SLOT) \
-       if (SLOT) { \
-               err = visit((PyObject *)(SLOT), arg); \
-               if (err) \
-                       return err; \
-       }
-
-       VISIT(su->obj);
-       VISIT(su->type);
-       VISIT(su->obj_type);
 
-#undef VISIT
+       Py_VISIT(su->obj);
+       Py_VISIT(su->type);
+       Py_VISIT(su->obj_type);
 
        return 0;
 }
index a116efc8637f7e22b073c593b584efb3f0aa6a2c..a8ab56ecd832bd71d58e84559e853180e11a92e5 100644 (file)
@@ -109,8 +109,7 @@ weakref_dealloc(PyObject *self)
 static int
 gc_traverse(PyWeakReference *self, visitproc visit, void *arg)
 {
-    if (self->wr_callback != NULL)
-        return visit(self->wr_callback, arg);
+    Py_VISIT(self->wr_callback);
     return 0;
 }
 
index cdbec2b4703696624ff0cf8dc9c8649077317796..cfbd83361fa74453b5d522f94f6f744ad49f9180 100644 (file)
@@ -39,15 +39,9 @@ tb_dealloc(PyTracebackObject *tb)
 static int
 tb_traverse(PyTracebackObject *tb, visitproc visit, void *arg)
 {
-       int err = 0;
-       if (tb->tb_next) {
-               err = visit((PyObject *)tb->tb_next, arg);
-               if (err)
-                       return err;
-       }
-       if (tb->tb_frame) 
-               err = visit((PyObject *)tb->tb_frame, arg);
-       return err;
+       Py_VISIT(tb->tb_next);
+       Py_VISIT(tb->tb_frame);
+       return 0;
 }
 
 static void