diff -r a156f602debc Doc/c-api/typeobj.rst --- a/Doc/c-api/typeobj.rst Tue Apr 28 12:42:20 2009 -0700 +++ b/Doc/c-api/typeobj.rst Tue Apr 28 19:26:52 2009 -0700 @@ -69,14 +69,14 @@ This is the type's type, in other words its metatype. It is initialized by the argument to the ``PyObject_HEAD_INIT`` macro, and its value should normally be - ``&PyType_Type``. However, for dynamically loadable extension modules that must + ``PyType_Type``. However, for dynamically loadable extension modules that must be usable on Windows (at least), the compiler complains that this is not a valid initializer. Therefore, the convention is to pass *NULL* to the ``PyObject_HEAD_INIT`` macro and to initialize this field explicitly at the start of the module's initialization function, before doing anything else. This is typically done like this:: - Foo_Type.ob_type = &PyType_Type; + Foo_Type.ob_type = PyType_Type; This should be done before any instances of the type are created. :cfunc:`PyType_Ready` checks if :attr:`ob_type` is *NULL*, and if so, @@ -726,7 +726,7 @@ dynamically creating a type object by calling the metatype. This field is not inherited by subtypes (obviously), but it defaults to - ``&PyBaseObject_Type`` (which to Python programmers is known as the type + ``PyBaseObject_Type`` (which to Python programmers is known as the type :class:`object`). @@ -904,7 +904,7 @@ deferred to :attr:`tp_init`. This field is inherited by subtypes, except it is not inherited by static types - whose :attr:`tp_base` is *NULL* or ``&PyBaseObject_Type``. + whose :attr:`tp_base` is *NULL* or ``PyBaseObject_Type``. .. cmember:: destructor PyTypeObject.tp_free diff -r a156f602debc Doc/extending/newtypes.rst --- a/Doc/extending/newtypes.rst Tue Apr 28 12:42:20 2009 -0700 +++ b/Doc/extending/newtypes.rst Tue Apr 28 19:26:52 2009 -0700 @@ -107,7 +107,7 @@ This line is a bit of a wart; what we'd like to write is:: - PyVarObject_HEAD_INIT(&PyType_Type, 0) + PyVarObject_HEAD_INIT(PyType_Type, 0) as the type of a type object is "type", but this isn't strictly conforming C and some compilers complain. Fortunately, this member will be filled in for us by @@ -861,7 +861,7 @@ { PyObject *m; - ShoddyType.tp_base = &PyList_Type; + ShoddyType.tp_base = PyList_Type; if (PyType_Ready(&ShoddyType) < 0) return NULL; @@ -1431,7 +1431,7 @@ The statically-declared type object for instances is defined this way:: PyTypeObject PyInstance_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) + PyVarObject_HEAD_INIT(PyType_Type, 0) 0, "module.instance", diff -r a156f602debc Doc/extending/windows.rst --- a/Doc/extending/windows.rst Tue Apr 28 12:42:20 2009 -0700 +++ b/Doc/extending/windows.rst Tue Apr 28 19:26:52 2009 -0700 @@ -169,7 +169,7 @@ If your module creates a new type, you may have trouble with this line:: - PyVarObject_HEAD_INIT(&PyType_Type, 0) + PyVarObject_HEAD_INIT(PyType_Type, 0) Change it to:: @@ -177,7 +177,7 @@ and add the following to the module initialization function:: - MyObject_Type.ob_type = &PyType_Type; + MyObject_Type.ob_type = PyType_Type; Refer to section 3 of the `Python FAQ `_ for details on why you must do this. diff -r a156f602debc Doc/includes/shoddy.c --- a/Doc/includes/shoddy.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Doc/includes/shoddy.c Tue Apr 28 19:26:52 2009 -0700 @@ -23,7 +23,7 @@ static int Shoddy_init(Shoddy *self, PyObject *args, PyObject *kwds) { - if (PyList_Type.tp_init((PyObject *)self, args, kwds) < 0) + if (PyList_Type->tp_init((PyObject *)self, args, kwds) < 0) return -1; self->state = 0; return 0; @@ -85,7 +85,7 @@ { PyObject *m; - ShoddyType.tp_base = &PyList_Type; + ShoddyType.tp_base = PyList_Type; if (PyType_Ready(&ShoddyType) < 0) return NULL; diff -r a156f602debc Include/boolobject.h --- a/Include/boolobject.h Tue Apr 28 12:42:20 2009 -0700 +++ b/Include/boolobject.h Tue Apr 28 19:26:52 2009 -0700 @@ -7,9 +7,9 @@ #endif -PyAPI_DATA(PyTypeObject) PyBool_Type; +PyAPI_DATA(PyTypeObject *) PyBool_Type; -#define PyBool_Check(x) (Py_TYPE(x) == &PyBool_Type) +#define PyBool_Check(x) (Py_TYPE(x) == PyBool_Type) /* Py_False and Py_True are the only two bools in existence. Don't forget to apply Py_INCREF() when returning either!!! */ @@ -28,6 +28,8 @@ /* Function to return a bool from a C long */ PyAPI_FUNC(PyObject *) PyBool_FromLong(long); +PyAPI_FUNC(int) PyBool_Init(void); + #ifdef __cplusplus } #endif diff -r a156f602debc Include/bytearrayobject.h --- a/Include/bytearrayobject.h Tue Apr 28 12:42:20 2009 -0700 +++ b/Include/bytearrayobject.h Tue Apr 28 19:26:52 2009 -0700 @@ -28,12 +28,12 @@ } PyByteArrayObject; /* Type object */ -PyAPI_DATA(PyTypeObject) PyByteArray_Type; -PyAPI_DATA(PyTypeObject) PyByteArrayIter_Type; +PyAPI_DATA(PyTypeObject *) PyByteArray_Type; +PyAPI_DATA(PyTypeObject *) PyByteArrayIter_Type; /* Type check macros */ -#define PyByteArray_Check(self) PyObject_TypeCheck(self, &PyByteArray_Type) -#define PyByteArray_CheckExact(self) (Py_TYPE(self) == &PyByteArray_Type) +#define PyByteArray_Check(self) PyObject_TypeCheck(self, PyByteArray_Type) +#define PyByteArray_CheckExact(self) (Py_TYPE(self) == PyByteArray_Type) /* Direct API functions */ PyAPI_FUNC(PyObject *) PyByteArray_FromObject(PyObject *); @@ -47,6 +47,8 @@ #define PyByteArray_AS_STRING(self) (assert(PyByteArray_Check(self)),((PyByteArrayObject *)(self))->ob_bytes) #define PyByteArray_GET_SIZE(self) (assert(PyByteArray_Check(self)),Py_SIZE(self)) +PyAPI_FUNC(int) PyByteArray_Init(void); + #ifdef __cplusplus } #endif diff -r a156f602debc Include/bytesobject.h --- a/Include/bytesobject.h Tue Apr 28 12:42:20 2009 -0700 +++ b/Include/bytesobject.h Tue Apr 28 19:26:52 2009 -0700 @@ -39,12 +39,12 @@ */ } PyBytesObject; -PyAPI_DATA(PyTypeObject) PyBytes_Type; -PyAPI_DATA(PyTypeObject) PyBytesIter_Type; +PyAPI_DATA(PyTypeObject *) PyBytes_Type; +PyAPI_DATA(PyTypeObject *) PyBytesIter_Type; #define PyBytes_Check(op) \ PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_BYTES_SUBCLASS) -#define PyBytes_CheckExact(op) (Py_TYPE(op) == &PyBytes_Type) +#define PyBytes_CheckExact(op) (Py_TYPE(op) == PyBytes_Type) PyAPI_FUNC(PyObject *) PyBytes_FromStringAndSize(const char *, Py_ssize_t); PyAPI_FUNC(PyObject *) PyBytes_FromString(const char *); @@ -115,6 +115,9 @@ #define F_ALT (1<<3) #define F_ZERO (1<<4) + +PyAPI_FUNC(int) PyBytes_Init(void); + #ifdef __cplusplus } #endif diff -r a156f602debc Include/cellobject.h --- a/Include/cellobject.h Tue Apr 28 12:42:20 2009 -0700 +++ b/Include/cellobject.h Tue Apr 28 19:26:52 2009 -0700 @@ -11,9 +11,9 @@ PyObject *ob_ref; /* Content of the cell or NULL when empty */ } PyCellObject; -PyAPI_DATA(PyTypeObject) PyCell_Type; +PyAPI_DATA(PyTypeObject *) PyCell_Type; -#define PyCell_Check(op) (Py_TYPE(op) == &PyCell_Type) +#define PyCell_Check(op) (Py_TYPE(op) == PyCell_Type) PyAPI_FUNC(PyObject *) PyCell_New(PyObject *); PyAPI_FUNC(PyObject *) PyCell_Get(PyObject *); @@ -22,6 +22,8 @@ #define PyCell_GET(op) (((PyCellObject *)(op))->ob_ref) #define PyCell_SET(op, v) (((PyCellObject *)(op))->ob_ref = v) +PyAPI_FUNC(int) PyCell_Init(void); + #ifdef __cplusplus } #endif diff -r a156f602debc Include/classobject.h --- a/Include/classobject.h Tue Apr 28 12:42:20 2009 -0700 +++ b/Include/classobject.h Tue Apr 28 19:26:52 2009 -0700 @@ -15,9 +15,9 @@ PyObject *im_weakreflist; /* List of weak references */ } PyMethodObject; -PyAPI_DATA(PyTypeObject) PyMethod_Type; +PyAPI_DATA(PyTypeObject *) PyMethod_Type; -#define PyMethod_Check(op) ((op)->ob_type == &PyMethod_Type) +#define PyMethod_Check(op) ((op)->ob_type == PyMethod_Type) PyAPI_FUNC(PyObject *) PyMethod_New(PyObject *, PyObject *); @@ -38,9 +38,9 @@ PyObject *func; } PyInstanceMethodObject; -PyAPI_DATA(PyTypeObject) PyInstanceMethod_Type; +PyAPI_DATA(PyTypeObject *) PyInstanceMethod_Type; -#define PyInstanceMethod_Check(op) ((op)->ob_type == &PyInstanceMethod_Type) +#define PyInstanceMethod_Check(op) ((op)->ob_type == PyInstanceMethod_Type) PyAPI_FUNC(PyObject *) PyInstanceMethod_New(PyObject *); PyAPI_FUNC(PyObject *) PyInstanceMethod_Function(PyObject *); @@ -50,7 +50,9 @@ #define PyInstanceMethod_GET_FUNCTION(meth) \ (((PyInstanceMethodObject *)meth) -> func) + +PyAPI_FUNC(int) Py_MethodInit(void); + #ifdef __cplusplus -} #endif #endif /* !Py_CLASSOBJECT_H */ diff -r a156f602debc Include/cobject.h --- a/Include/cobject.h Tue Apr 28 12:42:20 2009 -0700 +++ b/Include/cobject.h Tue Apr 28 19:26:52 2009 -0700 @@ -14,9 +14,9 @@ extern "C" { #endif -PyAPI_DATA(PyTypeObject) PyCObject_Type; +PyAPI_DATA(PyTypeObject *) PyCObject_Type; -#define PyCObject_Check(op) (Py_TYPE(op) == &PyCObject_Type) +#define PyCObject_Check(op) (Py_TYPE(op) == PyCObject_Type) /* Create a PyCObject from a pointer to a C object and an optional destructor function. If the second argument is non-null, then it @@ -57,6 +57,9 @@ } PyCObject; +PyAPI_FUNC(int) PyCObject_Init(void); + + #ifdef __cplusplus } #endif diff -r a156f602debc Include/code.h --- a/Include/code.h Tue Apr 28 12:42:20 2009 -0700 +++ b/Include/code.h Tue Apr 28 19:26:52 2009 -0700 @@ -61,9 +61,9 @@ #define CO_MAXBLOCKS 20 /* Max static block nesting within a function */ -PyAPI_DATA(PyTypeObject) PyCode_Type; +PyAPI_DATA(PyTypeObject *) PyCode_Type; -#define PyCode_Check(op) (Py_TYPE(op) == &PyCode_Type) +#define PyCode_Check(op) (Py_TYPE(op) == PyCode_Type) #define PyCode_GetNumFree(op) (PyTuple_GET_SIZE((op)->co_freevars)) /* Public interface */ @@ -93,6 +93,10 @@ PyAPI_FUNC(PyObject*) PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names, PyObject *lineno_obj); + +PyAPI_FUNC(int) PyCode_Init(void); + + #ifdef __cplusplus } #endif diff -r a156f602debc Include/complexobject.h --- a/Include/complexobject.h Tue Apr 28 12:42:20 2009 -0700 +++ b/Include/complexobject.h Tue Apr 28 19:26:52 2009 -0700 @@ -42,10 +42,10 @@ Py_complex cval; } PyComplexObject; -PyAPI_DATA(PyTypeObject) PyComplex_Type; +PyAPI_DATA(PyTypeObject *) PyComplex_Type; -#define PyComplex_Check(op) PyObject_TypeCheck(op, &PyComplex_Type) -#define PyComplex_CheckExact(op) (Py_TYPE(op) == &PyComplex_Type) +#define PyComplex_Check(op) PyObject_TypeCheck(op, PyComplex_Type) +#define PyComplex_CheckExact(op) (Py_TYPE(op) == PyComplex_Type) PyAPI_FUNC(PyObject *) PyComplex_FromCComplex(Py_complex); PyAPI_FUNC(PyObject *) PyComplex_FromDoubles(double real, double imag); @@ -54,6 +54,8 @@ PyAPI_FUNC(double) PyComplex_ImagAsDouble(PyObject *op); PyAPI_FUNC(Py_complex) PyComplex_AsCComplex(PyObject *op); +PyAPI_FUNC(int) PyComplex_Init(void); + #ifdef __cplusplus } #endif diff -r a156f602debc Include/descrobject.h --- a/Include/descrobject.h Tue Apr 28 12:42:20 2009 -0700 +++ b/Include/descrobject.h Tue Apr 28 19:26:52 2009 -0700 @@ -5,9 +5,8 @@ extern "C" { #endif -typedef PyObject *(*getter)(PyObject *, void *); -typedef int (*setter)(PyObject *, PyObject *, void *); +#if 0 typedef struct PyGetSetDef { char *name; getter get; @@ -15,6 +14,7 @@ char *doc; void *closure; } PyGetSetDef; +#endif /* 0 */ typedef PyObject *(*wrapperfunc)(PyObject *self, PyObject *args, void *wrapped); @@ -67,14 +67,12 @@ void *d_wrapped; /* This can be any function pointer */ } PyWrapperDescrObject; -PyAPI_DATA(PyTypeObject) PyClassMethodDescr_Type; -PyAPI_DATA(PyTypeObject) PyGetSetDescr_Type; -PyAPI_DATA(PyTypeObject) PyMemberDescr_Type; -PyAPI_DATA(PyTypeObject) PyMethodDescr_Type; -PyAPI_DATA(PyTypeObject) PyWrapperDescr_Type; -PyAPI_DATA(PyTypeObject) PyDictProxy_Type; -PyAPI_DATA(PyTypeObject) PyGetSetDescr_Type; -PyAPI_DATA(PyTypeObject) PyMemberDescr_Type; +PyAPI_DATA(PyTypeObject *) PyClassMethodDescr_Type; +PyAPI_DATA(PyTypeObject *) PyGetSetDescr_Type; +PyAPI_DATA(PyTypeObject *) PyMemberDescr_Type; +PyAPI_DATA(PyTypeObject *) PyMethodDescr_Type; +PyAPI_DATA(PyTypeObject *) PyWrapperDescr_Type; +PyAPI_DATA(PyTypeObject *) PyDictProxy_Type; PyAPI_FUNC(PyObject *) PyDescr_NewMethod(PyTypeObject *, PyMethodDef *); PyAPI_FUNC(PyObject *) PyDescr_NewClassMethod(PyTypeObject *, PyMethodDef *); @@ -90,7 +88,8 @@ PyAPI_FUNC(PyObject *) PyWrapper_New(PyObject *, PyObject *); -PyAPI_DATA(PyTypeObject) PyProperty_Type; +PyAPI_DATA(PyTypeObject *) PyProperty_Type; + #ifdef __cplusplus } #endif diff -r a156f602debc Include/dictobject.h --- a/Include/dictobject.h Tue Apr 28 12:42:20 2009 -0700 +++ b/Include/dictobject.h Tue Apr 28 19:26:52 2009 -0700 @@ -88,20 +88,20 @@ PyDictEntry ma_smalltable[PyDict_MINSIZE]; }; -PyAPI_DATA(PyTypeObject) PyDict_Type; -PyAPI_DATA(PyTypeObject) PyDictIterKey_Type; -PyAPI_DATA(PyTypeObject) PyDictIterValue_Type; -PyAPI_DATA(PyTypeObject) PyDictIterItem_Type; -PyAPI_DATA(PyTypeObject) PyDictKeys_Type; -PyAPI_DATA(PyTypeObject) PyDictItems_Type; -PyAPI_DATA(PyTypeObject) PyDictValues_Type; +PyAPI_DATA(PyTypeObject *) PyDict_Type; +PyAPI_DATA(PyTypeObject *) PyDictIterKey_Type; +PyAPI_DATA(PyTypeObject *) PyDictIterValue_Type; +PyAPI_DATA(PyTypeObject *) PyDictIterItem_Type; +PyAPI_DATA(PyTypeObject *) PyDictKeys_Type; +PyAPI_DATA(PyTypeObject *) PyDictItems_Type; +PyAPI_DATA(PyTypeObject *) PyDictValues_Type; #define PyDict_Check(op) \ PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_DICT_SUBCLASS) -#define PyDict_CheckExact(op) (Py_TYPE(op) == &PyDict_Type) -#define PyDictKeys_Check(op) (Py_TYPE(op) == &PyDictKeys_Type) -#define PyDictItems_Check(op) (Py_TYPE(op) == &PyDictItems_Type) -#define PyDictValues_Check(op) (Py_TYPE(op) == &PyDictValues_Type) +#define PyDict_CheckExact(op) (Py_TYPE(op) == PyDict_Type) +#define PyDictKeys_Check(op) (Py_TYPE(op) == PyDictKeys_Type) +#define PyDictItems_Check(op) (Py_TYPE(op) == PyDictItems_Type) +#define PyDictValues_Check(op) (Py_TYPE(op) == PyDictValues_Type) /* This excludes Values, since they are not sets. */ # define PyDictViewSet_Check(op) \ (PyDictKeys_Check(op) || PyDictItems_Check(op)) @@ -152,6 +152,8 @@ PyAPI_FUNC(int) PyDict_SetItemString(PyObject *dp, const char *key, PyObject *item); PyAPI_FUNC(int) PyDict_DelItemString(PyObject *dp, const char *key); +PyAPI_FUNC(int) PyDict_Init(void); + #ifdef __cplusplus } #endif diff -r a156f602debc Include/enumobject.h --- a/Include/enumobject.h Tue Apr 28 12:42:20 2009 -0700 +++ b/Include/enumobject.h Tue Apr 28 19:26:52 2009 -0700 @@ -7,8 +7,10 @@ extern "C" { #endif -PyAPI_DATA(PyTypeObject) PyEnum_Type; -PyAPI_DATA(PyTypeObject) PyReversed_Type; +PyAPI_DATA(PyTypeObject *) PyEnum_Type; +PyAPI_DATA(PyTypeObject *) PyReversed_Type; + +PyAPI_FUNC(int) PyEnum_Init(void); #ifdef __cplusplus } diff -r a156f602debc Include/fileobject.h --- a/Include/fileobject.h Tue Apr 28 12:42:20 2009 -0700 +++ b/Include/fileobject.h Tue Apr 28 19:26:52 2009 -0700 @@ -28,7 +28,7 @@ The std printer acts as a preliminary sys.stderr until the new io infrastructure is in place. */ PyAPI_FUNC(PyObject *) PyFile_NewStdPrinter(int); -PyAPI_DATA(PyTypeObject) PyStdPrinter_Type; +PyAPI_DATA(PyTypeObject *) PyStdPrinter_Type; #if defined _MSC_VER && _MSC_VER >= 1400 /* A routine to check if a file descriptor is valid on Windows. Returns 0 @@ -41,6 +41,8 @@ #define _PyVerify_fd(A) (1) /* dummy */ #endif +PyAPI_FUNC(int) PyFile_Init(void); + #ifdef __cplusplus } #endif diff -r a156f602debc Include/floatobject.h --- a/Include/floatobject.h Tue Apr 28 12:42:20 2009 -0700 +++ b/Include/floatobject.h Tue Apr 28 19:26:52 2009 -0700 @@ -16,10 +16,10 @@ double ob_fval; } PyFloatObject; -PyAPI_DATA(PyTypeObject) PyFloat_Type; +PyAPI_DATA(PyTypeObject *) PyFloat_Type; -#define PyFloat_Check(op) PyObject_TypeCheck(op, &PyFloat_Type) -#define PyFloat_CheckExact(op) (Py_TYPE(op) == &PyFloat_Type) +#define PyFloat_Check(op) PyObject_TypeCheck(op, PyFloat_Type) +#define PyFloat_CheckExact(op) (Py_TYPE(op) == PyFloat_Type) #ifdef Py_NAN #define Py_RETURN_NAN return PyFloat_FromDouble(Py_NAN) @@ -55,7 +55,7 @@ * routines produce a C double from such a string. The suffix (4 or 8) * specifies the number of bytes in the string. * - * On platforms that appear to use (see _PyFloat_Init()) IEEE-754 formats + * On platforms that appear to use (see PyFloat_Init()) IEEE-754 formats * these functions work by copying bits. On other platforms, the formats the * 4- byte format is identical to the IEEE-754 single precision format, and * the 8-byte format to the IEEE-754 double precision format, although the @@ -111,6 +111,8 @@ Py_UNICODE *format_spec, Py_ssize_t format_spec_len); +PyAPI_FUNC(int) PyFloat_Init(void); + #ifdef __cplusplus } #endif diff -r a156f602debc Include/frameobject.h --- a/Include/frameobject.h Tue Apr 28 12:42:20 2009 -0700 +++ b/Include/frameobject.h Tue Apr 28 19:26:52 2009 -0700 @@ -49,9 +49,9 @@ /* Standard object interface */ -PyAPI_DATA(PyTypeObject) PyFrame_Type; +PyAPI_DATA(PyTypeObject *) PyFrame_Type; -#define PyFrame_Check(op) (Py_TYPE(op) == &PyFrame_Type) +#define PyFrame_Check(op) (Py_TYPE(op) == PyFrame_Type) PyAPI_FUNC(PyFrameObject *) PyFrame_New(PyThreadState *, PyCodeObject *, PyObject *, PyObject *); @@ -75,6 +75,8 @@ PyAPI_FUNC(int) PyFrame_ClearFreeList(void); +PyAPI_FUNC(int) PyFrame_Init(void); + #ifdef __cplusplus } #endif diff -r a156f602debc Include/funcobject.h --- a/Include/funcobject.h Tue Apr 28 12:42:20 2009 -0700 +++ b/Include/funcobject.h Tue Apr 28 19:26:52 2009 -0700 @@ -39,9 +39,9 @@ */ } PyFunctionObject; -PyAPI_DATA(PyTypeObject) PyFunction_Type; +PyAPI_DATA(PyTypeObject *) PyFunction_Type; -#define PyFunction_Check(op) (Py_TYPE(op) == &PyFunction_Type) +#define PyFunction_Check(op) (Py_TYPE(op) == PyFunction_Type) PyAPI_FUNC(PyObject *) PyFunction_New(PyObject *, PyObject *); PyAPI_FUNC(PyObject *) PyFunction_GetCode(PyObject *); @@ -74,8 +74,8 @@ (((PyFunctionObject *)func) -> func_annotations) /* The classmethod and staticmethod types lives here, too */ -PyAPI_DATA(PyTypeObject) PyClassMethod_Type; -PyAPI_DATA(PyTypeObject) PyStaticMethod_Type; +PyAPI_DATA(PyTypeObject *) PyClassMethod_Type; +PyAPI_DATA(PyTypeObject *) PyStaticMethod_Type; PyAPI_FUNC(PyObject *) PyClassMethod_New(PyObject *); PyAPI_FUNC(PyObject *) PyStaticMethod_New(PyObject *); diff -r a156f602debc Include/genobject.h --- a/Include/genobject.h Tue Apr 28 12:42:20 2009 -0700 +++ b/Include/genobject.h Tue Apr 28 19:26:52 2009 -0700 @@ -26,14 +26,16 @@ PyObject *gi_weakreflist; } PyGenObject; -PyAPI_DATA(PyTypeObject) PyGen_Type; +PyAPI_DATA(PyTypeObject *) PyGen_Type; -#define PyGen_Check(op) PyObject_TypeCheck(op, &PyGen_Type) -#define PyGen_CheckExact(op) (Py_TYPE(op) == &PyGen_Type) +#define PyGen_Check(op) PyObject_TypeCheck(op, PyGen_Type) +#define PyGen_CheckExact(op) (Py_TYPE(op) == PyGen_Type) PyAPI_FUNC(PyObject *) PyGen_New(struct _frame *); PyAPI_FUNC(int) PyGen_NeedsFinalizing(PyGenObject *); +PyAPI_FUNC(int) PyGen_Init(void); + #ifdef __cplusplus } #endif diff -r a156f602debc Include/import.h --- a/Include/import.h Tue Apr 28 12:42:20 2009 -0700 +++ b/Include/import.h Tue Apr 28 19:26:52 2009 -0700 @@ -40,7 +40,7 @@ PyObject* (*initfunc)(void); }; -PyAPI_DATA(PyTypeObject) PyNullImporter_Type; +PyAPI_DATA(PyTypeObject *) PyNullImporter_Type; PyAPI_DATA(struct _inittab *) PyImport_Inittab; PyAPI_FUNC(int) PyImport_AppendInittab(const char *name, PyObject* (*initfunc)(void)); diff -r a156f602debc Include/iterobject.h --- a/Include/iterobject.h Tue Apr 28 12:42:20 2009 -0700 +++ b/Include/iterobject.h Tue Apr 28 19:26:52 2009 -0700 @@ -5,19 +5,20 @@ extern "C" { #endif -PyAPI_DATA(PyTypeObject) PySeqIter_Type; -PyAPI_DATA(PyTypeObject) PyCallIter_Type; -PyAPI_DATA(PyTypeObject) PyCmpWrapper_Type; +PyAPI_DATA(PyTypeObject *) PySeqIter_Type; +PyAPI_DATA(PyTypeObject *) PyCallIter_Type; -#define PySeqIter_Check(op) (Py_TYPE(op) == &PySeqIter_Type) +#define PySeqIter_Check(op) (Py_TYPE(op) == PySeqIter_Type) PyAPI_FUNC(PyObject *) PySeqIter_New(PyObject *); -#define PyCallIter_Check(op) (Py_TYPE(op) == &PyCallIter_Type) +#define PyCallIter_Check(op) (Py_TYPE(op) == PyCallIter_Type) PyAPI_FUNC(PyObject *) PyCallIter_New(PyObject *, PyObject *); +PyAPI_FUNC(int) PyIterObject_Init(void); + #ifdef __cplusplus } #endif diff -r a156f602debc Include/listobject.h --- a/Include/listobject.h Tue Apr 28 12:42:20 2009 -0700 +++ b/Include/listobject.h Tue Apr 28 19:26:52 2009 -0700 @@ -38,14 +38,16 @@ Py_ssize_t allocated; } PyListObject; -PyAPI_DATA(PyTypeObject) PyList_Type; -PyAPI_DATA(PyTypeObject) PyListIter_Type; -PyAPI_DATA(PyTypeObject) PyListRevIter_Type; -PyAPI_DATA(PyTypeObject) PySortWrapper_Type; +PyAPI_DATA(PyTypeObject *) PyList_Type; +PyAPI_DATA(PyTypeObject *) PyListIter_Type; +PyAPI_DATA(PyTypeObject *) PyListRevIter_Type; +PyAPI_DATA(PyTypeObject *) PySortWrapper_Type; #define PyList_Check(op) \ PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LIST_SUBCLASS) -#define PyList_CheckExact(op) (Py_TYPE(op) == &PyList_Type) +#define PyList_CheckExact(op) (Py_TYPE(op) == PyList_Type) + +PyAPI_FUNC(int) PyList_Init(void); PyAPI_FUNC(PyObject *) PyList_New(Py_ssize_t size); PyAPI_FUNC(Py_ssize_t) PyList_Size(PyObject *); diff -r a156f602debc Include/longobject.h --- a/Include/longobject.h Tue Apr 28 12:42:20 2009 -0700 +++ b/Include/longobject.h Tue Apr 28 19:26:52 2009 -0700 @@ -9,11 +9,11 @@ typedef struct _longobject PyLongObject; /* Revealed in longintrepr.h */ -PyAPI_DATA(PyTypeObject) PyLong_Type; +PyAPI_DATA(PyTypeObject *) PyLong_Type; #define PyLong_Check(op) \ PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LONG_SUBCLASS) -#define PyLong_CheckExact(op) (Py_TYPE(op) == &PyLong_Type) +#define PyLong_CheckExact(op) (Py_TYPE(op) == PyLong_Type) PyAPI_FUNC(PyObject *) PyLong_FromLong(long); PyAPI_FUNC(PyObject *) PyLong_FromUnsignedLong(unsigned long); @@ -140,6 +140,8 @@ PyAPI_FUNC(unsigned long) PyOS_strtoul(char *, char **, int); PyAPI_FUNC(long) PyOS_strtol(char *, char **, int); +PyAPI_FUNC(int) PyLong_Init(void); + #ifdef __cplusplus } #endif diff -r a156f602debc Include/memoryobject.h --- a/Include/memoryobject.h Tue Apr 28 12:42:20 2009 -0700 +++ b/Include/memoryobject.h Tue Apr 28 19:26:52 2009 -0700 @@ -6,9 +6,9 @@ extern "C" { #endif -PyAPI_DATA(PyTypeObject) PyMemoryView_Type; +PyAPI_DATA(PyTypeObject *) PyMemoryView_Type; -#define PyMemoryView_Check(op) (Py_TYPE(op) == &PyMemoryView_Type) +#define PyMemoryView_Check(op) (Py_TYPE(op) == PyMemoryView_Type) /* Get a pointer to the underlying Py_buffer of a memoryview object. */ #define PyMemoryView_GET_BUFFER(op) (&((PyMemoryViewObject *)(op))->view) @@ -68,6 +68,8 @@ } PyMemoryViewObject; +PyAPI_FUNC(int) PyMemoryView_Init(void); + #ifdef __cplusplus } #endif diff -r a156f602debc Include/methodobject.h --- a/Include/methodobject.h Tue Apr 28 12:42:20 2009 -0700 +++ b/Include/methodobject.h Tue Apr 28 19:26:52 2009 -0700 @@ -11,14 +11,9 @@ not Python methods in user-defined classes. See classobject.h for the latter. */ -PyAPI_DATA(PyTypeObject) PyCFunction_Type; +PyAPI_DATA(PyTypeObject *) PyCFunction_Type; -#define PyCFunction_Check(op) (Py_TYPE(op) == &PyCFunction_Type) - -typedef PyObject *(*PyCFunction)(PyObject *, PyObject *); -typedef PyObject *(*PyCFunctionWithKeywords)(PyObject *, PyObject *, - PyObject *); -typedef PyObject *(*PyNoArgsFunction)(PyObject *); +#define PyCFunction_Check(op) (Py_TYPE(op) == PyCFunction_Type) PyAPI_FUNC(PyCFunction) PyCFunction_GetFunction(PyObject *); PyAPI_FUNC(PyObject *) PyCFunction_GetSelf(PyObject *); @@ -34,6 +29,7 @@ (((PyCFunctionObject *)func) -> m_ml -> ml_flags) PyAPI_FUNC(PyObject *) PyCFunction_Call(PyObject *, PyObject *, PyObject *); +#if 0 struct PyMethodDef { const char *ml_name; /* The name of the built-in function/method */ PyCFunction ml_meth; /* The C function that implements it */ @@ -41,7 +37,7 @@ describe the args expected by the C func */ const char *ml_doc; /* The __doc__ attribute, or NULL */ }; -typedef struct PyMethodDef PyMethodDef; +#endif /* 0 */ #define PyCFunction_New(ML, SELF) PyCFunction_NewEx((ML), (SELF), NULL) PyAPI_FUNC(PyObject *) PyCFunction_NewEx(PyMethodDef *, PyObject *, diff -r a156f602debc Include/moduleobject.h --- a/Include/moduleobject.h Tue Apr 28 12:42:20 2009 -0700 +++ b/Include/moduleobject.h Tue Apr 28 19:26:52 2009 -0700 @@ -7,10 +7,10 @@ extern "C" { #endif -PyAPI_DATA(PyTypeObject) PyModule_Type; +PyAPI_DATA(PyTypeObject *) PyModule_Type; -#define PyModule_Check(op) PyObject_TypeCheck(op, &PyModule_Type) -#define PyModule_CheckExact(op) (Py_TYPE(op) == &PyModule_Type) +#define PyModule_Check(op) PyObject_TypeCheck(op, PyModule_Type) +#define PyModule_CheckExact(op) (Py_TYPE(op) == PyModule_Type) PyAPI_FUNC(PyObject *) PyModule_New(const char *); PyAPI_FUNC(PyObject *) PyModule_GetDict(PyObject *); @@ -42,6 +42,8 @@ }PyModuleDef; +PyAPI_FUNC(int) PyModule_Init(void); + #ifdef __cplusplus } #endif diff -r a156f602debc Include/object.h --- a/Include/object.h Tue Apr 28 12:42:20 2009 -0700 +++ b/Include/object.h Tue Apr 28 19:26:52 2009 -0700 @@ -93,22 +93,58 @@ #define PyObject_VAR_HEAD PyVarObject ob_base; #define Py_INVALID_SIZE (Py_ssize_t)-1 +struct _object; +typedef struct _object PyObject; + +typedef PyObject *(*PyCFunction)(PyObject *, PyObject *); +typedef PyObject *(*PyCFunctionWithKeywords)(PyObject *, PyObject *, + PyObject *); +typedef PyObject *(*PyNoArgsFunction)(PyObject *); + + +typedef PyObject *(*getter)(PyObject *, void *); +typedef int (*setter)(PyObject *, PyObject *, void *); + + + +struct _typeobject; +typedef struct _typeobject PyTypeObject; +struct _heaptypeobject; +typedef struct _heaptypeobject PyHeapTypeObject; + +struct PyGetSetDef; +typedef struct PyGetSetDef PyGetSetDef; + +struct PyMethodDef { + const char *ml_name; /* The name of the built-in function/method */ + PyCFunction ml_meth; /* The C function that implements it */ + int ml_flags; /* Combination of METH_xxx flags, which mostly + describe the args expected by the C func */ + const char *ml_doc; /* The __doc__ attribute, or NULL */ +}; +typedef struct PyMethodDef PyMethodDef; + +struct PyMemberDef; +typedef struct PyMemberDef PyMemberDef; + + /* Nothing is actually declared to be a PyObject, but every pointer to * a Python object can be cast to a PyObject*. This is inheritance built * by hand. Similarly every pointer to a variable-size Python object can, * in addition, be cast to PyVarObject*. */ -typedef struct _object { +struct _object { _PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt; - struct _typeobject *ob_type; -} PyObject; + PyTypeObject *ob_type; +}; typedef struct { PyObject ob_base; Py_ssize_t ob_size; /* Number of items in variable part */ } PyVarObject; + #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt) #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) #define Py_SIZE(ob) (((PyVarObject*)(ob))->ob_size) @@ -197,75 +233,18 @@ typedef int (*visitproc)(PyObject *, void *); typedef int (*traverseproc)(PyObject *, visitproc, void *); -typedef struct { - /* Number implementations must check *both* - arguments for proper type and implement the necessary conversions - in the slot functions themselves. */ - binaryfunc nb_add; - binaryfunc nb_subtract; - binaryfunc nb_multiply; - binaryfunc nb_remainder; - binaryfunc nb_divmod; - ternaryfunc nb_power; - unaryfunc nb_negative; - unaryfunc nb_positive; - unaryfunc nb_absolute; - inquiry nb_bool; - unaryfunc nb_invert; - binaryfunc nb_lshift; - binaryfunc nb_rshift; - binaryfunc nb_and; - binaryfunc nb_xor; - binaryfunc nb_or; - unaryfunc nb_int; - void *nb_reserved; /* the slot formerly known as nb_long */ - unaryfunc nb_float; +struct PyNumberMethods; +typedef struct PyNumberMethods PyNumberMethods; - binaryfunc nb_inplace_add; - binaryfunc nb_inplace_subtract; - binaryfunc nb_inplace_multiply; - binaryfunc nb_inplace_remainder; - ternaryfunc nb_inplace_power; - binaryfunc nb_inplace_lshift; - binaryfunc nb_inplace_rshift; - binaryfunc nb_inplace_and; - binaryfunc nb_inplace_xor; - binaryfunc nb_inplace_or; +struct PySequenceMethods; +typedef struct PySequenceMethods PySequenceMethods; - binaryfunc nb_floor_divide; - binaryfunc nb_true_divide; - binaryfunc nb_inplace_floor_divide; - binaryfunc nb_inplace_true_divide; +struct PyMappingMethods; +typedef struct PyMappingMethods PyMappingMethods; - unaryfunc nb_index; -} PyNumberMethods; - -typedef struct { - lenfunc sq_length; - binaryfunc sq_concat; - ssizeargfunc sq_repeat; - ssizeargfunc sq_item; - void *was_sq_slice; - ssizeobjargproc sq_ass_item; - void *was_sq_ass_slice; - objobjproc sq_contains; - - binaryfunc sq_inplace_concat; - ssizeargfunc sq_inplace_repeat; -} PySequenceMethods; - -typedef struct { - lenfunc mp_length; - binaryfunc mp_subscript; - objobjargproc mp_ass_subscript; -} PyMappingMethods; - - -typedef struct { - getbufferproc bf_getbuffer; - releasebufferproc bf_releasebuffer; -} PyBufferProcs; +struct PyBufferProcs; +typedef struct PyBufferProcs PyBufferProcs; typedef void (*freefunc)(void *); typedef void (*destructor)(PyObject *); @@ -282,118 +261,317 @@ typedef PyObject *(*descrgetfunc) (PyObject *, PyObject *, PyObject *); typedef int (*descrsetfunc) (PyObject *, PyObject *, PyObject *); typedef int (*initproc)(PyObject *, PyObject *, PyObject *); -typedef PyObject *(*newfunc)(struct _typeobject *, PyObject *, PyObject *); -typedef PyObject *(*allocfunc)(struct _typeobject *, Py_ssize_t); +typedef PyObject *(*newfunc)(PyTypeObject *, PyObject *, PyObject *); +typedef PyObject *(*allocfunc)(PyTypeObject *, Py_ssize_t); -typedef struct _typeobject { + +/* NEEDSWORK + decref find tp_dealloc in the object and calls it. + FastSubclass finds tp_flags in the object and inspects it. + + so the type object needs to expose at least that much. + everything else can go through the accessors, but those + are speed-critical. + + once we've converted all the type declarations + to use the new API (or whatever), we can move tp_dealloc + to the top of the object and get rid of the other gunk. + + BEFORE RELEASE that is. +*/ +#ifndef PY_TYPEPRIVATE + +struct _typeobject { PyObject_VAR_HEAD - const char *tp_name; /* For printing, in format "." */ - Py_ssize_t tp_basicsize, tp_itemsize; /* For allocation */ + const char *mysterious_thing_0; + Py_ssize_t mysterious_thing_1, mysterious_thing_2; /* Methods to implement standard operations */ destructor tp_dealloc; - printfunc tp_print; - getattrfunc tp_getattr; - setattrfunc tp_setattr; - void *tp_reserved; /* formerly known as tp_compare */ - reprfunc tp_repr; - /* Method suites for standard classes */ + printfunc mysterious_thing_3; + getattrfunc mysterious_thing_4; + setattrfunc mysterious_thing_5; + void *mysterious_thing_6; /* formerly known as tp_compare */ + reprfunc mysterious_thing_7; - PyNumberMethods *tp_as_number; - PySequenceMethods *tp_as_sequence; - PyMappingMethods *tp_as_mapping; + /* Method suites for standard classes */ - /* More standard operations (here for binary compatibility) */ + PyNumberMethods *mysterious_thing_8; + PySequenceMethods *mysterious_thing_9; + PyMappingMethods *mysterious_thing_a; - hashfunc tp_hash; - ternaryfunc tp_call; - reprfunc tp_str; - getattrofunc tp_getattro; - setattrofunc tp_setattro; + /* More standard operations (here for binary compatibility) */ - /* Functions to access object as input/output buffer */ - PyBufferProcs *tp_as_buffer; + hashfunc mysterious_thing_b; + ternaryfunc mysterious_thing_c; + reprfunc mysterious_thing_d; + getattrofunc mysterious_thing_e; + setattrofunc mysterious_thing_f; - /* Flags to define presence of optional/expanded features */ - long tp_flags; + /* Functions to access object as input/output buffer */ + PyBufferProcs *mysterious_thing_10; - const char *tp_doc; /* Documentation string */ + /* Flags to define presence of optional/expanded features */ + long tp_flags; +}; - /* Assigned meaning in release 2.0 */ - /* call function for all accessible objects */ - traverseproc tp_traverse; +#endif /* PY_TYPEPRIVATE */ - /* delete references to contained objects */ - inquiry tp_clear; - /* Assigned meaning in release 2.1 */ - /* rich comparisons */ - richcmpfunc tp_richcompare; +/* TODO NEEDSWORK explicitly number these? */ - /* weak reference enabler */ - Py_ssize_t tp_weaklistoffset; +/* +** This enum identifies which element you want to access +** in a type object. +** +** The comment after each tells you which accessor(s) to use. +** You must use the correct one, because they're type safe. +** +** Some of them are lists, rather than individual values, +** e.g. for pytoe_methods you'd append a method rather than +** "set" one, so the accessor lsited is PyType_AppendMethod. +** +** Some of them are boolean flags which are stored internally +** in a single "flags" int. Rather than access the "flags" entry +** as a whole, you must address the boolean flags individually +** using PyType_SetFlag() and PyType_GetFlag(). +*/ +typedef enum + { + pytoe_invalid = 0, - /* Iterators */ - getiterfunc tp_iter; - iternextfunc tp_iternext; + /* object + ** + ** _next and _prev are only active when Py_TRACE_REFS is on; + ** however, if we ifdef them here the enums will get renumbered. + ** so always leave them on here. + */ + pytoe_object_next, /* PyType_SetPyObject */ + pytoe_object_prev, /* PyType_SetPyObject */ + pytoe_object_refcnt, /* PyType_SetSize */ + pytoe_object_type, /* PyType_SetPyTypeObject */ + pytoe_object_size, /* PyType_SetSize */ - /* Attribute descriptor and subclassing stuff */ - struct PyMethodDef *tp_methods; - struct PyMemberDef *tp_members; - struct PyGetSetDef *tp_getset; - struct _typeobject *tp_base; - PyObject *tp_dict; - descrgetfunc tp_descr_get; - descrsetfunc tp_descr_set; - Py_ssize_t tp_dictoffset; - initproc tp_init; - allocfunc tp_alloc; - newfunc tp_new; - freefunc tp_free; /* Low-level free-memory routine */ - inquiry tp_is_gc; /* For PyObject_IS_GC */ - PyObject *tp_bases; - PyObject *tp_mro; /* method resolution order */ - PyObject *tp_cache; - PyObject *tp_subclasses; - PyObject *tp_weaklist; - destructor tp_del; + /* type object */ + pytoe_name, /* PyType_SetString */ + pytoe_basicsize, /* PyType_SetSize */ + pytoe_itemsize, /* PyType_SetSize */ + pytoe_dealloc, /* PyType_SetDestructorFunction */ + pytoe_print, /* PyType_SetPrintFunction */ + pytoe_getattr, /* PyType_SetAttrGetFunction */ + pytoe_setattr, /* PyType_SetAttrSetFunction */ + pytoe_repr, /* PyType_SetReprFunction */ + pytoe_hash, /* PyType_SetHashFunction */ + pytoe_call, /* PyType_SetTernaryFunction */ + pytoe_str, /* PyType_SetReprFunction */ + pytoe_getattro, /* PyType_SetAttrObjectGetFunction */ + pytoe_setattro, /* PyType_SetAttrObjectSetFunction */ + pytoe_doc, /* PyType_SetString */ + pytoe_traverse, /* PyType_SetTraverseFunction */ + pytoe_clear, /* PyType_SetInquiryFunction */ + pytoe_richcompare, /* PyType_SetRichCompareFunction */ + pytoe_weaklistoffset, /* PyType_SetSize */ + pytoe_iter, /* PyType_SetIteratorGetFunction */ + pytoe_iternext, /* PyType_SetIteratorNextFunction */ + pytoe_methods, /* PyType_AppendMethod */ + pytoe_members, /* PyType_AppendMember */ + pytoe_getset, /* PyType_AppendProperty */ + pytoe_base, /* PyType_SetPyTypeObject */ + pytoe_dict, /* PyType_SetPyObject */ + pytoe_descr_get, /* PyType_SetDescriptorGetFunction */ + pytoe_descr_set, /* PyType_SetDescriptorSetFunction */ + pytoe_dictoffset, /* PyType_SetSize */ + pytoe_init, /* PyType_SetInitFunction */ + pytoe_alloc, /* PyType_SetAllocFunction */ + pytoe_new, /* PyType_SetNewFunction */ + pytoe_free, /* PyType_SetFreeFunction */ + pytoe_is_gc, /* PyType_SetInquiryFunction */ + pytoe_bases, /* PyType_SetPyObject */ + pytoe_mro, /* PyType_SetPyObject */ + pytoe_cache, /* PyType_SetPyObject */ + pytoe_subclasses, /* PyType_SetPyObject */ + pytoe_weaklist, /* PyType_SetPyObject */ + pytoe_del, /* PyType_SetDestructorFunction */ + pytoe_allocs, /* PyType_SetSize */ + pytoe_frees, /* PyType_SetSize */ + pytoe_maxalloc, /* PyType_SetSize */ + pytoe_prev, /* PyType_SetPyTypeObject */ + pytoe_next, /* PyType_SetPyTypeObject */ + + /* type object flags */ + pytoe_flag_heaptype, /* PyType_SetFlag */ + pytoe_flag_basetype, /* PyType_SetFlag */ + pytoe_flag_ready, /* PyType_SetFlag */ + pytoe_flag_readying, /* PyType_SetFlag */ + pytoe_flag_have_gc, /* PyType_SetFlag */ + pytoe_flag_have_stackless_extension, /* PyType_SetFlag */ + pytoe_flag_dynamically_created, /* PyType_SetFlag */ + pytoe_flag_have_version_flag, /* PyType_SetFlag */ + pytoe_flag_valid_version_tag, /* PyType_SetFlag */ + pytoe_flag_is_abstract, /* PyType_SetFlag */ + pytoe_flag_int_subclass, /* PyType_SetFlag */ + pytoe_flag_long_subclass, /* PyType_SetFlag */ + pytoe_flag_list_subclass, /* PyType_SetFlag */ + pytoe_flag_tuple_subclass, /* PyType_SetFlag */ + pytoe_flag_bytes_subclass, /* PyType_SetFlag */ + pytoe_flag_unicode_subclass, /* PyType_SetFlag */ + pytoe_flag_dict_subclass, /* PyType_SetFlag */ + pytoe_flag_base_exception_subclass, /* PyType_SetFlag */ + pytoe_flag_type_subclass, /* PyType_SetFlag */ - /* Type attribute cache version tag. Added in version 2.6 */ - unsigned int tp_version_tag; + /* number methods */ + pytoe_number_add, /* PyType_SetBinaryFunction */ + pytoe_number_subtract, /* PyType_SetBinaryFunction */ + pytoe_number_multiply, /* PyType_SetBinaryFunction */ + pytoe_number_remainder, /* PyType_SetBinaryFunction */ + pytoe_number_divmod, /* PyType_SetBinaryFunction */ + pytoe_number_power, /* PyType_SetTernaryFunction */ + pytoe_number_negative, /* PyType_SetUnaryFunction */ + pytoe_number_positive, /* PyType_SetUnaryFunction */ + pytoe_number_absolute, /* PyType_SetUnaryFunction */ + pytoe_number_bool, /* PyType_SetInquiryFunction */ + pytoe_number_invert, /* PyType_SetUnaryFunction */ + pytoe_number_lshift, /* PyType_SetBinaryFunction */ + pytoe_number_rshift, /* PyType_SetBinaryFunction */ + pytoe_number_and, /* PyType_SetBinaryFunction */ + pytoe_number_xor, /* PyType_SetBinaryFunction */ + pytoe_number_or, /* PyType_SetBinaryFunction */ + pytoe_number_int, /* PyType_SetUnaryFunction */ + pytoe_number_float, /* PyType_SetUnaryFunction */ + pytoe_number_inplace_add, /* PyType_SetBinaryFunction */ + pytoe_number_inplace_subtract, /* PyType_SetBinaryFunction */ + pytoe_number_inplace_multiply, /* PyType_SetBinaryFunction */ + pytoe_number_inplace_remainder, /* PyType_SetBinaryFunction */ + pytoe_number_inplace_power, /* PyType_SetTernaryFunction */ + pytoe_number_inplace_lshift, /* PyType_SetBinaryFunction */ + pytoe_number_inplace_rshift, /* PyType_SetBinaryFunction */ + pytoe_number_inplace_and, /* PyType_SetBinaryFunction */ + pytoe_number_inplace_xor, /* PyType_SetBinaryFunction */ + pytoe_number_inplace_or, /* PyType_SetBinaryFunction */ + pytoe_number_floor_divide, /* PyType_SetBinaryFunction */ + pytoe_number_true_divide, /* PyType_SetBinaryFunction */ + pytoe_number_inplace_floor_divide, /* PyType_SetBinaryFunction */ + pytoe_number_inplace_true_divide, /* PyType_SetBinaryFunction */ + pytoe_number_index, /* PyType_SetUnaryFunction */ -#ifdef COUNT_ALLOCS - /* these must be last and never explicitly initialized */ - Py_ssize_t tp_allocs; - Py_ssize_t tp_frees; - Py_ssize_t tp_maxalloc; - struct _typeobject *tp_prev; - struct _typeobject *tp_next; -#endif -} PyTypeObject; + /* sequence methods */ + pytoe_sequence_length, /* PyType_SetLengthFunction */ + pytoe_sequence_concat, /* PyType_SetBinaryFunction */ + pytoe_sequence_repeat, /* PyType_SetSSizeFunction */ + pytoe_sequence_item, /* PyType_SetSSizeFunction */ + pytoe_sequence_ass_item, /* PyType_SetSSizeObjectFunction */ + pytoe_sequence_contains, /* PyType_SetObjectFunction */ + pytoe_sequence_inplace_concat, /* PyType_SetBinaryFunction */ + pytoe_sequence_inplace_repeat, /* PyType_SetSSizeFunction */ + /* mapping methods */ + pytoe_mapping_length, /* PyType_SetLengthFunction */ + pytoe_mapping_subscript, /* PyType_SetBinaryFunction */ + pytoe_mapping_ass_subscript, /* PyType_SetObjectObjectFunction */ -/* The *real* layout of a type object when allocated on the heap */ -typedef struct _heaptypeobject { - /* Note: there's a dependency on the order of these members - in slotptr() in typeobject.c . */ - PyTypeObject ht_type; - PyNumberMethods as_number; - PyMappingMethods as_mapping; - PySequenceMethods as_sequence; /* as_sequence comes after as_mapping, - so that the mapping wins when both - the mapping and the sequence define - a given operator (e.g. __getitem__). - see add_operators() in typeobject.c . */ - PyBufferProcs as_buffer; - PyObject *ht_name, *ht_slots; - /* here are optional user slots, followed by the members. */ -} PyHeapTypeObject; + /* buffer methods */ + pytoe_buffer_getbuffer, /* PyType_SetBufferGetFunction */ + pytoe_buffer_releasebuffer, /* PyType_SetBufferReleaseFunction */ -/* access macro to the members which are floating "behind" the object */ -#define PyHeapType_GET_MEMBERS(etype) \ - ((PyMemberDef *)(((char *)etype) + Py_TYPE(etype)->tp_basicsize)) + /* force PyTypeObjectElement to be at least four bytes */ + _pytoe_four_bytes = 0x10000000 +} PyTypeObjectElement; + + +PyAPI_FUNC(PyTypeObject *) PyType_New(const char *name, Py_ssize_t size, PyTypeObject *basetype); +PyAPI_FUNC(int) PyType_Activate(PyTypeObject *type); + +PyAPI_FUNC(int) PyType_SetSize(PyTypeObject *type, PyTypeObjectElement element, Py_ssize_t value); +PyAPI_FUNC(int) PyType_SetLong(PyTypeObject *type, PyTypeObjectElement element, long value); +PyAPI_FUNC(int) PyType_SetFlag(PyTypeObject *type, PyTypeObjectElement element, int value); +PyAPI_FUNC(int) PyType_SetString(PyTypeObject *type, PyTypeObjectElement element, const char *value); +PyAPI_FUNC(int) PyType_SetPyObject(PyTypeObject *type, PyTypeObjectElement element, PyObject *value); +PyAPI_FUNC(int) PyType_SetPyTypeObject(PyTypeObject *type, PyTypeObjectElement element, PyTypeObject *value); +PyAPI_FUNC(int) PyType_SetUnaryFunction(PyTypeObject *type, PyTypeObjectElement element, unaryfunc value); +PyAPI_FUNC(int) PyType_SetBinaryFunction(PyTypeObject *type, PyTypeObjectElement element, binaryfunc value); +PyAPI_FUNC(int) PyType_SetTernaryFunction(PyTypeObject *type, PyTypeObjectElement element, ternaryfunc value); +PyAPI_FUNC(int) PyType_SetInquiryFunction(PyTypeObject *type, PyTypeObjectElement element, inquiry value); +PyAPI_FUNC(int) PyType_SetLengthFunction(PyTypeObject *type, PyTypeObjectElement element, lenfunc value); +PyAPI_FUNC(int) PyType_SetSSizeFunction(PyTypeObject *type, PyTypeObjectElement element, ssizeargfunc value); +PyAPI_FUNC(int) PyType_SetSSizeObjectFunction(PyTypeObject *type, PyTypeObjectElement element, ssizeobjargproc value); +PyAPI_FUNC(int) PyType_SetObjectFunction(PyTypeObject *type, PyTypeObjectElement element, objobjproc value); +PyAPI_FUNC(int) PyType_SetObjectObjectFunction(PyTypeObject *type, PyTypeObjectElement element, objobjargproc value); +PyAPI_FUNC(int) PyType_SetBufferGetFunction(PyTypeObject *type, PyTypeObjectElement element, getbufferproc value); +PyAPI_FUNC(int) PyType_SetBufferReleaseFunction(PyTypeObject *type, PyTypeObjectElement element, releasebufferproc value); +PyAPI_FUNC(int) PyType_SetDestructorFunction(PyTypeObject *type, PyTypeObjectElement element, destructor value); +PyAPI_FUNC(int) PyType_SetPrintFunction(PyTypeObject *type, PyTypeObjectElement element, printfunc value); +PyAPI_FUNC(int) PyType_SetAttrGetFunction(PyTypeObject *type, PyTypeObjectElement element, getattrfunc value); +PyAPI_FUNC(int) PyType_SetAttrSetFunction(PyTypeObject *type, PyTypeObjectElement element, setattrfunc value); +PyAPI_FUNC(int) PyType_SetReprFunction(PyTypeObject *type, PyTypeObjectElement element, reprfunc value); +PyAPI_FUNC(int) PyType_SetHashFunction(PyTypeObject *type, PyTypeObjectElement element, hashfunc value); +PyAPI_FUNC(int) PyType_SetAttrObjectGetFunction(PyTypeObject *type, PyTypeObjectElement element, getattrofunc value); +PyAPI_FUNC(int) PyType_SetAttrObjectSetFunction(PyTypeObject *type, PyTypeObjectElement element, setattrofunc value); +PyAPI_FUNC(int) PyType_SetTraverseFunction(PyTypeObject *type, PyTypeObjectElement element, traverseproc value); +PyAPI_FUNC(int) PyType_SetRichCompareFunction(PyTypeObject *type, PyTypeObjectElement element, richcmpfunc value); +PyAPI_FUNC(int) PyType_SetIteratorGetFunction(PyTypeObject *type, PyTypeObjectElement element, getiterfunc value); +PyAPI_FUNC(int) PyType_SetIteratorNextFunction(PyTypeObject *type, PyTypeObjectElement element, iternextfunc value); +PyAPI_FUNC(int) PyType_SetDescriptorGetFunction(PyTypeObject *type, PyTypeObjectElement element, descrgetfunc value); +PyAPI_FUNC(int) PyType_SetDescriptorSetFunction(PyTypeObject *type, PyTypeObjectElement element, descrsetfunc value); +PyAPI_FUNC(int) PyType_SetInitFunction(PyTypeObject *type, PyTypeObjectElement element, initproc value); +PyAPI_FUNC(int) PyType_SetAllocFunction(PyTypeObject *type, PyTypeObjectElement element, allocfunc value); +PyAPI_FUNC(int) PyType_SetNewFunction(PyTypeObject *type, PyTypeObjectElement element, newfunc value); +PyAPI_FUNC(int) PyType_SetFreeFunction(PyTypeObject *type, PyTypeObjectElement element, freefunc value); +PyAPI_FUNC(int) PyType_AppendTypeObject(PyTypeObject *type, PyTypeObjectElement element, PyTypeObject *value); +PyAPI_FUNC(int) PyType_AppendMethod(PyTypeObject *type, struct PyMethodDef *value); +PyAPI_FUNC(int) PyType_AppendMember(PyTypeObject *type, struct PyMemberDef *value); +PyAPI_FUNC(int) PyType_AppendProperty(PyTypeObject *type, struct PyGetSetDef *value); + +PyAPI_FUNC(Py_ssize_t) PyType_GetSize(PyTypeObject *type, PyTypeObjectElement element); +PyAPI_FUNC(long) PyType_GetLong(PyTypeObject *type, PyTypeObjectElement element); +PyAPI_FUNC(int) PyType_GetFlag(PyTypeObject *type, PyTypeObjectElement element); +PyAPI_FUNC(Py_ssize_t) PyType_GetSize(PyTypeObject *type, PyTypeObjectElement element); +PyAPI_FUNC(const char *) PyType_GetString(PyTypeObject *type, PyTypeObjectElement element); +PyAPI_FUNC(PyObject *) PyType_GetPyObject(PyTypeObject *type, PyTypeObjectElement element); +PyAPI_FUNC(PyTypeObject *) PyType_GetPyTypeObject(PyTypeObject *type, PyTypeObjectElement element); +PyAPI_FUNC(unaryfunc) PyType_GetUnaryFunction(PyTypeObject *type, PyTypeObjectElement element); +PyAPI_FUNC(binaryfunc) PyType_GetBinaryFunction(PyTypeObject *type, PyTypeObjectElement element); +PyAPI_FUNC(ternaryfunc) PyType_GetTernaryFunction(PyTypeObject *type, PyTypeObjectElement element); +PyAPI_FUNC(inquiry) PyType_GetInquiryFunction(PyTypeObject *type, PyTypeObjectElement element); +PyAPI_FUNC(lenfunc) PyType_GetLengthFunction(PyTypeObject *type, PyTypeObjectElement element); +PyAPI_FUNC(ssizeargfunc) PyType_GetSSizeFunction(PyTypeObject *type, PyTypeObjectElement element); +PyAPI_FUNC(ssizeobjargproc) PyType_GetSSizeObjectFunction(PyTypeObject *type, PyTypeObjectElement element); +PyAPI_FUNC(objobjproc) PyType_GetObjectFunction(PyTypeObject *type, PyTypeObjectElement element); +PyAPI_FUNC(getbufferproc) PyType_GetBufferGetFunction(PyTypeObject *type, PyTypeObjectElement element); +PyAPI_FUNC(releasebufferproc) PyType_GetBufferReleaseFunction(PyTypeObject *type, PyTypeObjectElement element); +PyAPI_FUNC(destructor) PyType_GetDestructorFunction(PyTypeObject *type, PyTypeObjectElement element); +PyAPI_FUNC(printfunc) PyType_GetPrintFunction(PyTypeObject *type, PyTypeObjectElement element); +PyAPI_FUNC(getattrfunc) PyType_GetAttrGetFunction(PyTypeObject *type, PyTypeObjectElement element); +PyAPI_FUNC(setattrfunc) PyType_GetAttrSetFunction(PyTypeObject *type, PyTypeObjectElement element); +PyAPI_FUNC(reprfunc) PyType_GetReprFunction(PyTypeObject *type, PyTypeObjectElement element); +PyAPI_FUNC(hashfunc) PyType_GetHashFunction(PyTypeObject *type, PyTypeObjectElement element); +PyAPI_FUNC(getattrofunc) PyType_GetAttrObjectGetFunction(PyTypeObject *type, PyTypeObjectElement element); +PyAPI_FUNC(setattrofunc) PyType_GetAttrObjectSetFunction(PyTypeObject *type, PyTypeObjectElement element); +PyAPI_FUNC(traverseproc) PyType_GetTraverseFunction(PyTypeObject *type, PyTypeObjectElement element); +PyAPI_FUNC(richcmpfunc) PyType_GetRichCompareFunction(PyTypeObject *type, PyTypeObjectElement element); +PyAPI_FUNC(getiterfunc) PyType_GetIteratorGetFunction(PyTypeObject *type, PyTypeObjectElement element); +PyAPI_FUNC(iternextfunc) PyType_GetIteratorNextFunction(PyTypeObject *type, PyTypeObjectElement element); +PyAPI_FUNC(descrgetfunc) PyType_GetDescriptorGetFunction(PyTypeObject *type, PyTypeObjectElement element); +PyAPI_FUNC(descrsetfunc) PyType_GetDescriptorSetFunction(PyTypeObject *type, PyTypeObjectElement element); +PyAPI_FUNC(initproc) PyType_GetInitFunction(PyTypeObject *type, PyTypeObjectElement element); +PyAPI_FUNC(allocfunc) PyType_GetAllocFunction(PyTypeObject *type, PyTypeObjectElement element); +PyAPI_FUNC(newfunc) PyType_GetNewFunction(PyTypeObject *type, PyTypeObjectElement element); +PyAPI_FUNC(freefunc) PyType_GetFreeFunction(PyTypeObject *type, PyTypeObjectElement element); +PyAPI_FUNC(PyTypeObject *) PyType_GetPyTypeByIndex(PyTypeObject *type, PyTypeObjectElement element, Py_ssize_t index); +PyAPI_FUNC(int) PyType_GetPyMethodByIndex(PyTypeObject *type, Py_ssize_t index); +PyAPI_FUNC(int) PyType_GetPyMemberByIndex(PyTypeObject *type, Py_ssize_t index); +PyAPI_FUNC(int) PyType_GetPyPropertyByIndex(PyTypeObject *type, Py_ssize_t index); + + +/* convenience */ +#define Py_TYPE_NAME(o) (PyType_GetString(Py_TYPE(o), pytoe_name)) + + + +PyAPI_FUNC(struct PyMethodDef *) PyMethodDef_New(const char *name, PyCFunction method, int flags, const char *docstring); +PyAPI_FUNC(struct PyMemberDef *) PyMember_New(const char *name, int type, Py_ssize_t offset, int flags, const char *docstring); +PyAPI_FUNC(struct PyGetSetDef *) PyProperty_New(const char *name, getter get, setter set, void *closure, const char *docstring); /* Generic type check */ @@ -401,13 +579,13 @@ #define PyObject_TypeCheck(ob, tp) \ (Py_TYPE(ob) == (tp) || PyType_IsSubtype(Py_TYPE(ob), (tp))) -PyAPI_DATA(PyTypeObject) PyType_Type; /* built-in 'type' */ -PyAPI_DATA(PyTypeObject) PyBaseObject_Type; /* built-in 'object' */ -PyAPI_DATA(PyTypeObject) PySuper_Type; /* built-in 'super' */ +PyAPI_DATA(PyTypeObject *) PyType_Type; +PyAPI_DATA(PyTypeObject *) PyBaseObject_Type; +PyAPI_DATA(PyTypeObject *) PySuper_Type; /* built-in 'super' */ #define PyType_Check(op) \ PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TYPE_SUBCLASS) -#define PyType_CheckExact(op) (Py_TYPE(op) == &PyType_Type) +#define PyType_CheckExact(op) (Py_TYPE(op) == PyType_Type) PyAPI_FUNC(int) PyType_Ready(PyTypeObject *); PyAPI_FUNC(PyObject *) PyType_GenericAlloc(PyTypeObject *, Py_ssize_t); @@ -515,6 +693,14 @@ #define Py_TPFLAGS_HAVE_STACKLESS_EXTENSION 0 #endif +/* Type was created using PyType_New(); +** this is only used to ensure you *don't* call +** PyType_Ready() on a dynamically-created type, and that +** you *don't* call PyType_Activate() on a non-dynamically-created +** type. +*/ +#define Py_TPFLAGS_DYNAMICALLY_CREATED (1L<<17) + /* Objects support type attribute cache */ #define Py_TPFLAGS_HAVE_VERSION_TAG (1L<<18) #define Py_TPFLAGS_VALID_VERSION_TAG (1L<<19) diff -r a156f602debc Include/objimpl.h --- a/Include/objimpl.h Tue Apr 28 12:42:20 2009 -0700 +++ b/Include/objimpl.h Tue Apr 28 19:26:52 2009 -0700 @@ -330,12 +330,6 @@ #define PyObject_FROM_GC(op) (op) -/* Test if a type supports weak references */ -#define PyType_SUPPORTS_WEAKREFS(t) ((t)->tp_weaklistoffset > 0) - -#define PyObject_GET_WEAKREFS_LISTPTR(o) \ - ((PyObject **) (((char *) (o)) + Py_TYPE(o)->tp_weaklistoffset)) - #ifdef __cplusplus } #endif diff -r a156f602debc Include/pyerrors.h --- a/Include/pyerrors.h Tue Apr 28 12:42:20 2009 -0700 +++ b/Include/pyerrors.h Tue Apr 28 19:26:52 2009 -0700 @@ -99,8 +99,7 @@ #define PyExceptionInstance_Check(x) \ PyType_FastSubclass((x)->ob_type, Py_TPFLAGS_BASE_EXC_SUBCLASS) -#define PyExceptionClass_Name(x) \ - ((char *)(((PyTypeObject*)(x))->tp_name)) +#define PyExceptionClass_Name(x) PyType_GetString((PyTypeObject *)x, pytoe_name) #define PyExceptionInstance_Class(x) ((PyObject*)((x)->ob_type)) diff -r a156f602debc Include/pythonrun.h --- a/Include/pythonrun.h Tue Apr 28 12:42:20 2009 -0700 +++ b/Include/pythonrun.h Tue Apr 28 19:26:52 2009 -0700 @@ -123,11 +123,8 @@ PyAPI_FUNC(PyObject *) _PyBuiltin_Init(void); PyAPI_FUNC(PyObject *) _PySys_Init(void); PyAPI_FUNC(void) _PyImport_Init(void); -PyAPI_FUNC(void) _PyExc_Init(void); +PyAPI_FUNC(int) PyExc_Init(void); PyAPI_FUNC(void) _PyImportHooks_Init(void); -PyAPI_FUNC(int) _PyFrame_Init(void); -PyAPI_FUNC(void) _PyFloat_Init(void); -PyAPI_FUNC(int) PyByteArray_Init(void); /* Various internal finalizers */ PyAPI_FUNC(void) _PyExc_Fini(void); diff -r a156f602debc Include/pytypeconvert.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Include/pytypeconvert.h Tue Apr 28 19:26:52 2009 -0700 @@ -0,0 +1,424 @@ +#ifndef __PYTYPEREADY_H +#define __PYTYPEREADY_H + +struct PyNumberMethods { + /* Number implementations must check *both* + arguments for proper type and implement the necessary conversions + in the slot functions themselves. */ + + binaryfunc nb_add; + binaryfunc nb_subtract; + binaryfunc nb_multiply; + binaryfunc nb_remainder; + binaryfunc nb_divmod; + ternaryfunc nb_power; + unaryfunc nb_negative; + unaryfunc nb_positive; + unaryfunc nb_absolute; + inquiry nb_bool; + unaryfunc nb_invert; + binaryfunc nb_lshift; + binaryfunc nb_rshift; + binaryfunc nb_and; + binaryfunc nb_xor; + binaryfunc nb_or; + unaryfunc nb_int; + void *nb_reserved; /* the slot formerly known as nb_long */ + unaryfunc nb_float; + + binaryfunc nb_inplace_add; + binaryfunc nb_inplace_subtract; + binaryfunc nb_inplace_multiply; + binaryfunc nb_inplace_remainder; + ternaryfunc nb_inplace_power; + binaryfunc nb_inplace_lshift; + binaryfunc nb_inplace_rshift; + binaryfunc nb_inplace_and; + binaryfunc nb_inplace_xor; + binaryfunc nb_inplace_or; + + binaryfunc nb_floor_divide; + binaryfunc nb_true_divide; + binaryfunc nb_inplace_floor_divide; + binaryfunc nb_inplace_true_divide; + + unaryfunc nb_index; +}; + +struct PySequenceMethods { + lenfunc sq_length; + binaryfunc sq_concat; + ssizeargfunc sq_repeat; + ssizeargfunc sq_item; + void *was_sq_slice; + ssizeobjargproc sq_ass_item; + void *was_sq_ass_slice; + objobjproc sq_contains; + + binaryfunc sq_inplace_concat; + ssizeargfunc sq_inplace_repeat; +}; + +struct PyMappingMethods { + lenfunc mp_length; + binaryfunc mp_subscript; + objobjargproc mp_ass_subscript; +}; + +struct PyBufferProcs { + getbufferproc bf_getbuffer; + releasebufferproc bf_releasebuffer; +}; + +struct _typeobject { + PyObject_VAR_HEAD + const char *tp_name; /* For printing, in format "." */ + Py_ssize_t tp_basicsize, tp_itemsize; /* For allocation */ + + /* Methods to implement standard operations */ + + destructor tp_dealloc; + printfunc tp_print; + getattrfunc tp_getattr; + setattrfunc tp_setattr; + void *tp_reserved; /* formerly known as tp_compare */ + reprfunc tp_repr; + + /* Method suites for standard classes */ + + PyNumberMethods *tp_as_number; + PySequenceMethods *tp_as_sequence; + PyMappingMethods *tp_as_mapping; + + /* More standard operations (here for binary compatibility) */ + + hashfunc tp_hash; + ternaryfunc tp_call; + reprfunc tp_str; + getattrofunc tp_getattro; + setattrofunc tp_setattro; + + /* Functions to access object as input/output buffer */ + PyBufferProcs *tp_as_buffer; + + /* Flags to define presence of optional/expanded features */ + long tp_flags; + + const char *tp_doc; /* Documentation string */ + + /* Assigned meaning in release 2.0 */ + /* call function for all accessible objects */ + traverseproc tp_traverse; + + /* delete references to contained objects */ + inquiry tp_clear; + + /* Assigned meaning in release 2.1 */ + /* rich comparisons */ + richcmpfunc tp_richcompare; + + /* weak reference enabler */ + Py_ssize_t tp_weaklistoffset; + + /* Iterators */ + getiterfunc tp_iter; + iternextfunc tp_iternext; + + /* Attribute descriptor and subclassing stuff */ + struct PyMethodDef *tp_methods; + struct PyMemberDef *tp_members; + struct PyGetSetDef *tp_getset; + struct _typeobject *tp_base; + PyObject *tp_dict; + descrgetfunc tp_descr_get; + descrsetfunc tp_descr_set; + Py_ssize_t tp_dictoffset; + initproc tp_init; + allocfunc tp_alloc; + newfunc tp_new; + freefunc tp_free; /* Low-level free-memory routine */ + inquiry tp_is_gc; /* For PyObject_IS_GC */ + PyObject *tp_bases; + PyObject *tp_mro; /* method resolution order */ + PyObject *tp_cache; + PyObject *tp_subclasses; + PyObject *tp_weaklist; + destructor tp_del; + + /* Type attribute cache version tag. Added in version 2.6 */ + unsigned int tp_version_tag; + + #ifdef COUNT_ALLOCS + /* these must be last and never explicitly initialized */ + Py_ssize_t tp_allocs; + Py_ssize_t tp_frees; + Py_ssize_t tp_maxalloc; + struct _typeobject *tp_prev; + struct _typeobject *tp_next; + #endif +}; + +/* The *real* layout of a type object when allocated on the heap */ +struct _heaptypeobject { + /* Note: there's a dependency on the order of these members + in slotptr() in typeobject.c . */ + PyTypeObject ht_type; + PyNumberMethods as_number; + PyMappingMethods as_mapping; + PySequenceMethods as_sequence; /* as_sequence comes after as_mapping, + so that the mapping wins when both + the mapping and the sequence define + a given operator (e.g. __getitem__). + see add_operators() in typeobject.c . */ + PyBufferProcs as_buffer; + PyObject *ht_name, *ht_slots; + /* here are optional user slots, followed by the members. */ +}; + +struct PyGetSetDef { + char *name; + getter get; + setter set; + char *doc; + void *closure; +}; + +struct PyMemberDef { + /* Current version, use this */ + char *name; + int type; + Py_ssize_t offset; + int flags; + char *doc; +}; + + +static PyTypeObject *PyType_Convert(PyTypeObject *t) +{ + PyMethodDef *method; + PyMemberDef *member; + PyGetSetDef *property; + PyTypeObject *basetype = (PyTypeObject *)t->tp_base; + + if (!basetype) + basetype = PyBaseObject_Type; + + PyTypeObject *type = PyType_New(t->tp_name, t->tp_basicsize, basetype); + if (!type) { + return NULL; + } + + /* handle flag */ +#define _HF(setter, name, field) \ + if (t->field) PyType_Set ## setter(type, name, t->field) + + /* as number / sequence / mapping / buffer */ +#define _HB_SUBELEMENT(subelement, setter, name, field) \ + if (t->subelement && t->subelement->field) PyType_Set ## setter(type, name, t->subelement->field) +#define _HF_NB(setter, name, field) _HB_SUBELEMENT(tp_as_number, setter, name, field) +#define _HF_SQ(setter, name, field) _HB_SUBELEMENT(tp_as_sequence, setter, name, field) +#define _HF_MP(setter, name, field) _HB_SUBELEMENT(tp_as_mapping, setter, name, field) +#define _HF_BF(setter, name, field) _HB_SUBELEMENT(tp_as_buffer, setter, name, field) + + _HF(Size, pytoe_object_refcnt, ob_base.ob_base.ob_refcnt); + _HF(Size, pytoe_object_size, ob_base.ob_size); + _HF(Size, pytoe_basicsize, tp_basicsize); + _HF(Size, pytoe_itemsize, tp_itemsize); + _HF(Size, pytoe_weaklistoffset, tp_weaklistoffset); + _HF(Size, pytoe_dictoffset, tp_dictoffset); + +#ifdef COUNT_ALLOCS + _HF(Size, pytoe_allocs, tp_allocs); + _HF(Size, pytoe_frees, tp_frees); + _HF(Size, pytoe_maxalloc, tp_maxalloc); +#endif /* COUNT_ALLOCS */ + + /* as flag */ +#define _HF_FLAG(name, bitfield) if (t->tp_flags & bitfield) PyType_SetFlag(type, name, 1) + + _HF_FLAG(pytoe_flag_heaptype, Py_TPFLAGS_HEAPTYPE); + _HF_FLAG(pytoe_flag_basetype, Py_TPFLAGS_BASETYPE); + _HF_FLAG(pytoe_flag_ready, Py_TPFLAGS_READY); + _HF_FLAG(pytoe_flag_readying, Py_TPFLAGS_READYING); + _HF_FLAG(pytoe_flag_have_gc, Py_TPFLAGS_HAVE_GC); + _HF_FLAG(pytoe_flag_have_stackless_extension, Py_TPFLAGS_HAVE_STACKLESS_EXTENSION); + _HF_FLAG(pytoe_flag_dynamically_created, Py_TPFLAGS_DYNAMICALLY_CREATED); + _HF_FLAG(pytoe_flag_have_version_flag, Py_TPFLAGS_HAVE_VERSION_TAG); + _HF_FLAG(pytoe_flag_valid_version_tag, Py_TPFLAGS_VALID_VERSION_TAG); + _HF_FLAG(pytoe_flag_is_abstract, Py_TPFLAGS_IS_ABSTRACT); + _HF_FLAG(pytoe_flag_int_subclass, Py_TPFLAGS_INT_SUBCLASS); + _HF_FLAG(pytoe_flag_long_subclass, Py_TPFLAGS_LONG_SUBCLASS); + _HF_FLAG(pytoe_flag_list_subclass, Py_TPFLAGS_LIST_SUBCLASS); + _HF_FLAG(pytoe_flag_tuple_subclass, Py_TPFLAGS_TUPLE_SUBCLASS); + _HF_FLAG(pytoe_flag_bytes_subclass, Py_TPFLAGS_BYTES_SUBCLASS); + _HF_FLAG(pytoe_flag_unicode_subclass, Py_TPFLAGS_UNICODE_SUBCLASS); + _HF_FLAG(pytoe_flag_dict_subclass, Py_TPFLAGS_DICT_SUBCLASS); + _HF_FLAG(pytoe_flag_base_exception_subclass, Py_TPFLAGS_BASE_EXC_SUBCLASS); + _HF_FLAG(pytoe_flag_type_subclass, Py_TPFLAGS_TYPE_SUBCLASS); + + _HF(String, pytoe_doc, tp_doc); + _HF(String, pytoe_name, tp_name); + +#ifdef COUNT_ALLOCS + _HF(PyObject, pytoe_object_next, _ob_next); + _HF(PyObject, pytoe_object_prev, _ob_prev); +#endif /* Py_TRACE_REFS */ + _HF(PyObject, pytoe_dict, tp_dict); + _HF(PyObject, pytoe_bases, tp_bases); + _HF(PyObject, pytoe_mro, tp_mro); + _HF(PyObject, pytoe_cache, tp_cache); + _HF(PyObject, pytoe_subclasses, tp_subclasses); + _HF(PyObject, pytoe_weaklist, tp_weaklist); + + _HF(PyTypeObject, pytoe_object_type, ob_base.ob_base.ob_type); +#ifdef COUNT_ALLOCS + _HF(PyTypeObject, pytoe_prev, tp_prev); + _HF(PyTypeObject, pytoe_next, tp_next); +#endif /* COUNT_ALLOCS */ + _HF(PyTypeObject, pytoe_base, tp_base); + + _HF_NB(UnaryFunction, pytoe_number_negative, nb_negative); + _HF_NB(UnaryFunction, pytoe_number_positive, nb_positive); + _HF_NB(UnaryFunction, pytoe_number_absolute, nb_absolute); + _HF_NB(UnaryFunction, pytoe_number_invert, nb_invert); + _HF_NB(UnaryFunction, pytoe_number_int, nb_int); + _HF_NB(UnaryFunction, pytoe_number_float, nb_float); + _HF_NB(UnaryFunction, pytoe_number_index, nb_index); + + _HF_NB(BinaryFunction, pytoe_number_add, nb_add); + _HF_NB(BinaryFunction, pytoe_number_subtract, nb_subtract); + _HF_NB(BinaryFunction, pytoe_number_multiply, nb_multiply); + _HF_NB(BinaryFunction, pytoe_number_remainder, nb_remainder); + _HF_NB(BinaryFunction, pytoe_number_divmod, nb_divmod); + _HF_NB(BinaryFunction, pytoe_number_lshift, nb_lshift); + _HF_NB(BinaryFunction, pytoe_number_rshift, nb_rshift); + _HF_NB(BinaryFunction, pytoe_number_and, nb_and); + _HF_NB(BinaryFunction, pytoe_number_xor, nb_xor); + _HF_NB(BinaryFunction, pytoe_number_or, nb_or); + _HF_NB(BinaryFunction, pytoe_number_inplace_add, nb_inplace_add); + _HF_NB(BinaryFunction, pytoe_number_inplace_subtract, nb_inplace_subtract); + _HF_NB(BinaryFunction, pytoe_number_inplace_multiply, nb_inplace_multiply); + _HF_NB(BinaryFunction, pytoe_number_inplace_remainder, nb_inplace_remainder); + _HF_NB(BinaryFunction, pytoe_number_inplace_lshift, nb_inplace_lshift); + _HF_NB(BinaryFunction, pytoe_number_inplace_rshift, nb_inplace_rshift); + _HF_NB(BinaryFunction, pytoe_number_inplace_and, nb_inplace_and); + _HF_NB(BinaryFunction, pytoe_number_inplace_xor, nb_inplace_xor); + _HF_NB(BinaryFunction, pytoe_number_inplace_or, nb_inplace_or); + _HF_NB(BinaryFunction, pytoe_number_floor_divide, nb_floor_divide); + _HF_NB(BinaryFunction, pytoe_number_true_divide, nb_true_divide); + _HF_NB(BinaryFunction, pytoe_number_inplace_floor_divide, nb_inplace_floor_divide); + _HF_NB(BinaryFunction, pytoe_number_inplace_true_divide, nb_inplace_true_divide); + _HF_SQ(BinaryFunction, pytoe_sequence_concat, sq_concat); + _HF_SQ(BinaryFunction, pytoe_sequence_inplace_concat, sq_inplace_concat); + _HF_MP(BinaryFunction, pytoe_mapping_subscript, mp_subscript); + + _HF(TernaryFunction, pytoe_call, tp_call); + _HF_NB(TernaryFunction, pytoe_number_power, nb_power); + _HF_NB(TernaryFunction, pytoe_number_inplace_power, nb_inplace_power); + + _HF(InquiryFunction, pytoe_clear, tp_clear); + _HF(InquiryFunction, pytoe_is_gc, tp_is_gc); + _HF_NB(InquiryFunction, pytoe_number_bool, nb_bool); + /* _HF_BF(InquiryFunction, pytoe_buffer_multisegment, bf_multisegment); */ + + _HF_SQ(LengthFunction, pytoe_sequence_length, sq_length); + _HF_MP(LengthFunction, pytoe_mapping_length, mp_length); + + _HF_SQ(SSizeFunction, pytoe_sequence_repeat, sq_repeat); + _HF_SQ(SSizeFunction, pytoe_sequence_item, sq_item); + _HF_SQ(SSizeFunction, pytoe_sequence_inplace_repeat, sq_inplace_repeat); + + _HF_SQ(SSizeObjectFunction, pytoe_sequence_ass_item, sq_ass_item); + + _HF_SQ(ObjectFunction, pytoe_sequence_contains, sq_contains); + + _HF_MP(ObjectObjectFunction, pytoe_mapping_ass_subscript, mp_ass_subscript); + + _HF_BF(BufferGetFunction, pytoe_buffer_getbuffer, bf_getbuffer); + + _HF_BF(BufferReleaseFunction, pytoe_buffer_releasebuffer, bf_releasebuffer); + + _HF(DestructorFunction, pytoe_dealloc, tp_dealloc); + _HF(DestructorFunction, pytoe_del, tp_del); + + _HF(PrintFunction, pytoe_print, tp_print); + + _HF(AttrGetFunction, pytoe_getattr, tp_getattr); + + _HF(AttrSetFunction, pytoe_setattr, tp_setattr); + + _HF(ReprFunction, pytoe_repr, tp_repr); + _HF(ReprFunction, pytoe_str, tp_str); + + _HF(HashFunction, pytoe_hash, tp_hash); + + _HF(AttrObjectGetFunction, pytoe_getattro, tp_getattro); + + _HF(AttrObjectSetFunction, pytoe_setattro, tp_setattro); + + _HF(TraverseFunction, pytoe_traverse, tp_traverse); + + _HF(RichCompareFunction, pytoe_richcompare, tp_richcompare); + + _HF(IteratorGetFunction, pytoe_iter, tp_iter); + + _HF(IteratorNextFunction, pytoe_iternext, tp_iternext); + + _HF(DescriptorGetFunction, pytoe_descr_get, tp_descr_get); + + _HF(DescriptorSetFunction, pytoe_descr_set, tp_descr_set); + + _HF(InitFunction, pytoe_init, tp_init); + + _HF(AllocFunction, pytoe_alloc, tp_alloc); + + _HF(NewFunction, pytoe_new, tp_new); + + _HF(FreeFunction, pytoe_free, tp_free); + + method = t->tp_methods; + if (method) + for (; method->ml_name != NULL; method++) { + PyType_AppendMethod(type, PyMethodDef_New(method->ml_name, method->ml_meth, method->ml_flags, method->ml_doc)); + } + + member = t->tp_members; + if (member) + for (; member->name != NULL; member++) { + PyType_AppendMember(type, PyMember_New(member->name, member->type, member->offset, member->flags, member->doc)); + } + + property = t->tp_getset; + if (property) + for (; property->name != NULL; property++) { + PyType_AppendProperty(type, PyProperty_New(property->name, property->get, property->set, property->closure, property->doc)); + } + + PyType_Activate(type); + return type; +} + +#undef _HF + + +/* convenience macro + assumes that you change the declaration of your type from: + PyTypeObject PyFoo_Type + to: + PyTypeObject *PyFoo_Type; + PyTypeObject _PyFoo_Type; +*/ + +#define CONVERT_TYPE(name, metaclass, baseclass, description) \ +_ ## name.ob_base.ob_base.ob_type = metaclass; \ +_ ## name.tp_base = baseclass; \ +if ((name = PyType_Convert(&_ ## name)) == 0) { \ + Py_FatalError("Can't initialize " description); \ + return -1; \ +} \ + + + +#endif /* __PYTYPEREADY_H */ + + diff -r a156f602debc Include/rangeobject.h --- a/Include/rangeobject.h Tue Apr 28 12:42:20 2009 -0700 +++ b/Include/rangeobject.h Tue Apr 28 19:26:52 2009 -0700 @@ -15,11 +15,13 @@ they are represented by a start, stop, and step datamembers. */ -PyAPI_DATA(PyTypeObject) PyRange_Type; -PyAPI_DATA(PyTypeObject) PyRangeIter_Type; -PyAPI_DATA(PyTypeObject) PyLongRangeIter_Type; +PyAPI_DATA(PyTypeObject *) PyRange_Type; +PyAPI_DATA(PyTypeObject *) PyRangeIter_Type; +PyAPI_DATA(PyTypeObject *) PyLongRangeIter_Type; -#define PyRange_Check(op) (Py_TYPE(op) == &PyRange_Type) +#define PyRange_Check(op) (Py_TYPE(op) == PyRange_Type) + +PyAPI_FUNC(int) PyRange_Init(void); #ifdef __cplusplus } diff -r a156f602debc Include/setobject.h --- a/Include/setobject.h Tue Apr 28 12:42:20 2009 -0700 +++ b/Include/setobject.h Tue Apr 28 19:26:52 2009 -0700 @@ -56,9 +56,11 @@ PyObject *weakreflist; /* List of weak references */ }; -PyAPI_DATA(PyTypeObject) PySet_Type; -PyAPI_DATA(PyTypeObject) PyFrozenSet_Type; -PyAPI_DATA(PyTypeObject) PySetIter_Type; +PyAPI_FUNC(int) PySet_Init(void); + +PyAPI_DATA(PyTypeObject *) PySet_Type; +PyAPI_DATA(PyTypeObject *) PyFrozenSet_Type; +PyAPI_DATA(PyTypeObject *) PySetIter_Type; /* Invariants for frozensets: * data is immutable. @@ -67,19 +69,19 @@ * hash is -1 */ -#define PyFrozenSet_CheckExact(ob) (Py_TYPE(ob) == &PyFrozenSet_Type) +#define PyFrozenSet_CheckExact(ob) (Py_TYPE(ob) == PyFrozenSet_Type) #define PyAnySet_CheckExact(ob) \ - (Py_TYPE(ob) == &PySet_Type || Py_TYPE(ob) == &PyFrozenSet_Type) + (Py_TYPE(ob) == PySet_Type || Py_TYPE(ob) == PyFrozenSet_Type) #define PyAnySet_Check(ob) \ - (Py_TYPE(ob) == &PySet_Type || Py_TYPE(ob) == &PyFrozenSet_Type || \ - PyType_IsSubtype(Py_TYPE(ob), &PySet_Type) || \ - PyType_IsSubtype(Py_TYPE(ob), &PyFrozenSet_Type)) + (Py_TYPE(ob) == PySet_Type || Py_TYPE(ob) == PyFrozenSet_Type || \ + PyType_IsSubtype(Py_TYPE(ob), PySet_Type) || \ + PyType_IsSubtype(Py_TYPE(ob), PyFrozenSet_Type)) #define PySet_Check(ob) \ - (Py_TYPE(ob) == &PySet_Type || \ - PyType_IsSubtype(Py_TYPE(ob), &PySet_Type)) + (Py_TYPE(ob) == PySet_Type || \ + PyType_IsSubtype(Py_TYPE(ob), PySet_Type)) #define PyFrozenSet_Check(ob) \ - (Py_TYPE(ob) == &PyFrozenSet_Type || \ - PyType_IsSubtype(Py_TYPE(ob), &PyFrozenSet_Type)) + (Py_TYPE(ob) == PyFrozenSet_Type || \ + PyType_IsSubtype(Py_TYPE(ob), PyFrozenSet_Type)) PyAPI_FUNC(PyObject *) PySet_New(PyObject *); PyAPI_FUNC(PyObject *) PyFrozenSet_New(PyObject *); diff -r a156f602debc Include/sliceobject.h --- a/Include/sliceobject.h Tue Apr 28 12:42:20 2009 -0700 +++ b/Include/sliceobject.h Tue Apr 28 19:26:52 2009 -0700 @@ -24,10 +24,10 @@ PyObject *start, *stop, *step; /* not NULL */ } PySliceObject; -PyAPI_DATA(PyTypeObject) PySlice_Type; -PyAPI_DATA(PyTypeObject) PyEllipsis_Type; +PyAPI_DATA(PyTypeObject *) PySlice_Type; +PyAPI_DATA(PyTypeObject *) PyEllipsis_Type; -#define PySlice_Check(op) (Py_TYPE(op) == &PySlice_Type) +#define PySlice_Check(op) (Py_TYPE(op) == PySlice_Type) PyAPI_FUNC(PyObject *) PySlice_New(PyObject* start, PyObject* stop, PyObject* step); @@ -38,6 +38,8 @@ Py_ssize_t *start, Py_ssize_t *stop, Py_ssize_t *step, Py_ssize_t *slicelength); +PyAPI_FUNC(int) PySlice_Init(void); + #ifdef __cplusplus } #endif diff -r a156f602debc Include/structmember.h --- a/Include/structmember.h Tue Apr 28 12:42:20 2009 -0700 +++ b/Include/structmember.h Tue Apr 28 19:26:52 2009 -0700 @@ -25,6 +25,7 @@ flag is set). The array must be terminated with an entry whose name pointer is NULL. */ +#if 0 typedef struct PyMemberDef { /* Current version, use this */ char *name; @@ -33,6 +34,7 @@ int flags; char *doc; } PyMemberDef; +#endif /* 0 */ /* Types */ #define T_SHORT 0 diff -r a156f602debc Include/structseq.h --- a/Include/structseq.h Tue Apr 28 12:42:20 2009 -0700 +++ b/Include/structseq.h Tue Apr 28 19:26:52 2009 -0700 @@ -21,8 +21,7 @@ extern char* PyStructSequence_UnnamedField; -PyAPI_FUNC(void) PyStructSequence_InitType(PyTypeObject *type, - PyStructSequence_Desc *desc); +PyAPI_FUNC(PyTypeObject *) PyStructSequence_InitType(PyStructSequence_Desc *desc); PyAPI_FUNC(PyObject *) PyStructSequence_New(PyTypeObject* type); diff -r a156f602debc Include/symtable.h --- a/Include/symtable.h Tue Apr 28 12:42:20 2009 -0700 +++ b/Include/symtable.h Tue Apr 28 19:26:52 2009 -0700 @@ -51,9 +51,9 @@ struct symtable *ste_table; } PySTEntryObject; -PyAPI_DATA(PyTypeObject) PySTEntry_Type; +PyAPI_DATA(PyTypeObject *) PySTEntry_Type; -#define PySTEntry_Check(op) (Py_TYPE(op) == &PySTEntry_Type) +#define PySTEntry_Check(op) (Py_TYPE(op) == PySTEntry_Type) PyAPI_FUNC(int) PyST_GetScope(PySTEntryObject *, PyObject *); @@ -100,6 +100,9 @@ #define GENERATOR 1 #define GENERATOR_EXPRESSION 2 +PyAPI_FUNC(int) PySymtable_Init(void); + + #ifdef __cplusplus } #endif diff -r a156f602debc Include/traceback.h --- a/Include/traceback.h Tue Apr 28 12:42:20 2009 -0700 +++ b/Include/traceback.h Tue Apr 28 19:26:52 2009 -0700 @@ -22,8 +22,10 @@ PyAPI_FUNC(int) _Py_DisplaySourceLine(PyObject *, const char *, int, int); /* Reveal traceback type so we can typecheck traceback objects */ -PyAPI_DATA(PyTypeObject) PyTraceBack_Type; -#define PyTraceBack_Check(v) (Py_TYPE(v) == &PyTraceBack_Type) +PyAPI_DATA(PyTypeObject *) PyTraceBack_Type; +#define PyTraceBack_Check(v) (Py_TYPE(v) == PyTraceBack_Type) + +PyAPI_FUNC(int) PyTraceBack_Init(void); #ifdef __cplusplus } diff -r a156f602debc Include/tupleobject.h --- a/Include/tupleobject.h Tue Apr 28 12:42:20 2009 -0700 +++ b/Include/tupleobject.h Tue Apr 28 19:26:52 2009 -0700 @@ -31,12 +31,12 @@ */ } PyTupleObject; -PyAPI_DATA(PyTypeObject) PyTuple_Type; -PyAPI_DATA(PyTypeObject) PyTupleIter_Type; +PyAPI_DATA(PyTypeObject *) PyTuple_Type; +PyAPI_DATA(PyTypeObject *) PyTupleIter_Type; #define PyTuple_Check(op) \ PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TUPLE_SUBCLASS) -#define PyTuple_CheckExact(op) (Py_TYPE(op) == &PyTuple_Type) +#define PyTuple_CheckExact(op) (Py_TYPE(op) == PyTuple_Type) PyAPI_FUNC(PyObject *) PyTuple_New(Py_ssize_t size); PyAPI_FUNC(Py_ssize_t) PyTuple_Size(PyObject *); @@ -56,6 +56,8 @@ PyAPI_FUNC(int) PyTuple_ClearFreeList(void); +PyAPI_FUNC(int) PyTuple_Init(void); + #ifdef __cplusplus } #endif diff -r a156f602debc Include/unicodeobject.h --- a/Include/unicodeobject.h Tue Apr 28 12:42:20 2009 -0700 +++ b/Include/unicodeobject.h Tue Apr 28 19:26:52 2009 -0700 @@ -445,8 +445,8 @@ implementing the buffer protocol */ } PyUnicodeObject; -PyAPI_DATA(PyTypeObject) PyUnicode_Type; -PyAPI_DATA(PyTypeObject) PyUnicodeIter_Type; +PyAPI_DATA(PyTypeObject *) PyUnicode_Type; +PyAPI_DATA(PyTypeObject *) PyUnicodeIter_Type; #define SSTATE_NOT_INTERNED 0 #define SSTATE_INTERNED_MORTAL 1 @@ -454,7 +454,7 @@ #define PyUnicode_Check(op) \ PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_UNICODE_SUBCLASS) -#define PyUnicode_CheckExact(op) (Py_TYPE(op) == &PyUnicode_Type) +#define PyUnicode_CheckExact(op) (Py_TYPE(op) == PyUnicode_Type) /* Fast access macros */ #define PyUnicode_GET_SIZE(op) \ @@ -1598,6 +1598,9 @@ const Py_UNICODE *s, Py_UNICODE c ); + +PyAPI_FUNC(int) PyUnicode_Init(void); + #ifdef __cplusplus } #endif diff -r a156f602debc Include/weakrefobject.h --- a/Include/weakrefobject.h Tue Apr 28 12:42:20 2009 -0700 +++ b/Include/weakrefobject.h Tue Apr 28 19:26:52 2009 -0700 @@ -38,16 +38,16 @@ PyWeakReference *wr_next; }; -PyAPI_DATA(PyTypeObject) _PyWeakref_RefType; -PyAPI_DATA(PyTypeObject) _PyWeakref_ProxyType; -PyAPI_DATA(PyTypeObject) _PyWeakref_CallableProxyType; +PyAPI_DATA(PyTypeObject *) _PyWeakref_RefType; +PyAPI_DATA(PyTypeObject *) _PyWeakref_ProxyType; +PyAPI_DATA(PyTypeObject *) _PyWeakref_CallableProxyType; -#define PyWeakref_CheckRef(op) PyObject_TypeCheck(op, &_PyWeakref_RefType) +#define PyWeakref_CheckRef(op) PyObject_TypeCheck(op, _PyWeakref_RefType) #define PyWeakref_CheckRefExact(op) \ - (Py_TYPE(op) == &_PyWeakref_RefType) + (Py_TYPE(op) == _PyWeakref_RefType) #define PyWeakref_CheckProxy(op) \ - ((Py_TYPE(op) == &_PyWeakref_ProxyType) || \ - (Py_TYPE(op) == &_PyWeakref_CallableProxyType)) + ((Py_TYPE(op) == _PyWeakref_ProxyType) || \ + (Py_TYPE(op) == _PyWeakref_CallableProxyType)) /* This macro calls PyWeakref_CheckRef() last since that can involve a function call; this makes it more likely that the function call @@ -68,6 +68,14 @@ #define PyWeakref_GET_OBJECT(ref) (((PyWeakReference *)(ref))->wr_object) +/* Test if a type supports weak references */ +#define PyType_SUPPORTS_WEAKREFS(t) ((t)->tp_weaklistoffset > 0) + +#define PyObject_GET_WEAKREFS_LISTPTR(o) \ + ((PyObject **) (((char *) (o)) + Py_TYPE(o)->tp_weaklistoffset)) + + +PyAPI_FUNC(int) PyWeakref_Init(void); #ifdef __cplusplus } diff -r a156f602debc Modules/_bisectmodule.c --- a/Modules/_bisectmodule.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/_bisectmodule.c Tue Apr 28 19:26:52 2009 -0700 @@ -3,7 +3,9 @@ Converted to C by Dmitry Vasiliev (dima at hlabs.spb.ru). */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "../Objects/typeprivate.h" static Py_ssize_t internal_bisect_right(PyObject *list, PyObject *item, Py_ssize_t lo, Py_ssize_t hi) diff -r a156f602debc Modules/_codecsmodule.c --- a/Modules/_codecsmodule.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/_codecsmodule.c Tue Apr 28 19:26:52 2009 -0700 @@ -170,7 +170,7 @@ PyObject *v; if (!PyArg_ParseTuple(args, "O!|z:escape_encode", - &PyBytes_Type, &str, &errors)) + PyBytes_Type, &str, &errors)) return NULL; size = PyBytes_GET_SIZE(str); diff -r a156f602debc Modules/_collectionsmodule.c --- a/Modules/_collectionsmodule.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/_collectionsmodule.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,4 +1,6 @@ +#define PY_TYPEPRIVATE #include "Python.h" +#include "../Objects/typeprivate.h" #include "structmember.h" /* collections module implementation of a deque() datatype @@ -1251,7 +1253,7 @@ defdict_dealloc(defdictobject *dd) { Py_CLEAR(dd->default_factory); - PyDict_Type.tp_dealloc((PyObject *)dd); + PyDict_Type->tp_dealloc((PyObject *)dd); } static PyObject * @@ -1260,7 +1262,7 @@ PyObject *baserepr; PyObject *defrepr; PyObject *result; - baserepr = PyDict_Type.tp_repr((PyObject *)dd); + baserepr = PyDict_Type->tp_repr((PyObject *)dd); if (baserepr == NULL) return NULL; if (dd->default_factory == NULL) @@ -1292,14 +1294,14 @@ defdict_traverse(PyObject *self, visitproc visit, void *arg) { Py_VISIT(((defdictobject *)self)->default_factory); - return PyDict_Type.tp_traverse(self, visit, arg); + return PyDict_Type->tp_traverse(self, visit, arg); } static int defdict_tp_clear(defdictobject *dd) { Py_CLEAR(dd->default_factory); - return PyDict_Type.tp_clear((PyObject *)dd); + return PyDict_Type->tp_clear((PyObject *)dd); } static int @@ -1328,7 +1330,7 @@ return -1; Py_XINCREF(newdefault); dd->default_factory = newdefault; - result = PyDict_Type.tp_init(self, newargs, kwds); + result = PyDict_Type->tp_init(self, newargs, kwds); Py_DECREF(newargs); Py_XDECREF(olddefault); return result; @@ -1346,7 +1348,7 @@ #define DEFERRED_ADDRESS(ADDR) 0 static PyTypeObject defdict_type = { - PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0) + PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(PyType_Type), 0) "collections.defaultdict", /* tp_name */ sizeof(defdictobject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -1378,7 +1380,7 @@ defdict_methods, /* tp_methods */ defdict_members, /* tp_members */ 0, /* tp_getset */ - DEFERRED_ADDRESS(&PyDict_Type), /* tp_base */ + 0, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ @@ -1424,7 +1426,7 @@ Py_INCREF(&deque_type); PyModule_AddObject(m, "deque", (PyObject *)&deque_type); - defdict_type.tp_base = &PyDict_Type; + defdict_type.tp_base = PyDict_Type; if (PyType_Ready(&defdict_type) < 0) return NULL; Py_INCREF(&defdict_type); diff -r a156f602debc Modules/_csv.c --- a/Modules/_csv.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/_csv.c Tue Apr 28 19:26:52 2009 -0700 @@ -14,7 +14,9 @@ #define MODULE_VERSION "1.0" +#define PY_TYPEPRIVATE #include "Python.h" +#include "../Objects/typeprivate.h" #include "structmember.h" #define IS_BASESTRING(o) \ diff -r a156f602debc Modules/_ctypes/_ctypes.c --- a/Modules/_ctypes/_ctypes.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/_ctypes/_ctypes.c Tue Apr 28 19:26:52 2009 -0700 @@ -101,7 +101,9 @@ #define PY_SSIZE_T_CLEAN +#define PY_TYPEPRIVATE #include "Python.h" +#include "../../Objects/typeprivate.h" #include "structmember.h" #include @@ -331,7 +333,7 @@ /* create the new instance (which is a class, since we are a metatype!) */ - result = (PyTypeObject *)PyType_Type.tp_new(type, args, kwds); + result = (PyTypeObject *)PyType_Type->tp_new(type, args, kwds); if (!result) return NULL; @@ -664,7 +666,7 @@ StgDictObject *dict = PyType_stgdict((PyObject *)self); if (dict) Py_CLEAR(dict->proto); - return PyType_Type.tp_clear((PyObject *)self); + return PyType_Type->tp_clear((PyObject *)self); } static int @@ -673,14 +675,14 @@ StgDictObject *dict = PyType_stgdict((PyObject *)self); if (dict) Py_VISIT(dict->proto); - return PyType_Type.tp_traverse((PyObject *)self, visit, arg); + return PyType_Type->tp_traverse((PyObject *)self, visit, arg); } static int PyCStructType_setattro(PyObject *self, PyObject *key, PyObject *value) { /* XXX Should we disallow deleting _fields_? */ - if (-1 == PyType_Type.tp_setattro(self, key, value)) + if (-1 == PyType_Type->tp_setattro(self, key, value)) return -1; if (value && PyUnicode_Check(key) && @@ -892,7 +894,7 @@ /* create the new instance (which is a class, since we are a metatype!) */ - result = (PyTypeObject *)PyType_Type.tp_new(type, args, kwds); + result = (PyTypeObject *)PyType_Type->tp_new(type, args, kwds); if (result == NULL) { Py_DECREF((PyObject *)stgdict); return NULL; @@ -1353,7 +1355,7 @@ /* create the new instance (which is a class, since we are a metatype!) */ - result = (PyTypeObject *)PyType_Type.tp_new(type, args, kwds); + result = (PyTypeObject *)PyType_Type->tp_new(type, args, kwds); if (result == NULL) return NULL; @@ -1750,7 +1752,7 @@ /* create the new instance (which is a class, since we are a metatype!) */ - result = (PyTypeObject *)PyType_Type.tp_new(type, swapped_args, kwds); + result = (PyTypeObject *)PyType_Type->tp_new(type, swapped_args, kwds); Py_DECREF(swapped_args); if (result == NULL) return NULL; @@ -1823,7 +1825,7 @@ /* create the new instance (which is a class, since we are a metatype!) */ - result = (PyTypeObject *)PyType_Type.tp_new(type, args, kwds); + result = (PyTypeObject *)PyType_Type->tp_new(type, args, kwds); if (result == NULL) return NULL; @@ -2246,7 +2248,7 @@ /* create the new instance (which is a class, since we are a metatype!) */ - result = (PyTypeObject *)PyType_Type.tp_new(type, args, kwds); + result = (PyTypeObject *)PyType_Type->tp_new(type, args, kwds); if (result == NULL) { Py_DECREF((PyObject *)stgdict); return NULL; @@ -5274,7 +5276,7 @@ return NULL; /* StgDict is derived from PyDict_Type */ - PyCStgDict_Type.tp_base = &PyDict_Type; + PyCStgDict_Type.tp_base = PyDict_Type; if (PyType_Ready(&PyCStgDict_Type) < 0) return NULL; @@ -5283,27 +5285,27 @@ * Metaclasses */ - PyCStructType_Type.tp_base = &PyType_Type; + PyCStructType_Type.tp_base = PyType_Type; if (PyType_Ready(&PyCStructType_Type) < 0) return NULL; - UnionType_Type.tp_base = &PyType_Type; + UnionType_Type.tp_base = PyType_Type; if (PyType_Ready(&UnionType_Type) < 0) return NULL; - PyCPointerType_Type.tp_base = &PyType_Type; + PyCPointerType_Type.tp_base = PyType_Type; if (PyType_Ready(&PyCPointerType_Type) < 0) return NULL; - PyCArrayType_Type.tp_base = &PyType_Type; + PyCArrayType_Type.tp_base = PyType_Type; if (PyType_Ready(&PyCArrayType_Type) < 0) return NULL; - PyCSimpleType_Type.tp_base = &PyType_Type; + PyCSimpleType_Type.tp_base = PyType_Type; if (PyType_Ready(&PyCSimpleType_Type) < 0) return NULL; - PyCFuncPtrType_Type.tp_base = &PyType_Type; + PyCFuncPtrType_Type.tp_base = PyType_Type; if (PyType_Ready(&PyCFuncPtrType_Type) < 0) return NULL; diff -r a156f602debc Modules/_ctypes/_ctypes_test.c --- a/Modules/_ctypes/_ctypes_test.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/_ctypes/_ctypes_test.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,4 +1,6 @@ -#include +#define PY_TYPEPRIVATE +#include "Python.h" +#include "../../Objects/typeprivate.h" #ifdef MS_WIN32 #include diff -r a156f602debc Modules/_ctypes/callbacks.c --- a/Modules/_ctypes/callbacks.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/_ctypes/callbacks.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,4 +1,6 @@ +#define PY_TYPEPRIVATE #include "Python.h" +#include "../../Objects/typeprivate.h" #include "frameobject.h" #include @@ -463,6 +465,7 @@ return NULL; } + #ifdef MS_WIN32 static void LoadPython(void) diff -r a156f602debc Modules/_ctypes/callproc.c --- a/Modules/_ctypes/callproc.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/_ctypes/callproc.c Tue Apr 28 19:26:52 2009 -0700 @@ -54,7 +54,9 @@ */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "../../Objects/typeprivate.h" #include "structmember.h" #ifdef MS_WIN32 @@ -1279,8 +1281,8 @@ if (!PyArg_ParseTuple(args, "OiO!|O!", &pcom, &index, - &PyTuple_Type, &arguments, - &PyTuple_Type, &argtypes)) + PyTuple_Type, &arguments, + PyTuple_Type, &argtypes)) return NULL; if (argtypes && (PyTuple_GET_SIZE(arguments) != PyTuple_GET_SIZE(argtypes))) { @@ -1426,7 +1428,7 @@ if (!PyArg_ParseTuple(args, "O&O!", &_parse_voidp, &func, - &PyTuple_Type, &arguments)) + PyTuple_Type, &arguments)) return NULL; result = _ctypes_callproc((PPROC)func, @@ -1457,7 +1459,7 @@ if (!PyArg_ParseTuple(args, "O&O!", &_parse_voidp, &func, - &PyTuple_Type, &arguments)) + PyTuple_Type, &arguments)) return NULL; result = _ctypes_callproc((PPROC)func, diff -r a156f602debc Modules/_ctypes/cfield.c --- a/Modules/_ctypes/cfield.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/_ctypes/cfield.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,4 +1,6 @@ +#define PY_TYPEPRIVATE #include "Python.h" +#include "../../Objects/typeprivate.h" #include #ifdef MS_WIN32 diff -r a156f602debc Modules/_ctypes/malloc_closure.c --- a/Modules/_ctypes/malloc_closure.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/_ctypes/malloc_closure.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,4 +1,6 @@ -#include +#define PY_TYPEPRIVATE +#include "Python.h" +#include "../../Objects/typeprivate.h" #include #ifdef MS_WIN32 #include diff -r a156f602debc Modules/_ctypes/stgdict.c --- a/Modules/_ctypes/stgdict.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/_ctypes/stgdict.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,4 +1,6 @@ +#define PY_TYPEPRIVATE #include "Python.h" +#include "../../Objects/typeprivate.h" #include #ifdef MS_WIN32 #include @@ -19,7 +21,7 @@ static int PyCStgDict_init(StgDictObject *self, PyObject *args, PyObject *kwds) { - if (PyDict_Type.tp_init((PyObject *)self, args, kwds) < 0) + if (PyDict_Type->tp_init((PyObject *)self, args, kwds) < 0) return -1; self->format = NULL; self->ndim = 0; @@ -45,7 +47,7 @@ PyMem_Free(self->format); PyMem_Free(self->shape); PyMem_Free(self->ffi_type_pointer.elements); - PyDict_Type.tp_dealloc((PyObject *)self); + PyDict_Type->tp_dealloc((PyObject *)self); } int diff -r a156f602debc Modules/_curses_panel.c --- a/Modules/_curses_panel.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/_curses_panel.c Tue Apr 28 19:26:52 2009 -0700 @@ -10,7 +10,9 @@ /* Includes */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "../Objects/typeprivate.h" #include "py_curses.h" diff -r a156f602debc Modules/_cursesmodule.c --- a/Modules/_cursesmodule.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/_cursesmodule.c Tue Apr 28 19:26:52 2009 -0700 @@ -102,7 +102,9 @@ /* Includes */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "../Objects/typeprivate.h" #ifdef __osf__ #define STRICT_SYSV_CURSES /* Don't use ncurses extensions */ diff -r a156f602debc Modules/_dbmmodule.c --- a/Modules/_dbmmodule.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/_dbmmodule.c Tue Apr 28 19:26:52 2009 -0700 @@ -3,7 +3,9 @@ #define PY_SSIZE_T_CLEAN +#define PY_TYPEPRIVATE #include "Python.h" +#include "../Objects/typeprivate.h" #include #include diff -r a156f602debc Modules/_elementtree.c --- a/Modules/_elementtree.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/_elementtree.c Tue Apr 28 19:26:52 2009 -0700 @@ -46,7 +46,9 @@ /* Licensed to PSF under a Contributor Agreement. */ /* See http://www.python.org/2.4/license for licensing details. */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "../Objects/typeprivate.h" #define VERSION "1.0.6" @@ -465,7 +467,7 @@ PyObject* tag; PyObject* attrib = NULL; if (!PyArg_ParseTuple(args, "O|O!:Element", &tag, - &PyDict_Type, &attrib)) + PyDict_Type, &attrib)) return NULL; if (attrib || kw) { @@ -496,7 +498,7 @@ PyObject* attrib = NULL; if (!PyArg_ParseTuple(args, "O!O|O!:SubElement", &Element_Type, &parent, &tag, - &PyDict_Type, &attrib)) + PyDict_Type, &attrib)) return NULL; if (attrib || kw) { @@ -2431,7 +2433,7 @@ PyObject* events; /* event collector */ PyObject* event_set = Py_None; - if (!PyArg_ParseTuple(args, "O!|O:_setevents", &PyList_Type, &events, + if (!PyArg_ParseTuple(args, "O!|O:_setevents", PyList_Type, &events, &event_set)) return NULL; diff -r a156f602debc Modules/_functoolsmodule.c --- a/Modules/_functoolsmodule.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/_functoolsmodule.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,5 +1,7 @@ +#define PY_TYPEPRIVATE #include "Python.h" +#include "../Objects/typeprivate.h" #include "structmember.h" /* _functools module written and maintained diff -r a156f602debc Modules/_gdbmmodule.c --- a/Modules/_gdbmmodule.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/_gdbmmodule.c Tue Apr 28 19:26:52 2009 -0700 @@ -4,7 +4,9 @@ /* Doc strings: Mitch Chapman */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "../Objects/typeprivate.h" #include #include diff -r a156f602debc Modules/_hashopenssl.c --- a/Modules/_hashopenssl.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/_hashopenssl.c Tue Apr 28 19:26:52 2009 -0700 @@ -13,7 +13,9 @@ #define PY_SSIZE_T_CLEAN +#define PY_TYPEPRIVATE #include "Python.h" +#include "../Objects/typeprivate.h" #include "structmember.h" #include "hashlib.h" @@ -595,7 +597,7 @@ * but having some be unsupported. Only init appropriate * constants. */ - Py_TYPE(&EVPtype) = &PyType_Type; + Py_TYPE(&EVPtype) = PyType_Type; if (PyType_Ready(&EVPtype) < 0) return NULL; diff -r a156f602debc Modules/_io/_iomodule.c --- a/Modules/_io/_iomodule.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/_io/_iomodule.c Tue Apr 28 19:26:52 2009 -0700 @@ -8,7 +8,9 @@ */ #define PY_SSIZE_T_CLEAN +#define PY_TYPEPRIVATE #include "Python.h" +#include "pytypeconvert.h" #include "structmember.h" #include "_iomodule.h" @@ -167,7 +169,7 @@ 0, /* tp_alloc */ 0, /* tp_new */ }; -PyObject *PyExc_BlockingIOError = (PyObject *)&_PyExc_BlockingIOError; +PyObject *PyExc_BlockingIOError = NULL; /* @@ -394,7 +396,7 @@ } /* Create the Raw file stream */ - raw = PyObject_CallFunction((PyObject *)&PyFileIO_Type, + raw = PyObject_CallFunction((PyObject *)PyFileIO_Type, "Osi", file, rawmode, closefd); if (raw == NULL) return NULL; @@ -464,11 +466,11 @@ PyObject *Buffered_class; if (updating) - Buffered_class = (PyObject *)&PyBufferedRandom_Type; + Buffered_class = (PyObject *)PyBufferedRandom_Type; else if (writing || appending) - Buffered_class = (PyObject *)&PyBufferedWriter_Type; + Buffered_class = (PyObject *)PyBufferedWriter_Type; else if (reading) - Buffered_class = (PyObject *)&PyBufferedReader_Type; + Buffered_class = (PyObject *)PyBufferedReader_Type; else { PyErr_Format(PyExc_ValueError, "unknown mode: '%s'", mode); @@ -489,7 +491,7 @@ } /* wraps into a TextIOWrapper */ - wrapper = PyObject_CallFunction((PyObject *)&PyTextIOWrapper_Type, + wrapper = PyObject_CallFunction((PyObject *)PyTextIOWrapper_Type, "Osssi", buffer, encoding, errors, newline, @@ -626,7 +628,7 @@ goto fail; #define ADD_TYPE(type, name) \ - if (PyType_Ready(type) < 0) \ + if ((type = PyType_Convert(&_ ## type)) == 0) \ goto fail; \ Py_INCREF(type); \ if (PyModule_AddObject(m, name, (PyObject *)type) < 0) { \ @@ -640,7 +642,7 @@ /* UnsupportedOperation inherits from ValueError and IOError */ state->unsupported_operation = PyObject_CallFunction( - (PyObject *)&PyType_Type, "s(OO){}", + (PyObject *)PyType_Type, "s(OO){}", "UnsupportedOperation", PyExc_ValueError, PyExc_IOError); if (state->unsupported_operation == NULL) goto fail; @@ -650,52 +652,55 @@ goto fail; /* BlockingIOError */ - _PyExc_BlockingIOError.tp_base = (PyTypeObject *) PyExc_IOError; - ADD_TYPE(&_PyExc_BlockingIOError, "BlockingIOError"); + _PyExc_BlockingIOError.tp_base = (PyTypeObject *)PyExc_IOError; + ADD_TYPE(PyExc_BlockingIOError, "BlockingIOError"); /* Concrete base types of the IO ABCs. (the ABCs themselves are declared through inheritance in io.py) */ - ADD_TYPE(&PyIOBase_Type, "_IOBase"); - ADD_TYPE(&PyRawIOBase_Type, "_RawIOBase"); - ADD_TYPE(&PyBufferedIOBase_Type, "_BufferedIOBase"); - ADD_TYPE(&PyTextIOBase_Type, "_TextIOBase"); + ADD_TYPE(PyIOBase_Type, "_IOBase"); + _PyRawIOBase_Type.tp_base = PyIOBase_Type; + ADD_TYPE(PyRawIOBase_Type, "_RawIOBase"); + _PyBufferedIOBase_Type.tp_base = PyIOBase_Type; + ADD_TYPE(PyBufferedIOBase_Type, "_BufferedIOBase"); + _PyTextIOBase_Type.tp_base = PyIOBase_Type; + ADD_TYPE(PyTextIOBase_Type, "_TextIOBase"); /* Implementation of concrete IO objects. */ /* FileIO */ - PyFileIO_Type.tp_base = &PyRawIOBase_Type; - ADD_TYPE(&PyFileIO_Type, "FileIO"); + _PyFileIO_Type.tp_base = PyRawIOBase_Type; + ADD_TYPE(PyFileIO_Type, "FileIO"); /* BytesIO */ - PyBytesIO_Type.tp_base = &PyBufferedIOBase_Type; - ADD_TYPE(&PyBytesIO_Type, "BytesIO"); + _PyBytesIO_Type.tp_base = PyBufferedIOBase_Type; + ADD_TYPE(PyBytesIO_Type, "BytesIO"); /* StringIO */ - PyStringIO_Type.tp_base = &PyTextIOBase_Type; - ADD_TYPE(&PyStringIO_Type, "StringIO"); + _PyStringIO_Type.tp_base = PyTextIOBase_Type; + ADD_TYPE(PyStringIO_Type, "StringIO"); /* BufferedReader */ - PyBufferedReader_Type.tp_base = &PyBufferedIOBase_Type; - ADD_TYPE(&PyBufferedReader_Type, "BufferedReader"); + _PyBufferedReader_Type.tp_base = PyBufferedIOBase_Type; + ADD_TYPE(PyBufferedReader_Type, "BufferedReader"); /* BufferedWriter */ - PyBufferedWriter_Type.tp_base = &PyBufferedIOBase_Type; - ADD_TYPE(&PyBufferedWriter_Type, "BufferedWriter"); + _PyBufferedWriter_Type.tp_base = PyBufferedIOBase_Type; + ADD_TYPE(PyBufferedWriter_Type, "BufferedWriter"); /* BufferedRWPair */ - PyBufferedRWPair_Type.tp_base = &PyBufferedIOBase_Type; - ADD_TYPE(&PyBufferedRWPair_Type, "BufferedRWPair"); + _PyBufferedRWPair_Type.tp_base = PyBufferedIOBase_Type; + ADD_TYPE(PyBufferedRWPair_Type, "BufferedRWPair"); /* BufferedRandom */ - PyBufferedRandom_Type.tp_base = &PyBufferedIOBase_Type; - ADD_TYPE(&PyBufferedRandom_Type, "BufferedRandom"); + _PyBufferedRandom_Type.tp_base = PyBufferedIOBase_Type; + ADD_TYPE(PyBufferedRandom_Type, "BufferedRandom"); /* TextIOWrapper */ - PyTextIOWrapper_Type.tp_base = &PyTextIOBase_Type; - ADD_TYPE(&PyTextIOWrapper_Type, "TextIOWrapper"); + _PyTextIOWrapper_Type.tp_base = PyTextIOBase_Type; + ADD_TYPE(PyTextIOWrapper_Type, "TextIOWrapper"); /* IncrementalNewlineDecoder */ - ADD_TYPE(&PyIncrementalNewlineDecoder_Type, "IncrementalNewlineDecoder"); + ADD_TYPE(PyIncrementalNewlineDecoder_Type, "IncrementalNewlineDecoder"); /* Interned strings */ if (!(_PyIO_str_close = PyUnicode_InternFromString("close"))) diff -r a156f602debc Modules/_io/_iomodule.h --- a/Modules/_io/_iomodule.h Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/_io/_iomodule.h Tue Apr 28 19:26:52 2009 -0700 @@ -3,21 +3,34 @@ */ /* ABCs */ -extern PyTypeObject PyIOBase_Type; -extern PyTypeObject PyRawIOBase_Type; -extern PyTypeObject PyBufferedIOBase_Type; -extern PyTypeObject PyTextIOBase_Type; +extern PyTypeObject _PyIOBase_Type; +extern PyTypeObject *PyIOBase_Type; +extern PyTypeObject _PyRawIOBase_Type; +extern PyTypeObject *PyRawIOBase_Type; +extern PyTypeObject _PyBufferedIOBase_Type; +extern PyTypeObject *PyBufferedIOBase_Type; +extern PyTypeObject _PyTextIOBase_Type; +extern PyTypeObject *PyTextIOBase_Type; /* Concrete classes */ -extern PyTypeObject PyFileIO_Type; -extern PyTypeObject PyBytesIO_Type; -extern PyTypeObject PyStringIO_Type; -extern PyTypeObject PyBufferedReader_Type; -extern PyTypeObject PyBufferedWriter_Type; -extern PyTypeObject PyBufferedRWPair_Type; -extern PyTypeObject PyBufferedRandom_Type; -extern PyTypeObject PyTextIOWrapper_Type; -extern PyTypeObject PyIncrementalNewlineDecoder_Type; +extern PyTypeObject _PyFileIO_Type; +extern PyTypeObject *PyFileIO_Type; +extern PyTypeObject _PyBytesIO_Type; +extern PyTypeObject *PyBytesIO_Type; +extern PyTypeObject _PyStringIO_Type; +extern PyTypeObject *PyStringIO_Type; +extern PyTypeObject _PyBufferedReader_Type; +extern PyTypeObject *PyBufferedReader_Type; +extern PyTypeObject _PyBufferedWriter_Type; +extern PyTypeObject *PyBufferedWriter_Type; +extern PyTypeObject _PyBufferedRWPair_Type; +extern PyTypeObject *PyBufferedRWPair_Type; +extern PyTypeObject _PyBufferedRandom_Type; +extern PyTypeObject *PyBufferedRandom_Type; +extern PyTypeObject _PyTextIOWrapper_Type; +extern PyTypeObject *PyTextIOWrapper_Type; +extern PyTypeObject _PyIncrementalNewlineDecoder_Type; +extern PyTypeObject *PyIncrementalNewlineDecoder_Type; /* These functions are used as METH_NOARGS methods, are normally called * with args=NULL, and return a new reference. diff -r a156f602debc Modules/_io/bufferedio.c --- a/Modules/_io/bufferedio.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/_io/bufferedio.c Tue Apr 28 19:26:52 2009 -0700 @@ -8,7 +8,9 @@ */ #define PY_SSIZE_T_CLEAN +#define PY_TYPEPRIVATE #include "Python.h" +#include "pytypeconvert.h" #include "structmember.h" #include "pythread.h" #include "_iomodule.h" @@ -134,7 +136,8 @@ {NULL, NULL} }; -PyTypeObject PyBufferedIOBase_Type = { +PyTypeObject *PyBufferedIOBase_Type; +PyTypeObject _PyBufferedIOBase_Type = { PyVarObject_HEAD_INIT(NULL, 0) "_io._BufferedIOBase", /*tp_name*/ 0, /*tp_basicsize*/ @@ -165,7 +168,7 @@ BufferedIOBase_methods, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ - &PyIOBase_Type, /* tp_base */ + 0, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ @@ -1052,8 +1055,8 @@ CHECK_INITIALIZED(self); tp = Py_TYPE(self); - if (tp == &PyBufferedReader_Type || - tp == &PyBufferedRandom_Type) { + if (tp == PyBufferedReader_Type || + tp == PyBufferedRandom_Type) { /* Skip method call overhead for speed */ line = _Buffered_readline(self, -1); } @@ -1121,8 +1124,8 @@ return -1; _BufferedReader_reset_buf(self); - self->fast_closed_checks = (Py_TYPE(self) == &PyBufferedReader_Type && - Py_TYPE(raw) == &PyFileIO_Type); + self->fast_closed_checks = (Py_TYPE(self) == PyBufferedReader_Type && + Py_TYPE(raw) == PyFileIO_Type); self->ok = 1; return 0; @@ -1418,7 +1421,8 @@ }; -PyTypeObject PyBufferedReader_Type = { +PyTypeObject *PyBufferedReader_Type; +PyTypeObject _PyBufferedReader_Type = { PyVarObject_HEAD_INIT(NULL, 0) "_io.BufferedReader", /*tp_name*/ sizeof(BufferedObject), /*tp_basicsize*/ @@ -1523,8 +1527,8 @@ _BufferedWriter_reset_buf(self); self->pos = 0; - self->fast_closed_checks = (Py_TYPE(self) == &PyBufferedWriter_Type && - Py_TYPE(raw) == &PyFileIO_Type); + self->fast_closed_checks = (Py_TYPE(self) == PyBufferedWriter_Type && + Py_TYPE(raw) == PyFileIO_Type); self->ok = 1; return 0; @@ -1772,7 +1776,8 @@ }; -PyTypeObject PyBufferedWriter_Type = { +PyTypeObject *PyBufferedWriter_Type; +PyTypeObject _PyBufferedWriter_Type = { PyVarObject_HEAD_INIT(NULL, 0) "_io.BufferedWriter", /*tp_name*/ sizeof(BufferedObject), /*tp_basicsize*/ @@ -1866,12 +1871,12 @@ return -1; self->reader = (BufferedObject *) PyObject_CallFunction( - (PyObject *) &PyBufferedReader_Type, "On", reader, buffer_size); + (PyObject *) PyBufferedReader_Type, "On", reader, buffer_size); if (self->reader == NULL) return -1; self->writer = (BufferedObject *) PyObject_CallFunction( - (PyObject *) &PyBufferedWriter_Type, "On", writer, buffer_size); + (PyObject *) PyBufferedWriter_Type, "On", writer, buffer_size); if (self->writer == NULL) { Py_CLEAR(self->reader); return -1; @@ -2024,7 +2029,8 @@ {NULL} }; -PyTypeObject PyBufferedRWPair_Type = { +PyTypeObject *PyBufferedRWPair_Type; +PyTypeObject _PyBufferedRWPair_Type = { PyVarObject_HEAD_INIT(NULL, 0) "_io.BufferedRWPair", /*tp_name*/ sizeof(BufferedRWPairObject), /*tp_basicsize*/ @@ -2118,8 +2124,8 @@ _BufferedWriter_reset_buf(self); self->pos = 0; - self->fast_closed_checks = (Py_TYPE(self) == &PyBufferedRandom_Type && - Py_TYPE(raw) == &PyFileIO_Type); + self->fast_closed_checks = (Py_TYPE(self) == PyBufferedRandom_Type && + Py_TYPE(raw) == PyFileIO_Type); self->ok = 1; return 0; @@ -2161,7 +2167,8 @@ }; -PyTypeObject PyBufferedRandom_Type = { +PyTypeObject *PyBufferedRandom_Type; +PyTypeObject _PyBufferedRandom_Type = { PyVarObject_HEAD_INIT(NULL, 0) "_io.BufferedRandom", /*tp_name*/ sizeof(BufferedObject), /*tp_basicsize*/ diff -r a156f602debc Modules/_io/bytesio.c --- a/Modules/_io/bytesio.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/_io/bytesio.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,4 +1,6 @@ +#define PY_TYPEPRIVATE #include "Python.h" +#include "pytypeconvert.h" #include "structmember.h" /* for offsetof() */ #include "_iomodule.h" @@ -714,7 +716,8 @@ "Create a buffered I/O implementation using an in-memory bytes\n" "buffer, ready for reading and writing."); -PyTypeObject PyBytesIO_Type = { +PyTypeObject *PyBytesIO_Type; +PyTypeObject _PyBytesIO_Type = { PyVarObject_HEAD_INIT(NULL, 0) "_io.BytesIO", /*tp_name*/ sizeof(BytesIOObject), /*tp_basicsize*/ diff -r a156f602debc Modules/_io/fileio.c --- a/Modules/_io/fileio.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/_io/fileio.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,7 +1,9 @@ /* Author: Daniel Stutzbach */ #define PY_SSIZE_T_CLEAN +#define PY_TYPEPRIVATE #include "Python.h" +#include "pytypeconvert.h" #include #include #include @@ -53,9 +55,8 @@ PyObject *dict; } PyFileIOObject; -PyTypeObject PyFileIO_Type; -#define PyFileIO_Check(op) (PyObject_TypeCheck((op), &PyFileIO_Type)) +#define PyFileIO_Check(op) (PyObject_TypeCheck((op), PyFileIO_Type)) int _PyFileIO_closed(PyObject *self) @@ -108,7 +109,7 @@ if (errno < 0) return NULL; - return PyObject_CallMethod((PyObject*)&PyRawIOBase_Type, + return PyObject_CallMethod((PyObject*)PyRawIOBase_Type, "close", "O", self); } @@ -990,7 +991,8 @@ {NULL}, }; -PyTypeObject PyFileIO_Type = { +PyTypeObject *PyFileIO_Type; +PyTypeObject _PyFileIO_Type = { PyVarObject_HEAD_INIT(NULL, 0) "_io.FileIO", sizeof(PyFileIOObject), diff -r a156f602debc Modules/_io/iobase.c --- a/Modules/_io/iobase.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/_io/iobase.c Tue Apr 28 19:26:52 2009 -0700 @@ -9,7 +9,9 @@ #define PY_SSIZE_T_CLEAN +#define PY_TYPEPRIVATE #include "Python.h" +#include "pytypeconvert.h" #include "structmember.h" #include "_iomodule.h" @@ -704,7 +706,8 @@ }; -PyTypeObject PyIOBase_Type = { +PyTypeObject *PyIOBase_Type; +PyTypeObject _PyIOBase_Type = { PyVarObject_HEAD_INIT(NULL, 0) "_io._IOBase", /*tp_name*/ sizeof(IOBaseObject), /*tp_basicsize*/ @@ -852,7 +855,8 @@ {NULL, NULL} }; -PyTypeObject PyRawIOBase_Type = { +PyTypeObject *PyRawIOBase_Type; +PyTypeObject _PyRawIOBase_Type = { PyVarObject_HEAD_INIT(NULL, 0) "_io._RawIOBase", /*tp_name*/ 0, /*tp_basicsize*/ @@ -883,7 +887,7 @@ RawIOBase_methods, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ - &PyIOBase_Type, /* tp_base */ + 0, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ diff -r a156f602debc Modules/_io/stringio.c --- a/Modules/_io/stringio.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/_io/stringio.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,5 +1,7 @@ #define PY_SSIZE_T_CLEAN +#define PY_TYPEPRIVATE #include "Python.h" +#include "pytypeconvert.h" #include "structmember.h" #include "_iomodule.h" @@ -233,7 +235,7 @@ } else { PyErr_Format(PyExc_TypeError, "integer argument expected, got '%s'", - Py_TYPE(arg)->tp_name); + Py_TYPE_NAME(arg)); return NULL; } @@ -303,7 +305,7 @@ } else if (arg != Py_None) { PyErr_Format(PyExc_TypeError, "integer argument expected, got '%s'", - Py_TYPE(arg)->tp_name); + Py_TYPE_NAME(arg)); return NULL; } return _stringio_readline(self, limit); @@ -317,7 +319,7 @@ CHECK_INITIALIZED(self); CHECK_CLOSED(self); - if (Py_TYPE(self) == &PyStringIO_Type) { + if (Py_TYPE(self) == PyStringIO_Type) { /* Skip method call overhead for speed */ line = _stringio_readline(self, -1); } @@ -328,7 +330,7 @@ if (line && !PyUnicode_Check(line)) { PyErr_Format(PyExc_IOError, "readline() should have returned an str object, " - "not '%.200s'", Py_TYPE(line)->tp_name); + "not '%.200s'", Py_TYPE_NAME(line)); Py_DECREF(line); return NULL; } @@ -375,7 +377,7 @@ } else { PyErr_Format(PyExc_TypeError, "integer argument expected, got '%s'", - Py_TYPE(arg)->tp_name); + Py_TYPE_NAME(arg)); return NULL; } @@ -460,7 +462,7 @@ CHECK_INITIALIZED(self); if (!PyUnicode_Check(obj)) { PyErr_Format(PyExc_TypeError, "string argument expected, got '%s'", - Py_TYPE(obj)->tp_name); + Py_TYPE_NAME(obj)); return NULL; } CHECK_CLOSED(self); @@ -563,7 +565,7 @@ if (value && value != Py_None && !PyUnicode_Check(value)) { PyErr_Format(PyExc_ValueError, "initial_value must be str or None, not %.200s", - Py_TYPE(value)->tp_name); + Py_TYPE_NAME(value)); return -1; } @@ -593,7 +595,7 @@ if (self->readuniversal) { self->decoder = PyObject_CallFunction( - (PyObject *)&PyIncrementalNewlineDecoder_Type, + (PyObject *)PyIncrementalNewlineDecoder_Type, "Oi", Py_None, (int) self->readtranslate); if (self->decoder == NULL) return -1; @@ -726,7 +728,8 @@ {NULL} }; -PyTypeObject PyStringIO_Type = { +PyTypeObject *PyStringIO_Type; +PyTypeObject _PyStringIO_Type = { PyVarObject_HEAD_INIT(NULL, 0) "_io.StringIO", /*tp_name*/ sizeof(StringIOObject), /*tp_basicsize*/ diff -r a156f602debc Modules/_io/textio.c --- a/Modules/_io/textio.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/_io/textio.c Tue Apr 28 19:26:52 2009 -0700 @@ -7,7 +7,9 @@ */ #define PY_SSIZE_T_CLEAN +#define PY_TYPEPRIVATE #include "Python.h" +#include "pytypeconvert.h" #include "structmember.h" #include "_iomodule.h" @@ -105,7 +107,8 @@ {NULL} }; -PyTypeObject PyTextIOBase_Type = { +PyTypeObject *PyTextIOBase_Type; +PyTypeObject _PyTextIOBase_Type = { PyVarObject_HEAD_INIT(NULL, 0) "_io._TextIOBase", /*tp_name*/ 0, /*tp_basicsize*/ @@ -136,7 +139,7 @@ TextIOBase_methods, /* tp_methods */ 0, /* tp_members */ TextIOBase_getset, /* tp_getset */ - &PyIOBase_Type, /* tp_base */ + 0, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ @@ -542,7 +545,8 @@ {NULL} }; -PyTypeObject PyIncrementalNewlineDecoder_Type = { +PyTypeObject *PyIncrementalNewlineDecoder_Type; +PyTypeObject _PyIncrementalNewlineDecoder_Type = { PyVarObject_HEAD_INIT(NULL, 0) "_io.IncrementalNewlineDecoder", /*tp_name*/ sizeof(PyNewLineDecoderObject), /*tp_basicsize*/ @@ -896,7 +900,7 @@ if (self->readuniversal) { PyObject *incrementalDecoder = PyObject_CallFunction( - (PyObject *)&PyIncrementalNewlineDecoder_Type, + (PyObject *)PyIncrementalNewlineDecoder_Type, "Oi", self->decoder, (int)self->readtranslate); if (incrementalDecoder == NULL) goto error; @@ -943,14 +947,14 @@ self->buffer = buffer; Py_INCREF(buffer); - if (Py_TYPE(buffer) == &PyBufferedReader_Type || - Py_TYPE(buffer) == &PyBufferedWriter_Type || - Py_TYPE(buffer) == &PyBufferedRandom_Type) { + if (Py_TYPE(buffer) == PyBufferedReader_Type || + Py_TYPE(buffer) == PyBufferedWriter_Type || + Py_TYPE(buffer) == PyBufferedRandom_Type) { raw = PyObject_GetAttrString(buffer, "raw"); /* Cache the raw FileIO object to speed up 'closed' checks */ if (raw == NULL) PyErr_Clear(); - else if (Py_TYPE(raw) == &PyFileIO_Type) + else if (Py_TYPE(raw) == PyFileIO_Type) self->raw = raw; else Py_DECREF(raw); @@ -1035,7 +1039,7 @@ do { \ int r; \ PyObject *_res; \ - if (Py_TYPE(self) == &PyTextIOWrapper_Type) { \ + if (Py_TYPE(self) == PyTextIOWrapper_Type) { \ if (self->raw != NULL) \ r = _PyFileIO_closed(self->raw); \ else { \ @@ -1296,7 +1300,7 @@ eof = (PyBytes_Size(input_chunk) == 0); - if (Py_TYPE(self->decoder) == &PyIncrementalNewlineDecoder_Type) { + if (Py_TYPE(self->decoder) == PyIncrementalNewlineDecoder_Type) { decoded_chars = _PyIncrementalNewlineDecoder_decode( self->decoder, input_chunk, eof); } @@ -2256,7 +2260,7 @@ CHECK_INITIALIZED(self); self->telling = 0; - if (Py_TYPE(self) == &PyTextIOWrapper_Type) { + if (Py_TYPE(self) == PyTextIOWrapper_Type) { /* Skip method call overhead for speed */ line = _TextIOWrapper_readline(self, -1); } @@ -2377,7 +2381,8 @@ {NULL} }; -PyTypeObject PyTextIOWrapper_Type = { +PyTypeObject *PyTextIOWrapper_Type; +PyTypeObject _PyTextIOWrapper_Type = { PyVarObject_HEAD_INIT(NULL, 0) "_io.TextIOWrapper", /*tp_name*/ sizeof(PyTextIOWrapperObject), /*tp_basicsize*/ diff -r a156f602debc Modules/_json.c --- a/Modules/_json.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/_json.c Tue Apr 28 19:26:52 2009 -0700 @@ -581,7 +581,7 @@ else { PyErr_Format(PyExc_TypeError, "first argument must be a string or bytes, not %.80s", - Py_TYPE(pystr)->tp_name); + Py_TYPE_NAME(pystr)); return NULL; } } @@ -603,7 +603,7 @@ else { PyErr_Format(PyExc_TypeError, "first argument must be a string or unicode, not %.80s", - Py_TYPE(pystr)->tp_name); + Py_TYPE_NAME(pystr)); return NULL; } if (rval != NULL && PyBytes_Check(rval)) { diff -r a156f602debc Modules/_lsprof.c --- a/Modules/_lsprof.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/_lsprof.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,4 +1,6 @@ +#define PY_TYPEPRIVATE #include "Python.h" +#include "../Objects/typeprivate.h" #include "compile.h" #include "frameobject.h" #include "structseq.h" @@ -528,8 +530,8 @@ }; static int initialized; -static PyTypeObject StatsEntryType; -static PyTypeObject StatsSubEntryType; +static PyTypeObject *StatsEntryType; +static PyTypeObject *StatsSubEntryType; typedef struct { @@ -545,7 +547,7 @@ ProfilerEntry *entry = (ProfilerEntry*) sentry->header.key; int err; PyObject *sinfo; - sinfo = PyObject_CallFunction((PyObject*) &StatsSubEntryType, + sinfo = PyObject_CallFunction((PyObject*) StatsSubEntryType, "((Olldd))", entry->userObj, sentry->callcount, @@ -583,7 +585,7 @@ collect->sublist = Py_None; } - info = PyObject_CallFunction((PyObject*) &StatsEntryType, + info = PyObject_CallFunction((PyObject*) StatsEntryType, "((OllddO))", entry->userObj, entry->callcount, @@ -883,17 +885,16 @@ PyDict_SetItemString(d, "Profiler", (PyObject *)&PyProfiler_Type); if (!initialized) { - PyStructSequence_InitType(&StatsEntryType, - &profiler_entry_desc); - PyStructSequence_InitType(&StatsSubEntryType, - &profiler_subentry_desc); + StatsEntryType = PyStructSequence_InitType(&profiler_entry_desc); + StatsSubEntryType = + PyStructSequence_InitType(&profiler_subentry_desc); } - Py_INCREF((PyObject*) &StatsEntryType); - Py_INCREF((PyObject*) &StatsSubEntryType); + Py_INCREF((PyObject*) StatsEntryType); + Py_INCREF((PyObject*) StatsSubEntryType); PyModule_AddObject(module, "profiler_entry", - (PyObject*) &StatsEntryType); + (PyObject*) StatsEntryType); PyModule_AddObject(module, "profiler_subentry", - (PyObject*) &StatsSubEntryType); + (PyObject*) StatsSubEntryType); empty_tuple = PyTuple_New(0); initialized = 1; return module; diff -r a156f602debc Modules/_multiprocessing/multiprocessing.h --- a/Modules/_multiprocessing/multiprocessing.h Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/_multiprocessing/multiprocessing.h Tue Apr 28 19:26:52 2009 -0700 @@ -3,7 +3,9 @@ #define PY_SSIZE_T_CLEAN +#define PY_TYPEPRIVATE #include "Python.h" +#include "../../Objects/typeprivate.h" #include "structmember.h" #include "pythread.h" diff -r a156f602debc Modules/_pickle.c --- a/Modules/_pickle.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/_pickle.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,4 +1,6 @@ +#define PY_TYPEPRIVATE #include "Python.h" +#include "../Objects/typeprivate.h" #include "structmember.h" PyDoc_STRVAR(pickle_module_doc, @@ -1061,7 +1063,7 @@ if (bytelist == NULL) return -1; - reduce_value = Py_BuildValue("(O(O))", (PyObject *)&PyBytes_Type, + reduce_value = Py_BuildValue("(O(O))", (PyObject *)PyBytes_Type, bytelist); if (reduce_value == NULL) { Py_DECREF(bytelist); @@ -2242,11 +2244,11 @@ status = save_bool(self, obj); goto done; } - else if (type == &PyLong_Type) { + else if (type == PyLong_Type) { status = save_long(self, obj); goto done; } - else if (type == &PyFloat_Type) { + else if (type == PyFloat_Type) { status = save_float(self, obj); goto done; } @@ -2263,31 +2265,31 @@ goto done; } - if (type == &PyBytes_Type) { + if (type == PyBytes_Type) { status = save_bytes(self, obj); goto done; } - else if (type == &PyUnicode_Type) { + else if (type == PyUnicode_Type) { status = save_unicode(self, obj); goto done; } - else if (type == &PyDict_Type) { + else if (type == PyDict_Type) { status = save_dict(self, obj); goto done; } - else if (type == &PyList_Type) { + else if (type == PyList_Type) { status = save_list(self, obj); goto done; } - else if (type == &PyTuple_Type) { + else if (type == PyTuple_Type) { status = save_tuple(self, obj); goto done; } - else if (type == &PyType_Type) { + else if (type == PyType_Type) { status = save_global(self, obj, NULL); goto done; } - else if (type == &PyFunction_Type) { + else if (type == PyFunction_Type) { status = save_global(self, obj, NULL); if (status < 0 && PyErr_ExceptionMatches(PickleError)) { /* fall back to reduce */ @@ -2297,11 +2299,11 @@ goto done; } } - else if (type == &PyCFunction_Type) { + else if (type == PyCFunction_Type) { status = save_global(self, obj, NULL); goto done; } - else if (PyType_IsSubtype(type, &PyType_Type)) { + else if (PyType_IsSubtype(type, PyType_Type)) { status = save_global(self, obj, NULL); goto done; } diff -r a156f602debc Modules/_randommodule.c --- a/Modules/_randommodule.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/_randommodule.c Tue Apr 28 19:26:52 2009 -0700 @@ -66,7 +66,9 @@ /* ---------------------------------------------------------------*/ +#define PY_TYPEPRIVATE #include "Python.h" +#include "../Objects/typeprivate.h" #include /* for seeding to current time */ /* Period parameters -- These are all magic. Don't change. */ diff -r a156f602debc Modules/_sqlite/connection.c --- a/Modules/_sqlite/connection.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/_sqlite/connection.c Tue Apr 28 19:26:52 2009 -0700 @@ -77,8 +77,8 @@ Py_INCREF(Py_None); self->row_factory = Py_None; - Py_INCREF(&PyUnicode_Type); - self->text_factory = (PyObject*)&PyUnicode_Type; + Py_INCREF(PyUnicode_Type); + self->text_factory = (PyObject*)PyUnicode_Type; Py_BEGIN_ALLOW_THREADS rc = sqlite3_open(database, &self->db); @@ -1209,7 +1209,7 @@ goto finally; } - if (!PyArg_ParseTuple(args, "O!O:create_collation(name, callback)", &PyUnicode_Type, &name, &callable)) { + if (!PyArg_ParseTuple(args, "O!O:create_collation(name, callback)", PyUnicode_Type, &name, &callable)) { goto finally; } diff -r a156f602debc Modules/_sqlite/cursor.c --- a/Modules/_sqlite/cursor.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/_sqlite/cursor.c Tue Apr 28 19:26:52 2009 -0700 @@ -335,7 +335,7 @@ converted = PyFloat_FromDouble(sqlite3_column_double(self->statement->st, i)); } else if (coltype == SQLITE_TEXT) { val_str = (const char*)sqlite3_column_text(self->statement->st, i); - if ((self->connection->text_factory == (PyObject*)&PyUnicode_Type) + if ((self->connection->text_factory == (PyObject*)PyUnicode_Type) || (self->connection->text_factory == pysqlite_OptimizedUnicode)) { converted = pysqlite_unicode_from_string(val_str, @@ -362,9 +362,9 @@ Py_DECREF(buf_bytes); } } - } else if (self->connection->text_factory == (PyObject*)&PyBytes_Type) { + } else if (self->connection->text_factory == (PyObject*)PyBytes_Type) { converted = PyBytes_FromString(val_str); - } else if (self->connection->text_factory == (PyObject*)&PyByteArray_Type) { + } else if (self->connection->text_factory == (PyObject*)PyByteArray_Type) { converted = PyByteArray_FromStringAndSize(val_str, strlen(val_str)); } else { converted = PyObject_CallFunction(self->connection->text_factory, "y", val_str); @@ -421,8 +421,8 @@ } /* Make shooting yourself in the foot with not utf-8 decodable 8-bit-strings harder */ - allow_8bit_chars = ((self->connection->text_factory != (PyObject*)&PyUnicode_Type) && - (self->connection->text_factory != (PyObject*)&PyUnicode_Type && pysqlite_OptimizedUnicode)); + allow_8bit_chars = ((self->connection->text_factory != (PyObject*)PyUnicode_Type) && + (self->connection->text_factory != (PyObject*)PyUnicode_Type && pysqlite_OptimizedUnicode)); Py_XDECREF(self->next_row); self->next_row = NULL; diff -r a156f602debc Modules/_sqlite/microprotocols.c --- a/Modules/_sqlite/microprotocols.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/_sqlite/microprotocols.c Tue Apr 28 19:26:52 2009 -0700 @@ -23,7 +23,9 @@ * 3. This notice may not be removed or altered from any source distribution. */ -#include +#define PY_TYPEPRIVATE +#include "Python.h" +#include "../../Objects/typeprivate.h" #include #include "cursor.h" diff -r a156f602debc Modules/_sqlite/module.c --- a/Modules/_sqlite/module.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/_sqlite/module.c Tue Apr 28 19:26:52 2009 -0700 @@ -155,8 +155,8 @@ /* a basic type is adapted; there's a performance optimization if that's not the case * (99 % of all usages) */ - if (type == &PyLong_Type || type == &PyFloat_Type - || type == &PyUnicode_Type || type == &PyByteArray_Type) { + if (type == PyLong_Type || type == PyFloat_Type + || type == PyUnicode_Type || type == PyByteArray_Type) { pysqlite_BaseTypeAdapted = 1; } diff -r a156f602debc Modules/_sqlite/prepare_protocol.c --- a/Modules/_sqlite/prepare_protocol.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/_sqlite/prepare_protocol.c Tue Apr 28 19:26:52 2009 -0700 @@ -78,6 +78,6 @@ extern int pysqlite_prepare_protocol_setup_types(void) { pysqlite_PrepareProtocolType.tp_new = PyType_GenericNew; - Py_TYPE(&pysqlite_PrepareProtocolType)= &PyType_Type; + Py_TYPE(&pysqlite_PrepareProtocolType)= PyType_Type; return PyType_Ready(&pysqlite_PrepareProtocolType); } diff -r a156f602debc Modules/_sqlite/row.c --- a/Modules/_sqlite/row.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/_sqlite/row.c Tue Apr 28 19:26:52 2009 -0700 @@ -156,7 +156,7 @@ static int pysqlite_row_print(pysqlite_Row* self, FILE *fp, int flags) { - return (&PyTuple_Type)->tp_print(self->data, fp, flags); + return PyTuple_Type->tp_print(self->data, fp, flags); } static PyObject* pysqlite_iter(pysqlite_Row* self) diff -r a156f602debc Modules/_sre.c --- a/Modules/_sre.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/_sre.c Tue Apr 28 19:26:52 2009 -0700 @@ -41,7 +41,9 @@ #define PY_SSIZE_T_CLEAN +#define PY_TYPEPRIVATE #include "Python.h" +#include "pytypeconvert.h" #include "structmember.h" /* offsetof */ #include "sre.h" @@ -2505,7 +2507,7 @@ PatternObject* copy; int offset; - copy = PyObject_NEW_VAR(PatternObject, &Pattern_Type, self->codesize); + copy = PyObject_NEW_VAR(PatternObject, Pattern_Type, self->codesize); if (!copy) return NULL; @@ -2617,7 +2619,8 @@ {NULL} /* Sentinel */ }; -static PyTypeObject Pattern_Type = { +static PyTypeObject *Pattern_Type; +static PyTypeObject _Pattern_Type = { PyVarObject_HEAD_INIT(NULL, 0) "_" SRE_MODULE ".SRE_Pattern", sizeof(PatternObject), sizeof(SRE_CODE), @@ -2665,13 +2668,13 @@ PyObject* groupindex = NULL; PyObject* indexgroup = NULL; if (!PyArg_ParseTuple(args, "OiO!|nOO", &pattern, &flags, - &PyList_Type, &code, &groups, + PyList_Type, &code, &groups, &groupindex, &indexgroup)) return NULL; n = PyList_GET_SIZE(code); /* coverity[ampersand_in_size] */ - self = PyObject_NEW_VAR(PatternObject, &Pattern_Type, n); + self = PyObject_NEW_VAR(PatternObject, Pattern_Type, n); if (!self) return NULL; @@ -3516,7 +3519,7 @@ slots = 2 * (self->pattern->groups+1); - copy = PyObject_NEW_VAR(MatchObject, &Match_Type, slots); + copy = PyObject_NEW_VAR(MatchObject, Match_Type, slots); if (!copy) return NULL; @@ -3627,7 +3630,8 @@ /* FIXME: implement setattr("string", None) as a special case (to detach the associated string, if any */ -static PyTypeObject Match_Type = { +static PyTypeObject *Match_Type; +static PyTypeObject _Match_Type = { PyVarObject_HEAD_INIT(NULL,0) "_" SRE_MODULE ".SRE_Match", sizeof(MatchObject), sizeof(Py_ssize_t), @@ -3673,7 +3677,7 @@ /* create match object (with room for extra group marks) */ /* coverity[ampersand_in_size] */ - match = PyObject_NEW_VAR(MatchObject, &Match_Type, + match = PyObject_NEW_VAR(MatchObject, Match_Type, 2*(pattern->groups+1)); if (!match) return NULL; @@ -3811,7 +3815,8 @@ {NULL} /* Sentinel */ }; -static PyTypeObject Scanner_Type = { +static PyTypeObject *Scanner_Type; +static PyTypeObject _Scanner_Type = { PyVarObject_HEAD_INIT(NULL, 0) "_" SRE_MODULE ".SRE_Scanner", sizeof(ScannerObject), 0, @@ -3857,7 +3862,7 @@ return NULL; /* create scanner object */ - self = PyObject_NEW(ScannerObject, &Scanner_Type); + self = PyObject_NEW(ScannerObject, Scanner_Type); if (!self) return NULL; @@ -3892,6 +3897,7 @@ NULL }; + PyMODINIT_FUNC PyInit__sre(void) { PyObject* m; @@ -3899,11 +3905,9 @@ PyObject* x; /* Initialize object types */ - if (PyType_Ready(&Pattern_Type) < 0) - return NULL; - if (PyType_Ready(&Match_Type) < 0) - return NULL; - if (PyType_Ready(&Scanner_Type) < 0) + if (((Pattern_Type = PyType_Convert(&_Pattern_Type)) == 0) + || ((Match_Type = PyType_Convert(&_Match_Type)) == 0) + || ((Scanner_Type = PyType_Convert(&_Scanner_Type)) == 0) ) return NULL; m = PyModule_Create(&sremodule); diff -r a156f602debc Modules/_ssl.c --- a/Modules/_ssl.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/_ssl.c Tue Apr 28 19:26:52 2009 -0700 @@ -13,7 +13,9 @@ XXX what about SSL_MODE_AUTO_RETRY? */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "../Objects/typeprivate.h" #ifdef WITH_THREAD #include "pythread.h" diff -r a156f602debc Modules/_struct.c --- a/Modules/_struct.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/_struct.c Tue Apr 28 19:26:52 2009 -0700 @@ -5,7 +5,9 @@ #define PY_SSIZE_T_CLEAN +#define PY_TYPEPRIVATE #include "Python.h" +#include "../Objects/typeprivate.h" #include "structseq.h" #include "structmember.h" #include @@ -1948,7 +1950,7 @@ if (m == NULL) return NULL; - Py_TYPE(&PyStructType) = &PyType_Type; + Py_TYPE(&PyStructType) = PyType_Type; if (PyType_Ready(&PyStructType) < 0) return NULL; diff -r a156f602debc Modules/_testcapimodule.c --- a/Modules/_testcapimodule.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/_testcapimodule.c Tue Apr 28 19:26:52 2009 -0700 @@ -7,7 +7,9 @@ #define PY_SSIZE_T_CLEAN +#define PY_TYPEPRIVATE #include "Python.h" +#include "../Objects/typeprivate.h" #include #include "structmember.h" @@ -262,7 +264,7 @@ return NULL; } - if (type->tp_hash != PyType_Type.tp_hash) { + if (type->tp_hash != PyType_Type->tp_hash) { PyErr_SetString( TestError, "test_lazy_hash_inheritance: unexpected hash function"); @@ -1422,9 +1424,9 @@ if (m == NULL) return NULL; - Py_TYPE(&_HashInheritanceTester_Type)=&PyType_Type; + Py_TYPE(&_HashInheritanceTester_Type)=PyType_Type; - Py_TYPE(&test_structmembersType)=&PyType_Type; + Py_TYPE(&test_structmembersType)=PyType_Type; Py_INCREF(&test_structmembersType); PyModule_AddObject(m, "test_structmembersType", (PyObject *)&test_structmembersType); @@ -1450,8 +1452,8 @@ PyModule_AddObject(m, "PY_SSIZE_T_MAX", PyLong_FromSsize_t(PY_SSIZE_T_MAX)); PyModule_AddObject(m, "PY_SSIZE_T_MIN", PyLong_FromSsize_t(PY_SSIZE_T_MIN)); PyModule_AddObject(m, "SIZEOF_PYGC_HEAD", PyLong_FromSsize_t(sizeof(PyGC_Head))); - Py_INCREF(&PyInstanceMethod_Type); - PyModule_AddObject(m, "instancemethod", (PyObject *)&PyInstanceMethod_Type); + Py_INCREF(PyInstanceMethod_Type); + PyModule_AddObject(m, "instancemethod", (PyObject *)PyInstanceMethod_Type); TestError = PyErr_NewException("_testcapi.error", NULL, NULL); Py_INCREF(TestError); diff -r a156f602debc Modules/_threadmodule.c --- a/Modules/_threadmodule.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/_threadmodule.c Tue Apr 28 19:26:52 2009 -0700 @@ -2,7 +2,9 @@ /* Thread module */ /* Interface to Sjoerd's portable C thread library */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "pytypeconvert.h" #ifndef WITH_THREAD #error "Error! The rest of Python is not compiled with thread support." @@ -99,6 +101,7 @@ \n\ Return whether the lock is in the locked state."); + static PyMethodDef lock_methods[] = { {"acquire_lock", (PyCFunction)lock_PyThread_acquire_lock, METH_VARARGS, acquire_doc}, @@ -119,8 +122,22 @@ {NULL, NULL} /* sentinel */ }; -static PyTypeObject Locktype = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyDoc_STRVAR(lock_doc, +"A lock object is a synchronization primitive. To create a lock,\n\ +call the PyThread_allocate_lock() function. Methods are:\n\ +\n\ +acquire() -- lock the lock, possibly blocking until it can be obtained\n\ +release() -- unlock of the lock\n\ +locked() -- test whether the lock is currently locked\n\ +\n\ +A lock is not owned by the thread that locked it; another thread may\n\ +unlock it. A thread attempting to lock a lock that it has already locked\n\ +will block until another thread unlocks it. Deadlocks may ensue."); + + +static PyTypeObject *Locktype; +static PyTypeObject _Locktype = { + PyVarObject_HEAD_INIT(NULL, 0) "_thread.lock", /*tp_name*/ sizeof(lockobject), /*tp_size*/ 0, /*tp_itemsize*/ @@ -141,7 +158,7 @@ 0, /*tp_setattro*/ 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT, /*tp_flags*/ - 0, /*tp_doc*/ + lock_doc, /*tp_doc*/ 0, /*tp_traverse*/ 0, /*tp_clear*/ 0, /*tp_richcompare*/ @@ -155,7 +172,7 @@ newlockobject(void) { lockobject *self; - self = PyObject_New(lockobject, &Locktype); + self = PyObject_New(lockobject, Locktype); if (self == NULL) return NULL; self->lock_lock = PyThread_allocate_lock(); @@ -185,7 +202,7 @@ localobject *self; PyObject *tdict; - if (type->tp_init == PyBaseObject_Type.tp_init + if (type->tp_init == PyBaseObject_Type->tp_init && ((args && PyObject_IsTrue(args)) || (kw && PyObject_IsTrue(kw)))) { PyErr_SetString(PyExc_TypeError, @@ -294,7 +311,7 @@ Py_INCREF(ldict); self->dict = ldict; /* still borrowed */ - if (Py_TYPE(self)->tp_init != PyBaseObject_Type.tp_init && + if (Py_TYPE(self)->tp_init != PyBaseObject_Type->tp_init && Py_TYPE(self)->tp_init((PyObject*)self, self->args, self->kw) < 0) { /* we need to get rid of ldict from thread so @@ -349,7 +366,9 @@ static PyObject *local_getattro(localobject *, PyObject *); -static PyTypeObject localtype = { + +static PyTypeObject *localtype; +static PyTypeObject _localtype = { PyVarObject_HEAD_INIT(NULL, 0) /* tp_name */ "_thread._local", /* tp_basicsize */ sizeof(localobject), @@ -401,7 +420,7 @@ if (ldict == NULL) return NULL; - if (Py_TYPE(self) != &localtype) + if (Py_TYPE(self) != localtype) /* use generic lookup for subtypes */ return PyObject_GenericGetAttr((PyObject *)self, name); @@ -690,18 +709,6 @@ "This module provides primitive operations to write multi-threaded programs.\n\ The 'threading' module provides a more convenient interface."); -PyDoc_STRVAR(lock_doc, -"A lock object is a synchronization primitive. To create a lock,\n\ -call the PyThread_allocate_lock() function. Methods are:\n\ -\n\ -acquire() -- lock the lock, possibly blocking until it can be obtained\n\ -release() -- unlock of the lock\n\ -locked() -- test whether the lock is currently locked\n\ -\n\ -A lock is not owned by the thread that locked it; another thread may\n\ -unlock it. A thread attempting to lock a lock that it has already locked\n\ -will block until another thread unlocks it. Deadlocks may ensue."); - static struct PyModuleDef threadmodule = { PyModuleDef_HEAD_INIT, "_thread", @@ -715,15 +722,17 @@ }; + PyMODINIT_FUNC PyInit__thread(void) { PyObject *m, *d; /* Initialize types: */ - if (PyType_Ready(&localtype) < 0) - return NULL; - if (PyType_Ready(&Locktype) < 0) + _localtype.ob_base.ob_base.ob_type = + _Locktype.ob_base.ob_base.ob_type = PyType_Type; + if (((localtype = PyType_Convert(&_localtype)) == 0) + || ((Locktype = PyType_Convert(&_Locktype)) == 0) ) return NULL; /* Create the module and add the functions */ @@ -735,12 +744,11 @@ d = PyModule_GetDict(m); ThreadError = PyErr_NewException("_thread.error", NULL, NULL); PyDict_SetItemString(d, "error", ThreadError); - Locktype.tp_doc = lock_doc; - Py_INCREF(&Locktype); - PyDict_SetItemString(d, "LockType", (PyObject *)&Locktype); + Py_INCREF(Locktype); + PyDict_SetItemString(d, "LockType", (PyObject *)Locktype); - Py_INCREF(&localtype); - if (PyModule_AddObject(m, "_local", (PyObject *)&localtype) < 0) + Py_INCREF(localtype); + if (PyModule_AddObject(m, "_local", (PyObject *)localtype) < 0) return NULL; /* Initialize the C thread library */ diff -r a156f602debc Modules/_tkinter.c --- a/Modules/_tkinter.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/_tkinter.c Tue Apr 28 19:26:52 2009 -0700 @@ -22,7 +22,9 @@ */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "../Objects/typeprivate.h" #include #ifdef WITH_THREAD @@ -3125,7 +3127,7 @@ return NULL; PyDict_SetItemString(d, "TkttType", (PyObject *)&Tktt_Type); - Py_TYPE(&PyTclObject_Type) = &PyType_Type; + Py_TYPE(&PyTclObject_Type) = PyType_Type; PyDict_SetItemString(d, "Tcl_Obj", (PyObject *)&PyTclObject_Type); #ifdef TK_AQUA diff -r a156f602debc Modules/_weakref.c --- a/Modules/_weakref.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/_weakref.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,4 +1,6 @@ +#define PY_TYPEPRIVATE #include "Python.h" +#include "../Objects/typeprivate.h" #define GET_WEAKREFS_LISTPTR(o) \ @@ -108,18 +110,18 @@ m = PyModule_Create(&weakrefmodule); if (m != NULL) { - Py_INCREF(&_PyWeakref_RefType); + Py_INCREF(_PyWeakref_RefType); PyModule_AddObject(m, "ref", - (PyObject *) &_PyWeakref_RefType); - Py_INCREF(&_PyWeakref_RefType); + (PyObject *) _PyWeakref_RefType); + Py_INCREF(_PyWeakref_RefType); PyModule_AddObject(m, "ReferenceType", - (PyObject *) &_PyWeakref_RefType); - Py_INCREF(&_PyWeakref_ProxyType); + (PyObject *) _PyWeakref_RefType); + Py_INCREF(_PyWeakref_ProxyType); PyModule_AddObject(m, "ProxyType", - (PyObject *) &_PyWeakref_ProxyType); - Py_INCREF(&_PyWeakref_CallableProxyType); + (PyObject *) _PyWeakref_ProxyType); + Py_INCREF(_PyWeakref_CallableProxyType); PyModule_AddObject(m, "CallableProxyType", - (PyObject *) &_PyWeakref_CallableProxyType); + (PyObject *) _PyWeakref_CallableProxyType); } return m; } diff -r a156f602debc Modules/arraymodule.c --- a/Modules/arraymodule.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/arraymodule.c Tue Apr 28 19:26:52 2009 -0700 @@ -4,7 +4,9 @@ The item type is restricted to simple C types like int or float */ #define PY_SSIZE_T_CLEAN +#define PY_TYPEPRIVATE #include "Python.h" +#include "../Objects/typeprivate.h" #include "structmember.h" #ifdef STDC_HEADERS @@ -2175,7 +2177,7 @@ if (PyType_Ready(&Arraytype) < 0) return NULL; - Py_TYPE(&PyArrayIter_Type) = &PyType_Type; + Py_TYPE(&PyArrayIter_Type) = PyType_Type; m = PyModule_Create(&arraymodule); if (m == NULL) return NULL; diff -r a156f602debc Modules/audioop.c --- a/Modules/audioop.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/audioop.c Tue Apr 28 19:26:52 2009 -0700 @@ -1143,7 +1143,7 @@ else { if (!PyArg_ParseTuple(state, "iO!;audioop.ratecv: illegal state argument", - &d, &PyTuple_Type, &samps)) + &d, PyTuple_Type, &samps)) goto exit; if (PyTuple_Size(samps) != nchannels) { PyErr_SetString(AudioopError, diff -r a156f602debc Modules/bz2module.c --- a/Modules/bz2module.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/bz2module.c Tue Apr 28 19:26:52 2009 -0700 @@ -7,7 +7,9 @@ */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "../Objects/typeprivate.h" #include #include #include "structmember.h" @@ -2116,9 +2118,9 @@ { PyObject *m; - Py_TYPE(&BZ2File_Type) = &PyType_Type; - Py_TYPE(&BZ2Comp_Type) = &PyType_Type; - Py_TYPE(&BZ2Decomp_Type) = &PyType_Type; + Py_TYPE(&BZ2File_Type) = PyType_Type; + Py_TYPE(&BZ2Comp_Type) = PyType_Type; + Py_TYPE(&BZ2Decomp_Type) = PyType_Type; m = PyModule_Create(&bz2module); if (m == NULL) diff -r a156f602debc Modules/cjkcodecs/multibytecodec.c --- a/Modules/cjkcodecs/multibytecodec.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/cjkcodecs/multibytecodec.c Tue Apr 28 19:26:52 2009 -0700 @@ -5,7 +5,9 @@ */ #define PY_SSIZE_T_CLEAN +#define PY_TYPEPRIVATE #include "Python.h" +#include "../../Objects/typeprivate.h" #include "structmember.h" #include "multibytecodec.h" diff -r a156f602debc Modules/cryptmodule.c --- a/Modules/cryptmodule.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/cryptmodule.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,7 +1,9 @@ /* cryptmodule.c - by Steve Majewski */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "../Objects/typeprivate.h" #include diff -r a156f602debc Modules/datetimemodule.c --- a/Modules/datetimemodule.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/datetimemodule.c Tue Apr 28 19:26:52 2009 -0700 @@ -2,7 +2,9 @@ * http://www.zope.org/Members/fdrake/DateTimeWiki/FrontPage */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "../Objects/typeprivate.h" #include "modsupport.h" #include "structmember.h" diff -r a156f602debc Modules/gcmodule.c --- a/Modules/gcmodule.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/gcmodule.c Tue Apr 28 19:26:52 2009 -0700 @@ -23,7 +23,9 @@ */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "../Objects/typeprivate.h" #include "frameobject.h" /* for PyFrame_ClearFreeList */ /* Get an object's GC head */ @@ -967,6 +969,7 @@ return n; } + PyDoc_STRVAR(gc_enable__doc__, "enable() -> None\n" "\n" diff -r a156f602debc Modules/grpmodule.c --- a/Modules/grpmodule.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/grpmodule.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,7 +1,9 @@ /* UNIX group file access module */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "../Objects/typeprivate.h" #include "structseq.h" #include @@ -30,13 +32,13 @@ static int initialized; -static PyTypeObject StructGrpType; +static PyTypeObject *StructGrpType; static PyObject * mkgrent(struct group *p) { int setIndex = 0; - PyObject *v = PyStructSequence_New(&StructGrpType), *w; + PyObject *v = PyStructSequence_New(StructGrpType), *w; char **member; if (v == NULL) @@ -201,8 +203,8 @@ return NULL; d = PyModule_GetDict(m); if (!initialized) - PyStructSequence_InitType(&StructGrpType, &struct_group_type_desc); - PyDict_SetItemString(d, "struct_group", (PyObject *) &StructGrpType); + StructGrpType = PyStructSequence_InitType(&struct_group_type_desc); + PyDict_SetItemString(d, "struct_group", (PyObject *) StructGrpType); initialized = 1; return m; } diff -r a156f602debc Modules/itertoolsmodule.c --- a/Modules/itertoolsmodule.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/itertoolsmodule.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,5 +1,7 @@ +#define PY_TYPEPRIVATE #include "Python.h" +#include "../Objects/typeprivate.h" #include "structmember.h" /* Itertools module written and maintained @@ -3541,7 +3543,7 @@ NULL }; - Py_TYPE(&teedataobject_type) = &PyType_Type; + Py_TYPE(&teedataobject_type) = PyType_Type; m = PyModule_Create(&itertoolsmodule); if (m == NULL) return NULL; diff -r a156f602debc Modules/main.c --- a/Modules/main.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/main.c Tue Apr 28 19:26:52 2009 -0700 @@ -227,7 +227,7 @@ if ((argv0 = PyUnicode_FromWideChar(filename,wcslen(filename))) && (importer = PyImport_GetImporter(argv0)) && - (importer->ob_type != &PyNullImporter_Type)) + (importer->ob_type != PyNullImporter_Type)) { /* argv0 is usable as an import source, so put it in sys.path[0] and import __main__ */ diff -r a156f602debc Modules/mathmodule.c --- a/Modules/mathmodule.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/mathmodule.c Tue Apr 28 19:26:52 2009 -0700 @@ -52,7 +52,9 @@ returned. */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "../Objects/typeprivate.h" #include "longintrepr.h" /* just for SHIFT */ #ifdef _OSF_SOURCE diff -r a156f602debc Modules/md5module.c --- a/Modules/md5module.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/md5module.c Tue Apr 28 19:26:52 2009 -0700 @@ -16,7 +16,9 @@ /* MD5 objects */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "../Objects/typeprivate.h" #include "hashlib.h" @@ -577,7 +579,7 @@ PyMODINIT_FUNC PyInit__md5(void) { - Py_TYPE(&MD5type) = &PyType_Type; + Py_TYPE(&MD5type) = PyType_Type; if (PyType_Ready(&MD5type) < 0) return NULL; return PyModule_Create(&_md5module); diff -r a156f602debc Modules/mmapmodule.c --- a/Modules/mmapmodule.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/mmapmodule.c Tue Apr 28 19:26:52 2009 -0700 @@ -19,7 +19,9 @@ */ #define PY_SSIZE_T_CLEAN -#include +#define PY_TYPEPRIVATE +#include "Python.h" +#include "../Objects/typeprivate.h" #ifndef MS_WINDOWS #define UNIX diff -r a156f602debc Modules/operator.c --- a/Modules/operator.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/operator.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,5 +1,7 @@ +#define PY_TYPEPRIVATE #include "Python.h" +#include "../Objects/typeprivate.h" PyDoc_STRVAR(operator_doc, "Operator interface.\n\ diff -r a156f602debc Modules/ossaudiodev.c --- a/Modules/ossaudiodev.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/ossaudiodev.c Tue Apr 28 19:26:52 2009 -0700 @@ -19,7 +19,9 @@ * $Id: ossaudiodev.c 69214 2009-02-02 20:36:42Z mark.dickinson $ */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "../Objects/typeprivate.h" #include "structmember.h" #ifdef HAVE_FCNTL_H @@ -840,7 +842,7 @@ } static PyTypeObject OSSAudioType = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) + PyVarObject_HEAD_INIT(&_PyType_Type, 0) "ossaudiodev.oss_audio_device", /*tp_name*/ sizeof(oss_audio_t), /*tp_size*/ 0, /*tp_itemsize*/ @@ -872,7 +874,7 @@ }; static PyTypeObject OSSMixerType = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) + PyVarObject_HEAD_INIT(&_PyType_Type, 0) "ossaudiodev.oss_mixer_device", /*tp_name*/ sizeof(oss_mixer_t), /*tp_size*/ 0, /*tp_itemsize*/ diff -r a156f602debc Modules/parsermodule.c --- a/Modules/parsermodule.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/parsermodule.c Tue Apr 28 19:26:52 2009 -0700 @@ -25,7 +25,9 @@ * look like "NOTE(...)". */ +#define PY_TYPEPRIVATE #include "Python.h" /* general Python API */ +#include "../Objects/typeprivate.h" #include "Python-ast.h" /* mod_ty */ #include "graminit.h" /* symbols defined in the grammar */ #include "node.h" /* internal parser structure */ diff -r a156f602debc Modules/posixmodule.c --- a/Modules/posixmodule.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/posixmodule.c Tue Apr 28 19:26:52 2009 -0700 @@ -27,7 +27,9 @@ #define PY_SSIZE_T_CLEAN +#define PY_TYPEPRIVATE #include "Python.h" +#include "pytypeconvert.h" #include "structseq.h" #if defined(__VMS) @@ -1313,8 +1315,8 @@ }; static int initialized; -static PyTypeObject StatResultType; -static PyTypeObject StatVFSResultType; +static PyTypeObject *StatResultType; +static PyTypeObject *StatVFSResultType; static newfunc structseq_new; static PyObject * @@ -1392,7 +1394,7 @@ _pystat_fromstructstat(STRUCT_STAT *st) { unsigned long ansec, mnsec, cnsec; - PyObject *v = PyStructSequence_New(&StatResultType); + PyObject *v = PyStructSequence_New(StatResultType); if (v == NULL) return NULL; @@ -5584,7 +5586,7 @@ static PyObject* _pystatvfs_fromstructstatvfs(struct statvfs st) { - PyObject *v = PyStructSequence_New(&StatVFSResultType); + PyObject *v = PyStructSequence_New(StatVFSResultType); if (v == NULL) return NULL; @@ -7550,12 +7552,12 @@ stat_result_desc.fields[7].name = PyStructSequence_UnnamedField; stat_result_desc.fields[8].name = PyStructSequence_UnnamedField; stat_result_desc.fields[9].name = PyStructSequence_UnnamedField; - PyStructSequence_InitType(&StatResultType, &stat_result_desc); - structseq_new = StatResultType.tp_new; - StatResultType.tp_new = statresult_new; + StatResultType = PyStructSequence_InitType(&stat_result_desc); + structseq_new = PyType_GetNewFunction(StatResultType, pytoe_new); + PyType_SetNewFunction(StatResultType, pytoe_new, statresult_new); statvfs_result_desc.name = MODNAME ".statvfs_result"; - PyStructSequence_InitType(&StatVFSResultType, &statvfs_result_desc); + StatVFSResultType = PyStructSequence_InitType(&statvfs_result_desc); #ifdef NEED_TICKS_PER_SECOND # if defined(HAVE_SYSCONF) && defined(_SC_CLK_TCK) ticks_per_second = sysconf(_SC_CLK_TCK); @@ -7566,11 +7568,11 @@ # endif #endif } - Py_INCREF((PyObject*) &StatResultType); - PyModule_AddObject(m, "stat_result", (PyObject*) &StatResultType); - Py_INCREF((PyObject*) &StatVFSResultType); + Py_INCREF((PyObject*) StatResultType); + PyModule_AddObject(m, "stat_result", (PyObject*) StatResultType); + Py_INCREF((PyObject*) StatVFSResultType); PyModule_AddObject(m, "statvfs_result", - (PyObject*) &StatVFSResultType); + (PyObject*) StatVFSResultType); initialized = 1; #ifdef __APPLE__ diff -r a156f602debc Modules/pwdmodule.c --- a/Modules/pwdmodule.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/pwdmodule.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,7 +1,9 @@ /* UNIX password file access module */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "../Objects/typeprivate.h" #include "structseq.h" #include @@ -43,7 +45,7 @@ static int initialized; -static PyTypeObject StructPwdType; +static PyTypeObject *StructPwdType; static void sets(PyObject *v, int i, const char* val) @@ -63,7 +65,7 @@ mkpwent(struct passwd *p) { int setIndex = 0; - PyObject *v = PyStructSequence_New(&StructPwdType); + PyObject *v = PyStructSequence_New(StructPwdType); if (v == NULL) return NULL; @@ -203,13 +205,14 @@ if (m == NULL) return NULL; - if (!initialized) - PyStructSequence_InitType(&StructPwdType, - &struct_pwd_type_desc); - Py_INCREF((PyObject *) &StructPwdType); - PyModule_AddObject(m, "struct_passwd", (PyObject *) &StructPwdType); - /* And for b/w compatibility (this was defined by mistake): */ - PyModule_AddObject(m, "struct_pwent", (PyObject *) &StructPwdType); - initialized = 1; + if (!initialized) { + initialized = 1; + StructPwdType = PyStructSequence_InitType(&struct_pwd_type_desc); + Py_INCREF((PyObject *) StructPwdType); + PyModule_AddObject(m, "struct_passwd", (PyObject *) StructPwdType); + /* And for b/w compatibility (this was defined by mistake): */ + /* removed in python 3.1! */ + /* PyModule_AddObject(m, "struct_pwent", (PyObject *) StructPwdType); */ + } return m; } diff -r a156f602debc Modules/pyexpat.c --- a/Modules/pyexpat.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/pyexpat.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,4 +1,6 @@ +#define PY_TYPEPRIVATE #include "Python.h" +#include "../Objects/typeprivate.h" #include #include "frameobject.h" diff -r a156f602debc Modules/resource.c --- a/Modules/resource.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/resource.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,5 +1,7 @@ +#define PY_TYPEPRIVATE #include "Python.h" +#include "../Objects/typeprivate.h" #include "structseq.h" #include #include @@ -56,7 +58,7 @@ }; static int initialized; -static PyTypeObject StructRUsageType; +static PyTypeObject *StructRUsageType; static PyObject * resource_getrusage(PyObject *self, PyObject *args) @@ -78,7 +80,7 @@ return NULL; } - result = PyStructSequence_New(&StructRUsageType); + result = PyStructSequence_New(StructRUsageType); if (!result) return NULL; @@ -256,11 +258,10 @@ Py_INCREF(ResourceError); PyModule_AddObject(m, "error", ResourceError); if (!initialized) - PyStructSequence_InitType(&StructRUsageType, - &struct_rusage_desc); - Py_INCREF(&StructRUsageType); + StructRUsageType = PyStructSequence_InitType(&struct_rusage_desc); + Py_INCREF(StructRUsageType); PyModule_AddObject(m, "struct_rusage", - (PyObject*) &StructRUsageType); + (PyObject*) StructRUsageType); /* insert constants */ #ifdef RLIMIT_CPU diff -r a156f602debc Modules/selectmodule.c --- a/Modules/selectmodule.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/selectmodule.c Tue Apr 28 19:26:52 2009 -0700 @@ -4,7 +4,9 @@ have any value except INVALID_SOCKET. */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "../Objects/typeprivate.h" #include #ifdef __APPLE__ @@ -1802,7 +1804,7 @@ #endif /* HAVE_POLL */ #ifdef HAVE_EPOLL - Py_TYPE(&pyEpoll_Type) = &PyType_Type; + Py_TYPE(&pyEpoll_Type) = PyType_Type; if (PyType_Ready(&pyEpoll_Type) < 0) return NULL; @@ -1829,14 +1831,14 @@ #ifdef HAVE_KQUEUE kqueue_event_Type.tp_new = PyType_GenericNew; - Py_TYPE(&kqueue_event_Type) = &PyType_Type; + Py_TYPE(&kqueue_event_Type) = PyType_Type; if(PyType_Ready(&kqueue_event_Type) < 0) return NULL; Py_INCREF(&kqueue_event_Type); PyModule_AddObject(m, "kevent", (PyObject *)&kqueue_event_Type); - Py_TYPE(&kqueue_queue_Type) = &PyType_Type; + Py_TYPE(&kqueue_queue_Type) = PyType_Type; if(PyType_Ready(&kqueue_queue_Type) < 0) return NULL; Py_INCREF(&kqueue_queue_Type); diff -r a156f602debc Modules/sha1module.c --- a/Modules/sha1module.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/sha1module.c Tue Apr 28 19:26:52 2009 -0700 @@ -16,7 +16,9 @@ /* SHA1 objects */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "../Objects/typeprivate.h" #include "hashlib.h" @@ -553,7 +555,7 @@ PyMODINIT_FUNC PyInit__sha1(void) { - Py_TYPE(&SHA1type) = &PyType_Type; + Py_TYPE(&SHA1type) = PyType_Type; if (PyType_Ready(&SHA1type) < 0) return NULL; return PyModule_Create(&_sha1module); diff -r a156f602debc Modules/sha256module.c --- a/Modules/sha256module.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/sha256module.c Tue Apr 28 19:26:52 2009 -0700 @@ -16,7 +16,9 @@ /* SHA objects */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "../Objects/typeprivate.h" #include "structmember.h" #include "hashlib.h" @@ -722,10 +724,10 @@ PyMODINIT_FUNC PyInit__sha256(void) { - Py_TYPE(&SHA224type) = &PyType_Type; + Py_TYPE(&SHA224type) = PyType_Type; if (PyType_Ready(&SHA224type) < 0) return NULL; - Py_TYPE(&SHA256type) = &PyType_Type; + Py_TYPE(&SHA256type) = PyType_Type; if (PyType_Ready(&SHA256type) < 0) return NULL; return PyModule_Create(&_sha256module); diff -r a156f602debc Modules/sha512module.c --- a/Modules/sha512module.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/sha512module.c Tue Apr 28 19:26:52 2009 -0700 @@ -16,7 +16,9 @@ /* SHA objects */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "../Objects/typeprivate.h" #include "structmember.h" #include "hashlib.h" @@ -788,10 +790,10 @@ PyMODINIT_FUNC PyInit__sha512(void) { - Py_TYPE(&SHA384type) = &PyType_Type; + Py_TYPE(&SHA384type) = PyType_Type; if (PyType_Ready(&SHA384type) < 0) return NULL; - Py_TYPE(&SHA512type) = &PyType_Type; + Py_TYPE(&SHA512type) = PyType_Type; if (PyType_Ready(&SHA512type) < 0) return NULL; return PyModule_Create(&_sha512module); diff -r a156f602debc Modules/signalmodule.c --- a/Modules/signalmodule.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/signalmodule.c Tue Apr 28 19:26:52 2009 -0700 @@ -3,7 +3,9 @@ /* XXX Signals should be recorded per thread, now we have thread state. */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "../Objects/typeprivate.h" #include "intrcheck.h" #ifdef MS_WINDOWS diff -r a156f602debc Modules/socketmodule.c --- a/Modules/socketmodule.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/socketmodule.c Tue Apr 28 19:26:52 2009 -0700 @@ -89,7 +89,9 @@ # pragma weak inet_aton #endif +#define PY_TYPEPRIVATE #include "Python.h" +#include "../Objects/typeprivate.h" #include "structmember.h" #undef MAX @@ -4182,7 +4184,7 @@ if (!os_init()) return NULL; - Py_TYPE(&sock_type) = &PyType_Type; + Py_TYPE(&sock_type) = PyType_Type; m = PyModule_Create(&socketmodule); if (m == NULL) return NULL; diff -r a156f602debc Modules/spwdmodule.c --- a/Modules/spwdmodule.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/spwdmodule.c Tue Apr 28 19:26:52 2009 -0700 @@ -3,7 +3,9 @@ /* A lot of code has been taken from pwdmodule.c */ /* For info also see http://www.unixpapa.com/incnote/passwd.html */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "../Objects/typeprivate.h" #include "structseq.h" #include @@ -53,7 +55,7 @@ }; static int initialized; -static PyTypeObject StructSpwdType; +static PyTypeObject *StructSpwdType; static void @@ -70,7 +72,7 @@ static PyObject *mkspent(struct spwd *p) { int setIndex = 0; - PyObject *v = PyStructSequence_New(&StructSpwdType); + PyObject *v = PyStructSequence_New(StructSpwdType); if (v == NULL) return NULL; @@ -188,10 +190,9 @@ if (m == NULL) return NULL; if (!initialized) - PyStructSequence_InitType(&StructSpwdType, - &struct_spwd_type_desc); - Py_INCREF((PyObject *) &StructSpwdType); - PyModule_AddObject(m, "struct_spwd", (PyObject *) &StructSpwdType); + StructSpwdType = PyStructSequence_InitType(&struct_spwd_type_desc); + Py_INCREF((PyObject *) StructSpwdType); + PyModule_AddObject(m, "struct_spwd", (PyObject *) StructSpwdType); initialized = 1; return m; } diff -r a156f602debc Modules/timemodule.c --- a/Modules/timemodule.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/timemodule.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,7 +1,9 @@ /* Time module */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "../Objects/typeprivate.h" #include "structseq.h" #include "timefuncs.h" @@ -227,13 +229,13 @@ 9, }; -static int initialized; -static PyTypeObject StructTimeType; +static int initialized = 0; +static PyTypeObject *StructTimeType = NULL; static PyObject * tmtotuple(struct tm *p) { - PyObject *v = PyStructSequence_New(&StructTimeType); + PyObject *v = PyStructSequence_New(StructTimeType); if (v == NULL) return NULL; @@ -366,7 +368,7 @@ t = args; Py_INCREF(t); } - else if (Py_TYPE(args) == &StructTimeType) { + else if (Py_TYPE(args) == StructTimeType) { t = structtime_totuple(args); } else { @@ -921,11 +923,10 @@ SetConsoleCtrlHandler( PyCtrlHandler, TRUE); #endif /* MS_WINDOWS */ if (!initialized) { - PyStructSequence_InitType(&StructTimeType, - &struct_time_type_desc); + StructTimeType = PyStructSequence_InitType(&struct_time_type_desc); } - Py_INCREF(&StructTimeType); - PyModule_AddObject(m, "struct_time", (PyObject*) &StructTimeType); + Py_INCREF(StructTimeType); + PyModule_AddObject(m, "struct_time", (PyObject*) StructTimeType); initialized = 1; return m; } diff -r a156f602debc Modules/unicodedata.c --- a/Modules/unicodedata.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/unicodedata.c Tue Apr 28 19:26:52 2009 -0700 @@ -12,7 +12,9 @@ ------------------------------------------------------------------------ */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "../Objects/typeprivate.h" #include "ucnhash.h" #include "structmember.h" @@ -125,7 +127,7 @@ long rc; Py_UCS4 c; - if (!PyArg_ParseTuple(args, "O!|O:decimal", &PyUnicode_Type, &v, &defobj)) + if (!PyArg_ParseTuple(args, "O!|O:decimal", PyUnicode_Type, &v, &defobj)) return NULL; c = getuchar(v); if (c == (Py_UCS4)-1) @@ -175,7 +177,7 @@ long rc; Py_UCS4 c; - if (!PyArg_ParseTuple(args, "O!|O:digit", &PyUnicode_Type, &v, &defobj)) + if (!PyArg_ParseTuple(args, "O!|O:digit", PyUnicode_Type, &v, &defobj)) return NULL; c = getuchar(v); if (c == (Py_UCS4)-1) @@ -210,7 +212,7 @@ double rc; Py_UCS4 c; - if (!PyArg_ParseTuple(args, "O!|O:numeric", &PyUnicode_Type, &v, &defobj)) + if (!PyArg_ParseTuple(args, "O!|O:numeric", PyUnicode_Type, &v, &defobj)) return NULL; c = getuchar(v); if (c == (Py_UCS4)-1) @@ -258,7 +260,7 @@ Py_UCS4 c; if (!PyArg_ParseTuple(args, "O!:category", - &PyUnicode_Type, &v)) + PyUnicode_Type, &v)) return NULL; c = getuchar(v); if (c == (Py_UCS4)-1) @@ -287,7 +289,7 @@ Py_UCS4 c; if (!PyArg_ParseTuple(args, "O!:bidirectional", - &PyUnicode_Type, &v)) + PyUnicode_Type, &v)) return NULL; c = getuchar(v); if (c == (Py_UCS4)-1) @@ -318,7 +320,7 @@ Py_UCS4 c; if (!PyArg_ParseTuple(args, "O!:combining", - &PyUnicode_Type, &v)) + PyUnicode_Type, &v)) return NULL; c = getuchar(v); if (c == (Py_UCS4)-1) @@ -347,7 +349,7 @@ Py_UCS4 c; if (!PyArg_ParseTuple(args, "O!:mirrored", - &PyUnicode_Type, &v)) + PyUnicode_Type, &v)) return NULL; c = getuchar(v); if (c == (Py_UCS4)-1) @@ -377,7 +379,7 @@ Py_UCS4 c; if (!PyArg_ParseTuple(args, "O!:east_asian_width", - &PyUnicode_Type, &v)) + PyUnicode_Type, &v)) return NULL; c = getuchar(v); if (c == (Py_UCS4)-1) @@ -408,7 +410,7 @@ Py_UCS4 c; if (!PyArg_ParseTuple(args, "O!:decomposition", - &PyUnicode_Type, &v)) + PyUnicode_Type, &v)) return NULL; c = getuchar(v); if (c == (Py_UCS4)-1) @@ -769,7 +771,7 @@ PyObject *input; if(!PyArg_ParseTuple(args, "sO!:normalize", - &form, &PyUnicode_Type, &input)) + &form, PyUnicode_Type, &input)) return NULL; if (PyUnicode_GetSize(input) == 0) { @@ -1104,7 +1106,7 @@ PyUnicodeObject* v; PyObject* defobj = NULL; - if (!PyArg_ParseTuple(args, "O!|O:name", &PyUnicode_Type, &v, &defobj)) + if (!PyArg_ParseTuple(args, "O!|O:name", PyUnicode_Type, &v, &defobj)) return NULL; c = getuchar(v); @@ -1259,7 +1261,7 @@ { PyObject *m, *v; - Py_TYPE(&UCD_Type) = &PyType_Type; + Py_TYPE(&UCD_Type) = PyType_Type; m = PyModule_Create(&unicodedatamodule); if (!m) diff -r a156f602debc Modules/xxmodule.c --- a/Modules/xxmodule.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/xxmodule.c Tue Apr 28 19:26:52 2009 -0700 @@ -14,7 +14,9 @@ /* Xxo objects */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "../Objects/typeprivate.h" static PyObject *ErrorObject; @@ -357,9 +359,9 @@ /* Due to cross platform compiler issues the slots must be filled * here. It's required for portability to Windows without requiring * C++. */ - Null_Type.tp_base = &PyBaseObject_Type; + Null_Type.tp_base = PyBaseObject_Type; Null_Type.tp_new = PyType_GenericNew; - Str_Type.tp_base = &PyUnicode_Type; + Str_Type.tp_base = PyUnicode_Type; /* Finalize the type object including setting type of the new type * object; doing it here is required for portability, too. */ diff -r a156f602debc Modules/xxsubtype.c --- a/Modules/xxsubtype.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/xxsubtype.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,4 +1,6 @@ +#define PY_TYPEPRIVATE #include "Python.h" +#include "pytypeconvert.h" #include "structmember.h" PyDoc_STRVAR(xxsubtype__doc__, @@ -82,7 +84,7 @@ static int spamlist_init(spamlistobject *self, PyObject *args, PyObject *kwds) { - if (PyList_Type.tp_init((PyObject *)self, args, kwds) < 0) + if (PyList_Type->tp_init((PyObject *)self, args, kwds) < 0) return -1; self->state = 0; return 0; @@ -100,8 +102,9 @@ {0} }; -static PyTypeObject spamlist_type = { - PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0) +static PyTypeObject *spamlist_type; +static PyTypeObject _spamlist_type = { + PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(PyType_Type), 0) "xxsubtype.spamlist", sizeof(spamlistobject), 0, @@ -131,7 +134,7 @@ spamlist_methods, /* tp_methods */ 0, /* tp_members */ spamlist_getsets, /* tp_getset */ - DEFERRED_ADDRESS(&PyList_Type), /* tp_base */ + 0, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ @@ -179,7 +182,7 @@ static int spamdict_init(spamdictobject *self, PyObject *args, PyObject *kwds) { - if (PyDict_Type.tp_init((PyObject *)self, args, kwds) < 0) + if (PyType_GetInitFunction(PyDict_Type, pytoe_init)((PyObject *)self, args, kwds) < 0) return -1; self->state = 0; return 0; @@ -191,8 +194,9 @@ {0} }; -static PyTypeObject spamdict_type = { - PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0) +static PyTypeObject *spamdict_type; +static PyTypeObject _spamdict_type = { + PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(PyType_Type), 0) "xxsubtype.spamdict", sizeof(spamdictobject), 0, @@ -222,7 +226,7 @@ spamdict_methods, /* tp_methods */ spamdict_members, /* tp_members */ 0, /* tp_getset */ - DEFERRED_ADDRESS(&PyDict_Type), /* tp_base */ + 0, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ @@ -277,33 +281,28 @@ /* Fill in deferred data addresses. This must be done before PyType_Ready() is called. Note that PyType_Ready() automatically - initializes the ob.ob_type field to &PyType_Type if it's NULL, + initializes the ob.ob_type field to PyType_Type if it's NULL, so it's not necessary to fill in ob_type first. */ - spamdict_type.tp_base = &PyDict_Type; - if (PyType_Ready(&spamdict_type) < 0) + _spamdict_type.tp_base = PyDict_Type; + if ((spamdict_type = PyType_Convert(&_spamdict_type)) == 0) return NULL; - spamlist_type.tp_base = &PyList_Type; - if (PyType_Ready(&spamlist_type) < 0) + _spamlist_type.tp_base = PyList_Type; + if ((spamlist_type = PyType_Convert(&_spamlist_type)) == 0) return NULL; m = PyModule_Create(&xxsubtypemodule); if (m == NULL) return NULL; - if (PyType_Ready(&spamlist_type) < 0) - return NULL; - if (PyType_Ready(&spamdict_type) < 0) + Py_INCREF(spamlist_type); + if (PyModule_AddObject(m, "spamlist", + (PyObject *) spamlist_type) < 0) return NULL; - Py_INCREF(&spamlist_type); - if (PyModule_AddObject(m, "spamlist", - (PyObject *) &spamlist_type) < 0) - return NULL; - - Py_INCREF(&spamdict_type); + Py_INCREF(spamdict_type); if (PyModule_AddObject(m, "spamdict", - (PyObject *) &spamdict_type) < 0) + (PyObject *) spamdict_type) < 0) return NULL; return m; } diff -r a156f602debc Modules/zipimport.c --- a/Modules/zipimport.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/zipimport.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,4 +1,6 @@ +#define PY_TYPEPRIVATE #include "Python.h" +#include "pytypeconvert.h" #include "structmember.h" #include "osdefs.h" #include "marshal.h" @@ -50,7 +52,7 @@ int *p_ispackage, char **p_modpath); -#define ZipImporter_Check(op) PyObject_TypeCheck(op, &ZipImporter_Type) +#define ZipImporter_Check(op) PyObject_TypeCheck(op, ZipImporter_Type) /* zipimporter.__init__ @@ -588,8 +590,9 @@ #define DEFERRED_ADDRESS(ADDR) 0 -static PyTypeObject ZipImporter_Type = { - PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0) +static PyTypeObject *ZipImporter_Type; +static PyTypeObject _ZipImporter_Type = { + PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(PyType_Type), 0) "zipimport.zipimporter", sizeof(ZipImporter), 0, /* tp_itemsize */ @@ -1193,7 +1196,7 @@ { PyObject *mod; - if (PyType_Ready(&ZipImporter_Type) < 0) + if ((ZipImporter_Type = PyType_Convert(&_ZipImporter_Type)) == 0) return NULL; /* Correct directory separator */ @@ -1225,9 +1228,9 @@ ZipImportError) < 0) return NULL; - Py_INCREF(&ZipImporter_Type); + Py_INCREF(ZipImporter_Type); if (PyModule_AddObject(mod, "zipimporter", - (PyObject *)&ZipImporter_Type) < 0) + (PyObject *)ZipImporter_Type) < 0) return NULL; zip_directory_cache = PyDict_New(); diff -r a156f602debc Modules/zlibmodule.c --- a/Modules/zlibmodule.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Modules/zlibmodule.c Tue Apr 28 19:26:52 2009 -0700 @@ -4,7 +4,9 @@ /* Windows users: read Python's PCbuild\readme.txt */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "../Objects/typeprivate.h" #include "structmember.h" #include "zlib.h" diff -r a156f602debc Objects/abstract.c --- a/Objects/abstract.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Objects/abstract.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,10 +1,14 @@ /* Abstract Object Interface (many thanks to Jim Fulton) */ +#define PY_TYPEPRIVATE + #include "Python.h" #include #include "structmember.h" /* we need the offsetof() macro from there */ #include "longintrepr.h" +#include "typeprivate.h" + /* Shorthands to return certain errors */ @@ -1454,7 +1458,7 @@ int PySequence_Check(PyObject *s) { - if (PyObject_IsInstance(s, (PyObject *)&PyDict_Type)) + if (PyObject_IsInstance(s, (PyObject *)PyDict_Type)) return 0; return s != NULL && s->ob_type->tp_as_sequence && s->ob_type->tp_as_sequence->sq_item != NULL; diff -r a156f602debc Objects/boolobject.c --- a/Objects/boolobject.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Objects/boolobject.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,7 +1,9 @@ /* Boolean type, a subtype of int */ +#define PY_TYPEPRIVATE #include "Python.h" #include "longintrepr.h" +#include "pytypeconvert.h" /* We define bool_repr to return "False" or "True" */ @@ -60,7 +62,7 @@ bool_and(PyObject *a, PyObject *b) { if (!PyBool_Check(a) || !PyBool_Check(b)) - return PyLong_Type.tp_as_number->nb_and(a, b); + return PyType_GetBinaryFunction(PyLong_Type, pytoe_number_and)(a, b); return PyBool_FromLong((a == Py_True) & (b == Py_True)); } @@ -68,7 +70,7 @@ bool_or(PyObject *a, PyObject *b) { if (!PyBool_Check(a) || !PyBool_Check(b)) - return PyLong_Type.tp_as_number->nb_or(a, b); + return PyType_GetBinaryFunction(PyLong_Type, pytoe_number_or)(a, b); return PyBool_FromLong((a == Py_True) | (b == Py_True)); } @@ -76,7 +78,7 @@ bool_xor(PyObject *a, PyObject *b) { if (!PyBool_Check(a) || !PyBool_Check(b)) - return PyLong_Type.tp_as_number->nb_xor(a, b); + return PyType_GetBinaryFunction(PyLong_Type, pytoe_number_or)(a, b); return PyBool_FromLong((a == Py_True) ^ (b == Py_True)); } @@ -130,8 +132,9 @@ /* The type object for bool. Note that this cannot be subclassed! */ -PyTypeObject PyBool_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject *PyBool_Type; +PyTypeObject _PyBool_Type = { + PyVarObject_HEAD_INIT(NULL, 0) "bool", sizeof(struct _longobject), 0, @@ -161,7 +164,7 @@ 0, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ - &PyLong_Type, /* tp_base */ + 0, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ @@ -174,11 +177,21 @@ /* The objects representing bool values False and True */ struct _longobject _Py_FalseStruct = { - PyVarObject_HEAD_INIT(&PyBool_Type, 0) + PyVarObject_HEAD_INIT(NULL, 0) { 0 } }; struct _longobject _Py_TrueStruct = { - PyVarObject_HEAD_INIT(&PyBool_Type, 1) + PyVarObject_HEAD_INIT(NULL, 1) { 1 } }; + + +int PyBool_Init(void) +{ + CONVERT_TYPE(PyBool_Type, PyType_Type, PyLong_Type, "bool type"); + _Py_FalseStruct.ob_base.ob_base.ob_type = PyBool_Type; + _Py_TrueStruct.ob_base.ob_base.ob_type = PyBool_Type; + return 0; +} + diff -r a156f602debc Objects/bytearrayobject.c --- a/Objects/bytearrayobject.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Objects/bytearrayobject.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,31 +1,17 @@ /* PyByteArray (bytearray) implementation */ +#define PY_TYPEPRIVATE + #define PY_SSIZE_T_CLEAN #include "Python.h" #include "structmember.h" #include "bytes_methods.h" +#include "pytypeconvert.h" + + static PyByteArrayObject *nullbytes = NULL; -void -PyByteArray_Fini(void) -{ - Py_CLEAR(nullbytes); -} - -int -PyByteArray_Init(void) -{ - nullbytes = PyObject_New(PyByteArrayObject, &PyByteArray_Type); - if (nullbytes == NULL) - return 0; - nullbytes->ob_bytes = NULL; - Py_SIZE(nullbytes) = nullbytes->ob_alloc = 0; - nullbytes->ob_exports = 0; - return 1; -} - -/* end nullbytes support */ /* Helpers */ @@ -116,7 +102,7 @@ PyObject * PyByteArray_FromObject(PyObject *input) { - return PyObject_CallFunctionObjArgs((PyObject *)&PyByteArray_Type, + return PyObject_CallFunctionObjArgs((PyObject *)PyByteArray_Type, input, NULL); } @@ -137,7 +123,7 @@ return PyErr_NoMemory(); } - new = PyObject_New(PyByteArrayObject, &PyByteArray_Type); + new = PyObject_New(PyByteArrayObject, PyByteArray_Type); if (new == NULL) return NULL; @@ -953,8 +939,8 @@ /* Bytes can be compared to anything that supports the (binary) buffer API. Except that a comparison with Unicode is always an error, even if the comparison is for equality. */ - if (PyObject_IsInstance(self, (PyObject*)&PyUnicode_Type) || - PyObject_IsInstance(other, (PyObject*)&PyUnicode_Type)) { + if (PyObject_IsInstance(self, (PyObject*)PyUnicode_Type) || + PyObject_IsInstance(other, (PyObject*)PyUnicode_Type)) { if (Py_BytesWarningFlag && (op == Py_EQ || op == Py_NE)) { if (PyErr_WarnEx(PyExc_BytesWarning, "Comparison between bytearray and string", 1)) @@ -3186,8 +3172,9 @@ static PyObject *bytearray_iter(PyObject *seq); -PyTypeObject PyByteArray_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject *PyByteArray_Type; +PyTypeObject _PyByteArray_Type = { + PyVarObject_HEAD_INIT(NULL, 0) "bytearray", sizeof(PyByteArrayObject), 0, @@ -3294,8 +3281,9 @@ {NULL, NULL} /* sentinel */ }; -PyTypeObject PyByteArrayIter_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject *PyByteArrayIter_Type; +PyTypeObject _PyByteArrayIter_Type = { + PyVarObject_HEAD_INIT(NULL, 0) "bytearray_iterator", /* tp_name */ sizeof(bytesiterobject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -3336,7 +3324,7 @@ PyErr_BadInternalCall(); return NULL; } - it = PyObject_GC_New(bytesiterobject, &PyByteArrayIter_Type); + it = PyObject_GC_New(bytesiterobject, PyByteArrayIter_Type); if (it == NULL) return NULL; it->it_index = 0; @@ -3345,3 +3333,33 @@ _PyObject_GC_TRACK(it); return (PyObject *)it; } + + + +void +PyByteArray_Fini(void) +{ + Py_CLEAR(nullbytes); +} + +int +PyByteArray_Init(void) +{ + CONVERT_TYPE(PyByteArray_Type, PyType_Type, NULL, "bytearray type"); + CONVERT_TYPE(PyByteArrayIter_Type, PyType_Type, NULL, "bytearray iterator type"); + + nullbytes = PyObject_New(PyByteArrayObject, PyByteArray_Type); + if (nullbytes == NULL) { + Py_FatalError("Py_Initialize: can't init bytes"); + return 1; + } + nullbytes->ob_bytes = NULL; + Py_SIZE(nullbytes) = nullbytes->ob_alloc = 0; + nullbytes->ob_exports = 0; + + return 0; +} + +/* end nullbytes support */ + + diff -r a156f602debc Objects/bytes_methods.c --- a/Objects/bytes_methods.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Objects/bytes_methods.c Tue Apr 28 19:26:52 2009 -0700 @@ -407,17 +407,17 @@ static Py_ssize_t _getbuffer(PyObject *obj, Py_buffer *view) { - PyBufferProcs *buffer = Py_TYPE(obj)->tp_as_buffer; + getbufferproc getbuffer = PyType_GetBufferGetFunction(Py_TYPE(obj), pytoe_buffer_getbuffer); - if (buffer == NULL || buffer->bf_getbuffer == NULL) + if (getbuffer == NULL) { PyErr_Format(PyExc_TypeError, "Type %.100s doesn't support the buffer API", - Py_TYPE(obj)->tp_name); + Py_TYPE_NAME(obj)); return -1; } - if (buffer->bf_getbuffer(obj, view, PyBUF_SIMPLE) < 0) + if (getbuffer(obj, view, PyBUF_SIMPLE) < 0) return -1; return view->len; } diff -r a156f602debc Objects/bytesobject.c --- a/Objects/bytesobject.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Objects/bytesobject.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,8 +1,10 @@ /* bytes object implementation */ +#define PY_TYPEPRIVATE #define PY_SSIZE_T_CLEAN #include "Python.h" +#include "typeprivate.h" #include "bytes_methods.h" #include @@ -10,17 +12,17 @@ static Py_ssize_t _getbuffer(PyObject *obj, Py_buffer *view) { - PyBufferProcs *buffer = Py_TYPE(obj)->tp_as_buffer; + getbufferproc getbuffer = PyType_GetBufferGetFunction(Py_TYPE(obj), pytoe_buffer_getbuffer); - if (buffer == NULL || buffer->bf_getbuffer == NULL) + if (getbuffer == NULL) { PyErr_Format(PyExc_TypeError, "Type %.100s doesn't support the buffer API", - Py_TYPE(obj)->tp_name); + Py_TYPE_NAME(obj)); return -1; } - if (buffer->bf_getbuffer(obj, view, PyBUF_SIMPLE) < 0) + if (getbuffer(obj, view, PyBUF_SIMPLE) < 0) return -1; return view->len; } @@ -102,7 +104,7 @@ op = (PyBytesObject *)PyObject_MALLOC(PyBytesObject_SIZE + size); if (op == NULL) return PyErr_NoMemory(); - PyObject_INIT_VAR(op, &PyBytes_Type, size); + PyObject_INIT_VAR(op, PyBytes_Type, size); op->ob_shash = -1; if (str != NULL) Py_MEMCPY(op->ob_sval, str, size); @@ -150,7 +152,7 @@ op = (PyBytesObject *)PyObject_MALLOC(PyBytesObject_SIZE + size); if (op == NULL) return PyErr_NoMemory(); - PyObject_INIT_VAR(op, &PyBytes_Type, size); + PyObject_INIT_VAR(op, PyBytes_Type, size); op->ob_shash = -1; Py_MEMCPY(op->ob_sval, str, size+1); /* share short strings */ @@ -765,7 +767,7 @@ op = (PyBytesObject *)PyObject_MALLOC(PyBytesObject_SIZE + nbytes); if (op == NULL) return PyErr_NoMemory(); - PyObject_INIT_VAR(op, &PyBytes_Type, size); + PyObject_INIT_VAR(op, PyBytes_Type, size); op->ob_shash = -1; op->ob_sval[size] = '\0'; if (Py_SIZE(a) == 1 && n > 0) { @@ -830,9 +832,9 @@ if (!(PyBytes_Check(a) && PyBytes_Check(b))) { if (Py_BytesWarningFlag && (op == Py_EQ || op == Py_NE) && (PyObject_IsInstance((PyObject*)a, - (PyObject*)&PyUnicode_Type) || + (PyObject*)PyUnicode_Type) || PyObject_IsInstance((PyObject*)b, - (PyObject*)&PyUnicode_Type))) { + (PyObject*)PyUnicode_Type))) { if (PyErr_WarnEx(PyExc_BytesWarning, "Comparison between bytes and string", 1)) return NULL; @@ -2899,7 +2901,7 @@ PyObject *new = NULL; static char *kwlist[] = {"source", "encoding", "errors", 0}; - if (type != &PyBytes_Type) + if (type != PyBytes_Type) return str_subtype_new(type, args, kwds); if (!PyArg_ParseTupleAndKeywords(args, kwds, "|Oss:bytes", kwlist, &x, &encoding, &errors)) @@ -3057,8 +3059,8 @@ PyObject *tmp, *pnew; Py_ssize_t n; - assert(PyType_IsSubtype(type, &PyBytes_Type)); - tmp = bytes_new(&PyBytes_Type, args, kwds); + assert(PyType_IsSubtype(type, PyBytes_Type)); + tmp = bytes_new(PyBytes_Type, args, kwds); if (tmp == NULL) return NULL; assert(PyBytes_CheckExact(tmp)); @@ -3088,8 +3090,11 @@ static PyObject *bytes_iter(PyObject *seq); -PyTypeObject PyBytes_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +/* note: bytes MUST be hard-coded, can't use PyType_New(). + it's used heavily in the implementation of types themselves. +*/ +PyTypeObject _PyBytes_Type = { + PyVarObject_HEAD_INIT(&_PyType_Type, 0) "bytes", PyBytesObject_SIZE, sizeof(char), @@ -3120,7 +3125,7 @@ bytes_methods, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ - &PyBaseObject_Type, /* tp_base */ + &_PyBaseObject_Type, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ @@ -3130,6 +3135,7 @@ bytes_new, /* tp_new */ PyObject_Del, /* tp_free */ }; +PyTypeObject *PyBytes_Type = &_PyBytes_Type; void PyBytes_Concat(register PyObject **pv, register PyObject *w) @@ -3421,8 +3427,8 @@ {NULL, NULL} /* sentinel */ }; -PyTypeObject PyBytesIter_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject _PyBytesIter_Type = { + PyVarObject_HEAD_INIT(&_PyType_Type, 0) "bytes_iterator", /* tp_name */ sizeof(striterobject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -3453,6 +3459,7 @@ striter_methods, /* tp_methods */ 0, }; +PyTypeObject *PyBytesIter_Type = &_PyBytesIter_Type; static PyObject * bytes_iter(PyObject *seq) @@ -3463,7 +3470,7 @@ PyErr_BadInternalCall(); return NULL; } - it = PyObject_GC_New(striterobject, &PyBytesIter_Type); + it = PyObject_GC_New(striterobject, PyBytesIter_Type); if (it == NULL) return NULL; it->it_index = 0; @@ -3472,3 +3479,10 @@ _PyObject_GC_TRACK(it); return (PyObject *)it; } + + +/* TODO remove this! */ +int PyBytes_Init(void) { + return 0; +} + diff -r a156f602debc Objects/cellobject.c --- a/Objects/cellobject.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Objects/cellobject.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,13 +1,15 @@ /* Cell object implementation */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "pytypeconvert.h" PyObject * PyCell_New(PyObject *obj) { PyCellObject *op; - op = (PyCellObject *)PyObject_GC_New(PyCellObject, &PyCell_Type); + op = (PyCellObject *)PyObject_GC_New(PyCellObject, PyCell_Type); if (op == NULL) return NULL; op->ob_ref = obj; @@ -145,8 +147,9 @@ {NULL} /* sentinel */ }; -PyTypeObject PyCell_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject *PyCell_Type; +PyTypeObject _PyCell_Type = { + PyVarObject_HEAD_INIT(NULL, 0) "cell", sizeof(PyCellObject), 0, @@ -177,3 +180,9 @@ 0, /* tp_members */ cell_getsetlist, /* tp_getset */ }; + +int PyCell_Init(void) { + CONVERT_TYPE(PyCell_Type, PyType_Type, NULL, "cell type"); + return 0; +} + diff -r a156f602debc Objects/classobject.c --- a/Objects/classobject.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Objects/classobject.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,6 +1,8 @@ /* Class object implementation (dead now except for methods) */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "pytypeconvert.h" #include "structmember.h" #define TP_DESCR_GET(t) ((t)->tp_descr_get) @@ -54,11 +56,11 @@ im = free_list; if (im != NULL) { free_list = (PyMethodObject *)(im->im_self); - PyObject_INIT(im, &PyMethod_Type); + PyObject_INIT(im, PyMethod_Type); numfree--; } else { - im = PyObject_GC_New(PyMethodObject, &PyMethod_Type); + im = PyObject_GC_New(PyMethodObject, PyMethod_Type); if (im == NULL) return NULL; } @@ -339,8 +341,9 @@ return PyMethod_New(PyMethod_GET_FUNCTION(meth), obj); } -PyTypeObject PyMethod_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject *PyMethod_Type; +PyTypeObject _PyMethod_Type = { + PyVarObject_HEAD_INIT(NULL, 0) "method", sizeof(PyMethodObject), 0, @@ -411,7 +414,7 @@ PyInstanceMethod_New(PyObject *func) { PyInstanceMethodObject *method; method = PyObject_GC_New(PyInstanceMethodObject, - &PyInstanceMethod_Type); + PyInstanceMethod_Type); if (method == NULL) return NULL; Py_INCREF(func); method->func = func; @@ -605,8 +608,9 @@ return PyInstanceMethod_New(func); } -PyTypeObject PyInstanceMethod_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject *PyInstanceMethod_Type; +PyTypeObject _PyInstanceMethod_Type = { + PyVarObject_HEAD_INIT(NULL, 0) "instancemethod", /* tp_name */ sizeof(PyInstanceMethodObject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -646,3 +650,10 @@ 0, /* tp_alloc */ instancemethod_new, /* tp_new */ }; + +int Py_MethodInit(void) { + CONVERT_TYPE(PyMethod_Type, PyType_Type, NULL, "method type"); + CONVERT_TYPE(PyInstanceMethod_Type, PyType_Type, NULL, "instance method type"); + return 0; +} + diff -r a156f602debc Objects/cobject.c --- a/Objects/cobject.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Objects/cobject.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,7 +1,9 @@ /* Wrap void* pointers to be passed between C modules */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "pytypeconvert.h" /* Declarations for objects of type PyCObject */ @@ -14,7 +16,7 @@ { PyCObject *self; - self = PyObject_NEW(PyCObject, &PyCObject_Type); + self = PyObject_NEW(PyCObject, PyCObject_Type); if (self == NULL) return NULL; self->cobject=cobj; @@ -36,7 +38,7 @@ " description"); return NULL; } - self = PyObject_NEW(PyCObject, &PyCObject_Type); + self = PyObject_NEW(PyCObject, PyCObject_Type); if (self == NULL) return NULL; self->cobject = cobj; @@ -50,7 +52,7 @@ PyCObject_AsVoidPtr(PyObject *self) { if (self) { - if (self->ob_type == &PyCObject_Type) + if (PyCObject_Check(self)) return ((PyCObject *)self)->cobject; PyErr_SetString(PyExc_TypeError, "PyCObject_AsVoidPtr with non-C-object"); @@ -65,7 +67,7 @@ PyCObject_GetDesc(PyObject *self) { if (self) { - if (self->ob_type == &PyCObject_Type) + if (PyCObject_Check(self)) return ((PyCObject *)self)->desc; PyErr_SetString(PyExc_TypeError, "PyCObject_GetDesc with non-C-object"); @@ -127,8 +129,9 @@ extension modules, so that extension modules can use the Python import\n\ mechanism to link to one another."); -PyTypeObject PyCObject_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject *PyCObject_Type; +PyTypeObject _PyCObject_Type = { + PyVarObject_HEAD_INIT(NULL, 0) "PyCObject", /*tp_name*/ sizeof(PyCObject), /*tp_basicsize*/ 0, /*tp_itemsize*/ @@ -151,3 +154,9 @@ 0, /*tp_flags*/ PyCObject_Type__doc__ /*tp_doc*/ }; + +int PyCObject_Init(void) { + CONVERT_TYPE(PyCObject_Type, PyType_Type, NULL, "CObject type"); + return 0; +} + diff -r a156f602debc Objects/codeobject.c --- a/Objects/codeobject.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Objects/codeobject.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,4 +1,6 @@ +#define PY_TYPEPRIVATE #include "Python.h" +#include "pytypeconvert.h" #include "code.h" #include "structmember.h" @@ -81,7 +83,7 @@ continue; PyUnicode_InternInPlace(&PyTuple_GET_ITEM(consts, i)); } - co = PyObject_NEW(PyCodeObject, &PyCode_Type); + co = PyObject_NEW(PyCodeObject, PyCode_Type); if (co != NULL) { co->co_argcount = argcount; co->co_kwonlyargcount = kwonlyargcount; @@ -159,7 +161,7 @@ PyExc_TypeError, "name tuples must contain only " "strings, not '%.500s'", - item->ob_type->tp_name); + Py_TYPE_NAME(item)); Py_DECREF(newtuple); return NULL; } @@ -209,13 +211,13 @@ &argcount, &kwonlyargcount, &nlocals, &stacksize, &flags, &code, - &PyTuple_Type, &consts, - &PyTuple_Type, &names, - &PyTuple_Type, &varnames, + PyTuple_Type, &consts, + PyTuple_Type, &names, + PyTuple_Type, &varnames, &filename, &name, &firstlineno, &lnotab, - &PyTuple_Type, &freevars, - &PyTuple_Type, &cellvars)) + PyTuple_Type, &freevars, + PyTuple_Type, &cellvars)) return NULL; if (argcount < 0) { @@ -390,8 +392,9 @@ /* XXX code objects need to participate in GC? */ -PyTypeObject PyCode_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject *PyCode_Type; +PyTypeObject _PyCode_Type = { + PyVarObject_HEAD_INIT(NULL, 0) "code", sizeof(PyCodeObject), 0, @@ -624,3 +627,9 @@ return line; } + +int PyCode_Init(void) { + CONVERT_TYPE(PyCode_Type, PyType_Type, NULL, "code type"); + return 0; +} + diff -r a156f602debc Objects/complexobject.c --- a/Objects/complexobject.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Objects/complexobject.c Tue Apr 28 19:26:52 2009 -0700 @@ -5,7 +5,9 @@ /* Submitted by Jim Hugunin */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "pytypeconvert.h" #include "structmember.h" #ifdef HAVE_IEEEFP_H @@ -223,7 +225,7 @@ op = (PyComplexObject *) PyObject_MALLOC(sizeof(PyComplexObject)); if (op == NULL) return PyErr_NoMemory(); - PyObject_INIT(op, &PyComplex_Type); + PyObject_INIT(op, PyComplex_Type); op->cval = cval; return (PyObject *) op; } @@ -885,7 +887,7 @@ /* Special-case for a single argument when type(arg) is complex. */ if (PyComplex_CheckExact(r) && i == NULL && - type == &PyComplex_Type) { + type == PyComplex_Type) { /* Note that we can't know whether it's safe to return a complex *subclass* instance as-is, hence the restriction to exact complexes here. If either the input or the @@ -1052,8 +1054,9 @@ 0, /* nb_inplace_true_divide */ }; -PyTypeObject PyComplex_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject *PyComplex_Type; +PyTypeObject _PyComplex_Type = { + PyVarObject_HEAD_INIT(NULL, 0) "complex", sizeof(PyComplexObject), 0, @@ -1094,4 +1097,9 @@ PyObject_Del, /* tp_free */ }; +int PyComplex_Init(void) { + CONVERT_TYPE(PyComplex_Type, PyType_Type, NULL, "complex type"); + return 0; +} + #endif diff -r a156f602debc Objects/descrobject.c --- a/Objects/descrobject.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Objects/descrobject.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,6 +1,8 @@ /* Descriptors -- a new, flexible way to describe attributes */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "typeprivate.h" #include "structmember.h" /* Why is this not included in Python.h? */ static void @@ -383,8 +385,11 @@ return 0; } -PyTypeObject PyMethodDescr_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +/* note: descriptors MUST be hard-coded, can't use PyType_New(). + they are used heavily in the implementation of types themselves. +*/ +PyTypeObject _PyMethodDescr_Type = { + PyVarObject_HEAD_INIT(&_PyType_Type, 0) "method_descriptor", sizeof(PyMethodDescrObject), 0, @@ -419,10 +424,14 @@ (descrgetfunc)method_get, /* tp_descr_get */ 0, /* tp_descr_set */ }; +PyTypeObject *PyMethodDescr_Type = &_PyMethodDescr_Type; /* This is for METH_CLASS in C, not for "f = classmethod(f)" in Python! */ -PyTypeObject PyClassMethodDescr_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +/* note: descriptors MUST be hard-coded, can't use PyType_New(). + they are used heavily in the implementation of types themselves. +*/ +PyTypeObject _PyClassMethodDescr_Type = { + PyVarObject_HEAD_INIT(&_PyType_Type, 0) "classmethod_descriptor", sizeof(PyMethodDescrObject), 0, @@ -457,9 +466,13 @@ (descrgetfunc)classmethod_get, /* tp_descr_get */ 0, /* tp_descr_set */ }; +PyTypeObject *PyClassMethodDescr_Type = &_PyClassMethodDescr_Type; -PyTypeObject PyMemberDescr_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +/* note: descriptors MUST be hard-coded, can't use PyType_New(). + they are used heavily in the implementation of types themselves. +*/ +PyTypeObject _PyMemberDescr_Type = { + PyVarObject_HEAD_INIT(&_PyType_Type, 0) "member_descriptor", sizeof(PyMemberDescrObject), 0, @@ -494,9 +507,13 @@ (descrgetfunc)member_get, /* tp_descr_get */ (descrsetfunc)member_set, /* tp_descr_set */ }; +PyTypeObject *PyMemberDescr_Type = &_PyMemberDescr_Type; -PyTypeObject PyGetSetDescr_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +/* note: descriptors MUST be hard-coded, can't use PyType_New(). + they are used heavily in the implementation of types themselves. +*/ +PyTypeObject _PyGetSetDescr_Type = { + PyVarObject_HEAD_INIT(&_PyType_Type, 0) "getset_descriptor", sizeof(PyGetSetDescrObject), 0, @@ -531,9 +548,13 @@ (descrgetfunc)getset_get, /* tp_descr_get */ (descrsetfunc)getset_set, /* tp_descr_set */ }; +PyTypeObject *PyGetSetDescr_Type = &_PyGetSetDescr_Type; -PyTypeObject PyWrapperDescr_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +/* note: descriptors MUST be hard-coded, can't use PyType_New(). + they are used heavily in the implementation of types themselves. +*/ +PyTypeObject _PyWrapperDescr_Type = { + PyVarObject_HEAD_INIT(&_PyType_Type, 0) "wrapper_descriptor", sizeof(PyWrapperDescrObject), 0, @@ -568,6 +589,7 @@ (descrgetfunc)wrapperdescr_get, /* tp_descr_get */ 0, /* tp_descr_set */ }; +PyTypeObject *PyWrapperDescr_Type = &_PyWrapperDescr_Type; static PyDescrObject * descr_new(PyTypeObject *descrtype, PyTypeObject *type, const char *name) @@ -592,7 +614,7 @@ { PyMethodDescrObject *descr; - descr = (PyMethodDescrObject *)descr_new(&PyMethodDescr_Type, + descr = (PyMethodDescrObject *)descr_new(PyMethodDescr_Type, type, method->ml_name); if (descr != NULL) descr->d_method = method; @@ -604,7 +626,7 @@ { PyMethodDescrObject *descr; - descr = (PyMethodDescrObject *)descr_new(&PyClassMethodDescr_Type, + descr = (PyMethodDescrObject *)descr_new(PyClassMethodDescr_Type, type, method->ml_name); if (descr != NULL) descr->d_method = method; @@ -616,7 +638,7 @@ { PyMemberDescrObject *descr; - descr = (PyMemberDescrObject *)descr_new(&PyMemberDescr_Type, + descr = (PyMemberDescrObject *)descr_new(PyMemberDescr_Type, type, member->name); if (descr != NULL) descr->d_member = member; @@ -628,7 +650,7 @@ { PyGetSetDescrObject *descr; - descr = (PyGetSetDescrObject *)descr_new(&PyGetSetDescr_Type, + descr = (PyGetSetDescrObject *)descr_new(PyGetSetDescr_Type, type, getset->name); if (descr != NULL) descr->d_getset = getset; @@ -640,7 +662,7 @@ { PyWrapperDescrObject *descr; - descr = (PyWrapperDescrObject *)descr_new(&PyWrapperDescr_Type, + descr = (PyWrapperDescrObject *)descr_new(PyWrapperDescr_Type, type, base->name); if (descr != NULL) { descr->d_base = base; @@ -780,8 +802,11 @@ return PyObject_RichCompare(v->dict, w, op); } -PyTypeObject PyDictProxy_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +/* note: descriptors MUST be hard-coded, can't use PyType_New(). + they are used heavily in the implementation of types themselves. +*/ +PyTypeObject _PyDictProxy_Type = { + PyVarObject_HEAD_INIT(&_PyType_Type, 0) "dict_proxy", /* tp_name */ sizeof(proxyobject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -817,13 +842,14 @@ 0, /* tp_descr_get */ 0, /* tp_descr_set */ }; +PyTypeObject *PyDictProxy_Type = &_PyDictProxy_Type; PyObject * PyDictProxy_New(PyObject *dict) { proxyobject *pp; - pp = PyObject_GC_New(proxyobject, &PyDictProxy_Type); + pp = PyObject_GC_New(proxyobject, PyDictProxy_Type); if (pp != NULL) { Py_INCREF(dict); pp->dict = dict; @@ -1014,7 +1040,7 @@ } static PyTypeObject wrappertype = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) + PyVarObject_HEAD_INIT(&_PyType_Type, 0) "method-wrapper", /* tp_name */ sizeof(wrapperobject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -1057,7 +1083,7 @@ wrapperobject *wp; PyWrapperDescrObject *descr; - assert(PyObject_TypeCheck(d, &PyWrapperDescr_Type)); + assert(PyObject_TypeCheck(d, PyWrapperDescr_Type)); descr = (PyWrapperDescrObject *)d; assert(PyObject_IsInstance(self, (PyObject *)(descr->d_type))); @@ -1345,8 +1371,11 @@ return 0; } -PyTypeObject PyProperty_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +/* note: descriptors MUST be hard-coded, can't use PyType_New(). + they are used heavily in the implementation of types themselves. +*/ +PyTypeObject _PyProperty_Type = { + PyVarObject_HEAD_INIT(&_PyType_Type, 0) "property", /* tp_name */ sizeof(propertyobject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -1388,3 +1417,6 @@ PyType_GenericNew, /* tp_new */ PyObject_GC_Del, /* tp_free */ }; +PyTypeObject *PyProperty_Type = &_PyProperty_Type; + + diff -r a156f602debc Objects/dictobject.c --- a/Objects/dictobject.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Objects/dictobject.c Tue Apr 28 19:26:52 2009 -0700 @@ -7,7 +7,9 @@ tuning dictionaries, and several ideas for possible optimizations. */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "typeprivate.h" #include "stringlib/eq.h" @@ -259,7 +261,7 @@ if (numfree) { mp = free_list[--numfree]; assert (mp != NULL); - assert (Py_TYPE(mp) == &PyDict_Type); + assert (Py_TYPE(mp) == PyDict_Type); _Py_NewReference((PyObject *)mp); if (mp->ma_fill) { EMPTY_TO_MINSIZE(mp); @@ -275,7 +277,7 @@ count_reuse++; #endif } else { - mp = PyObject_GC_New(PyDictObject, &PyDict_Type); + mp = PyObject_GC_New(PyDictObject, PyDict_Type); if (mp == NULL) return NULL; EMPTY_TO_MINSIZE(mp); @@ -1014,7 +1016,7 @@ } if (mp->ma_table != mp->ma_smalltable) PyMem_DEL(mp->ma_table); - if (numfree < PyDict_MAXFREELIST && Py_TYPE(mp) == &PyDict_Type) + if (numfree < PyDict_MAXFREELIST && Py_TYPE(mp) == PyDict_Type) free_list[numfree++] = mp; else Py_TYPE(mp)->tp_free((PyObject *)mp); @@ -2066,7 +2068,7 @@ INIT_NONZERO_DICT_SLOTS(d); d->ma_lookup = lookdict_unicode; /* The object has been implicitely tracked by tp_alloc */ - if (type == &PyDict_Type) + if (type == PyDict_Type) _PyObject_GC_UNTRACK(d); #ifdef SHOW_CONVERSION_COUNTS ++created; @@ -2090,7 +2092,7 @@ static PyObject * dict_iter(PyDictObject *dict) { - return dictiter_new(dict, &PyDictIterKey_Type); + return dictiter_new(dict, PyDictIterKey_Type); } PyDoc_STRVAR(dictionary_doc, @@ -2104,8 +2106,11 @@ "dict(**kwargs) -> new dictionary initialized with the name=value pairs\n" " in the keyword argument list. For example: dict(one=1, two=2)"); -PyTypeObject PyDict_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +/* note: dict MUST be hard-coded, can't use PyType_New(). + it's used heavily in the implementation of types themselves. +*/ +PyTypeObject _PyDict_Type = { + PyVarObject_HEAD_INIT(&_PyType_Type, 0) "dict", sizeof(PyDictObject), 0, @@ -2146,6 +2151,7 @@ dict_new, /* tp_new */ PyObject_GC_Del, /* tp_free */ }; +PyTypeObject *PyDict_Type = &_PyDict_Type; /* For backward compatibility with old dictionary interface */ @@ -2211,7 +2217,7 @@ di->di_used = dict->ma_used; di->di_pos = 0; di->len = dict->ma_used; - if (itertype == &PyDictIterItem_Type) { + if (itertype == PyDictIterItem_Type) { di->di_result = PyTuple_Pack(2, Py_None, Py_None); if (di->di_result == NULL) { Py_DECREF(di); @@ -2297,8 +2303,8 @@ return NULL; } -PyTypeObject PyDictIterKey_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject _PyDictIterKey_Type = { + PyVarObject_HEAD_INIT(&_PyType_Type, 0) "dict_keyiterator", /* tp_name */ sizeof(dictiterobject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -2329,6 +2335,7 @@ dictiter_methods, /* tp_methods */ 0, }; +PyTypeObject *PyDictIterKey_Type = &_PyDictIterKey_Type; static PyObject *dictiter_iternextvalue(dictiterobject *di) { @@ -2369,8 +2376,8 @@ return NULL; } -PyTypeObject PyDictIterValue_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject _PyDictIterValue_Type = { + PyVarObject_HEAD_INIT(&_PyType_Type, 0) "dict_valueiterator", /* tp_name */ sizeof(dictiterobject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -2401,6 +2408,7 @@ dictiter_methods, /* tp_methods */ 0, }; +PyTypeObject *PyDictIterValue_Type = &_PyDictIterValue_Type; static PyObject *dictiter_iternextitem(dictiterobject *di) { @@ -2455,8 +2463,8 @@ return NULL; } -PyTypeObject PyDictIterItem_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject _PyDictIterItem_Type = { + PyVarObject_HEAD_INIT(&_PyType_Type, 0) "dict_itemiterator", /* tp_name */ sizeof(dictiterobject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -2487,6 +2495,7 @@ dictiter_methods, /* tp_methods */ 0, }; +PyTypeObject *PyDictIterItem_Type = &_PyDictIterItem_Type; /***********************************************/ @@ -2667,7 +2676,7 @@ if (dv->dv_dict == NULL) { Py_RETURN_NONE; } - return dictiter_new(dv->dv_dict, &PyDictIterKey_Type); + return dictiter_new(dv->dv_dict, PyDictIterKey_Type); } static int @@ -2785,8 +2794,8 @@ {NULL, NULL} /* sentinel */ }; -PyTypeObject PyDictKeys_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject _PyDictKeys_Type = { + PyVarObject_HEAD_INIT(&_PyType_Type, 0) "dict_keys", /* tp_name */ sizeof(dictviewobject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -2817,11 +2826,12 @@ dictkeys_methods, /* tp_methods */ 0, }; +PyTypeObject *PyDictKeys_Type = &_PyDictKeys_Type; static PyObject * dictkeys_new(PyObject *dict) { - return dictview_new(dict, &PyDictKeys_Type); + return dictview_new(dict, PyDictKeys_Type); } /*** dict_items ***/ @@ -2832,7 +2842,7 @@ if (dv->dv_dict == NULL) { Py_RETURN_NONE; } - return dictiter_new(dv->dv_dict, &PyDictIterItem_Type); + return dictiter_new(dv->dv_dict, PyDictIterItem_Type); } static int @@ -2869,8 +2879,8 @@ {NULL, NULL} /* sentinel */ }; -PyTypeObject PyDictItems_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject _PyDictItems_Type = { + PyVarObject_HEAD_INIT(&_PyType_Type, 0) "dict_items", /* tp_name */ sizeof(dictviewobject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -2901,11 +2911,12 @@ dictitems_methods, /* tp_methods */ 0, }; +PyTypeObject *PyDictItems_Type = &_PyDictItems_Type; static PyObject * dictitems_new(PyObject *dict) { - return dictview_new(dict, &PyDictItems_Type); + return dictview_new(dict, PyDictItems_Type); } /*** dict_values ***/ @@ -2916,7 +2927,7 @@ if (dv->dv_dict == NULL) { Py_RETURN_NONE; } - return dictiter_new(dv->dv_dict, &PyDictIterValue_Type); + return dictiter_new(dv->dv_dict, PyDictIterValue_Type); } static PySequenceMethods dictvalues_as_sequence = { @@ -2934,8 +2945,8 @@ {NULL, NULL} /* sentinel */ }; -PyTypeObject PyDictValues_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject _PyDictValues_Type = { + PyVarObject_HEAD_INIT(&_PyType_Type, 0) "dict_values", /* tp_name */ sizeof(dictviewobject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -2966,9 +2977,17 @@ dictvalues_methods, /* tp_methods */ 0, }; +PyTypeObject *PyDictValues_Type = &_PyDictValues_Type; static PyObject * dictvalues_new(PyObject *dict) { - return dictview_new(dict, &PyDictValues_Type); + return dictview_new(dict, PyDictValues_Type); } + + +/* TODO remove this! */ +int PyDict_Init(void) { + return 0; +} + diff -r a156f602debc Objects/enumobject.c --- a/Objects/enumobject.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Objects/enumobject.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,6 +1,8 @@ /* enumerate object */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "pytypeconvert.h" typedef struct { PyObject_HEAD @@ -166,8 +168,9 @@ "zero) and a value yielded by the iterable argument. enumerate is useful\n" "for obtaining an indexed list: (0, seq[0]), (1, seq[1]), (2, seq[2]), ..."); -PyTypeObject PyEnum_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject *PyEnum_Type; +PyTypeObject _PyEnum_Type = { + PyVarObject_HEAD_INIT(NULL, 0) "enumerate", /* tp_name */ sizeof(enumobject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -225,7 +228,7 @@ PyObject *seq; reversedobject *ro; - if (type == &PyReversed_Type && !_PyArg_NoKeywords("reversed()", kwds)) + if (type == PyReversed_Type && !_PyArg_NoKeywords("reversed()", kwds)) return NULL; if (!PyArg_UnpackTuple(args, "reversed", 1, 1, &seq) ) @@ -316,8 +319,9 @@ {NULL, NULL} /* sentinel */ }; -PyTypeObject PyReversed_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject *PyReversed_Type; +PyTypeObject _PyReversed_Type = { + PyVarObject_HEAD_INIT(NULL, 0) "reversed", /* tp_name */ sizeof(reversedobject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -359,3 +363,10 @@ reversed_new, /* tp_new */ PyObject_GC_Del, /* tp_free */ }; + +int PyEnum_Init(void) { + CONVERT_TYPE(PyEnum_Type, PyType_Type, NULL, "enumerate iterator type"); + CONVERT_TYPE(PyReversed_Type, PyType_Type, NULL, "reversed iterator type"); + return 0; +} + diff -r a156f602debc Objects/exceptions.c --- a/Objects/exceptions.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Objects/exceptions.c Tue Apr 28 19:26:52 2009 -0700 @@ -5,7 +5,9 @@ */ #define PY_SSIZE_T_CLEAN +#define PY_TYPEPRIVATE #include +#include "pytypeconvert.h" #include "structmember.h" #include "osdefs.h" @@ -1415,11 +1417,11 @@ Py_CLEAR(err->reason); if (!PyArg_ParseTuple(args, "O!O!nnO!", - &PyUnicode_Type, &err->encoding, - &PyUnicode_Type, &err->object, + PyUnicode_Type, &err->encoding, + PyUnicode_Type, &err->object, &err->start, &err->end, - &PyUnicode_Type, &err->reason)) { + PyUnicode_Type, &err->reason)) { err->encoding = err->object = err->reason = NULL; return -1; } @@ -1507,11 +1509,11 @@ Py_CLEAR(ude->reason); if (!PyArg_ParseTuple(args, "O!OnnO!", - &PyUnicode_Type, &ude->encoding, + PyUnicode_Type, &ude->encoding, &ude->object, &ude->start, &ude->end, - &PyUnicode_Type, &ude->reason)) { + PyUnicode_Type, &ude->reason)) { ude->encoding = ude->object = ude->reason = NULL; return -1; } @@ -1599,10 +1601,10 @@ Py_CLEAR(self->reason); if (!PyArg_ParseTuple(args, "O!nnO!", - &PyUnicode_Type, &self->object, + PyUnicode_Type, &self->object, &self->start, &self->end, - &PyUnicode_Type, &self->reason)) { + PyUnicode_Type, &self->reason)) { self->object = self->reason = NULL; return -1; } @@ -1817,16 +1819,21 @@ */ PyObject *PyExc_RecursionErrorInst = NULL; -#define PRE_INIT(TYPE) if (PyType_Ready(&_PyExc_ ## TYPE) < 0) \ - Py_FatalError("exceptions bootstrapping error."); +/* note: exceptions are hard-coded for now. they could concievably + be created with the new type API, but we'd have to change the + way they were declared ('cause they take their base class as a + static parameter.) +*/ +#define PRE_INIT(TYPE) if (PyType_Ready((PyTypeObject *)PyExc_ ## TYPE) < 0) \ + Py_FatalError("Can't initialize " #TYPE " exception type."); #define POST_INIT(TYPE) Py_INCREF(PyExc_ ## TYPE); \ if (PyDict_SetItemString(bdict, # TYPE, PyExc_ ## TYPE)) \ Py_FatalError("Module dictionary insertion problem."); -void -_PyExc_Init(void) +int +PyExc_Init(void) { PyObject *bltinmod, *bdict; @@ -1861,6 +1868,10 @@ PRE_INIT(KeyError) PRE_INIT(ValueError) PRE_INIT(UnicodeError) + /* hack, while we haven't converted to the new type api fully yet */ + _PyExc_UnicodeEncodeError.tp_base = (PyTypeObject *)PyExc_UnicodeError; + _PyExc_UnicodeDecodeError.tp_base = (PyTypeObject *)PyExc_UnicodeError; + _PyExc_UnicodeTranslateError.tp_base = (PyTypeObject *)PyExc_UnicodeError; PRE_INIT(UnicodeEncodeError) PRE_INIT(UnicodeDecodeError) PRE_INIT(UnicodeTranslateError) @@ -1947,11 +1958,11 @@ POST_INIT(UnicodeWarning) POST_INIT(BytesWarning) - PyExc_MemoryErrorInst = BaseException_new(&_PyExc_MemoryError, NULL, NULL); + PyExc_MemoryErrorInst = BaseException_new((PyTypeObject *)PyExc_MemoryError, NULL, NULL); if (!PyExc_MemoryErrorInst) Py_FatalError("Cannot pre-allocate MemoryError instance"); - PyExc_RecursionErrorInst = BaseException_new(&_PyExc_RuntimeError, NULL, NULL); + PyExc_RecursionErrorInst = BaseException_new((PyTypeObject *)PyExc_RuntimeError, NULL, NULL); if (!PyExc_RecursionErrorInst) Py_FatalError("Cannot pre-allocate RuntimeError instance for " "recursion errors"); @@ -1975,6 +1986,8 @@ } Py_DECREF(bltinmod); + + return 0; } void diff -r a156f602debc Objects/fileobject.c --- a/Objects/fileobject.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Objects/fileobject.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,7 +1,9 @@ /* File object implementation (what's left of it -- see io.py) */ #define PY_SSIZE_T_CLEAN +#define PY_TYPEPRIVATE #include "Python.h" +#include "pytypeconvert.h" #ifdef HAVE_GETC_UNLOCKED #define GETC(f) getc_unlocked(f) @@ -370,7 +372,7 @@ } self = PyObject_New(PyStdPrinter_Object, - &PyStdPrinter_Type); + PyStdPrinter_Type); if (self != NULL) { self->fd = fd; } @@ -480,8 +482,9 @@ {0}, }; -PyTypeObject PyStdPrinter_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject *PyStdPrinter_Type; +PyTypeObject _PyStdPrinter_Type = { + PyVarObject_HEAD_INIT(NULL, 0) "stderrprinter", /* tp_name */ sizeof(PyStdPrinter_Object), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -523,6 +526,11 @@ PyObject_Del, /* tp_free */ }; +int PyFile_Init(void) { + CONVERT_TYPE(PyStdPrinter_Type, PyType_Type, NULL, "StdPrinter type"); + return 0; +} + #ifdef __cplusplus } diff -r a156f602debc Objects/floatobject.c --- a/Objects/floatobject.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Objects/floatobject.c Tue Apr 28 19:26:52 2009 -0700 @@ -4,7 +4,9 @@ /* XXX There should be overflow checks here, but it's hard to check for any kind of float exception without losing portability. */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "pytypeconvert.h" #include "structseq.h" #include @@ -70,7 +72,7 @@ return DBL_MIN; } -static PyTypeObject FloatInfoType; +static PyTypeObject *FloatInfoType = NULL; PyDoc_STRVAR(floatinfo__doc__, "sys.floatinfo\n\ @@ -112,7 +114,7 @@ PyObject* floatinfo; int pos = 0; - floatinfo = PyStructSequence_New(&FloatInfoType); + floatinfo = PyStructSequence_New(FloatInfoType); if (floatinfo == NULL) { return NULL; } @@ -154,7 +156,7 @@ /* Inline PyObject_New */ op = free_list; free_list = (PyFloatObject *)Py_TYPE(op); - PyObject_INIT(op, &PyFloat_Type); + PyObject_INIT(op, PyFloat_Type); op->ob_fval = fval; return (PyObject *) op; } @@ -727,7 +729,7 @@ /* Negative numbers raised to fractional powers * become complex. */ - return PyComplex_Type.tp_as_number->nb_power(v, w, z); + return PyType_GetTernaryFunction(PyComplex_Type, pytoe_number_power)(v, w, z); } /* iw is an exact integer, albeit perhaps a very large one. * -1 raised to an exact integer should never be exceptional. @@ -1441,7 +1443,6 @@ PyObject *numerator = NULL; PyObject *denominator = NULL; PyObject *result_pair = NULL; - PyNumberMethods *long_methods = PyLong_Type.tp_as_number; #define INPLACE_UPDATE(obj, call) \ prev = obj; \ @@ -1483,11 +1484,11 @@ py_exponent = PyLong_FromLong(labs((long)exponent)); if (py_exponent == NULL) goto error; INPLACE_UPDATE(py_exponent, - long_methods->nb_lshift(denominator, py_exponent)); + PyType_GetBinaryFunction(PyLong_Type, pytoe_number_lshift)(denominator, py_exponent)); if (py_exponent == NULL) goto error; if (exponent > 0) { INPLACE_UPDATE(numerator, - long_methods->nb_multiply(numerator, py_exponent)); + PyType_GetBinaryFunction(PyLong_Type, pytoe_number_multiply)(numerator, py_exponent)); if (numerator == NULL) goto error; } else { @@ -1530,7 +1531,7 @@ PyObject *x = Py_False; /* Integer zero */ static char *kwlist[] = {"x", 0}; - if (type != &PyFloat_Type) + if (type != PyFloat_Type) return float_subtype_new(type, args, kwds); /* Wimp out */ if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:float", kwlist, &x)) return NULL; @@ -1551,8 +1552,8 @@ { PyObject *tmp, *newobj; - assert(PyType_IsSubtype(type, &PyFloat_Type)); - tmp = float_new(&PyFloat_Type, args, kwds); + assert(PyType_IsSubtype(type, PyFloat_Type)); + tmp = float_new(PyFloat_Type, args, kwds); if (tmp == NULL) return NULL; assert(PyFloat_CheckExact(tmp)); @@ -1813,8 +1814,9 @@ 0, /* nb_inplace_true_divide */ }; -PyTypeObject PyFloat_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject *PyFloat_Type; +PyTypeObject _PyFloat_Type = { + PyVarObject_HEAD_INIT(NULL, 0) "float", sizeof(PyFloatObject), 0, @@ -1854,8 +1856,8 @@ float_new, /* tp_new */ }; -void -_PyFloat_Init(void) +int +PyFloat_Init(void) { /* We attempt to determine if this machine is using IEEE floating point formats by peering at the bits of some @@ -1903,9 +1905,16 @@ double_format = detected_double_format; float_format = detected_float_format; + CONVERT_TYPE(PyFloat_Type, PyType_Type, NULL, "float type"); + /* Init float info */ - if (FloatInfoType.tp_name == 0) - PyStructSequence_InitType(&FloatInfoType, &floatinfo_desc); + if (FloatInfoType == NULL) { + FloatInfoType = PyStructSequence_InitType(&floatinfo_desc); + if (FloatInfoType == NULL) { + return -1; + } + } + return 0; } int @@ -2412,3 +2421,4 @@ return x; } } + diff -r a156f602debc Objects/frameobject.c --- a/Objects/frameobject.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Objects/frameobject.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,6 +1,8 @@ /* Frame object implementation */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "pytypeconvert.h" #include "code.h" #include "frameobject.h" @@ -537,8 +539,9 @@ {NULL, NULL} /* sentinel */ }; -PyTypeObject PyFrame_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject *PyFrame_Type; +PyTypeObject _PyFrame_Type = { + PyVarObject_HEAD_INIT(NULL, 0) "frame", sizeof(PyFrameObject), sizeof(PyObject *), @@ -574,12 +577,13 @@ static PyObject *builtin_object; -int _PyFrame_Init() +int PyFrame_Init(void) { + CONVERT_TYPE(PyFrame_Type, PyType_Type, NULL, "frame type"); builtin_object = PyUnicode_InternFromString("__builtins__"); if (builtin_object == NULL) - return 0; - return 1; + return 1; + return 0; } PyFrameObject * @@ -641,7 +645,7 @@ extras = code->co_stacksize + code->co_nlocals + ncells + nfrees; if (free_list == NULL) { - f = PyObject_GC_NewVar(PyFrameObject, &PyFrame_Type, + f = PyObject_GC_NewVar(PyFrameObject, PyFrame_Type, extras); if (f == NULL) { Py_DECREF(builtins); diff -r a156f602debc Objects/funcobject.c --- a/Objects/funcobject.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Objects/funcobject.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,7 +1,9 @@ /* Function object implementation */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "typeprivate.h" #include "code.h" #include "eval.h" #include "structmember.h" @@ -10,7 +12,7 @@ PyFunction_New(PyObject *code, PyObject *globals) { PyFunctionObject *op = PyObject_GC_New(PyFunctionObject, - &PyFunction_Type); + PyFunction_Type); static PyObject *__name__ = 0; if (op != NULL) { PyObject *doc; @@ -478,8 +480,8 @@ if (!PyArg_ParseTupleAndKeywords(args, kw, "O!O!|OOO:function", kwlist, - &PyCode_Type, &code, - &PyDict_Type, &globals, + PyCode_Type, &code, + PyDict_Type, &globals, &name, &defaults, &closure)) return NULL; if (name != Py_None && !PyUnicode_Check(name)) { @@ -650,8 +652,11 @@ return PyMethod_New(func, obj); } -PyTypeObject PyFunction_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +/* note: PyFunction MUST be hard-coded, can't use PyType_New(). + it's used heavily in the implementation of types themselves. +*/ +PyTypeObject _PyFunction_Type = { + PyVarObject_HEAD_INIT(&_PyType_Type, 0) "function", sizeof(PyFunctionObject), 0, @@ -690,6 +695,7 @@ 0, /* tp_alloc */ func_new, /* tp_new */ }; +PyTypeObject *PyFunction_Type = &_PyFunction_Type; /* Class method object */ @@ -796,8 +802,11 @@ Class methods are different than C++ or Java static methods.\n\ If you want those, see the staticmethod builtin."); -PyTypeObject PyClassMethod_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +/* note: class method MUST be hard-coded, can't use PyType_New(). + it's used heavily in the implementation of types themselves. +*/ +PyTypeObject _PyClassMethod_Type = { + PyVarObject_HEAD_INIT(&_PyType_Type, 0) "classmethod", sizeof(classmethod), 0, @@ -837,12 +846,13 @@ PyType_GenericNew, /* tp_new */ PyObject_GC_Del, /* tp_free */ }; +PyTypeObject *PyClassMethod_Type = &_PyClassMethod_Type; PyObject * PyClassMethod_New(PyObject *callable) { classmethod *cm = (classmethod *) - PyType_GenericAlloc(&PyClassMethod_Type, 0); + PyType_GenericAlloc(PyClassMethod_Type, 0); if (cm != NULL) { Py_INCREF(callable); cm->cm_callable = callable; @@ -943,8 +953,11 @@ Static methods in Python are similar to those found in Java or C++.\n\ For a more advanced concept, see the classmethod builtin."); -PyTypeObject PyStaticMethod_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +/* note: static method MUST be hard-coded, can't use PyType_New(). + it's used heavily in the implementation of types themselves. +*/ +PyTypeObject _PyStaticMethod_Type = { + PyVarObject_HEAD_INIT(&_PyType_Type, 0) "staticmethod", sizeof(staticmethod), 0, @@ -984,15 +997,18 @@ PyType_GenericNew, /* tp_new */ PyObject_GC_Del, /* tp_free */ }; +PyTypeObject *PyStaticMethod_Type = &_PyStaticMethod_Type; + PyObject * PyStaticMethod_New(PyObject *callable) { staticmethod *sm = (staticmethod *) - PyType_GenericAlloc(&PyStaticMethod_Type, 0); + PyType_GenericAlloc(PyStaticMethod_Type, 0); if (sm != NULL) { Py_INCREF(callable); sm->sm_callable = callable; } return (PyObject *)sm; } + diff -r a156f602debc Objects/genobject.c --- a/Objects/genobject.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Objects/genobject.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,6 +1,8 @@ /* Generator object implementation */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "pytypeconvert.h" #include "frameobject.h" #include "genobject.h" #include "ceval.h" @@ -323,8 +325,9 @@ {NULL, NULL} /* Sentinel */ }; -PyTypeObject PyGen_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject *PyGen_Type; +PyTypeObject _PyGen_Type = { + PyVarObject_HEAD_INIT(NULL, 0) "generator", /* tp_name */ sizeof(PyGenObject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -377,7 +380,7 @@ PyObject * PyGen_New(PyFrameObject *f) { - PyGenObject *gen = PyObject_GC_New(PyGenObject, &PyGen_Type); + PyGenObject *gen = PyObject_GC_New(PyGenObject, PyGen_Type); if (gen == NULL) { Py_DECREF(f); return NULL; @@ -410,3 +413,9 @@ /* No blocks except loops, it's safe to skip finalization. */ return 0; } + +int PyGen_Init(void) { + CONVERT_TYPE(PyGen_Type, PyType_Type, NULL, "generator type"); + return 0; +} + diff -r a156f602debc Objects/iterobject.c --- a/Objects/iterobject.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Objects/iterobject.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,6 +1,8 @@ /* Iterator objects */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "pytypeconvert.h" typedef struct { PyObject_HEAD @@ -17,7 +19,7 @@ PyErr_BadInternalCall(); return NULL; } - it = PyObject_GC_New(seqiterobject, &PySeqIter_Type); + it = PyObject_GC_New(seqiterobject, PySeqIter_Type); if (it == NULL) return NULL; it->it_index = 0; @@ -93,8 +95,9 @@ {NULL, NULL} /* sentinel */ }; -PyTypeObject PySeqIter_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject *PySeqIter_Type; +PyTypeObject _PySeqIter_Type = { + PyVarObject_HEAD_INIT(NULL, 0) "iterator", /* tp_name */ sizeof(seqiterobject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -138,7 +141,7 @@ PyCallIter_New(PyObject *callable, PyObject *sentinel) { calliterobject *it; - it = PyObject_GC_New(calliterobject, &PyCallIter_Type); + it = PyObject_GC_New(calliterobject, PyCallIter_Type); if (it == NULL) return NULL; Py_INCREF(callable); @@ -197,8 +200,9 @@ return NULL; } -PyTypeObject PyCallIter_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject *PyCallIter_Type; +PyTypeObject _PyCallIter_Type = { + PyVarObject_HEAD_INIT(NULL, 0) "callable_iterator", /* tp_name */ sizeof(calliterobject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -230,3 +234,8 @@ }; +int PyIterObject_Init(void) { + CONVERT_TYPE(PySeqIter_Type, PyType_Type, NULL, ""); + CONVERT_TYPE(PyCallIter_Type, PyType_Type, NULL, ""); + return 0; +} diff -r a156f602debc Objects/listobject.c --- a/Objects/listobject.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Objects/listobject.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,6 +1,8 @@ /* List object implementation */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "pytypeconvert.h" #ifdef STDC_HEADERS #include @@ -139,7 +141,7 @@ count_reuse++; #endif } else { - op = PyObject_GC_New(PyListObject, &PyList_Type); + op = PyObject_GC_New(PyListObject, PyList_Type); if (op == NULL) return NULL; #ifdef SHOW_ALLOC_COUNT @@ -1778,8 +1780,8 @@ static void sortwrapper_dealloc(sortwrapperobject *); -PyTypeObject PySortWrapper_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject _PySortWrapper_Type = { + PyVarObject_HEAD_INIT(NULL, 0) "sortwrapper", /* tp_name */ sizeof(sortwrapperobject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -1805,12 +1807,13 @@ 0, /* tp_clear */ (richcmpfunc)sortwrapper_richcompare, /* tp_richcompare */ }; +PyTypeObject *PySortWrapper_Type = &_PySortWrapper_Type; static PyObject * sortwrapper_richcompare(sortwrapperobject *a, sortwrapperobject *b, int op) { - if (!PyObject_TypeCheck(b, &PySortWrapper_Type)) { + if (!PyObject_TypeCheck(b, PySortWrapper_Type)) { PyErr_SetString(PyExc_TypeError, "expected a sortwrapperobject"); return NULL; @@ -1834,7 +1837,7 @@ { sortwrapperobject *so; - so = PyObject_New(sortwrapperobject, &PySortWrapper_Type); + so = PyObject_New(sortwrapperobject, PySortWrapper_Type); if (so == NULL) return NULL; so->key = key; @@ -1848,7 +1851,7 @@ { PyObject *value; - if (!PyObject_TypeCheck(so, &PySortWrapper_Type)) { + if (!PyObject_TypeCheck(so, PySortWrapper_Type)) { PyErr_SetString(PyExc_TypeError, "expected a sortwrapperobject"); return NULL; @@ -2560,8 +2563,8 @@ (objobjargproc)list_ass_subscript }; -PyTypeObject PyList_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject _PyList_Type = { + PyVarObject_HEAD_INIT(NULL, 0) "list", sizeof(PyListObject), 0, @@ -2602,6 +2605,7 @@ PyType_GenericNew, /* tp_new */ PyObject_GC_Del, /* tp_free */ }; +PyTypeObject *PyList_Type = &_PyList_Type; /*********************** List Iterator **************************/ @@ -2625,8 +2629,8 @@ {NULL, NULL} /* sentinel */ }; -PyTypeObject PyListIter_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject _PyListIter_Type = { + PyVarObject_HEAD_INIT(NULL, 0) "list_iterator", /* tp_name */ sizeof(listiterobject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -2657,6 +2661,7 @@ listiter_methods, /* tp_methods */ 0, /* tp_members */ }; +PyTypeObject *PyListIter_Type = &_PyListIter_Type; static PyObject * @@ -2668,7 +2673,7 @@ PyErr_BadInternalCall(); return NULL; } - it = PyObject_GC_New(listiterobject, &PyListIter_Type); + it = PyObject_GC_New(listiterobject, PyListIter_Type); if (it == NULL) return NULL; it->it_index = 0; @@ -2747,8 +2752,8 @@ {NULL, NULL} /* sentinel */ }; -PyTypeObject PyListRevIter_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject _PyListRevIter_Type = { + PyVarObject_HEAD_INIT(NULL, 0) "list_reverseiterator", /* tp_name */ sizeof(listreviterobject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -2779,13 +2784,14 @@ listreviter_methods, /* tp_methods */ 0, }; +PyTypeObject *PyListRevIter_Type = &_PyListRevIter_Type; static PyObject * list_reversed(PyListObject *seq, PyObject *unused) { listreviterobject *it; - it = PyObject_GC_New(listreviterobject, &PyListRevIter_Type); + it = PyObject_GC_New(listreviterobject, PyListRevIter_Type); if (it == NULL) return NULL; assert(PyList_Check(seq)); @@ -2841,3 +2847,13 @@ return PyLong_FromSsize_t(len); } + +int PyList_Init(void) +{ + CONVERT_TYPE(PyList_Type, PyType_Type, NULL, "list type"); + CONVERT_TYPE(PyListIter_Type, PyType_Type, NULL, "list iterator type"); + CONVERT_TYPE(PyListRevIter_Type, PyType_Type, NULL, "list reversed iterator type"); + CONVERT_TYPE(PySortWrapper_Type, PyType_Type, NULL, "list sort wrapper type"); + return 0; +} + diff -r a156f602debc Objects/longobject.c --- a/Objects/longobject.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Objects/longobject.c Tue Apr 28 19:26:52 2009 -0700 @@ -2,7 +2,9 @@ /* XXX The functional organization of this file is terrible */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "pytypeconvert.h" #include "longintrepr.h" #include "structseq.h" @@ -147,7 +149,7 @@ PyErr_NoMemory(); return NULL; } - return (PyLongObject*)PyObject_INIT_VAR(result, &PyLong_Type, size); + return (PyLongObject*)PyObject_INIT_VAR(result, PyLong_Type, size); } PyObject * @@ -3290,7 +3292,7 @@ arguments to double. */ Py_DECREF(a); Py_DECREF(b); - return PyFloat_Type.tp_as_number->nb_power(v, w, x); + return PyType_GetTernaryFunction(PyFloat_Type, pytoe_number_power)(v, w, x); } } @@ -3754,7 +3756,7 @@ int base = -909; /* unlikely! */ static char *kwlist[] = {"x", "base", 0}; - if (type != &PyLong_Type) + if (type != PyLong_Type) return long_subtype_new(type, args, kwds); /* Wimp out */ if (!PyArg_ParseTupleAndKeywords(args, kwds, "|Oi:int", kwlist, &x, &base)) @@ -3804,8 +3806,8 @@ PyLongObject *tmp, *newobj; Py_ssize_t i, n; - assert(PyType_IsSubtype(type, &PyLong_Type)); - tmp = (PyLongObject *)long_new(&PyLong_Type, args, kwds); + assert(PyType_IsSubtype(type, PyLong_Type)); + tmp = (PyLongObject *)long_new(PyLong_Type, args, kwds); if (tmp == NULL) return NULL; assert(PyLong_CheckExact(tmp)); @@ -4156,8 +4158,9 @@ long_long, /* nb_index */ }; -PyTypeObject PyLong_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject *PyLong_Type; +PyTypeObject _PyLong_Type = { + PyVarObject_HEAD_INIT(NULL, 0) "int", /* tp_name */ offsetof(PyLongObject, ob_digit), /* tp_basicsize */ sizeof(digit), /* tp_itemsize */ @@ -4199,7 +4202,7 @@ PyObject_Del, /* tp_free */ }; -static PyTypeObject Int_InfoType; +static PyTypeObject *Int_InfoType; PyDoc_STRVAR(int_info__doc__, "sys.int_info\n\ @@ -4226,7 +4229,7 @@ { PyObject* int_info; int field = 0; - int_info = PyStructSequence_New(&Int_InfoType); + int_info = PyStructSequence_New(Int_InfoType); if (int_info == NULL) return NULL; PyStructSequence_SET_ITEM(int_info, field++, @@ -4241,15 +4244,17 @@ } int -_PyLong_Init(void) -{ +PyLong_Init(void) +{ + CONVERT_TYPE(PyLong_Type, PyType_Type, NULL, "int type"); + #if NSMALLNEGINTS + NSMALLPOSINTS > 0 int ival, size; PyLongObject *v = small_ints; for (ival = -NSMALLNEGINTS; ival < NSMALLPOSINTS; ival++, v++) { size = (ival < 0) ? -1 : ((ival == 0) ? 0 : 1); - if (Py_TYPE(v) == &PyLong_Type) { + if (Py_TYPE(v) == PyLong_Type) { /* The element is already initialized, most likely * the Python interpreter was initialized before. */ @@ -4266,17 +4271,21 @@ assert(v->ob_digit[0] == abs(ival)); } else { - PyObject_INIT(v, &PyLong_Type); + PyObject_INIT(v, PyLong_Type); } Py_SIZE(v) = size; v->ob_digit[0] = abs(ival); } #endif /* initialize int_info */ - if (Int_InfoType.tp_name == 0) - PyStructSequence_InitType(&Int_InfoType, &int_info_desc); - - return 1; + if (Int_InfoType == NULL) { + Int_InfoType = PyStructSequence_InitType(&int_info_desc); + if (Int_InfoType == NULL) { + return -1; + } + } + + return 0; } void diff -r a156f602debc Objects/memoryobject.c --- a/Objects/memoryobject.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Objects/memoryobject.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,7 +1,9 @@ /* Memoryview object implementation */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "pytypeconvert.h" static Py_ssize_t get_shape0(Py_buffer *buf) @@ -61,7 +63,7 @@ PyMemoryViewObject *mview; mview = (PyMemoryViewObject *) - PyObject_GC_New(PyMemoryViewObject, &PyMemoryView_Type); + PyObject_GC_New(PyMemoryViewObject, PyMemoryView_Type); if (mview == NULL) return NULL; mview->base = NULL; @@ -85,7 +87,7 @@ } mview = (PyMemoryViewObject *) - PyObject_GC_New(PyMemoryViewObject, &PyMemoryView_Type); + PyObject_GC_New(PyMemoryViewObject, PyMemoryView_Type); if (mview == NULL) return NULL; @@ -259,7 +261,7 @@ return NULL; } - mem = PyObject_GC_New(PyMemoryViewObject, &PyMemoryView_Type); + mem = PyObject_GC_New(PyMemoryViewObject, PyMemoryView_Type); if (mem == NULL) return NULL; @@ -414,7 +416,7 @@ memory_tobytes(PyMemoryViewObject *mem, PyObject *noargs) { return PyObject_CallFunctionObjArgs( - (PyObject *) &PyBytes_Type, mem, NULL); + (PyObject *)PyBytes_Type, mem, NULL); } /* TODO: rewrite this function using the struct module to unpack @@ -780,8 +782,9 @@ }; -PyTypeObject PyMemoryView_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject *PyMemoryView_Type; +PyTypeObject _PyMemoryView_Type = { + PyVarObject_HEAD_INIT(NULL, 0) "memoryview", sizeof(PyMemoryViewObject), 0, @@ -820,3 +823,9 @@ 0, /* tp_alloc */ memory_new, /* tp_new */ }; + +int PyMemoryView_Init(void) { + CONVERT_TYPE(PyMemoryView_Type, PyType_Type, NULL, "memory view type"); + return 0; +} + diff -r a156f602debc Objects/methodobject.c --- a/Objects/methodobject.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Objects/methodobject.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,7 +1,9 @@ /* Method object implementation */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "typeprivate.h" #include "structmember.h" /* Free list for method objects to safe malloc/free overhead @@ -20,11 +22,11 @@ op = free_list; if (op != NULL) { free_list = (PyCFunctionObject *)(op->m_self); - PyObject_INIT(op, &PyCFunction_Type); + PyObject_INIT(op, PyCFunction_Type); numfree--; } else { - op = PyObject_GC_New(PyCFunctionObject, &PyCFunction_Type); + op = PyObject_GC_New(PyCFunctionObject, PyCFunction_Type); if (op == NULL) return NULL; } @@ -245,8 +247,11 @@ } -PyTypeObject PyCFunction_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +/* note: CFunction MUST be hard-coded, can't use PyType_New(). + it's used heavily in the implementation of types themselves. +*/ +PyTypeObject _PyCFunction_Type = { + PyVarObject_HEAD_INIT(&_PyType_Type, 0) "builtin_function_or_method", sizeof(PyCFunctionObject), 0, @@ -279,6 +284,7 @@ 0, /* tp_base */ 0, /* tp_dict */ }; +PyTypeObject *PyCFunction_Type = &_PyCFunction_Type; /* Clear out the free list */ diff -r a156f602debc Objects/moduleobject.c --- a/Objects/moduleobject.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Objects/moduleobject.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,7 +1,9 @@ /* Module object implementation */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "pytypeconvert.h" #include "structmember.h" static Py_ssize_t max_module_number; @@ -18,8 +20,9 @@ {0} }; -static PyTypeObject moduledef_type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +static PyTypeObject *moduledef_type; +static PyTypeObject _moduledef_type = { + PyVarObject_HEAD_INIT(NULL, 0) "moduledef", /* tp_name */ sizeof(struct PyModuleDef), /* tp_size */ 0, /* tp_itemsize */ @@ -31,7 +34,7 @@ { PyModuleObject *m; PyObject *nameobj; - m = PyObject_GC_New(PyModuleObject, &PyModule_Type); + m = PyObject_GC_New(PyModuleObject, PyModule_Type); if (m == NULL) return NULL; m->md_def = NULL; @@ -69,12 +72,16 @@ PyModuleObject *m; if (!Py_IsInitialized()) Py_FatalError("Interpreter not initialized (version mismatch?)"); - if (PyType_Ready(&moduledef_type) < 0) - return NULL; + if (!moduledef_type) { + _moduledef_type.ob_base.ob_base.ob_type = PyType_Type; + moduledef_type = PyType_Convert(&_moduledef_type); + if (!moduledef_type) + return NULL; + } if (module->m_base.m_index == 0) { max_module_number++; Py_REFCNT(module) = 1; - Py_TYPE(module) = &moduledef_type; + Py_TYPE(module) = moduledef_type; module->m_base.m_index = max_module_number; } name = module->m_name; @@ -370,8 +377,9 @@ Create a module object.\n\ The name must be a string; the optional doc argument can have any type."); -PyTypeObject PyModule_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject *PyModule_Type; +PyTypeObject _PyModule_Type = { + PyVarObject_HEAD_INIT(NULL, 0) "module", /* tp_name */ sizeof(PyModuleObject), /* tp_size */ 0, /* tp_itemsize */ @@ -412,3 +420,8 @@ PyType_GenericNew, /* tp_new */ PyObject_GC_Del, /* tp_free */ }; + +int PyModule_Init(void) { + CONVERT_TYPE(PyModule_Type, PyType_Type, NULL, "module object"); + return 0; +} diff -r a156f602debc Objects/object.c --- a/Objects/object.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Objects/object.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,7 +1,9 @@ /* Generic object operations; and implementation of None (NoObject) */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "typeprivate.h" #include "sliceobject.h" /* For PyEllipsis_Type */ #include "frameobject.h" @@ -350,17 +352,11 @@ if (op == NULL) fprintf(stderr, "NULL\n"); else { -#ifdef WITH_THREAD PyGILState_STATE gil; -#endif fprintf(stderr, "object : "); -#ifdef WITH_THREAD gil = PyGILState_Ensure(); -#endif (void)PyObject_Print(op, stderr, 0); -#ifdef WITH_THREAD PyGILState_Release(gil); -#endif /* XXX(twouters) cast refcount to long until %zd is universally available */ fprintf(stderr, "\n" @@ -1424,7 +1420,7 @@ static PyTypeObject PyNone_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) + PyVarObject_HEAD_INIT(&_PyType_Type, 0) "NoneType", 0, 0, @@ -1455,7 +1451,7 @@ } static PyTypeObject PyNotImplemented_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) + PyVarObject_HEAD_INIT(&_PyType_Type, 0) "NotImplementedType", 0, 0, @@ -1479,129 +1475,21 @@ void _Py_ReadyTypes(void) { - if (PyType_Ready(&PyType_Type) < 0) + /* PyType_Type must be created by hand! */ + if (PyType_Ready(&_PyType_Type) < 0) Py_FatalError("Can't initialize type type"); - if (PyType_Ready(&_PyWeakref_RefType) < 0) - Py_FatalError("Can't initialize weakref type"); - - if (PyType_Ready(&_PyWeakref_CallableProxyType) < 0) - Py_FatalError("Can't initialize callable weakref proxy type"); - - if (PyType_Ready(&_PyWeakref_ProxyType) < 0) - Py_FatalError("Can't initialize weakref proxy type"); - - if (PyType_Ready(&PyBool_Type) < 0) - Py_FatalError("Can't initialize bool type"); - - if (PyType_Ready(&PyByteArray_Type) < 0) - Py_FatalError("Can't initialize bytearray type"); - - if (PyType_Ready(&PyBytes_Type) < 0) - Py_FatalError("Can't initialize 'str'"); - - if (PyType_Ready(&PyList_Type) < 0) - Py_FatalError("Can't initialize list type"); - if (PyType_Ready(&PyNone_Type) < 0) Py_FatalError("Can't initialize None type"); - if (PyType_Ready(Py_Ellipsis->ob_type) < 0) - Py_FatalError("Can't initialize type(Ellipsis)"); - if (PyType_Ready(&PyNotImplemented_Type) < 0) Py_FatalError("Can't initialize NotImplemented type"); - if (PyType_Ready(&PyTraceBack_Type) < 0) - Py_FatalError("Can't initialize traceback type"); - - if (PyType_Ready(&PySuper_Type) < 0) + if (PyType_Ready(PySuper_Type) < 0) Py_FatalError("Can't initialize super type"); - if (PyType_Ready(&PyBaseObject_Type) < 0) + if (PyType_Ready(&_PyBaseObject_Type) < 0) Py_FatalError("Can't initialize object type"); - - if (PyType_Ready(&PyRange_Type) < 0) - Py_FatalError("Can't initialize range type"); - - if (PyType_Ready(&PyDict_Type) < 0) - Py_FatalError("Can't initialize dict type"); - - if (PyType_Ready(&PySet_Type) < 0) - Py_FatalError("Can't initialize set type"); - - if (PyType_Ready(&PyUnicode_Type) < 0) - Py_FatalError("Can't initialize str type"); - - if (PyType_Ready(&PySlice_Type) < 0) - Py_FatalError("Can't initialize slice type"); - - if (PyType_Ready(&PyStaticMethod_Type) < 0) - Py_FatalError("Can't initialize static method type"); - -#ifndef WITHOUT_COMPLEX - if (PyType_Ready(&PyComplex_Type) < 0) - Py_FatalError("Can't initialize complex type"); -#endif - if (PyType_Ready(&PyFloat_Type) < 0) - Py_FatalError("Can't initialize float type"); - - if (PyType_Ready(&PyLong_Type) < 0) - Py_FatalError("Can't initialize int type"); - - if (PyType_Ready(&PyFrozenSet_Type) < 0) - Py_FatalError("Can't initialize frozenset type"); - - if (PyType_Ready(&PyProperty_Type) < 0) - Py_FatalError("Can't initialize property type"); - - if (PyType_Ready(&PyMemoryView_Type) < 0) - Py_FatalError("Can't initialize memoryview type"); - - if (PyType_Ready(&PyTuple_Type) < 0) - Py_FatalError("Can't initialize tuple type"); - - if (PyType_Ready(&PyEnum_Type) < 0) - Py_FatalError("Can't initialize enumerate type"); - - if (PyType_Ready(&PyReversed_Type) < 0) - Py_FatalError("Can't initialize reversed type"); - - if (PyType_Ready(&PyStdPrinter_Type) < 0) - Py_FatalError("Can't initialize StdPrinter"); - - if (PyType_Ready(&PyCode_Type) < 0) - Py_FatalError("Can't initialize code type"); - - if (PyType_Ready(&PyFrame_Type) < 0) - Py_FatalError("Can't initialize frame type"); - - if (PyType_Ready(&PyCFunction_Type) < 0) - Py_FatalError("Can't initialize builtin function type"); - - if (PyType_Ready(&PyMethod_Type) < 0) - Py_FatalError("Can't initialize method type"); - - if (PyType_Ready(&PyFunction_Type) < 0) - Py_FatalError("Can't initialize function type"); - - if (PyType_Ready(&PyDictProxy_Type) < 0) - Py_FatalError("Can't initialize dict proxy type"); - - if (PyType_Ready(&PyGen_Type) < 0) - Py_FatalError("Can't initialize generator type"); - - if (PyType_Ready(&PyGetSetDescr_Type) < 0) - Py_FatalError("Can't initialize get-set descriptor type"); - - if (PyType_Ready(&PyWrapperDescr_Type) < 0) - Py_FatalError("Can't initialize wrapper type"); - - if (PyType_Ready(&PyEllipsis_Type) < 0) - Py_FatalError("Can't initialize ellipsis type"); - - if (PyType_Ready(&PyMemberDescr_Type) < 0) - Py_FatalError("Can't initialize member descriptor type"); } @@ -1717,10 +1605,6 @@ #endif -/* Hack to force loading of cobject.o */ -PyTypeObject *_Py_cobject_hack = &PyCObject_Type; - - /* Hack to force loading of abstract.o */ Py_ssize_t (*_Py_abstract_hack)(PyObject *) = PyObject_Size; diff -r a156f602debc Objects/rangeobject.c --- a/Objects/rangeobject.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Objects/rangeobject.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,6 +1,8 @@ /* Range object implementation */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "pytypeconvert.h" /* Support objects whose length is > PY_SSIZE_T_MAX. @@ -81,7 +83,7 @@ goto Fail; } - obj = PyObject_New(rangeobject, &PyRange_Type); + obj = PyObject_New(rangeobject, PyRange_Type); if (obj == NULL) goto Fail; obj->start = start; @@ -280,8 +282,9 @@ {NULL, NULL} /* sentinel */ }; -PyTypeObject PyRange_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject *PyRange_Type; +PyTypeObject _PyRange_Type = { + PyVarObject_HEAD_INIT(NULL, 0) "range", /* Name of this type */ sizeof(rangeobject), /* Basic object size */ 0, /* Item size for varobject */ @@ -375,8 +378,9 @@ {NULL, NULL} /* sentinel */ }; -PyTypeObject PyRangeIter_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject *PyRangeIter_Type; +PyTypeObject _PyRangeIter_Type = { + PyVarObject_HEAD_INIT(NULL, 0) "range_iterator", /* tp_name */ sizeof(rangeiterobject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -449,7 +453,7 @@ static PyObject * int_range_iter(long start, long stop, long step) { - rangeiterobject *it = PyObject_New(rangeiterobject, &PyRangeIter_Type); + rangeiterobject *it = PyObject_New(rangeiterobject, PyRangeIter_Type); if (it == NULL) return NULL; it->start = start; @@ -527,8 +531,9 @@ return result; } -PyTypeObject PyLongRangeIter_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject *PyLongRangeIter_Type; +PyTypeObject _PyLongRangeIter_Type = { + PyVarObject_HEAD_INIT(NULL, 0) "longrange_iterator", /* tp_name */ sizeof(longrangeiterobject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -584,7 +589,7 @@ and try again with a long range. */ PyErr_Clear(); - it = PyObject_New(longrangeiterobject, &PyLongRangeIter_Type); + it = PyObject_New(longrangeiterobject, PyLongRangeIter_Type); if (it == NULL) return NULL; @@ -650,7 +655,7 @@ } PyErr_Clear(); - it = PyObject_New(longrangeiterobject, &PyLongRangeIter_Type); + it = PyObject_New(longrangeiterobject, PyLongRangeIter_Type); if (it == NULL) return NULL; @@ -700,3 +705,12 @@ PyObject_Del(it); return NULL; } + + +int PyRange_Init(void) { + CONVERT_TYPE(PyRange_Type, PyType_Type, NULL, "range type"); + CONVERT_TYPE(PyRangeIter_Type, PyType_Type, NULL, "range iterator type"); + CONVERT_TYPE(PyLongRangeIter_Type, PyType_Type, NULL, "long range iterator type"); + return 0; +} + diff -r a156f602debc Objects/setobject.c --- a/Objects/setobject.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Objects/setobject.c Tue Apr 28 19:26:52 2009 -0700 @@ -7,9 +7,12 @@ All rights reserved. */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "pytypeconvert.h" #include "structmember.h" #include "stringlib/eq.h" +#include "pytypeconvert.h" /* Set a key error with the specified argument, wrapping it in a * tuple automatically so that tuple keys are not unpacked as the @@ -617,7 +620,7 @@ *u++ = '}'; } Py_DECREF(listrepr); - if (Py_TYPE(so) != &PySet_Type) { + if (Py_TYPE(so) != PySet_Type) { PyObject *tmp = PyUnicode_FromFormat("%s(%U)", Py_TYPE(so)->tp_name, result); @@ -866,8 +869,9 @@ return NULL; } -PyTypeObject PySetIter_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject *PySetIter_Type; +PyTypeObject _PySetIter_Type = { + PyVarObject_HEAD_INIT(NULL, 0) "set_iterator", /* tp_name */ sizeof(setiterobject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -902,7 +906,7 @@ static PyObject * set_iter(PySetObject *so) { - setiterobject *si = PyObject_GC_New(setiterobject, &PySetIter_Type); + setiterobject *si = PyObject_GC_New(setiterobject, PySetIter_Type); if (si == NULL) return NULL; Py_INCREF(so); @@ -996,7 +1000,7 @@ /* create PySetObject structure */ if (numfree && - (type == &PySet_Type || type == &PyFrozenSet_Type)) { + (type == PySet_Type || type == PyFrozenSet_Type)) { so = free_list[--numfree]; assert (so != NULL && PyAnySet_CheckExact(so)); Py_TYPE(so) = type; @@ -1028,11 +1032,11 @@ static PyObject * make_new_set_basetype(PyTypeObject *type, PyObject *iterable) { - if (type != &PySet_Type && type != &PyFrozenSet_Type) { - if (PyType_IsSubtype(type, &PySet_Type)) - type = &PySet_Type; + if (type != PySet_Type && type != PyFrozenSet_Type) { + if (PyType_IsSubtype(type, PySet_Type)) + type = PySet_Type; else - type = &PyFrozenSet_Type; + type = PyFrozenSet_Type; } return make_new_set(type, iterable); } @@ -1045,13 +1049,13 @@ { PyObject *iterable = NULL, *result; - if (type == &PyFrozenSet_Type && !_PyArg_NoKeywords("frozenset()", kwds)) + if (type == PyFrozenSet_Type && !_PyArg_NoKeywords("frozenset()", kwds)) return NULL; if (!PyArg_UnpackTuple(args, type->tp_name, 0, 1, &iterable)) return NULL; - if (type != &PyFrozenSet_Type) + if (type != PyFrozenSet_Type) return make_new_set(type, iterable); if (iterable != NULL) { @@ -1089,7 +1093,7 @@ static PyObject * set_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { - if (type == &PySet_Type && !_PyArg_NoKeywords("set()", kwds)) + if (type == PySet_Type && !_PyArg_NoKeywords("set()", kwds)) return NULL; return make_new_set(type, NULL); @@ -1137,8 +1141,8 @@ memcpy(b->smalltable, tab, sizeof(tab)); } - if (PyType_IsSubtype(Py_TYPE(a), &PyFrozenSet_Type) && - PyType_IsSubtype(Py_TYPE(b), &PyFrozenSet_Type)) { + if (PyType_IsSubtype(Py_TYPE(a), PyFrozenSet_Type) && + PyType_IsSubtype(Py_TYPE(b), PyFrozenSet_Type)) { h = a->hash; a->hash = b->hash; b->hash = h; } else { a->hash = -1; @@ -1742,7 +1746,7 @@ if (!PyAnySet_Check(other)) { PyObject *tmp, *result; - tmp = make_new_set(&PySet_Type, other); + tmp = make_new_set(PySet_Type, other); if (tmp == NULL) return NULL; result = set_issubset(so, tmp); @@ -1770,7 +1774,7 @@ PyObject *tmp, *result; if (!PyAnySet_Check(other)) { - tmp = make_new_set(&PySet_Type, other); + tmp = make_new_set(PySet_Type, other); if (tmp == NULL) return NULL; result = set_issuperset(so, tmp); @@ -1848,7 +1852,7 @@ if (!PySet_Check(key) || !PyErr_ExceptionMatches(PyExc_TypeError)) return -1; PyErr_Clear(); - tmpkey = make_new_set(&PyFrozenSet_Type, NULL); + tmpkey = make_new_set(PyFrozenSet_Type, NULL); if (tmpkey == NULL) return -1; set_swap_bodies((PySetObject *)tmpkey, (PySetObject *)key); @@ -1883,7 +1887,7 @@ if (!PySet_Check(key) || !PyErr_ExceptionMatches(PyExc_TypeError)) return NULL; PyErr_Clear(); - tmpkey = make_new_set(&PyFrozenSet_Type, NULL); + tmpkey = make_new_set(PyFrozenSet_Type, NULL); if (tmpkey == NULL) return NULL; set_swap_bodies((PySetObject *)tmpkey, (PySetObject *)key); @@ -1917,7 +1921,7 @@ if (!PySet_Check(key) || !PyErr_ExceptionMatches(PyExc_TypeError)) return NULL; PyErr_Clear(); - tmpkey = make_new_set(&PyFrozenSet_Type, NULL); + tmpkey = make_new_set(PyFrozenSet_Type, NULL); if (tmpkey == NULL) return NULL; set_swap_bodies((PySetObject *)tmpkey, (PySetObject *)key); @@ -2094,8 +2098,9 @@ \n\ Build an unordered collection of unique elements."); -PyTypeObject PySet_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject *PySet_Type; +PyTypeObject _PySet_Type = { + PyVarObject_HEAD_INIT(NULL, 0) "set", /* tp_name */ sizeof(PySetObject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -2191,8 +2196,9 @@ \n\ Build an immutable unordered collection of unique elements."); -PyTypeObject PyFrozenSet_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject *PyFrozenSet_Type; +PyTypeObject _PyFrozenSet_Type = { + PyVarObject_HEAD_INIT(NULL, 0) "frozenset", /* tp_name */ sizeof(PySetObject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -2235,19 +2241,26 @@ PyObject_GC_Del, /* tp_free */ }; +int PySet_Init(void) +{ + CONVERT_TYPE(PySet_Type, PyType_Type, NULL, "set type"); + CONVERT_TYPE(PyFrozenSet_Type, PyType_Type, NULL, "frozenset type"); + CONVERT_TYPE(PySetIter_Type, PyType_Type, NULL, "set iterator type"); + return 0; +} /***** C API functions *************************************************/ PyObject * PySet_New(PyObject *iterable) { - return make_new_set(&PySet_Type, iterable); + return make_new_set(PySet_Type, iterable); } PyObject * PyFrozenSet_New(PyObject *iterable) { - return make_new_set(&PyFrozenSet_Type, iterable); + return make_new_set(PyFrozenSet_Type, iterable); } Py_ssize_t diff -r a156f602debc Objects/sliceobject.c --- a/Objects/sliceobject.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Objects/sliceobject.c Tue Apr 28 19:26:52 2009 -0700 @@ -13,7 +13,9 @@ this type and there is exactly one in existence. */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "pytypeconvert.h" #include "structmember.h" static PyObject * @@ -22,8 +24,9 @@ return PyUnicode_FromString("Ellipsis"); } -PyTypeObject PyEllipsis_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject *PyEllipsis_Type; +PyTypeObject _PyEllipsis_Type = { + PyVarObject_HEAD_INIT(NULL, 0) "ellipsis", /* tp_name */ 0, /* tp_basicsize */ 0, /* tp_itemsize */ @@ -47,7 +50,7 @@ PyObject _Py_EllipsisObject = { _PyObject_EXTRA_INIT - 1, &PyEllipsis_Type + 1, NULL }; @@ -60,7 +63,7 @@ PyObject * PySlice_New(PyObject *start, PyObject *stop, PyObject *step) { - PySliceObject *obj = PyObject_New(PySliceObject, &PySlice_Type); + PySliceObject *obj = PyObject_New(PySliceObject, PySlice_Type); if (obj == NULL) return NULL; @@ -343,8 +346,9 @@ return -1L; } -PyTypeObject PySlice_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject *PySlice_Type; +PyTypeObject _PySlice_Type = { + PyVarObject_HEAD_INIT(NULL, 0) "slice", /* Name of this type */ sizeof(PySliceObject), /* Basic object size */ 0, /* Item size for varobject */ @@ -383,3 +387,11 @@ 0, /* tp_alloc */ slice_new, /* tp_new */ }; + + +int PySlice_Init(void) { + CONVERT_TYPE(PyEllipsis_Type, PyType_Type, NULL, "Ellipsis type"); + CONVERT_TYPE(PySlice_Type, PyType_Type, NULL, "slice type"); + _Py_EllipsisObject.ob_type = PyEllipsis_Type; + return 0; +} diff -r a156f602debc Objects/stringlib/formatter.h --- a/Objects/stringlib/formatter.h Tue Apr 28 12:42:20 2009 -0700 +++ b/Objects/stringlib/formatter.h Tue Apr 28 19:26:52 2009 -0700 @@ -1028,7 +1028,7 @@ break; default: /* unknown */ - unknown_presentation_type(format.type, obj->ob_type->tp_name); + unknown_presentation_type(format.type, Py_TYPE_NAME(obj)); goto done; } @@ -1090,7 +1090,7 @@ default: /* unknown */ - unknown_presentation_type(format.type, obj->ob_type->tp_name); + unknown_presentation_type(format.type, Py_TYPE_NAME(obj)); goto done; } @@ -1188,7 +1188,7 @@ default: /* unknown */ - unknown_presentation_type(format.type, obj->ob_type->tp_name); + unknown_presentation_type(format.type, Py_TYPE_NAME(obj)); goto done; } diff -r a156f602debc Objects/stringlib/string_format.h --- a/Objects/stringlib/string_format.h Tue Apr 28 12:42:20 2009 -0700 +++ b/Objects/stringlib/string_format.h Tue Apr 28 19:26:52 2009 -0700 @@ -1138,7 +1138,7 @@ }; static PyTypeObject PyFormatterIter_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) + PyVarObject_HEAD_INIT(&_PyType_Type, 0) "formatteriterator", /* tp_name */ sizeof(formatteriterobject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -1271,7 +1271,7 @@ }; static PyTypeObject PyFieldNameIter_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) + PyVarObject_HEAD_INIT(&_PyType_Type, 0) "fieldnameiterator", /* tp_name */ sizeof(fieldnameiterobject), /* tp_basicsize */ 0, /* tp_itemsize */ diff -r a156f602debc Objects/structseq.c --- a/Objects/structseq.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Objects/structseq.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,7 +1,9 @@ /* Implementation helper: a struct that looks like a tuple. See timemodule and posixmodule for example uses. */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "pytypeconvert.h" #include "structmember.h" #include "structseq.h" @@ -432,7 +434,7 @@ }; static PyTypeObject _struct_sequence_template = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) + PyVarObject_HEAD_INIT(NULL, 0) NULL, /* tp_name */ 0, /* tp_basicsize */ 0, /* tp_itemsize */ @@ -472,21 +474,16 @@ structseq_new, /* tp_new */ }; -void -PyStructSequence_InitType(PyTypeObject *type, PyStructSequence_Desc *desc) +PyTypeObject * +PyStructSequence_InitType(PyStructSequence_Desc *desc) { + PyTypeObject _type; + PyTypeObject *type = &_type; + PyTypeObject *type2; PyObject *dict; PyMemberDef* members; int n_members, n_unnamed_members, i, k; -#ifdef Py_TRACE_REFS - /* if the type object was chained, unchain it first - before overwriting its storage */ - if (type->ob_base.ob_base._ob_next) { - _Py_ForgetReference((PyObject*)type); - } -#endif - n_unnamed_members = 0; for (i = 0; desc->fields[i].name != NULL; ++i) if (desc->fields[i].name == PyStructSequence_UnnamedField) @@ -494,6 +491,7 @@ n_members = i; memcpy(type, &_struct_sequence_template, sizeof(PyTypeObject)); + type->ob_base.ob_base.ob_type = PyType_Type; type->tp_name = desc->name; type->tp_doc = desc->doc; type->tp_basicsize = sizeof(PyStructSequence)+ @@ -502,7 +500,7 @@ members = PyMem_NEW(PyMemberDef, n_members-n_unnamed_members+1); if (members == NULL) - return; + return NULL; for (i = k = 0; i < n_members; ++i) { if (desc->fields[i].name == PyStructSequence_UnnamedField) @@ -519,8 +517,11 @@ type->tp_members = members; - if (PyType_Ready(type) < 0) - return; + if ((type2 = PyType_Convert(type)) == 0) { + Py_FatalError("Can't initialize some struct sequence type"); + return NULL; + } + type = type2; Py_INCREF(type); dict = type->tp_dict; @@ -536,4 +537,6 @@ SET_DICT_FROM_INT(visible_length_key, desc->n_in_sequence); SET_DICT_FROM_INT(real_length_key, n_members); SET_DICT_FROM_INT(unnamed_fields_key, n_unnamed_members); + + return type; } diff -r a156f602debc Objects/tupleobject.c --- a/Objects/tupleobject.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Objects/tupleobject.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,7 +1,11 @@ /* Tuple object implementation */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "typeprivate.h" + +static PyTypeObject _PyTuple_Type; /* Speed optimization to avoid frequent malloc/free of small tuples */ #ifndef PyTuple_MAXSAVESIZE @@ -72,7 +76,7 @@ /* Inline PyObject_InitVar */ #ifdef Py_TRACE_REFS Py_SIZE(op) = size; - Py_TYPE(op) = &PyTuple_Type; + Py_TYPE(op) = PyTuple_Type; #endif _Py_NewReference((PyObject *)op); } @@ -88,7 +92,7 @@ } nbytes += sizeof(PyTupleObject) - sizeof(PyObject *); - op = PyObject_GC_NewVar(PyTupleObject, &PyTuple_Type, size); + op = PyObject_GC_NewVar(PyTupleObject, PyTuple_Type, size); if (op == NULL) return NULL; } @@ -222,7 +226,7 @@ #if PyTuple_MAXSAVESIZE > 0 if (len < PyTuple_MAXSAVESIZE && numfree[len] < PyTuple_MAXFREELIST && - Py_TYPE(op) == &PyTuple_Type) + Py_TYPE(op) == PyTuple_Type) { op->ob_item[0] = (PyObject *) free_list[len]; numfree[len]++; @@ -621,7 +625,7 @@ PyObject *arg = NULL; static char *kwlist[] = {"sequence", 0}; - if (type != &PyTuple_Type) + if (type != PyTuple_Type) return tuple_subtype_new(type, args, kwds); if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:tuple", kwlist, &arg)) return NULL; @@ -638,8 +642,8 @@ PyObject *tmp, *newobj, *item; Py_ssize_t i, n; - assert(PyType_IsSubtype(type, &PyTuple_Type)); - tmp = tuple_new(&PyTuple_Type, args, kwds); + assert(PyType_IsSubtype(type, PyTuple_Type)); + tmp = tuple_new(PyTuple_Type, args, kwds); if (tmp == NULL) return NULL; assert(PyTuple_Check(tmp)); @@ -740,7 +744,7 @@ { Py_ssize_t res; - res = PyTuple_Type.tp_basicsize + Py_SIZE(self) * sizeof(PyObject *); + res = _PyTuple_Type.tp_basicsize + Py_SIZE(self) * sizeof(PyObject *); return PyLong_FromSsize_t(res); } @@ -769,8 +773,11 @@ static PyObject *tuple_iter(PyObject *seq); -PyTypeObject PyTuple_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +/* note: tuple MUST be hard-coded, can't use PyType_New(). + it's used heavily in the implementation of types themselves. +*/ +static PyTypeObject _PyTuple_Type = { + PyVarObject_HEAD_INIT(&_PyType_Type, 0) "tuple", sizeof(PyTupleObject) - sizeof(PyObject *), sizeof(PyObject *), @@ -811,6 +818,7 @@ tuple_new, /* tp_new */ PyObject_GC_Del, /* tp_free */ }; +PyTypeObject *PyTuple_Type = &_PyTuple_Type; /* The following function breaks the notion that tuples are immutable: it changes the size of a tuple. We get away with this only if there @@ -828,7 +836,7 @@ Py_ssize_t oldsize; v = (PyTupleObject *) *pv; - if (v == NULL || Py_TYPE(v) != &PyTuple_Type || + if (v == NULL || Py_TYPE(v) != PyTuple_Type || (Py_SIZE(v) != 0 && Py_REFCNT(v) != 1)) { *pv = 0; Py_XDECREF(v); @@ -974,8 +982,8 @@ {NULL, NULL} /* sentinel */ }; -PyTypeObject PyTupleIter_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +static PyTypeObject _PyTupleIter_Type = { + PyVarObject_HEAD_INIT(&_PyType_Type, 0) "tuple_iterator", /* tp_name */ sizeof(tupleiterobject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -1006,6 +1014,7 @@ tupleiter_methods, /* tp_methods */ 0, }; +PyTypeObject *PyTupleIter_Type = &_PyTupleIter_Type; static PyObject * tuple_iter(PyObject *seq) @@ -1016,7 +1025,7 @@ PyErr_BadInternalCall(); return NULL; } - it = PyObject_GC_New(tupleiterobject, &PyTupleIter_Type); + it = PyObject_GC_New(tupleiterobject, PyTupleIter_Type); if (it == NULL) return NULL; it->it_index = 0; diff -r a156f602debc Objects/typeobject.c --- a/Objects/typeobject.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Objects/typeobject.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,6 +1,8 @@ /* Type object implementation */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "typeprivate.h" #include "frameobject.h" #include "structmember.h" @@ -47,7 +49,7 @@ } next_version_tag = 0; /* mark all version tags as invalid */ - PyType_Modified(&PyBaseObject_Type); + PyType_Modified(PyBaseObject_Type); return cur_version_tag; } @@ -172,7 +174,7 @@ Py_INCREF(Py_None); } /* mark all version tags as invalid */ - PyType_Modified(&PyBaseObject_Type); + PyType_Modified(PyBaseObject_Type); return 1; } bases = type->tp_bases; @@ -266,7 +268,7 @@ Py_INCREF(value); - Py_DECREF(et->ht_name); + Py_XDECREF(et->ht_name); et->ht_name = value; type->tp_name = tp_name; @@ -682,7 +684,7 @@ if (obj != NULL) { /* Ugly exception: when the call was type(something), don't call tp_init on the result. */ - if (type == &PyType_Type && + if (type == PyType_Type && PyTuple_Check(args) && PyTuple_GET_SIZE(args) == 1 && (kwds == NULL || (PyDict_Check(kwds) && PyDict_Size(kwds) == 0))) @@ -1108,7 +1110,7 @@ return 1; a = a->tp_base; } while (a != NULL); - return b == &PyBaseObject_Type; + return b == PyBaseObject_Type; } } @@ -1516,7 +1518,7 @@ PyObject *mro, *result, *tuple; int checkit = 0; - if (Py_TYPE(type) == &PyType_Type) { + if (Py_TYPE(type) == PyType_Type) { result = mro_implementation(type); } else { @@ -1661,7 +1663,7 @@ if (type->tp_base) base = solid_base(type->tp_base); else - base = &PyBaseObject_Type; + base = PyBaseObject_Type; if (extra_ivars(type, base)) return type; else @@ -1929,8 +1931,8 @@ /* Check arguments: (name, bases, dict) */ if (!PyArg_ParseTupleAndKeywords(args, kwds, "UO!O!:type", kwlist, &name, - &PyTuple_Type, &bases, - &PyDict_Type, &dict)) + PyTuple_Type, &bases, + PyDict_Type, &dict)) return NULL; /* Determine the proper metatype to deal with this, @@ -1963,7 +1965,7 @@ /* Adjust for empty tuple bases */ if (nbases == 0) { - bases = PyTuple_Pack(1, &PyBaseObject_Type); + bases = PyTuple_Pack(1, PyBaseObject_Type); if (bases == NULL) return NULL; nbases = 1; @@ -2581,8 +2583,8 @@ return type->tp_flags & Py_TPFLAGS_HEAPTYPE; } -PyTypeObject PyType_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject _PyType_Type = { + PyVarObject_HEAD_INIT(&_PyType_Type, 0) "type", /* tp_name */ sizeof(PyHeapTypeObject), /* tp_basicsize */ sizeof(PyMemberDef), /* tp_itemsize */ @@ -2624,7 +2626,7 @@ PyObject_GC_Del, /* tp_free */ (inquiry)type_is_gc, /* tp_is_gc */ }; - +PyTypeObject *PyType_Type = &_PyType_Type; /* The base type of all types (eventually)... except itself. */ @@ -3260,7 +3262,7 @@ Py_DECREF(reduce); return NULL; } - objreduce = PyDict_GetItemString(PyBaseObject_Type.tp_dict, + objreduce = PyDict_GetItemString(PyBaseObject_Type->tp_dict, "__reduce__"); override = (clsreduce != objreduce); Py_DECREF(clsreduce); @@ -3354,8 +3356,8 @@ }; -PyTypeObject PyBaseObject_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject _PyBaseObject_Type = { + PyVarObject_HEAD_INIT(&_PyType_Type, 0) "object", /* tp_name */ sizeof(PyObject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -3395,6 +3397,7 @@ object_new, /* tp_new */ PyObject_Del, /* tp_free */ }; +PyTypeObject *PyBaseObject_Type = &_PyBaseObject_Type; /* Add the methods from tp_methods to the __dict__ in a type object */ @@ -3503,7 +3506,7 @@ inherit tp_new; static extension types that specify some other built-in type as the default are considered new-style-aware so they also inherit object.__new__. */ - if (base != &PyBaseObject_Type || + if (base != PyBaseObject_Type || (type->tp_flags & Py_TPFLAGS_HEAPTYPE)) { if (type->tp_new == NULL) type->tp_new = base->tp_new; @@ -3521,22 +3524,29 @@ COPYVAL(tp_weaklistoffset); COPYVAL(tp_dictoffset); + /* if we haven't initialized basic types yet, + none of these will be true, + and some of them may be null + */ + if (!PyList_Type) + return; + /* Setup fast subclass flags */ if (PyType_IsSubtype(base, (PyTypeObject*)PyExc_BaseException)) type->tp_flags |= Py_TPFLAGS_BASE_EXC_SUBCLASS; - else if (PyType_IsSubtype(base, &PyType_Type)) + else if (PyType_IsSubtype(base, PyType_Type)) type->tp_flags |= Py_TPFLAGS_TYPE_SUBCLASS; - else if (PyType_IsSubtype(base, &PyLong_Type)) + else if (PyType_IsSubtype(base, PyLong_Type)) type->tp_flags |= Py_TPFLAGS_LONG_SUBCLASS; - else if (PyType_IsSubtype(base, &PyBytes_Type)) + else if (PyType_IsSubtype(base, PyBytes_Type)) type->tp_flags |= Py_TPFLAGS_BYTES_SUBCLASS; - else if (PyType_IsSubtype(base, &PyUnicode_Type)) + else if (PyType_IsSubtype(base, PyUnicode_Type)) type->tp_flags |= Py_TPFLAGS_UNICODE_SUBCLASS; - else if (PyType_IsSubtype(base, &PyTuple_Type)) + else if (PyType_IsSubtype(base, PyTuple_Type)) type->tp_flags |= Py_TPFLAGS_TUPLE_SUBCLASS; - else if (PyType_IsSubtype(base, &PyList_Type)) + else if (PyType_IsSubtype(base, PyList_Type)) type->tp_flags |= Py_TPFLAGS_LIST_SUBCLASS; - else if (PyType_IsSubtype(base, &PyDict_Type)) + else if (PyType_IsSubtype(base, PyDict_Type)) type->tp_flags |= Py_TPFLAGS_DICT_SUBCLASS; } @@ -3718,8 +3728,947 @@ static int add_operators(PyTypeObject *); -int -PyType_Ready(PyTypeObject *type) +/* +** +** NEAL START HERE +** +*/ + +PyTypeObject * +PyType_New(const char *name, Py_ssize_t size, PyTypeObject *basetype) +{ + PyTypeObject *returnvalue = NULL; + PyObject *dict = NULL; + PyObject *bases = NULL; + + if ((name == NULL) || (size < 0) || (basetype == NULL)) + return NULL; + + returnvalue = (PyTypeObject *)_PyObject_GC_Malloc(sizeof(PyHeapTypeObject)); + if (returnvalue) { + memset(returnvalue, 0, sizeof(PyHeapTypeObject)); + } + dict = PyDict_New(); + bases = PyTuple_Pack(1, basetype); + + if ( (returnvalue == NULL) + || (dict == NULL) + || (bases == NULL) + ) + goto FAILURE; + + /* this reflects the reference we return to the caller */ + returnvalue->ob_base.ob_base.ob_refcnt = 1; + returnvalue->ob_base.ob_size = sizeof(PyHeapTypeObject); + returnvalue->tp_basicsize = size; + + PyType_SetFlag(returnvalue, pytoe_flag_have_version_flag, 1); + PyType_SetFlag(returnvalue, pytoe_flag_dynamically_created, 1); + PyType_SetFlag(returnvalue, pytoe_flag_basetype, 1); + PyType_SetFlag(returnvalue, pytoe_flag_heaptype, 1); + if (PyType_GetFlag(basetype, pytoe_flag_have_gc) + && !PyType_GetFlag(basetype, pytoe_flag_dynamically_created)) { + PyType_SetFlag(basetype, pytoe_flag_have_gc, 1); + } + + if (PyType_SetString(returnvalue, pytoe_name, name)) + goto FAILURE; + + returnvalue->tp_bases = bases; + Py_INCREF(bases); + /* inherit_special(returnvalue, basetype); */ + + returnvalue->tp_dict = dict; + + PyObject_Init((PyObject *)returnvalue, PyType_Type); + + return returnvalue; + +FAILURE: + if (returnvalue != NULL) + PyObject_GC_Del((void *)returnvalue); + Py_XDECREF(dict); + Py_XDECREF(bases); + return NULL; +} + + + +#define SET_STARTUP() \ + switch (element) { \ + +#define GET_STARTUP() SET_STARTUP() + +#define SET_ELEMENT(element, field) \ + case element: \ + type->field = value; \ + return 0; \ + +#define GET_ELEMENT(element, field) \ + case element: \ + return type->field; \ + +#define SET_INCREF_ELEMENT(element, field) \ + case element: \ + if (type->field != NULL) { \ + Py_DECREF(type->field); \ + } \ + type->field = value; \ + Py_INCREF(value); \ + return 0; \ + +#define _SET_SUB_ELEMENT(element, field, subelement) \ + case element: \ + if (!type->tp_ ## subelement) \ + type->tp_ ## subelement = &((PyHeapTypeObject *)type)->subelement; \ + type->tp_ ## subelement->field = value; \ + return 0; \ + +#define _SET_INCREF_SUB_ELEMENT(element, field, subelement) \ + case element: \ + if (!type->tp_ ## subelement) \ + type->tp_ ## subelement = &((PyHeapTypeObject *)type)->subelement; \ + if (type->tp_ ## subelement->field != NULL) { \ + Py_DECREF(type->tp_ ## subelement->field); \ + } \ + type->tp_ ## subelement->field = value; \ + Py_INCREF(value); \ + return 0; \ + +#define SET_NUMBER_ELEMENT(element, field) _SET_SUB_ELEMENT(element, field, as_number) +#define SET_SEQUENCE_ELEMENT(element, field) _SET_SUB_ELEMENT(element, field, as_sequence) +#define SET_MAPPING_ELEMENT(element, field) _SET_SUB_ELEMENT(element, field, as_mapping) +#define SET_BUFFER_ELEMENT(element, field) _SET_SUB_ELEMENT(element, field, as_buffer) + +#define _GET_SUB_ELEMENT(element, field, subelement) \ + case element: \ + if (!type->tp_ ## subelement) \ + type->tp_ ## subelement = &((PyHeapTypeObject *)type)->subelement; \ + return type->tp_ ## subelement->field; \ + +#define GET_NUMBER_ELEMENT(element, field) _GET_SUB_ELEMENT(element, field, as_number) +#define GET_SEQUENCE_ELEMENT(element, field) _GET_SUB_ELEMENT(element, field, as_sequence) +#define GET_MAPPING_ELEMENT(element, field) _GET_SUB_ELEMENT(element, field, as_mapping) +#define GET_BUFFER_ELEMENT(element, field) _GET_SUB_ELEMENT(element, field, as_buffer) + +#define SET_HEAP_ELEMENT(element, field) \ + case element: \ + { \ + PyHeapTypeObject *heaptype; \ + if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE)) \ + return -1; \ + heaptype = (PyHeapTypeObject *)type; \ + type->field = value; \ + return 0; \ + } \ + +#define SET_HEAP_INCREF_ELEMENT(element, field) \ + case element: \ + { \ + PyHeapTypeObject *heaptype; \ + if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE)) \ + return -1; \ + heaptype = (PyHeapTypeObject *)type; \ + heaptype->field = value; \ + Py_INCREF(value); \ + return 0; \ + } \ + +#define SET_SHUTDOWN() \ + default: \ + break; \ + } \ + return -1; \ + + +#define GET_SHUTDOWN(failure) \ + default: \ + break; \ + } \ + return failure; \ + + + + +int +PyType_SetSize(PyTypeObject *type, PyTypeObjectElement element, Py_ssize_t value) +{ + SET_STARTUP() + SET_ELEMENT(pytoe_object_refcnt, ob_base.ob_base.ob_refcnt); + SET_ELEMENT(pytoe_object_size, ob_base.ob_size); + SET_ELEMENT(pytoe_basicsize, tp_basicsize); + SET_ELEMENT(pytoe_itemsize, tp_itemsize); + SET_ELEMENT(pytoe_weaklistoffset, tp_weaklistoffset); + SET_ELEMENT(pytoe_dictoffset, tp_dictoffset); + +#ifdef COUNT_ALLOCS + SET_ELEMENT(pytoe_allocs, tp_allocs); + SET_ELEMENT(pytoe_frees, tp_frees); + SET_ELEMENT(pytoe_maxalloc, tp_maxalloc); +#endif /* COUNT_ALLOCS */ + + SET_SHUTDOWN(); +} + +int +PyType_SetLong(PyTypeObject *type, PyTypeObjectElement element, long value) +{ + SET_STARTUP(); + + SET_SHUTDOWN(); +} + + +int PyType_SetFlag(PyTypeObject *type, PyTypeObjectElement element, int value) +{ + SET_STARTUP(); + +#define SET_FLAG(element, bitfield) \ + case element: \ + if (value) { \ + type->tp_flags |= bitfield; \ + } else { \ + type->tp_flags &= ~bitfield; \ + } \ + return 0; \ + + SET_FLAG(pytoe_flag_heaptype, Py_TPFLAGS_HEAPTYPE) + SET_FLAG(pytoe_flag_basetype, Py_TPFLAGS_BASETYPE) + SET_FLAG(pytoe_flag_ready, Py_TPFLAGS_READY) + SET_FLAG(pytoe_flag_readying, Py_TPFLAGS_READYING) + SET_FLAG(pytoe_flag_have_gc, Py_TPFLAGS_HAVE_GC) + SET_FLAG(pytoe_flag_have_stackless_extension, Py_TPFLAGS_HAVE_STACKLESS_EXTENSION); + SET_FLAG(pytoe_flag_dynamically_created, Py_TPFLAGS_DYNAMICALLY_CREATED) + SET_FLAG(pytoe_flag_have_version_flag, Py_TPFLAGS_HAVE_VERSION_TAG) + SET_FLAG(pytoe_flag_valid_version_tag, Py_TPFLAGS_VALID_VERSION_TAG) + SET_FLAG(pytoe_flag_is_abstract, Py_TPFLAGS_IS_ABSTRACT) + SET_FLAG(pytoe_flag_int_subclass, Py_TPFLAGS_INT_SUBCLASS) + SET_FLAG(pytoe_flag_long_subclass, Py_TPFLAGS_LONG_SUBCLASS) + SET_FLAG(pytoe_flag_list_subclass, Py_TPFLAGS_LIST_SUBCLASS) + SET_FLAG(pytoe_flag_tuple_subclass, Py_TPFLAGS_TUPLE_SUBCLASS) + SET_FLAG(pytoe_flag_bytes_subclass, Py_TPFLAGS_BYTES_SUBCLASS); + SET_FLAG(pytoe_flag_unicode_subclass, Py_TPFLAGS_UNICODE_SUBCLASS) + SET_FLAG(pytoe_flag_dict_subclass, Py_TPFLAGS_DICT_SUBCLASS) + SET_FLAG(pytoe_flag_base_exception_subclass, Py_TPFLAGS_BASE_EXC_SUBCLASS) + SET_FLAG(pytoe_flag_type_subclass, Py_TPFLAGS_TYPE_SUBCLASS) + + SET_SHUTDOWN(); +} + + +int PyType_GetFlag(PyTypeObject *type, PyTypeObjectElement element) +{ + GET_STARTUP(); + +#define GET_FLAG(element, bitfield) \ + case element: \ + return (type->tp_flags & bitfield) ? 1 : 0; \ + + GET_FLAG(pytoe_flag_heaptype, Py_TPFLAGS_HEAPTYPE) + GET_FLAG(pytoe_flag_basetype, Py_TPFLAGS_BASETYPE) + GET_FLAG(pytoe_flag_ready, Py_TPFLAGS_READY) + GET_FLAG(pytoe_flag_readying, Py_TPFLAGS_READYING) + GET_FLAG(pytoe_flag_have_gc, Py_TPFLAGS_HAVE_GC) + GET_FLAG(pytoe_flag_have_stackless_extension, Py_TPFLAGS_HAVE_STACKLESS_EXTENSION); + GET_FLAG(pytoe_flag_dynamically_created, Py_TPFLAGS_DYNAMICALLY_CREATED) + GET_FLAG(pytoe_flag_have_version_flag, Py_TPFLAGS_HAVE_VERSION_TAG) + GET_FLAG(pytoe_flag_valid_version_tag, Py_TPFLAGS_VALID_VERSION_TAG) + GET_FLAG(pytoe_flag_is_abstract, Py_TPFLAGS_IS_ABSTRACT) + GET_FLAG(pytoe_flag_int_subclass, Py_TPFLAGS_INT_SUBCLASS) + GET_FLAG(pytoe_flag_long_subclass, Py_TPFLAGS_LONG_SUBCLASS) + GET_FLAG(pytoe_flag_list_subclass, Py_TPFLAGS_LIST_SUBCLASS) + GET_FLAG(pytoe_flag_tuple_subclass, Py_TPFLAGS_TUPLE_SUBCLASS) + GET_FLAG(pytoe_flag_bytes_subclass, Py_TPFLAGS_BYTES_SUBCLASS); + GET_FLAG(pytoe_flag_unicode_subclass, Py_TPFLAGS_UNICODE_SUBCLASS) + GET_FLAG(pytoe_flag_dict_subclass, Py_TPFLAGS_DICT_SUBCLASS) + GET_FLAG(pytoe_flag_base_exception_subclass, Py_TPFLAGS_BASE_EXC_SUBCLASS) + GET_FLAG(pytoe_flag_type_subclass, Py_TPFLAGS_TYPE_SUBCLASS) + + GET_SHUTDOWN(-1); +} + + +int +PyType_SetString(PyTypeObject *type, PyTypeObjectElement element, const char *value) +{ + SET_STARTUP(); + + case pytoe_doc: + { + /* + ** tp_doc in a PyHeapTypeObject is assumed to be PyObject malloc'd; + ** we also set __doc__ for you. + */ + size_t length = strlen(value) + 1; + char *dup = (char *)PyObject_MALLOC(length); + PyObject *unicode = PyUnicode_FromString(value); + if (!(dup && unicode)) + { + if (dup) + PyObject_FREE(dup); + Py_XDECREF(unicode); + return -1; + } + memcpy(dup, value, length); + type->tp_doc = dup; + PyDict_SetItemString(type->tp_dict, "__doc__", unicode); + Py_DECREF(unicode); + return 0; + } + + case pytoe_name: + { + PyObject *unicode = PyUnicode_FromString(value); + int returnValue; + if (!unicode) + return -1; + returnValue = type_set_name(type, unicode, NULL); + if (returnValue) + return returnValue; + type->tp_name = value; + return 0; + } + + SET_SHUTDOWN(); +} + + +const char * +PyType_GetString(PyTypeObject *type, PyTypeObjectElement element) +{ + GET_STARTUP(); + GET_ELEMENT(pytoe_doc, tp_doc); + GET_ELEMENT(pytoe_name, tp_name); + GET_SHUTDOWN(NULL); +} + + +int +PyType_SetPyObject(PyTypeObject *type, PyTypeObjectElement element, PyObject *value) +{ + SET_STARTUP(); +#ifdef COUNT_ALLOCS + SET_INCREF_ELEMENT(pytoe_object_next, _ob_next); + SET_INCREF_ELEMENT(pytoe_object_prev, _ob_prev); +#endif /* COUNT_ALLOCS */ + SET_INCREF_ELEMENT(pytoe_dict, tp_dict); + SET_INCREF_ELEMENT(pytoe_bases, tp_bases); + SET_INCREF_ELEMENT(pytoe_mro, tp_mro); + SET_INCREF_ELEMENT(pytoe_cache, tp_cache); + SET_INCREF_ELEMENT(pytoe_subclasses, tp_subclasses); + SET_INCREF_ELEMENT(pytoe_weaklist, tp_weaklist); +/* SET_HEAP_INCREF_ELEMENT(pytoe_slots, ht_slots); */ + SET_SHUTDOWN(); +} + + +int +PyType_SetPyTypeObject(PyTypeObject *type, PyTypeObjectElement element, PyTypeObject *value) +{ + SET_STARTUP(); + SET_INCREF_ELEMENT(pytoe_object_type, ob_base.ob_base.ob_type); +#ifdef COUNT_ALLOCS + SET_INCREF_ELEMENT(pytoe_prev, tp_prev); + SET_INCREF_ELEMENT(pytoe_next, tp_next); +#endif /* COUNT_ALLOCS */ + SET_INCREF_ELEMENT(pytoe_base, tp_base); + SET_SHUTDOWN(); +} + + +int +PyType_SetUnaryFunction(PyTypeObject *type, PyTypeObjectElement element, unaryfunc value) +{ + SET_STARTUP(); + SET_NUMBER_ELEMENT(pytoe_number_negative, nb_negative); + SET_NUMBER_ELEMENT(pytoe_number_positive, nb_positive); + SET_NUMBER_ELEMENT(pytoe_number_absolute, nb_absolute); + SET_NUMBER_ELEMENT(pytoe_number_invert, nb_invert); + SET_NUMBER_ELEMENT(pytoe_number_int, nb_int); + SET_NUMBER_ELEMENT(pytoe_number_float, nb_float); + SET_NUMBER_ELEMENT(pytoe_number_index, nb_index); + SET_SHUTDOWN(); +} + + +int +PyType_SetBinaryFunction(PyTypeObject *type, PyTypeObjectElement element, binaryfunc value) +{ + SET_STARTUP(); + SET_NUMBER_ELEMENT(pytoe_number_add, nb_add); + SET_NUMBER_ELEMENT(pytoe_number_subtract, nb_subtract); + SET_NUMBER_ELEMENT(pytoe_number_multiply, nb_multiply); + SET_NUMBER_ELEMENT(pytoe_number_remainder, nb_remainder); + SET_NUMBER_ELEMENT(pytoe_number_divmod, nb_divmod); + SET_NUMBER_ELEMENT(pytoe_number_lshift, nb_lshift); + SET_NUMBER_ELEMENT(pytoe_number_rshift, nb_rshift); + SET_NUMBER_ELEMENT(pytoe_number_and, nb_and); + SET_NUMBER_ELEMENT(pytoe_number_xor, nb_xor); + SET_NUMBER_ELEMENT(pytoe_number_or, nb_or); + SET_NUMBER_ELEMENT(pytoe_number_inplace_add, nb_inplace_add); + SET_NUMBER_ELEMENT(pytoe_number_inplace_subtract, nb_inplace_subtract); + SET_NUMBER_ELEMENT(pytoe_number_inplace_multiply, nb_inplace_multiply); + SET_NUMBER_ELEMENT(pytoe_number_inplace_remainder, nb_inplace_remainder); + SET_NUMBER_ELEMENT(pytoe_number_inplace_lshift, nb_inplace_lshift); + SET_NUMBER_ELEMENT(pytoe_number_inplace_rshift, nb_inplace_rshift); + SET_NUMBER_ELEMENT(pytoe_number_inplace_and, nb_inplace_and); + SET_NUMBER_ELEMENT(pytoe_number_inplace_xor, nb_inplace_xor); + SET_NUMBER_ELEMENT(pytoe_number_inplace_or, nb_inplace_or); + SET_NUMBER_ELEMENT(pytoe_number_floor_divide, nb_floor_divide); + SET_NUMBER_ELEMENT(pytoe_number_true_divide, nb_true_divide); + SET_NUMBER_ELEMENT(pytoe_number_inplace_floor_divide, nb_inplace_floor_divide); + SET_NUMBER_ELEMENT(pytoe_number_inplace_true_divide, nb_inplace_true_divide); + SET_SEQUENCE_ELEMENT(pytoe_sequence_concat, sq_concat); + SET_SEQUENCE_ELEMENT(pytoe_sequence_inplace_concat, sq_inplace_concat); + SET_MAPPING_ELEMENT(pytoe_mapping_subscript, mp_subscript); + SET_SHUTDOWN(); +} + + +binaryfunc +PyType_GetBinaryFunction(PyTypeObject *type, PyTypeObjectElement element) +{ + GET_STARTUP(); + GET_NUMBER_ELEMENT(pytoe_number_add, nb_add); + GET_NUMBER_ELEMENT(pytoe_number_subtract, nb_subtract); + GET_NUMBER_ELEMENT(pytoe_number_multiply, nb_multiply); + GET_NUMBER_ELEMENT(pytoe_number_remainder, nb_remainder); + GET_NUMBER_ELEMENT(pytoe_number_divmod, nb_divmod); + GET_NUMBER_ELEMENT(pytoe_number_lshift, nb_lshift); + GET_NUMBER_ELEMENT(pytoe_number_rshift, nb_rshift); + GET_NUMBER_ELEMENT(pytoe_number_and, nb_and); + GET_NUMBER_ELEMENT(pytoe_number_xor, nb_xor); + GET_NUMBER_ELEMENT(pytoe_number_or, nb_or); + GET_NUMBER_ELEMENT(pytoe_number_inplace_add, nb_inplace_add); + GET_NUMBER_ELEMENT(pytoe_number_inplace_subtract, nb_inplace_subtract); + GET_NUMBER_ELEMENT(pytoe_number_inplace_multiply, nb_inplace_multiply); + GET_NUMBER_ELEMENT(pytoe_number_inplace_remainder, nb_inplace_remainder); + GET_NUMBER_ELEMENT(pytoe_number_inplace_lshift, nb_inplace_lshift); + GET_NUMBER_ELEMENT(pytoe_number_inplace_rshift, nb_inplace_rshift); + GET_NUMBER_ELEMENT(pytoe_number_inplace_and, nb_inplace_and); + GET_NUMBER_ELEMENT(pytoe_number_inplace_xor, nb_inplace_xor); + GET_NUMBER_ELEMENT(pytoe_number_inplace_or, nb_inplace_or); + GET_NUMBER_ELEMENT(pytoe_number_floor_divide, nb_floor_divide); + GET_NUMBER_ELEMENT(pytoe_number_true_divide, nb_true_divide); + GET_NUMBER_ELEMENT(pytoe_number_inplace_floor_divide, nb_inplace_floor_divide); + GET_NUMBER_ELEMENT(pytoe_number_inplace_true_divide, nb_inplace_true_divide); + GET_SEQUENCE_ELEMENT(pytoe_sequence_concat, sq_concat); + GET_SEQUENCE_ELEMENT(pytoe_sequence_inplace_concat, sq_inplace_concat); + GET_MAPPING_ELEMENT(pytoe_mapping_subscript, mp_subscript); + GET_SHUTDOWN(NULL); +} + + +int +PyType_SetTernaryFunction(PyTypeObject *type, PyTypeObjectElement element, ternaryfunc value) +{ + SET_STARTUP(); + SET_ELEMENT(pytoe_call, tp_call); + SET_NUMBER_ELEMENT(pytoe_number_power, nb_power); + SET_NUMBER_ELEMENT(pytoe_number_inplace_power, nb_inplace_power); + SET_SHUTDOWN(); +} + + +ternaryfunc +PyType_GetTernaryFunction(PyTypeObject *type, PyTypeObjectElement element) +{ + GET_STARTUP(); + GET_ELEMENT(pytoe_call, tp_call); + GET_NUMBER_ELEMENT(pytoe_number_power, nb_power); + GET_NUMBER_ELEMENT(pytoe_number_inplace_power, nb_inplace_power); + GET_SHUTDOWN(NULL); +} + + +int +PyType_SetInquiryFunction(PyTypeObject *type, PyTypeObjectElement element, inquiry value) +{ + SET_STARTUP(); + SET_ELEMENT(pytoe_clear, tp_clear); + SET_ELEMENT(pytoe_is_gc, tp_is_gc); + SET_NUMBER_ELEMENT(pytoe_number_bool, nb_bool); + SET_SHUTDOWN(); +} + + +int +PyType_SetLengthFunction(PyTypeObject *type, PyTypeObjectElement element, lenfunc value) +{ + SET_STARTUP(); + SET_SEQUENCE_ELEMENT(pytoe_sequence_length, sq_length); + SET_MAPPING_ELEMENT(pytoe_mapping_length, mp_length); + SET_SHUTDOWN(); +} + + +int +PyType_SetSSizeFunction(PyTypeObject *type, PyTypeObjectElement element, ssizeargfunc value) +{ + SET_STARTUP(); + SET_SEQUENCE_ELEMENT(pytoe_sequence_repeat, sq_repeat); + SET_SEQUENCE_ELEMENT(pytoe_sequence_item, sq_item); + SET_SEQUENCE_ELEMENT(pytoe_sequence_inplace_repeat, sq_inplace_repeat); + SET_SHUTDOWN(); +} + + +/* +int +PyType_SetSSizeSSizeFunction(PyTypeObject *type, PyTypeObjectElement element, ssizessizeargfunc value) +{ + SET_STARTUP(); + SET_SEQUENCE_ELEMENT(pytoe_sequence_slice, sq_slice); + SET_SHUTDOWN(); +} +*/ + + +int +PyType_SetSSizeObjectFunction(PyTypeObject *type, PyTypeObjectElement element, ssizeobjargproc value) +{ + SET_STARTUP(); + SET_SEQUENCE_ELEMENT(pytoe_sequence_ass_item, sq_ass_item); + SET_SHUTDOWN(); +} + +/* +int +PyType_SetSSizeSSizeObjectFunction(PyTypeObject *type, PyTypeObjectElement element, ssizessizeobjargproc value) +{ + SET_STARTUP(); + SET_SEQUENCE_ELEMENT(pytoe_sequence_ass_slice, sq_ass_slice); + SET_SHUTDOWN(); +} + +*/ + + + +int +PyType_SetObjectFunction(PyTypeObject *type, PyTypeObjectElement element, objobjproc value) +{ + SET_STARTUP(); + SET_SEQUENCE_ELEMENT(pytoe_sequence_contains, sq_contains); + SET_SHUTDOWN(); +} + + +int +PyType_SetObjectObjectFunction(PyTypeObject *type, PyTypeObjectElement element, objobjargproc value) +{ + SET_STARTUP(); + SET_MAPPING_ELEMENT(pytoe_mapping_ass_subscript, mp_ass_subscript); + SET_SHUTDOWN(); +} + + +int +PyType_SetBufferGetFunction(PyTypeObject *type, PyTypeObjectElement element, getbufferproc value) +{ + SET_STARTUP(); + SET_BUFFER_ELEMENT(pytoe_buffer_getbuffer, bf_getbuffer); + SET_SHUTDOWN(); +} + + +getbufferproc +PyType_GetBufferGetFunction(PyTypeObject *type, PyTypeObjectElement element) +{ + GET_STARTUP(); + GET_BUFFER_ELEMENT(pytoe_buffer_getbuffer, bf_getbuffer); + GET_SHUTDOWN(NULL); +} + + +int +PyType_SetBufferReleaseFunction(PyTypeObject *type, PyTypeObjectElement element, releasebufferproc value) +{ + SET_STARTUP(); + SET_BUFFER_ELEMENT(pytoe_buffer_releasebuffer, bf_releasebuffer); + SET_SHUTDOWN(); +} + + +releasebufferproc +PyType_GetBufferReleaseFunction(PyTypeObject *type, PyTypeObjectElement element) +{ + GET_STARTUP(); + GET_BUFFER_ELEMENT(pytoe_buffer_releasebuffer, bf_releasebuffer); + GET_SHUTDOWN(NULL); +} + + +int +PyType_SetDestructorFunction(PyTypeObject *type, PyTypeObjectElement element, destructor value) +{ + SET_STARTUP(); + SET_ELEMENT(pytoe_dealloc, tp_dealloc); + SET_ELEMENT(pytoe_del, tp_del); + SET_SHUTDOWN(); +} + + +int +PyType_SetPrintFunction(PyTypeObject *type, PyTypeObjectElement element, printfunc value) +{ + SET_STARTUP(); + SET_ELEMENT(pytoe_print, tp_print); + SET_SHUTDOWN(); +} + + +int +PyType_SetAttrGetFunction(PyTypeObject *type, PyTypeObjectElement element, getattrfunc value) +{ + SET_STARTUP(); + SET_ELEMENT(pytoe_getattr, tp_getattr); + SET_SHUTDOWN(); +} + + +int +PyType_SetAttrSetFunction(PyTypeObject *type, PyTypeObjectElement element, setattrfunc value) +{ + SET_STARTUP(); + SET_ELEMENT(pytoe_setattr, tp_setattr); + SET_SHUTDOWN(); +} + + +int +PyType_SetReprFunction(PyTypeObject *type, PyTypeObjectElement element, reprfunc value) +{ + SET_STARTUP(); + SET_ELEMENT(pytoe_repr, tp_repr); + SET_ELEMENT(pytoe_str, tp_str); + SET_SHUTDOWN(); +} + + +int +PyType_SetHashFunction(PyTypeObject *type, PyTypeObjectElement element, hashfunc value) +{ + SET_STARTUP(); + SET_ELEMENT(pytoe_hash, tp_hash); + SET_SHUTDOWN(); +} + + +hashfunc +PyType_GetHashFunction(PyTypeObject *type, PyTypeObjectElement element) +{ + GET_STARTUP(); + GET_ELEMENT(pytoe_hash, tp_hash); + GET_SHUTDOWN(NULL); +} + + +int +PyType_SetAttrObjectGetFunction(PyTypeObject *type, PyTypeObjectElement element, getattrofunc value) +{ + SET_STARTUP(); + SET_ELEMENT(pytoe_getattro, tp_getattro); + SET_SHUTDOWN(); +} + + +int +PyType_SetAttrObjectSetFunction(PyTypeObject *type, PyTypeObjectElement element, setattrofunc value) +{ + SET_STARTUP(); + SET_ELEMENT(pytoe_setattro, tp_setattro); + SET_SHUTDOWN(); +} + + +int +PyType_SetTraverseFunction(PyTypeObject *type, PyTypeObjectElement element, traverseproc value) +{ + SET_STARTUP(); + SET_ELEMENT(pytoe_traverse, tp_traverse); + SET_SHUTDOWN(); +} + + +int +PyType_SetRichCompareFunction(PyTypeObject *type, PyTypeObjectElement element, richcmpfunc value) +{ + SET_STARTUP(); + SET_ELEMENT(pytoe_richcompare, tp_richcompare); + SET_SHUTDOWN(); +} + + +int +PyType_SetIteratorGetFunction(PyTypeObject *type, PyTypeObjectElement element, getiterfunc value) +{ + SET_STARTUP(); + SET_ELEMENT(pytoe_iter, tp_iter); + SET_SHUTDOWN(); +} + + +int +PyType_SetIteratorNextFunction(PyTypeObject *type, PyTypeObjectElement element, iternextfunc value) +{ + SET_STARTUP(); + SET_ELEMENT(pytoe_iternext, tp_iternext); + SET_SHUTDOWN(); +} + + +int +PyType_SetDescriptorGetFunction(PyTypeObject *type, PyTypeObjectElement element, descrgetfunc value) +{ + SET_STARTUP(); + SET_ELEMENT(pytoe_descr_get, tp_descr_get); + SET_SHUTDOWN(); +} + + +int +PyType_SetDescriptorSetFunction(PyTypeObject *type, PyTypeObjectElement element, descrsetfunc value) +{ + SET_STARTUP(); + SET_ELEMENT(pytoe_descr_set, tp_descr_set); + SET_SHUTDOWN(); +} + + +int +PyType_SetInitFunction(PyTypeObject *type, PyTypeObjectElement element, initproc value) +{ + SET_STARTUP(); + SET_ELEMENT(pytoe_init, tp_init); + SET_SHUTDOWN(); +} + + +initproc +PyType_GetInitFunction(PyTypeObject *type, PyTypeObjectElement element) +{ + GET_STARTUP(); + GET_ELEMENT(pytoe_init, tp_init); + GET_SHUTDOWN(NULL); +} + + +int +PyType_SetAllocFunction(PyTypeObject *type, PyTypeObjectElement element, allocfunc value) +{ + SET_STARTUP(); + SET_ELEMENT(pytoe_alloc, tp_alloc); + SET_SHUTDOWN(); +} + + +int +PyType_SetNewFunction(PyTypeObject *type, PyTypeObjectElement element, newfunc value) +{ + SET_STARTUP(); + SET_ELEMENT(pytoe_new, tp_new); + SET_SHUTDOWN(); +} + + +newfunc +PyType_GetNewFunction(PyTypeObject *type, PyTypeObjectElement element) +{ + GET_STARTUP(); + GET_ELEMENT(pytoe_new, tp_new); + GET_SHUTDOWN(NULL); +} + + +int +PyType_SetFreeFunction(PyTypeObject *type, PyTypeObjectElement element, freefunc value) +{ + SET_STARTUP(); + SET_ELEMENT(pytoe_free, tp_free); + SET_SHUTDOWN(); +} + + +#define APPEND_STARTUP(__type) \ + __type **list; \ + __type *trace; \ + Py_ssize_t count; \ + \ + +#define APPEND_ELEMENT(name, listname) \ + list = &(type->listname); \ + +#define APPEND_SHUTDOWN(__type) \ + /* count how many members are in it so far */ \ + trace = *list; \ + count = 0; \ + if (trace != NULL) \ + { \ + while (*(int *)trace++) \ + count++; \ + } \ + /* make room for one more member, and add one for the NULL end */ \ + trace = (__type *)PyMem_Realloc(*list, sizeof(__type) * (count + 2)); \ + if (trace == NULL) \ + return -1; \ + *list = trace; \ + trace[count] = *value; \ + memset(trace + count + 1, 0, sizeof(__type)); \ + return 0; \ + +int +PyType_AppendType(PyTypeObject *type, PyTypeObjectElement element, PyTypeObject *value) +{ + int returnValue; + /* + + PyObject *tp_bases; + +you're only partly done with bases, so far + + PyObject *tp_mro; // method resolution order + PyObject *tp_cache; + PyObject *tp_subclasses; + PyObject *tp_weaklist; + + + */ + int count = PyTuple_Size(type->tp_bases); + returnValue = _PyTuple_Resize(&type->tp_bases, count + 1); + if (returnValue != 0) + return returnValue; + PyTuple_SetItem(type->tp_bases, count, (PyObject *)value); + return 0; +} + + +int +PyType_AppendMethod(PyTypeObject *type, PyMethodDef *value) +{ + APPEND_STARTUP(struct PyMethodDef); + APPEND_ELEMENT(pytoe_method, tp_methods); + APPEND_SHUTDOWN(struct PyMethodDef); +} + + +int +PyType_AppendMember(PyTypeObject *type, PyMemberDef *value) +{ + APPEND_STARTUP(struct PyMemberDef); + APPEND_ELEMENT(pytoe_member, tp_members); + APPEND_SHUTDOWN(struct PyMemberDef); +} + + +int +PyType_AppendProperty(PyTypeObject *type, PyGetSetDef *value) +{ + APPEND_STARTUP(struct PyGetSetDef); + APPEND_ELEMENT(pytoe_getset, tp_getset); + APPEND_SHUTDOWN(struct PyGetSetDef); +} + + + +PyAPI_FUNC(PyMethodDef *) PyMethodDef_New(const char *name, PyCFunction method, int flags, const char *docstring) +{ + int nameLength; + int docstringLength; + PyMethodDef *returnvalue; + + nameLength = strlen(name) + 1; + if (docstring) + docstringLength = strlen(docstring) + 1; + else + docstringLength = 0; + returnvalue = (PyMethodDef *)PyMem_Malloc(sizeof(PyMethodDef) + nameLength + docstringLength); + + if (returnvalue == NULL) + return NULL; + + returnvalue->ml_name = (char *)(returnvalue + 1); + memcpy((void *)returnvalue->ml_name, name, nameLength); + if (docstring) { + returnvalue->ml_doc = returnvalue->ml_name + nameLength; + memcpy((char *)returnvalue->ml_doc, docstring, docstringLength); + } else { + returnvalue->ml_doc = NULL; + } + returnvalue->ml_meth = method; + returnvalue->ml_flags = flags; + + return returnvalue; +} + + +PyAPI_FUNC(PyMemberDef *) PyMember_New(const char *name, int type, Py_ssize_t offset, int flags, const char *docstring) +{ + int nameLength; + int docstringLength; + PyMemberDef *returnvalue; + + nameLength = strlen(name) + 1; + if (docstring) + docstringLength = strlen(docstring) + 1; + else + docstringLength = 0; + returnvalue = (PyMemberDef *)PyMem_Malloc(sizeof(PyMemberDef) + nameLength + docstringLength); + + if (returnvalue == NULL) + return NULL; + + returnvalue->name = (char *)(returnvalue + 1); + memcpy(returnvalue->name, name, nameLength); + if (docstring) { + returnvalue->doc = returnvalue->name + nameLength; + memcpy(returnvalue->doc, docstring, docstringLength); + } else { + returnvalue->doc = NULL; + } + returnvalue->type = type; + returnvalue->flags = flags; + returnvalue->offset = offset; + + return returnvalue; +} + + +PyAPI_FUNC(PyGetSetDef *) PyProperty_New(const char *name, getter get, setter set, void *closure, const char *docstring) +{ + int nameLength; + int docstringLength; + PyGetSetDef *returnvalue; + + nameLength = strlen(name) + 1; + if (docstring) + docstringLength = strlen(docstring) + 1; + else + docstringLength = 0; + returnvalue = (PyGetSetDef *)PyMem_Malloc(sizeof(PyGetSetDef) + nameLength + docstringLength); + + if (returnvalue == NULL) + return NULL; + + returnvalue->name = (char *)(returnvalue + 1); + memcpy(returnvalue->name, name, nameLength); + if (docstring) { + returnvalue->doc = returnvalue->name + nameLength; + memcpy(returnvalue->doc, docstring, docstringLength); + } else { + returnvalue->doc = NULL; + } + + returnvalue->get = get; + returnvalue->set = set; + returnvalue->closure = closure; + + return returnvalue; +} + + +int +PyType_Activate(PyTypeObject *type) { PyObject *dict, *bases; PyTypeObject *base; @@ -3744,13 +4693,13 @@ /* Initialize tp_base (defaults to BaseObject unless that's us) */ base = type->tp_base; - if (base == NULL && type != &PyBaseObject_Type) { - base = type->tp_base = &PyBaseObject_Type; + if (base == NULL && type != PyBaseObject_Type) { + base = type->tp_base = PyBaseObject_Type; Py_INCREF(base); } /* Now the only way base can still be NULL is if type is - * &PyBaseObject_Type. + * PyBaseObject_Type. */ /* Initialize the base class */ @@ -3763,8 +4712,8 @@ compilable separately on Windows can call PyType_Ready() instead of initializing the ob_type field of their type objects. */ /* The test for base != NULL is really unnecessary, since base is only - NULL when type is &PyBaseObject_Type, and we know its ob_type is - not NULL (it's initialized to &PyType_Type). But coverity doesn't + NULL when type is PyBaseObject_Type, and we know its ob_type is + not NULL (it's initialized to PyType_Type). But coverity doesn't know that. */ if (Py_TYPE(type) == NULL && base != NULL) Py_TYPE(type) = Py_TYPE(base); @@ -3918,6 +4867,19 @@ return -1; } +/* Backwards compatibility */ +int +PyType_Ready(PyTypeObject *type) +{ + return PyType_Activate(type); +} + +/* +** +** NEAL END HERE +** +*/ + static int add_subclass(PyTypeObject *base, PyTypeObject *type) { @@ -4934,7 +5896,7 @@ if (res == NULL) return -1; if (PyLong_Check(res)) - h = PyLong_Type.tp_hash(res); + h = PyType_GetHashFunction(PyLong_Type, pytoe_hash)(res); else h = PyLong_AsLong(res); Py_DECREF(res); @@ -5034,7 +5996,7 @@ needed, with call_attribute. */ getattribute = _PyType_Lookup(tp, getattribute_str); if (getattribute == NULL || - (Py_TYPE(getattribute) == &PyWrapperDescr_Type && + (Py_TYPE(getattribute) == PyWrapperDescr_Type && ((PyWrapperDescrObject *)getattribute)->d_wrapped == (void *)PyObject_GenericGetAttr)) res = PyObject_GenericGetAttr(self, name); @@ -5653,7 +6615,7 @@ } continue; } - if (Py_TYPE(descr) == &PyWrapperDescr_Type) { + if (Py_TYPE(descr) == PyWrapperDescr_Type) { void **tptr = resolve_slotdups(type, p->name_strobj); if (tptr == NULL || tptr == ptr) generic = p->function; @@ -5668,7 +6630,7 @@ use_generic = 1; } } - else if (Py_TYPE(descr) == &PyCFunction_Type && + else if (Py_TYPE(descr) == PyCFunction_Type && PyCFunction_GET_FUNCTION(descr) == (PyCFunction)tp_new_wrapper && ptr == (void**)&type->tp_new) @@ -6122,7 +7084,7 @@ Py_INCREF(self); return self; } - if (Py_TYPE(su) != &PySuper_Type) + if (Py_TYPE(su) != PySuper_Type) /* If su is an instance of a (strict) subclass of super, call its type */ return PyObject_CallFunctionObjArgs((PyObject *)Py_TYPE(su), @@ -6132,7 +7094,7 @@ PyTypeObject *obj_type = supercheck(su->type, obj); if (obj_type == NULL) return NULL; - newobj = (superobject *)PySuper_Type.tp_new(&PySuper_Type, + newobj = (superobject *)PySuper_Type->tp_new(PySuper_Type, NULL, NULL); if (newobj == NULL) return NULL; @@ -6155,7 +7117,7 @@ if (!_PyArg_NoKeywords("super", kwds)) return -1; - if (!PyArg_ParseTuple(args, "|O!O:super", &PyType_Type, &type, &obj)) + if (!PyArg_ParseTuple(args, "|O!O:super", PyType_Type, &type, &obj)) return -1; if (type == NULL) { @@ -6263,8 +7225,8 @@ return 0; } -PyTypeObject PySuper_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject _PySuper_Type = { + PyVarObject_HEAD_INIT(&_PyType_Type, 0) "super", /* tp_name */ sizeof(superobject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -6306,3 +7268,4 @@ PyType_GenericNew, /* tp_new */ PyObject_GC_Del, /* tp_free */ }; +PyTypeObject *PySuper_Type = &_PySuper_Type; diff -r a156f602debc Objects/typeprivate.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Objects/typeprivate.h Tue Apr 28 19:26:52 2009 -0700 @@ -0,0 +1,207 @@ +#ifndef __TYPEPRIVATE_H +#define __TYPEPRIVATE_H + +struct PyNumberMethods { + /* Number implementations must check *both* + arguments for proper type and implement the necessary conversions + in the slot functions themselves. */ + + binaryfunc nb_add; + binaryfunc nb_subtract; + binaryfunc nb_multiply; + binaryfunc nb_remainder; + binaryfunc nb_divmod; + ternaryfunc nb_power; + unaryfunc nb_negative; + unaryfunc nb_positive; + unaryfunc nb_absolute; + inquiry nb_bool; + unaryfunc nb_invert; + binaryfunc nb_lshift; + binaryfunc nb_rshift; + binaryfunc nb_and; + binaryfunc nb_xor; + binaryfunc nb_or; + unaryfunc nb_int; + void *nb_reserved; /* the slot formerly known as nb_long */ + unaryfunc nb_float; + + binaryfunc nb_inplace_add; + binaryfunc nb_inplace_subtract; + binaryfunc nb_inplace_multiply; + binaryfunc nb_inplace_remainder; + ternaryfunc nb_inplace_power; + binaryfunc nb_inplace_lshift; + binaryfunc nb_inplace_rshift; + binaryfunc nb_inplace_and; + binaryfunc nb_inplace_xor; + binaryfunc nb_inplace_or; + + binaryfunc nb_floor_divide; + binaryfunc nb_true_divide; + binaryfunc nb_inplace_floor_divide; + binaryfunc nb_inplace_true_divide; + + unaryfunc nb_index; +}; + +struct PySequenceMethods { + lenfunc sq_length; + binaryfunc sq_concat; + ssizeargfunc sq_repeat; + ssizeargfunc sq_item; + void *was_sq_slice; + ssizeobjargproc sq_ass_item; + void *was_sq_ass_slice; + objobjproc sq_contains; + + binaryfunc sq_inplace_concat; + ssizeargfunc sq_inplace_repeat; +}; + +struct PyMappingMethods { + lenfunc mp_length; + binaryfunc mp_subscript; + objobjargproc mp_ass_subscript; +}; + +struct PyBufferProcs { + getbufferproc bf_getbuffer; + releasebufferproc bf_releasebuffer; +}; + + +struct _typeobject { + PyObject_VAR_HEAD + const char *tp_name; /* For printing, in format "." */ + Py_ssize_t tp_basicsize, tp_itemsize; /* For allocation */ + + /* Methods to implement standard operations */ + + destructor tp_dealloc; + printfunc tp_print; + getattrfunc tp_getattr; + setattrfunc tp_setattr; + void *tp_reserved; /* formerly known as tp_compare */ + reprfunc tp_repr; + + /* Method suites for standard classes */ + + PyNumberMethods *tp_as_number; + PySequenceMethods *tp_as_sequence; + PyMappingMethods *tp_as_mapping; + + /* More standard operations (here for binary compatibility) */ + + hashfunc tp_hash; + ternaryfunc tp_call; + reprfunc tp_str; + getattrofunc tp_getattro; + setattrofunc tp_setattro; + + /* Functions to access object as input/output buffer */ + PyBufferProcs *tp_as_buffer; + + /* Flags to define presence of optional/expanded features */ + long tp_flags; + + const char *tp_doc; /* Documentation string */ + + /* Assigned meaning in release 2.0 */ + /* call function for all accessible objects */ + traverseproc tp_traverse; + + /* delete references to contained objects */ + inquiry tp_clear; + + /* Assigned meaning in release 2.1 */ + /* rich comparisons */ + richcmpfunc tp_richcompare; + + /* weak reference enabler */ + Py_ssize_t tp_weaklistoffset; + + /* Iterators */ + getiterfunc tp_iter; + iternextfunc tp_iternext; + + /* Attribute descriptor and subclassing stuff */ + struct PyMethodDef *tp_methods; + struct PyMemberDef *tp_members; + struct PyGetSetDef *tp_getset; + struct _typeobject *tp_base; + PyObject *tp_dict; + descrgetfunc tp_descr_get; + descrsetfunc tp_descr_set; + Py_ssize_t tp_dictoffset; + initproc tp_init; + allocfunc tp_alloc; + newfunc tp_new; + freefunc tp_free; /* Low-level free-memory routine */ + inquiry tp_is_gc; /* For PyObject_IS_GC */ + PyObject *tp_bases; + PyObject *tp_mro; /* method resolution order */ + PyObject *tp_cache; + PyObject *tp_subclasses; + PyObject *tp_weaklist; + destructor tp_del; + + /* Type attribute cache version tag. Added in version 2.6 */ + unsigned int tp_version_tag; + + #ifdef COUNT_ALLOCS + /* these must be last and never explicitly initialized */ + Py_ssize_t tp_allocs; + Py_ssize_t tp_frees; + Py_ssize_t tp_maxalloc; + struct _typeobject *tp_prev; + struct _typeobject *tp_next; + #endif +}; + + +/* The *real* layout of a type object when allocated on the heap */ +struct _heaptypeobject { + /* Note: there's a dependency on the order of these members + in slotptr() in typeobject.c . */ + PyTypeObject ht_type; + PyNumberMethods as_number; + PyMappingMethods as_mapping; + PySequenceMethods as_sequence; /* as_sequence comes after as_mapping, + so that the mapping wins when both + the mapping and the sequence define + a given operator (e.g. __getitem__). + see add_operators() in typeobject.c . */ + PyBufferProcs as_buffer; + PyObject *ht_name, *ht_slots; + /* here are optional user slots, followed by the members. */ +} ; + +/* access macro to the members which are floating "behind" the object */ +#define PyHeapType_GET_MEMBERS(etype) \ + ((PyMemberDef *)(((char *)etype) + Py_TYPE(etype)->tp_basicsize)) + +struct PyGetSetDef { + char *name; + getter get; + setter set; + char *doc; + void *closure; +}; + +struct PyMemberDef { + /* Current version, use this */ + char *name; + int type; + Py_ssize_t offset; + int flags; + char *doc; +}; + +PyAPI_DATA(PyTypeObject) _PyType_Type; +PyAPI_DATA(PyTypeObject) _PyBaseObject_Type; +PyAPI_DATA(PyTypeObject) _PySuper_Type; + + +#endif /* __TYPEPRIVATE_H */ + diff -r a156f602debc Objects/unicodeobject.c --- a/Objects/unicodeobject.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Objects/unicodeobject.c Tue Apr 28 19:26:52 2009 -0700 @@ -40,7 +40,9 @@ */ #define PY_SSIZE_T_CLEAN +#define PY_TYPEPRIVATE #include "Python.h" +#include "typeprivate.h" #include "bytes_methods.h" #include "unicodeobject.h" @@ -83,7 +85,7 @@ /* --- Globals ------------------------------------------------------------ - The globals are initialized by the _PyUnicode_Init() API and should + The globals are initialized by the PyUnicode_Init() API and should not be used before calling that API. */ @@ -334,11 +336,11 @@ size_t new_size = sizeof(Py_UNICODE) * ((size_t)length + 1); unicode->str = (Py_UNICODE*) PyObject_MALLOC(new_size); } - PyObject_INIT(unicode, &PyUnicode_Type); + PyObject_INIT(unicode, PyUnicode_Type); } else { size_t new_size; - unicode = PyObject_New(PyUnicodeObject, &PyUnicode_Type); + unicode = PyObject_New(PyUnicodeObject, PyUnicode_Type); if (unicode == NULL) return NULL; new_size = sizeof(Py_UNICODE) * ((size_t)length + 1); @@ -1658,7 +1660,7 @@ PyErr_SetString(PyExc_TypeError, &argparse[4]); goto onError; } - if (!PyArg_ParseTuple(restuple, argparse, &PyUnicode_Type, &repunicode, &newpos)) + if (!PyArg_ParseTuple(restuple, argparse, PyUnicode_Type, &repunicode, &newpos)) goto onError; /* Copy back the bytes variables, which might have been modified by the @@ -3922,7 +3924,7 @@ Py_DECREF(restuple); return NULL; } - if (!PyArg_ParseTuple(restuple, argparse, &PyUnicode_Type, + if (!PyArg_ParseTuple(restuple, argparse, PyUnicode_Type, &resunicode, newpos)) { Py_DECREF(restuple); return NULL; @@ -4620,7 +4622,7 @@ PyObject_FREE(o); } -static PyTypeObject EncodingMapType = { +static PyTypeObject _EncodingMapType = { PyVarObject_HEAD_INIT(NULL, 0) "EncodingMap", /*tp_name*/ sizeof(struct encoding_map), /*tp_basicsize*/ @@ -4663,6 +4665,7 @@ 0, /*tp_free*/ 0, /*tp_is_gc*/ }; +static PyTypeObject *EncodingMapType = &_EncodingMapType; PyObject* PyUnicode_BuildEncodingMap(PyObject* string) @@ -4743,7 +4746,7 @@ 16*count2 + 128*count3 - 1); if (!result) return PyErr_NoMemory(); - PyObject_Init(result, &EncodingMapType); + PyObject_Init(result, EncodingMapType); mresult = (struct encoding_map*)result; mresult->count2 = count2; mresult->count3 = count3; @@ -4880,7 +4883,7 @@ char *outstart; Py_ssize_t outsize = PyBytes_GET_SIZE(*outobj); - if (Py_TYPE(mapping) == &EncodingMapType) { + if (Py_TYPE(mapping) == EncodingMapType) { int res = encoding_map_lookup(c, mapping); Py_ssize_t requiredsize = *outpos+1; if (res == -1) @@ -4952,7 +4955,7 @@ /* find all unencodable characters */ while (collendpos < size) { PyObject *rep; - if (Py_TYPE(mapping) == &EncodingMapType) { + if (Py_TYPE(mapping) == EncodingMapType) { int res = encoding_map_lookup(p[collendpos], mapping); if (res != -1) break; @@ -5196,7 +5199,7 @@ Py_DECREF(restuple); return NULL; } - if (!PyArg_ParseTuple(restuple, argparse, &PyUnicode_Type, + if (!PyArg_ParseTuple(restuple, argparse, PyUnicode_Type, &resunicode, &i_newpos)) { Py_DECREF(restuple); return NULL; @@ -9400,7 +9403,7 @@ char *encoding = NULL; char *errors = NULL; - if (type != &PyUnicode_Type) + if (type != PyUnicode_Type) return unicode_subtype_new(type, args, kwds); if (!PyArg_ParseTupleAndKeywords(args, kwds, "|Oss:str", kwlist, &x, &encoding, &errors)) @@ -9419,8 +9422,8 @@ PyUnicodeObject *tmp, *pnew; Py_ssize_t n; - assert(PyType_IsSubtype(type, &PyUnicode_Type)); - tmp = (PyUnicodeObject *)unicode_new(&PyUnicode_Type, args, kwds); + assert(PyType_IsSubtype(type, PyUnicode_Type)); + tmp = (PyUnicodeObject *)unicode_new(PyUnicode_Type, args, kwds); if (tmp == NULL) return NULL; assert(PyUnicode_Check(tmp)); @@ -9452,8 +9455,11 @@ static PyObject *unicode_iter(PyObject *seq); -PyTypeObject PyUnicode_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +/* note: str MUST be hard-coded, can't use PyType_New(). + it's used heavily in the implementation of types themselves. +*/ +PyTypeObject _PyUnicode_Type = { + PyVarObject_HEAD_INIT(&_PyType_Type, 0) "str", /* tp_name */ sizeof(PyUnicodeObject), /* tp_size */ 0, /* tp_itemsize */ @@ -9485,7 +9491,7 @@ unicode_methods, /* tp_methods */ 0, /* tp_members */ 0, /* tp_getset */ - &PyBaseObject_Type, /* tp_base */ + &_PyBaseObject_Type, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ @@ -9495,83 +9501,8 @@ unicode_new, /* tp_new */ PyObject_Del, /* tp_free */ }; - -/* Initialize the Unicode implementation */ - -void _PyUnicode_Init(void) -{ - int i; - - /* XXX - move this array to unicodectype.c ? */ - Py_UNICODE linebreak[] = { - 0x000A, /* LINE FEED */ - 0x000D, /* CARRIAGE RETURN */ - 0x001C, /* FILE SEPARATOR */ - 0x001D, /* GROUP SEPARATOR */ - 0x001E, /* RECORD SEPARATOR */ - 0x0085, /* NEXT LINE */ - 0x2028, /* LINE SEPARATOR */ - 0x2029, /* PARAGRAPH SEPARATOR */ - }; - - /* Init the implementation */ - free_list = NULL; - numfree = 0; - unicode_empty = _PyUnicode_New(0); - if (!unicode_empty) - return; - - for (i = 0; i < 256; i++) - unicode_latin1[i] = NULL; - if (PyType_Ready(&PyUnicode_Type) < 0) - Py_FatalError("Can't initialize 'unicode'"); - - /* initialize the linebreak bloom filter */ - bloom_linebreak = make_bloom_mask( - linebreak, sizeof(linebreak) / sizeof(linebreak[0]) - ); - - PyType_Ready(&EncodingMapType); -} - -/* Finalize the Unicode implementation */ - -int -PyUnicode_ClearFreeList(void) -{ - int freelist_size = numfree; - PyUnicodeObject *u; - - for (u = free_list; u != NULL;) { - PyUnicodeObject *v = u; - u = *(PyUnicodeObject **)u; - if (v->str) - PyObject_DEL(v->str); - Py_XDECREF(v->defenc); - PyObject_Del(v); - numfree--; - } - free_list = NULL; - assert(numfree == 0); - return freelist_size; -} - -void -_PyUnicode_Fini(void) -{ - int i; - - Py_XDECREF(unicode_empty); - unicode_empty = NULL; - - for (i = 0; i < 256; i++) { - if (unicode_latin1[i]) { - Py_DECREF(unicode_latin1[i]); - unicode_latin1[i] = NULL; - } - } - (void)PyUnicode_ClearFreeList(); -} +PyTypeObject *PyUnicode_Type = &_PyUnicode_Type; + void PyUnicode_InternInPlace(PyObject **p) @@ -9758,8 +9689,8 @@ {NULL, NULL} /* sentinel */ }; -PyTypeObject PyUnicodeIter_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject _PyUnicodeIter_Type = { + PyVarObject_HEAD_INIT(&_PyType_Type, 0) "str_iterator", /* tp_name */ sizeof(unicodeiterobject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -9790,6 +9721,7 @@ unicodeiter_methods, /* tp_methods */ 0, }; +PyTypeObject *PyUnicodeIter_Type = &_PyUnicodeIter_Type; static PyObject * unicode_iter(PyObject *seq) @@ -9800,7 +9732,7 @@ PyErr_BadInternalCall(); return NULL; } - it = PyObject_GC_New(unicodeiterobject, &PyUnicodeIter_Type); + it = PyObject_GC_New(unicodeiterobject, PyUnicodeIter_Type); if (it == NULL) return NULL; it->it_index = 0; @@ -9862,6 +9794,82 @@ } + +/* Initialize the Unicode implementation */ + +int PyUnicode_Init(void) +{ + int i; + + /* XXX - move this array to unicodectype.c ? */ + Py_UNICODE linebreak[] = { + 0x000A, /* LINE FEED */ + 0x000D, /* CARRIAGE RETURN */ + 0x001C, /* FILE SEPARATOR */ + 0x001D, /* GROUP SEPARATOR */ + 0x001E, /* RECORD SEPARATOR */ + 0x0085, /* NEXT LINE */ + 0x2028, /* LINE SEPARATOR */ + 0x2029, /* PARAGRAPH SEPARATOR */ + }; + + /* Init the implementation */ + free_list = NULL; + numfree = 0; + unicode_empty = _PyUnicode_New(0); + if (!unicode_empty) + return 1; + + for (i = 0; i < 256; i++) + unicode_latin1[i] = NULL; + + /* initialize the linebreak bloom filter */ + bloom_linebreak = make_bloom_mask( + linebreak, sizeof(linebreak) / sizeof(linebreak[0]) + ); + + return 0; +} + +/* Finalize the Unicode implementation */ + +int +PyUnicode_ClearFreeList(void) +{ + int freelist_size = numfree; + PyUnicodeObject *u; + + for (u = free_list; u != NULL;) { + PyUnicodeObject *v = u; + u = *(PyUnicodeObject **)u; + if (v->str) + PyObject_DEL(v->str); + Py_XDECREF(v->defenc); + PyObject_Del(v); + numfree--; + } + free_list = NULL; + assert(numfree == 0); + return freelist_size; +} + +void +_PyUnicode_Fini(void) +{ + int i; + + Py_XDECREF(unicode_empty); + unicode_empty = NULL; + + for (i = 0; i < 256; i++) { + if (unicode_latin1[i]) { + Py_DECREF(unicode_latin1[i]); + unicode_latin1[i] = NULL; + } + } + (void)PyUnicode_ClearFreeList(); +} + #ifdef __cplusplus } #endif diff -r a156f602debc Objects/weakrefobject.c --- a/Objects/weakrefobject.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Objects/weakrefobject.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,4 +1,6 @@ +#define PY_TYPEPRIVATE #include "Python.h" +#include "typeprivate.h" #include "structmember.h" @@ -33,7 +35,7 @@ { PyWeakReference *result; - result = PyObject_GC_New(PyWeakReference, &_PyWeakref_RefType); + result = PyObject_GC_New(PyWeakReference, _PyWeakref_RefType); if (result) { init_weakref(result, ob, callback); PyObject_GC_Track(result); @@ -286,7 +288,7 @@ callback = NULL; list = GET_WEAKREFS_LISTPTR(ob); get_basic_refs(*list, &ref, &proxy); - if (callback == NULL && type == &_PyWeakref_RefType) { + if (callback == NULL && type == _PyWeakref_RefType) { if (ref != NULL) { /* We can re-use an existing reference. */ Py_INCREF(ref); @@ -302,7 +304,7 @@ self = (PyWeakReference *) (type->tp_alloc(type, 0)); if (self != NULL) { init_weakref(self, ob, callback); - if (callback == NULL && type == &_PyWeakref_RefType) { + if (callback == NULL && type == _PyWeakref_RefType) { insert_head(self, list); } else { @@ -332,9 +334,11 @@ } -PyTypeObject -_PyWeakref_RefType = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +/* note: weakref MUST be hard-coded, can't use PyType_New(). + it's used heavily in the implementation of types themselves. +*/ +PyTypeObject __PyWeakref_RefType = { + PyVarObject_HEAD_INIT(&_PyType_Type, 0) "weakref", sizeof(PyWeakReference), 0, @@ -375,6 +379,7 @@ weakref___new__, /*tp_new*/ PyObject_GC_Del, /*tp_free*/ }; +PyTypeObject *_PyWeakref_RefType = &__PyWeakref_RefType; static int @@ -631,9 +636,8 @@ }; -PyTypeObject -_PyWeakref_ProxyType = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject __PyWeakref_ProxyType = { + PyVarObject_HEAD_INIT(&_PyType_Type, 0) "weakproxy", sizeof(PyWeakReference), 0, @@ -662,11 +666,11 @@ (getiterfunc)proxy_iter, /* tp_iter */ (iternextfunc)proxy_iternext, /* tp_iternext */ }; +PyTypeObject *_PyWeakref_ProxyType = &__PyWeakref_ProxyType; -PyTypeObject -_PyWeakref_CallableProxyType = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject __PyWeakref_CallableProxyType = { + PyVarObject_HEAD_INIT(&_PyType_Type, 0) "weakcallableproxy", sizeof(PyWeakReference), 0, @@ -695,6 +699,7 @@ (getiterfunc)proxy_iter, /* tp_iter */ (iternextfunc)proxy_iternext, /* tp_iternext */ }; +PyTypeObject *_PyWeakref_CallableProxyType = &__PyWeakref_CallableProxyType; @@ -790,9 +795,9 @@ PyWeakReference *prev; if (PyCallable_Check(ob)) - Py_TYPE(result) = &_PyWeakref_CallableProxyType; + Py_TYPE(result) = _PyWeakref_CallableProxyType; else - Py_TYPE(result) = &_PyWeakref_ProxyType; + Py_TYPE(result) = _PyWeakref_ProxyType; get_basic_refs(*list, &ref, &proxy); if (callback == NULL) { if (proxy != NULL) { @@ -930,3 +935,9 @@ PyErr_Restore(err_type, err_value, err_tb); } } + +/* TODO remove this! */ +int PyWeakref_Init(void) { + return 0; +} + diff -r a156f602debc Parser/asdl_c.py --- a/Parser/asdl_c.py Tue Apr 28 12:42:20 2009 -0700 +++ b/Parser/asdl_c.py Tue Apr 28 19:26:52 2009 -0700 @@ -654,7 +654,7 @@ }; static PyTypeObject AST_type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) + PyVarObject_HEAD_INIT(PyType_Type, 0) "_ast.AST", sizeof(PyObject), 0, @@ -710,7 +710,7 @@ } PyTuple_SET_ITEM(fnames, i, field); } - result = PyObject_CallFunction((PyObject*)&PyType_Type, "U(O){sOss}", + result = PyObject_CallFunction((PyObject*)PyType_Type, "U(O){sOss}", type, base, "_fields", fnames, "__module__", "_ast"); Py_DECREF(fnames); return (PyTypeObject*)result; @@ -1149,7 +1149,9 @@ f = open(p, "w") f.write(auto_gen_msg) f.write(c_file_msg % parse_version(mod)) + f.write('#define PY_TYPEPRIVATE\n') f.write('#include "Python.h"\n') + f.write('#include "../Objects/typeprivate.h"\n') f.write('#include "%s-ast.h"\n' % mod.name) f.write('\n') f.write("static PyTypeObject AST_type;\n") diff -r a156f602debc Python/Python-ast.c --- a/Python/Python-ast.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Python/Python-ast.c Tue Apr 28 19:26:52 2009 -0700 @@ -9,7 +9,9 @@ containing the grammar change. */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "../Objects/typeprivate.h" #include "Python-ast.h" static PyTypeObject AST_type; @@ -471,7 +473,7 @@ }; static PyTypeObject AST_type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) + PyVarObject_HEAD_INIT(&_PyType_Type, 0) "_ast.AST", sizeof(PyObject), 0, @@ -527,7 +529,7 @@ } PyTuple_SET_ITEM(fnames, i, field); } - result = PyObject_CallFunction((PyObject*)&PyType_Type, "U(O){sOss}", + result = PyObject_CallFunction((PyObject*)PyType_Type, "U(O){sOss}", type, base, "_fields", fnames, "__module__", "_ast"); Py_DECREF(fnames); return (PyTypeObject*)result; diff -r a156f602debc Python/_warnings.c --- a/Python/_warnings.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Python/_warnings.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,4 +1,6 @@ +#define PY_TYPEPRIVATE #include "Python.h" +#include "pytypeconvert.h" #include "frameobject.h" #define MODULE_NAME "_warnings" diff -r a156f602debc Python/bltinmodule.c --- a/Python/bltinmodule.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Python/bltinmodule.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,6 +1,8 @@ /* Built-in functions */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "pytypeconvert.h" #include "Python-ast.h" #include "node.h" @@ -99,7 +101,7 @@ } if (meta == NULL) { if (PyTuple_GET_SIZE(bases) == 0) - meta = (PyObject *) (&PyType_Type); + meta = (PyObject *) (PyType_Type); else { PyObject *base0 = PyTuple_GET_ITEM(bases, 0); meta = (PyObject *) (base0->ob_type); @@ -317,7 +319,7 @@ PyObject *it; } filterobject; -PyTypeObject PyFilter_Type; +PyTypeObject *PyFilter_Type; static PyObject * filter_new(PyTypeObject *type, PyObject *args, PyObject *kwds) @@ -326,7 +328,7 @@ PyObject *it; filterobject *lz; - if (type == &PyFilter_Type && !_PyArg_NoKeywords("filter()", kwds)) + if (type == PyFilter_Type && !_PyArg_NoKeywords("filter()", kwds)) return NULL; if (!PyArg_UnpackTuple(args, "filter", 2, 2, &func, &seq)) @@ -381,7 +383,7 @@ if (item == NULL) return NULL; - if (lz->func == Py_None || lz->func == (PyObject *)&PyBool_Type) { + if (lz->func == Py_None || lz->func == (PyObject *)PyBool_Type) { ok = PyObject_IsTrue(item); } else { PyObject *good; @@ -406,8 +408,8 @@ Return an iterator yielding those items of iterable for which function(item)\n\ is true. If function is None, return the items that are true."); -PyTypeObject PyFilter_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject _PyFilter_Type = { + PyVarObject_HEAD_INIT(NULL, 0) "filter", /* tp_name */ sizeof(filterobject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -913,7 +915,7 @@ PyObject *func; } mapobject; -PyTypeObject PyMap_Type; +PyTypeObject *PyMap_Type; static PyObject * map_new(PyTypeObject *type, PyObject *args, PyObject *kwds) @@ -922,7 +924,7 @@ mapobject *lz; Py_ssize_t numargs, i; - if (type == &PyMap_Type && !_PyArg_NoKeywords("map()", kwds)) + if (type == PyMap_Type && !_PyArg_NoKeywords("map()", kwds)) return NULL; numargs = PyTuple_Size(args); @@ -1009,8 +1011,8 @@ Make an iterator that computes the function using arguments from\n\ each of the iterables. Stops when the shortest iterable is exhausted."); -PyTypeObject PyMap_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject _PyMap_Type = { + PyVarObject_HEAD_INIT(NULL, 0) "map", /* tp_name */ sizeof(mapobject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -2031,7 +2033,7 @@ PyObject *result; } zipobject; -PyTypeObject PyZip_Type; +PyTypeObject *PyZip_Type; static PyObject * zip_new(PyTypeObject *type, PyObject *args, PyObject *kwds) @@ -2042,7 +2044,7 @@ PyObject *result; Py_ssize_t tuplesize = PySequence_Length(args); - if (type == &PyZip_Type && !_PyArg_NoKeywords("zip()", kwds)) + if (type == PyZip_Type && !_PyArg_NoKeywords("zip()", kwds)) return NULL; /* args must be a tuple */ @@ -2158,8 +2160,8 @@ method continues until the shortest iterable in the argument sequence\n\ is exhausted and then it raises StopIteration."); -PyTypeObject PyZip_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject _PyZip_Type = { + PyVarObject_HEAD_INIT(NULL, 0) "zip", /* tp_name */ sizeof(zipobject), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -2266,10 +2268,19 @@ }; +static int __init(void) { + CONVERT_TYPE(PyMap_Type, PyType_Type, NULL, "map type"); + CONVERT_TYPE(PyZip_Type, PyType_Type, NULL, "zip type"); + CONVERT_TYPE(PyFilter_Type, PyType_Type, NULL, "filter type"); + return 0; +} + PyObject * _PyBuiltin_Init(void) { PyObject *mod, *dict, *debug; + if (__init()) + return NULL; mod = PyModule_Create(&builtinsmodule); if (mod == NULL) return NULL; @@ -2297,34 +2308,34 @@ SETBUILTIN("NotImplemented", Py_NotImplemented); SETBUILTIN("False", Py_False); SETBUILTIN("True", Py_True); - SETBUILTIN("bool", &PyBool_Type); - SETBUILTIN("memoryview", &PyMemoryView_Type); - SETBUILTIN("bytearray", &PyByteArray_Type); - SETBUILTIN("bytes", &PyBytes_Type); - SETBUILTIN("classmethod", &PyClassMethod_Type); + SETBUILTIN("bool", PyBool_Type); + SETBUILTIN("memoryview", PyMemoryView_Type); + SETBUILTIN("bytearray", PyByteArray_Type); + SETBUILTIN("bytes", PyBytes_Type); + SETBUILTIN("classmethod", PyClassMethod_Type); #ifndef WITHOUT_COMPLEX - SETBUILTIN("complex", &PyComplex_Type); + SETBUILTIN("complex", PyComplex_Type); #endif - SETBUILTIN("dict", &PyDict_Type); - SETBUILTIN("enumerate", &PyEnum_Type); - SETBUILTIN("filter", &PyFilter_Type); - SETBUILTIN("float", &PyFloat_Type); - SETBUILTIN("frozenset", &PyFrozenSet_Type); - SETBUILTIN("property", &PyProperty_Type); - SETBUILTIN("int", &PyLong_Type); - SETBUILTIN("list", &PyList_Type); - SETBUILTIN("map", &PyMap_Type); - SETBUILTIN("object", &PyBaseObject_Type); - SETBUILTIN("range", &PyRange_Type); - SETBUILTIN("reversed", &PyReversed_Type); - SETBUILTIN("set", &PySet_Type); - SETBUILTIN("slice", &PySlice_Type); - SETBUILTIN("staticmethod", &PyStaticMethod_Type); - SETBUILTIN("str", &PyUnicode_Type); - SETBUILTIN("super", &PySuper_Type); - SETBUILTIN("tuple", &PyTuple_Type); - SETBUILTIN("type", &PyType_Type); - SETBUILTIN("zip", &PyZip_Type); + SETBUILTIN("dict", PyDict_Type); + SETBUILTIN("enumerate", PyEnum_Type); + SETBUILTIN("filter", PyFilter_Type); + SETBUILTIN("float", PyFloat_Type); + SETBUILTIN("frozenset", PyFrozenSet_Type); + SETBUILTIN("property", PyProperty_Type); + SETBUILTIN("int", PyLong_Type); + SETBUILTIN("list", PyList_Type); + SETBUILTIN("map", PyMap_Type); + SETBUILTIN("object", PyBaseObject_Type); + SETBUILTIN("range", PyRange_Type); + SETBUILTIN("reversed", PyReversed_Type); + SETBUILTIN("set", PySet_Type); + SETBUILTIN("slice", PySlice_Type); + SETBUILTIN("staticmethod", PyStaticMethod_Type); + SETBUILTIN("str", PyUnicode_Type); + SETBUILTIN("super", PySuper_Type); + SETBUILTIN("tuple", PyTuple_Type); + SETBUILTIN("type", PyType_Type); + SETBUILTIN("zip", PyZip_Type); debug = PyBool_FromLong(Py_OptimizeFlag == 0); if (PyDict_SetItemString(dict, "__debug__", debug) < 0) { Py_XDECREF(debug); diff -r a156f602debc Python/ceval.c --- a/Python/ceval.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Python/ceval.c Tue Apr 28 19:26:52 2009 -0700 @@ -9,7 +9,9 @@ /* enable more aggressive intra-module optimizations, where available */ #define PY_LOCAL_AGGRESSIVE +#define PY_TYPEPRIVATE #include "Python.h" +#include "../Objects/typeprivate.h" #include "code.h" #include "frameobject.h" diff -r a156f602debc Python/codecs.c --- a/Python/codecs.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Python/codecs.c Tue Apr 28 19:26:52 2009 -0700 @@ -8,7 +8,9 @@ ------------------------------------------------------------------------ */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "../Objects/typeprivate.h" #include /* --- Codec Registry ----------------------------------------------------- */ diff -r a156f602debc Python/errors.c --- a/Python/errors.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Python/errors.c Tue Apr 28 19:26:52 2009 -0700 @@ -687,7 +687,7 @@ goto failure; } /* Create a real new-style class. */ - result = PyObject_CallFunction((PyObject *)&PyType_Type, "UOO", + result = PyObject_CallFunction((PyObject *)PyType_Type, "UOO", dot+1, bases, dict); failure: Py_XDECREF(bases); diff -r a156f602debc Python/getargs.c --- a/Python/getargs.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Python/getargs.c Tue Apr 28 19:26:52 2009 -0700 @@ -436,7 +436,7 @@ toplevel ? "expected %d arguments, not %.50s" : "must be %d-item sequence, not %.50s", n, - arg == Py_None ? "None" : arg->ob_type->tp_name); + arg == Py_None ? "None" : Py_TYPE_NAME(arg)); return msgbuf; } @@ -517,7 +517,7 @@ assert(arg != NULL); PyOS_snprintf(msgbuf, bufsize, "must be %.50s, not %.50s", expected, - arg == Py_None ? "None" : arg->ob_type->tp_name); + arg == Py_None ? "None" : Py_TYPE_NAME(arg)); return msgbuf; } @@ -1217,7 +1217,7 @@ if (PyType_IsSubtype(arg->ob_type, type)) *p = arg; else - return converterr(type->tp_name, arg, msgbuf, bufsize); + return converterr(PyType_GetString(type, pytoe_name), arg, msgbuf, bufsize); } else if (*format == '?') { @@ -1250,18 +1250,20 @@ case 'w': { /* memory buffer, read-write access */ void **p = va_arg(*p_va, void **); - PyBufferProcs *pb = arg->ob_type->tp_as_buffer; + getbufferproc getbuffer = PyType_GetBufferGetFunction(Py_TYPE(arg), pytoe_buffer_getbuffer); + releasebufferproc releasebuffer = PyType_GetBufferReleaseFunction(Py_TYPE(arg), pytoe_buffer_releasebuffer); + Py_ssize_t count; int temp=-1; Py_buffer view; - if (pb && pb->bf_releasebuffer && *format != '*') + if (releasebuffer && *format != '*') /* Buffer must be released, yet caller does not use the Py_buffer protocol. */ return converterr("pinned buffer", arg, msgbuf, bufsize); - if (pb && pb->bf_getbuffer && *format == '*') { + if (getbuffer && *format == '*') { /* Caller is interested in Py_buffer, and the object supports it directly. */ format++; @@ -1280,8 +1282,7 @@ } /* Here we have processed w*, only w and w# remain. */ - if (pb == NULL || - pb->bf_getbuffer == NULL || + if (getbuffer == NULL || ((temp = PyObject_GetBuffer(arg, &view, PyBUF_SIMPLE)) != 0) || view.readonly == 1) { @@ -1307,7 +1308,8 @@ compatibility */ case 't': { /* 8-bit character buffer, read-only access */ char **p = va_arg(*p_va, char **); - PyBufferProcs *pb = arg->ob_type->tp_as_buffer; + getbufferproc getbuffer = PyType_GetBufferGetFunction(Py_TYPE(arg), pytoe_buffer_getbuffer); + releasebufferproc releasebuffer = PyType_GetBufferReleaseFunction(Py_TYPE(arg), pytoe_buffer_releasebuffer); Py_ssize_t count; Py_buffer view; @@ -1315,7 +1317,7 @@ return converterr( "invalid use of 't' format character", arg, msgbuf, bufsize); - if (pb == NULL || pb->bf_getbuffer == NULL) + if (getbuffer == NULL) return converterr( "bytes or read-only character buffer", arg, msgbuf, bufsize); @@ -1326,7 +1328,7 @@ count = view.len; *p = view.buf; - if (pb->bf_releasebuffer) + if (releasebuffer) return converterr( "string or pinned buffer", arg, msgbuf, bufsize); @@ -1354,15 +1356,15 @@ static Py_ssize_t convertbuffer(PyObject *arg, void **p, char **errmsg) { - PyBufferProcs *pb = arg->ob_type->tp_as_buffer; + getbufferproc getbuffer = PyType_GetBufferGetFunction(Py_TYPE(arg), pytoe_buffer_getbuffer); + releasebufferproc releasebuffer = PyType_GetBufferReleaseFunction(Py_TYPE(arg), pytoe_buffer_releasebuffer); Py_ssize_t count; Py_buffer view; *errmsg = NULL; *p = NULL; - if (pb == NULL || - pb->bf_getbuffer == NULL || - pb->bf_releasebuffer != NULL) { + if (getbuffer == NULL || + releasebuffer != NULL) { *errmsg = "bytes or read-only buffer"; return -1; } @@ -1384,12 +1386,13 @@ { void *buf; Py_ssize_t count; - PyBufferProcs *pb = arg->ob_type->tp_as_buffer; - if (pb == NULL) { + getbufferproc getbuffer = PyType_GetBufferGetFunction(Py_TYPE(arg), pytoe_buffer_getbuffer); + releasebufferproc releasebuffer = PyType_GetBufferReleaseFunction(Py_TYPE(arg), pytoe_buffer_releasebuffer); + if (!(getbuffer || releasebuffer)) { *errmsg = "bytes or buffer"; return -1; } - if (pb->bf_getbuffer) { + if (getbuffer) { if (PyObject_GetBuffer(arg, view, 0) < 0) { *errmsg = "convertible to a buffer"; return -1; diff -r a156f602debc Python/import.c --- a/Python/import.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Python/import.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,7 +1,9 @@ /* Module definition and import implementation */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "pytypeconvert.h" #include "Python-ast.h" #undef Yield /* undefine macro conflicting with winbase.h */ @@ -169,6 +171,9 @@ } } +static int __init_PyNullImporter_Type(void); + + void _PyImportHooks_Init(void) { @@ -177,7 +182,7 @@ /* adding sys.path_hooks and sys.path_importer_cache, setting up zipimport */ - if (PyType_Ready(&PyNullImporter_Type) < 0) + if (__init_PyNullImporter_Type()) goto error; if (Py_VerboseFlag) @@ -1232,7 +1237,7 @@ } if (importer == NULL) { importer = PyObject_CallFunctionObjArgs( - (PyObject *)&PyNullImporter_Type, p, NULL + (PyObject *)PyNullImporter_Type, p, NULL ); if (importer == NULL) { if (PyErr_ExceptionMatches(PyExc_ImportError)) { @@ -3359,7 +3364,8 @@ }; -PyTypeObject PyNullImporter_Type = { +PyTypeObject *PyNullImporter_Type = NULL; +PyTypeObject _PyNullImporter_Type = { PyVarObject_HEAD_INIT(NULL, 0) "imp.NullImporter", /*tp_name*/ sizeof(NullImporter), /*tp_basicsize*/ @@ -3417,8 +3423,8 @@ { PyObject *m, *d; - if (PyType_Ready(&PyNullImporter_Type) < 0) - return NULL; + if (__init_PyNullImporter_Type()) + goto failure; m = PyModule_Create(&impmodule); if (m == NULL) @@ -3438,8 +3444,8 @@ if (setint(d, "PY_CODERESOURCE", PY_CODERESOURCE) < 0) goto failure; if (setint(d, "IMP_HOOK", IMP_HOOK) < 0) goto failure; - Py_INCREF(&PyNullImporter_Type); - PyModule_AddObject(m, "NullImporter", (PyObject *)&PyNullImporter_Type); + Py_INCREF(PyNullImporter_Type); + PyModule_AddObject(m, "NullImporter", (PyObject *)PyNullImporter_Type); return m; failure: Py_XDECREF(m); @@ -3500,6 +3506,15 @@ return PyImport_ExtendInittab(newtab); } +static int __init_PyNullImporter_Type(void) { + if (PyNullImporter_Type) { + return 0; + } + CONVERT_TYPE(PyNullImporter_Type, NULL, NULL, "null importer type"); + return 0; +} + + #ifdef __cplusplus } #endif diff -r a156f602debc Python/marshal.c --- a/Python/marshal.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Python/marshal.c Tue Apr 28 19:26:52 2009 -0700 @@ -6,7 +6,9 @@ #define PY_SSIZE_T_CLEAN +#define PY_TYPEPRIVATE #include "Python.h" +#include "../Objects/typeprivate.h" #include "longintrepr.h" #include "code.h" #include "marshal.h" @@ -360,7 +362,7 @@ else if (PyAnySet_CheckExact(v)) { PyObject *value, *it; - if (PyObject_TypeCheck(v, &PySet_Type)) + if (PyObject_TypeCheck(v, PySet_Type)) w_byte(TYPE_SET, p); else w_byte(TYPE_FROZENSET, p); diff -r a156f602debc Python/pythonrun.c --- a/Python/pythonrun.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Python/pythonrun.c Tue Apr 28 19:26:52 2009 -0700 @@ -18,6 +18,8 @@ #include "eval.h" #include "marshal.h" #include "osdefs.h" +#include "weakrefobject.h" +#include "frameobject.h" #ifdef HAVE_SIGNAL_H #include @@ -162,6 +164,7 @@ } #endif + void Py_InitializeEx(int install_sigs) { @@ -204,27 +207,43 @@ (void) PyThreadState_Swap(tstate); _Py_ReadyTypes(); - - if (!_PyFrame_Init()) - Py_FatalError("Py_Initialize: can't init frames"); - - if (!_PyLong_Init()) - Py_FatalError("Py_Initialize: can't init longs"); - - if (!PyByteArray_Init()) - Py_FatalError("Py_Initialize: can't init bytes"); - - _PyFloat_Init(); + PyDict_Init(); + PyLong_Init(); + PyBytes_Init(); + PyWeakref_Init(); + PyByteArray_Init(); + PyList_Init(); + PySlice_Init(); + PyTraceBack_Init(); + PyModule_Init(); + PyRange_Init(); + PySet_Init(); +#ifndef WITHOUT_COMPLEX + PyComplex_Init(); +#endif + PyBool_Init(); + PyMemoryView_Init(); + PyEnum_Init(); + PyFile_Init(); + PyCode_Init(); + PyFrame_Init(); + Py_MethodInit(); + PyGen_Init(); + PyCell_Init(); + PyCObject_Init(); + PySymtable_Init(); + PyFloat_Init(); interp->modules = PyDict_New(); if (interp->modules == NULL) - Py_FatalError("Py_Initialize: can't make modules dictionary"); + Py_FatalError("_Py_ReadyTypes: can't make modules dictionary"); interp->modules_reloading = PyDict_New(); if (interp->modules_reloading == NULL) - Py_FatalError("Py_Initialize: can't make modules_reloading dictionary"); + Py_FatalError("_Py_ReadyTypes: can't make modules_reloading dictionary"); /* Init Unicode implementation; relies on the codec registry */ - _PyUnicode_Init(); + PyUnicode_Init(); + PyIterObject_Init(); bimod = _PyBuiltin_Init(); if (bimod == NULL) @@ -236,7 +255,7 @@ Py_INCREF(interp->builtins); /* initialize builtin exceptions */ - _PyExc_Init(); + PyExc_Init(); sysmod = _PySys_Init(); if (sysmod == NULL) @@ -569,7 +588,7 @@ } /* initialize builtin exceptions */ - _PyExc_Init(); + PyExc_Init(); sysmod = _PyImport_FindExtension("sys", "sys"); if (bimod != NULL && sysmod != NULL) { @@ -1439,7 +1458,7 @@ if (!PyExceptionInstance_Check(value)) { PyFile_WriteString("TypeError: print_exception(): Exception expected for value, ", f); - PyFile_WriteString(Py_TYPE(value)->tp_name, f); + PyFile_WriteString(PyExceptionClass_Name(value), f); PyFile_WriteString(" found\n", f); return; } @@ -1484,12 +1503,12 @@ /* Don't do anything else */ } else { - PyObject* moduleName; - char* className; + PyObject * moduleName; + const char * className; assert(PyExceptionClass_Check(type)); className = PyExceptionClass_Name(type); if (className != NULL) { - char *dot = strrchr(className, '.'); + const char *dot = strrchr(className, '.'); if (dot != NULL) className = dot+1; } diff -r a156f602debc Python/structmember.c --- a/Python/structmember.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Python/structmember.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,7 +1,9 @@ /* Map C struct members to Python object attributes */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "../Objects/typeprivate.h" #include "structmember.h" diff -r a156f602debc Python/symtable.c --- a/Python/symtable.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Python/symtable.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,4 +1,6 @@ +#define PY_TYPEPRIVATE #include "Python.h" +#include "pytypeconvert.h" #include "Python-ast.h" #include "code.h" #include "symtable.h" @@ -33,7 +35,7 @@ k = PyLong_FromVoidPtr(key); if (k == NULL) goto fail; - ste = PyObject_New(PySTEntryObject, &PySTEntry_Type); + ste = PyObject_New(PySTEntryObject, PySTEntry_Type); if (ste == NULL) goto fail; ste->ste_table = st; @@ -121,8 +123,9 @@ {NULL} }; -PyTypeObject PySTEntry_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject *PySTEntry_Type; +PyTypeObject _PySTEntry_Type = { + PyVarObject_HEAD_INIT(NULL, 0) "symtable entry", sizeof(PySTEntryObject), 0, @@ -1677,3 +1680,8 @@ e->v.DictComp.key, e->v.DictComp.value); } + +int PySymtable_Init(void) { + CONVERT_TYPE(PySTEntry_Type, PyType_Type, NULL, "symbol table entry type"); + return 0; +} diff -r a156f602debc Python/sysmodule.c --- a/Python/sysmodule.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Python/sysmodule.c Tue Apr 28 19:26:52 2009 -0700 @@ -14,7 +14,9 @@ - ps1, ps2: optional primary and secondary prompts (strings) */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "../Objects/typeprivate.h" #include "structseq.h" #include "code.h" #include "frameobject.h" @@ -783,7 +785,7 @@ sys_call_tracing(PyObject *self, PyObject *args) { PyObject *func, *funcargs; - if (!PyArg_ParseTuple(args, "OO!:call_tracing", &func, &PyTuple_Type, &funcargs)) + if (!PyArg_ParseTuple(args, "OO!:call_tracing", &func, PyTuple_Type, &funcargs)) return NULL; return _PyEval_CallTracing(func, funcargs); } @@ -1159,7 +1161,7 @@ \n\ Flags provided through command line arguments or environment vars."); -static PyTypeObject FlagsType; +static PyTypeObject *FlagsType; static PyStructSequence_Field flags_fields[] = { {"debug", "-d"}, @@ -1198,7 +1200,7 @@ int pos = 0; PyObject *seq; - seq = PyStructSequence_New(&FlagsType); + seq = PyStructSequence_New(FlagsType); if (seq == NULL) return NULL; @@ -1234,7 +1236,7 @@ \n\ Version information as a named tuple."); -static PyTypeObject VersionInfoType; +static PyTypeObject *VersionInfoType = NULL; static PyStructSequence_Field version_info_fields[] = { {"major", "Major release number"}, @@ -1259,7 +1261,7 @@ char *s; int pos = 0; - version_info = PyStructSequence_New(&VersionInfoType); + version_info = PyStructSequence_New(VersionInfoType); if (version_info == NULL) { return NULL; } @@ -1414,20 +1416,20 @@ } /* version_info */ - if (VersionInfoType.tp_name == 0) - PyStructSequence_InitType(&VersionInfoType, &version_info_desc); + if (VersionInfoType == NULL) + VersionInfoType = PyStructSequence_InitType(&version_info_desc); SET_SYS_FROM_STRING("version_info", make_version_info()); /* prevent user from creating new instances */ - VersionInfoType.tp_init = NULL; - VersionInfoType.tp_new = NULL; + VersionInfoType->tp_init = NULL; + VersionInfoType->tp_new = NULL; /* flags */ - if (FlagsType.tp_name == 0) - PyStructSequence_InitType(&FlagsType, &flags_desc); + if (FlagsType == NULL) + FlagsType = PyStructSequence_InitType(&flags_desc); SET_SYS_FROM_STRING("flags", make_flags()); /* prevent user from creating new instances */ - FlagsType.tp_init = NULL; - FlagsType.tp_new = NULL; + FlagsType->tp_init = NULL; + FlagsType->tp_new = NULL; /* float repr style: 0.03 (short) vs 0.029999999999999999 (legacy) */ #ifndef PY_NO_SHORT_FLOAT_REPR diff -r a156f602debc Python/traceback.c --- a/Python/traceback.c Tue Apr 28 12:42:20 2009 -0700 +++ b/Python/traceback.c Tue Apr 28 19:26:52 2009 -0700 @@ -1,7 +1,9 @@ /* Traceback implementation */ +#define PY_TYPEPRIVATE #include "Python.h" +#include "pytypeconvert.h" #include "code.h" #include "frameobject.h" @@ -63,8 +65,9 @@ Py_CLEAR(tb->tb_frame); } -PyTypeObject PyTraceBack_Type = { - PyVarObject_HEAD_INIT(&PyType_Type, 0) +PyTypeObject *PyTraceBack_Type; +PyTypeObject _PyTraceBack_Type = { + PyVarObject_HEAD_INIT(NULL, 0) "traceback", sizeof(PyTracebackObject), 0, @@ -107,7 +110,7 @@ PyErr_BadInternalCall(); return NULL; } - tb = PyObject_GC_New(PyTracebackObject, &PyTraceBack_Type); + tb = PyObject_GC_New(PyTracebackObject, PyTraceBack_Type); if (tb != NULL) { Py_XINCREF(next); tb->tb_next = next; @@ -372,3 +375,9 @@ err = tb_printinternal((PyTracebackObject *)v, f, limit); return err; } + +int PyTraceBack_Init(void) { + CONVERT_TYPE(PyTraceBack_Type, PyType_Type, NULL, "traceback type"); + return 0; +} + diff -r a156f602debc Tools/framer/framer/template.py --- a/Tools/framer/framer/template.py Tue Apr 28 12:42:20 2009 -0700 +++ b/Tools/framer/framer/template.py Tue Apr 28 19:26:52 2009 -0700 @@ -86,7 +86,7 @@ return; """ -type_init_type = " %(CTypeName)s.ob_type = &PyType_Type;" +type_init_type = " %(CTypeName)s.ob_type = PyType_Type;" module_add_type = """\ if (!PyObject_SetAttrString(mod, "%(TypeName)s", (PyObject *)&%(CTypeName)s)) diff -r a156f602debc Tools/modulator/Templates/object_tail --- a/Tools/modulator/Templates/object_tail Tue Apr 28 12:42:20 2009 -0700 +++ b/Tools/modulator/Templates/object_tail Tue Apr 28 19:26:52 2009 -0700 @@ -4,7 +4,7 @@ ; static PyTypeObject $Abbrev$type = { - PyObject_HEAD_INIT(&PyType_Type) + PyObject_HEAD_INIT(PyType_Type) 0, /*ob_size*/ "$name$", /*tp_name*/ sizeof($abbrev$object), /*tp_basicsize*/