]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Patch #1675981: remove unreachable code from type.__new__() method.
authorŽiga Seilnacht <ziga.seilnacht@gmail.com>
Sun, 11 Mar 2007 16:01:51 +0000 (16:01 +0000)
committerŽiga Seilnacht <ziga.seilnacht@gmail.com>
Sun, 11 Mar 2007 16:01:51 +0000 (16:01 +0000)
__dict__ and __weakref__ are removed from the slots tuple earlier
in the code, in the loop that mangles slot names.
 (backport from rev. 54270)

Misc/NEWS
Objects/typeobject.c

index 7080ff7998a7b07e8a4259a2f5aa81565f57521f..47137be18deaa5ffbdb30727ae76542590855530 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,8 @@ What's New in Python 2.5.1c1?
 Core and builtins
 -----------------
 
+- Patch #1675981: remove unreachable code from ``type.__new__()`` method.
+
 - Patch #1638879: don't accept strings with embedded NUL bytes in long().
 
 - Bug #1674503: close the file opened by execfile() in an error condition.
index c4a20fd5c9fb25258a23ccb5985c7b2834939184..4f2740230dd9327b50e68471461cc614183abe73 100644 (file)
@@ -1935,13 +1935,11 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
                                PyTuple_GET_ITEM(slots, i));
                        mp->type = T_OBJECT_EX;
                        mp->offset = slotoffset;
-                       if (base->tp_weaklistoffset == 0 &&
-                           strcmp(mp->name, "__weakref__") == 0) {
-                               add_weak++;
-                               mp->type = T_OBJECT;
-                               mp->flags = READONLY;
-                               type->tp_weaklistoffset = slotoffset;
-                       }
+
+                       /* __dict__ and __weakref__ are already filtered out */
+                       assert(strcmp(mp->name, "__dict__") != 0);
+                       assert(strcmp(mp->name, "__weakref__") != 0);
+
                        slotoffset += sizeof(PyObject *);
                }
        }