diff options
-rw-r--r-- | Include/patchlevel.h | 4 | ||||
-rw-r--r-- | Lib/test/test_os.py | 3 | ||||
-rw-r--r-- | Modules/Setup.dist | 6 | ||||
-rw-r--r-- | Objects/typeobject.c | 37 | ||||
-rw-r--r-- | setup.py | 4 |
5 files changed, 36 insertions, 18 deletions
diff --git a/Include/patchlevel.h b/Include/patchlevel.h index 3d22616..2c3b5dd 100644 --- a/Include/patchlevel.h +++ b/Include/patchlevel.h @@ -23,10 +23,10 @@ #define PY_MINOR_VERSION 2 #define PY_MICRO_VERSION 0 #define PY_RELEASE_LEVEL PY_RELEASE_LEVEL_ALPHA -#define PY_RELEASE_SERIAL 1 +#define PY_RELEASE_SERIAL 2 /* Version as a string */ -#define PY_VERSION "2.2a1+" +#define PY_VERSION "2.2a2+" /* Version as a single 4-byte hex number, e.g. 0x010502B2 == 1.5.2b2. Use this for numeric comparisons, e.g. #if PY_VERSION_HEX >= ... */ diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index 0ea9f78..9cddb5f 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -6,6 +6,9 @@ import os import unittest import warnings +warnings.filterwarnings("ignore", "tempnam", RuntimeWarning, __name__) +warnings.filterwarnings("ignore", "tmpnam", RuntimeWarning, __name__) + from test_support import TESTFN, run_unittest diff --git a/Modules/Setup.dist b/Modules/Setup.dist index e9c2a94..61afe8c 100644 --- a/Modules/Setup.dist +++ b/Modules/Setup.dist @@ -98,6 +98,7 @@ PYTHONPATH=$(COREPYTHONPATH) posix posixmodule.c # posix (UNIX) system calls _sre _sre.c # Fredrik Lundh's new regular expressions +new newmodule.c # Tommy Burnette's 'new' module # The rest of the modules listed in this file are all commented out by # default. Usually they can be detected and built as dynamically @@ -347,11 +348,6 @@ GLHACK=-Dclear=__GLclear #_curses_panel _curses_panel.c -lpanel -lncurses -# Tommy Burnette's 'new' module (creates new empty objects of certain kinds): - -#new newmodule.c - - # Generic (SunOS / SVR4) dynamic loading module. # This is not needed for dynamic loading of Python modules -- # it is a highly experimental and dangerous device for calling diff --git a/Objects/typeobject.c b/Objects/typeobject.c index f2e6f4d4..b64e10b 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -2091,29 +2091,52 @@ static struct wrapperbase tab_init[] = { static PyObject * tp_new_wrapper(PyObject *self, PyObject *args, PyObject *kwds) { - PyTypeObject *type, *subtype; + PyTypeObject *type, *subtype, *staticbase; PyObject *arg0, *res; if (self == NULL || !PyType_Check(self)) Py_FatalError("__new__() called with non-type 'self'"); type = (PyTypeObject *)self; if (!PyTuple_Check(args) || PyTuple_GET_SIZE(args) < 1) { - PyErr_SetString(PyExc_TypeError, - "T.__new__(): not enough arguments"); + PyErr_Format(PyExc_TypeError, + "%s.__new__(): not enough arguments", + type->tp_name); return NULL; } arg0 = PyTuple_GET_ITEM(args, 0); if (!PyType_Check(arg0)) { - PyErr_SetString(PyExc_TypeError, - "T.__new__(S): S is not a type object"); + PyErr_Format(PyExc_TypeError, + "%s.__new__(X): X is not a type object (%s)", + type->tp_name, + arg0->ob_type->tp_name); return NULL; } subtype = (PyTypeObject *)arg0; if (!PyType_IsSubtype(subtype, type)) { - PyErr_SetString(PyExc_TypeError, - "T.__new__(S): S is not a subtype of T"); + PyErr_Format(PyExc_TypeError, + "%s.__new__(%s): %s is not a subtype of %s", + type->tp_name, + subtype->tp_name, + subtype->tp_name, + type->tp_name); + return NULL; + } + + /* Check that the use doesn't do something silly and unsafe like + object.__new__(dictionary). To do this, we check that the + most derived base that's not a heap type is this type. */ + staticbase = subtype; + while (staticbase && (staticbase->tp_flags & Py_TPFLAGS_HEAPTYPE)) + staticbase = staticbase->tp_base; + if (staticbase != type) { + PyErr_Format(PyExc_TypeError, + "%s.__new__(%s) is not safe, use %s.__new__()", + type->tp_name, + subtype->tp_name, + staticbase == NULL ? "?" : staticbase->tp_name); return NULL; } + args = PyTuple_GetSlice(args, 1, PyTuple_GET_SIZE(args)); if (args == NULL) return NULL; @@ -269,10 +269,6 @@ class PyBuildExt(build_ext): # (NIST's Secure Hash Algorithm.) exts.append( Extension('sha', ['shamodule.c']) ) - # Tommy Burnette's 'new' module (creates new empty objects of certain - # kinds): - exts.append( Extension('new', ['newmodule.c']) ) - # Helper module for various ascii-encoders exts.append( Extension('binascii', ['binascii.c']) ) |