Rev 144: Merge the correct fix for bug #586122. in http://bazaar.launchpad.net/~meliae-dev/meliae/trunk

John Arbash Meinel john at arbash-meinel.com
Wed Jun 30 19:07:11 BST 2010


At http://bazaar.launchpad.net/~meliae-dev/meliae/trunk

------------------------------------------------------------
revno: 144 [merge]
revision-id: john at arbash-meinel.com-20100630180653-gqj6g8xqiwlppeu0
parent: john at arbash-meinel.com-20100630175131-wudoc6z6auonw8ro
parent: john at arbash-meinel.com-20100630180555-6b373fu7aamk9t8a
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: trunk
timestamp: Wed 2010-06-30 13:06:53 -0500
message:
  Merge the correct fix for bug #586122.
  
  Don't call PyType_Type.tp_traverse as we can trip an assertion on some debug builds.
modified:
  meliae/_scanner_core.c         _scanner_core.c-20090402012435-66bb6fp08v4begco-1
-------------- next part --------------
=== modified file 'meliae/_scanner_core.c'
--- a/meliae/_scanner_core.c	2009-12-30 16:25:15 +0000
+++ b/meliae/_scanner_core.c	2010-06-30 18:05:55 +0000
@@ -1,4 +1,4 @@
-/* Copyright (C) 2009 Canonical Ltd
+/* Copyright (C) 2009, 2010 Canonical Ltd
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 3 as
@@ -397,6 +397,7 @@
 {
     Py_ssize_t size;
     int retval;
+    int do_traverse;
 
     if (info->nodump != NULL && 
         info->nodump != Py_None
@@ -473,12 +474,26 @@
         _write_to_ref_info(info, ", \"len\": " SSIZET_FMT, PyDict_Size(c_obj));
     }
     _write_static_to_info(info, ", \"refs\": [");
-    if (Py_TYPE(c_obj)->tp_traverse != NULL) {
+    do_traverse = 1;
+    if (Py_TYPE(c_obj)->tp_traverse == NULL
+        || (Py_TYPE(c_obj)->tp_traverse == PyType_Type.tp_traverse
+            && !PyType_HasFeature((PyTypeObject*)c_obj, Py_TPFLAGS_HEAPTYPE)))
+    {
+        /* Obviously we don't traverse if there is no traverse function. But
+         * also, if this is a 'Type' (class definition), then
+         * PyTypeObject.tp_traverse has an assertion about whether this type is
+         * a HEAPTYPE. In debug builds, this can trip and cause failures, even
+         * though it doesn't seem to hurt anything.
+         *  See: https://bugs.launchpad.net/bugs/586122
+         */
+        do_traverse = 0;
+    }
+    if (do_traverse) {
         info->first = 1;
         Py_TYPE(c_obj)->tp_traverse(c_obj, _dump_reference, info);
     }
     _write_static_to_info(info, "]}\n");
-    if (Py_TYPE(c_obj)->tp_traverse != NULL && recurse != 0) {
+    if (do_traverse && recurse != 0) {
         if (recurse == 2) { /* Always dump one layer deeper */
             Py_TYPE(c_obj)->tp_traverse(c_obj, _dump_child, info);
         } else if (recurse == 1) {
@@ -514,7 +529,10 @@
     if (lst == NULL) {
         return NULL;
     }
-    if (Py_TYPE(c_obj)->tp_traverse != NULL) {
+    if (Py_TYPE(c_obj)->tp_traverse != NULL
+        && (Py_TYPE(c_obj)->tp_traverse != PyType_Type.tp_traverse
+            || PyType_HasFeature((PyTypeObject *)c_obj, Py_TPFLAGS_HEAPTYPE)))
+    {
         Py_TYPE(c_obj)->tp_traverse(c_obj, _append_object, lst);
     }
     return lst;



More information about the bazaar-commits mailing list