]> granicus.if.org Git - python/commitdiff
Patch #1675981: remove unreachable code from type.__new__() method.
authorŽiga Seilnacht <ziga.seilnacht@gmail.com>
Sun, 11 Mar 2007 15:54:54 +0000 (15:54 +0000)
committerŽiga Seilnacht <ziga.seilnacht@gmail.com>
Sun, 11 Mar 2007 15:54:54 +0000 (15:54 +0000)
__dict__ and __weakref__ are removed from the slots tuple earlier
in the code, in the loop that mangles slot names. Will backport.

Misc/NEWS
Objects/typeobject.c

index 4ac68492f7137c30b8e6d5dec98ee63a61ab06bd..8d93d0130c2e19c65aed9119a34c7537b9e653ef 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,8 @@ What's New in Python 2.6 alpha 1?
 Core and builtins
 -----------------
 
+- Patch #1675981: remove unreachable code from ``type.__new__()`` method.
+
 - Patch #1491866: change the complex() constructor to allow parthensized
   forms. This means complex(repr(x)) now works instead of raising a
   ValueError.
index c2ed4b5666b1583f4a2d9217d915e43ed4b6d9a9..020a9bb646a47a0f2f85debe99fc17449404bf2d 100644 (file)
@@ -1997,13 +1997,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 *);
                }
        }