diff options
author | Guido van Rossum <guido@python.org> | 2006-08-17 05:42:55 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2006-08-17 05:42:55 (GMT) |
commit | 50e9fb9e2d6b4b12524116ab775ac6543e4a5332 (patch) | |
tree | 96f41e9a6d07a2754fcaceb7b54a7c11f112687f /Modules | |
parent | d033ddf4dc501e0920adec9e193750e515bbd128 (diff) | |
download | cpython-50e9fb9e2d6b4b12524116ab775ac6543e4a5332.zip cpython-50e9fb9e2d6b4b12524116ab775ac6543e4a5332.tar.gz cpython-50e9fb9e2d6b4b12524116ab775ac6543e4a5332.tar.bz2 |
Completely get rid of PyClass and PyInstance.
(classobject.[ch] aren't empty yet because they also define PyMethod.)
This breaks lots of stuff, notably cPickle. But it's a step in the right
direction. I'll clean it up later.
(Also a few unrelated changes, e.g. T_NONE to define a "struct member"
that is always None, and simplification of __hash__ -- these are unfinished.)
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_sre.c | 14 | ||||
-rw-r--r-- | Modules/arraymodule.c | 3 | ||||
-rw-r--r-- | Modules/cPickle.c | 219 | ||||
-rw-r--r-- | Modules/gcmodule.c | 31 |
4 files changed, 13 insertions, 254 deletions
diff --git a/Modules/_sre.c b/Modules/_sre.c index 68d511e..6f1e2b6 100644 --- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -3363,19 +3363,19 @@ static PyMethodDef _functions[] = { {NULL, NULL} }; -#if PY_VERSION_HEX < 0x02030000 -DL_EXPORT(void) init_sre(void) -#else PyMODINIT_FUNC init_sre(void) -#endif { PyObject* m; PyObject* d; PyObject* x; - /* Patch object types */ - Pattern_Type.ob_type = Match_Type.ob_type = - Scanner_Type.ob_type = &PyType_Type; + /* Initialize object types */ + if (PyType_Ready(&Pattern_Type) < 0) + return; + if (PyType_Ready(&Match_Type) < 0) + return; + if (PyType_Ready(&Scanner_Type) < 0) + return; m = Py_InitModule("_" SRE_MODULE, _functions); if (m == NULL) diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c index b739cc8..e44b8e1 100644 --- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -2112,7 +2112,8 @@ initarray(void) { PyObject *m; - Arraytype.ob_type = &PyType_Type; + if (PyType_Ready(&Arraytype) < 0) + return; PyArrayIter_Type.ob_type = &PyType_Type; m = Py_InitModule3("array", a_methods, module_doc); if (m == NULL) diff --git a/Modules/cPickle.c b/Modules/cPickle.c index 24c98cc..d6b4581 100644 --- a/Modules/cPickle.c +++ b/Modules/cPickle.c @@ -1786,148 +1786,6 @@ save_dict(Picklerobject *self, PyObject *args) } -static int -save_inst(Picklerobject *self, PyObject *args) -{ - PyObject *class = 0, *module = 0, *name = 0, *state = 0, - *getinitargs_func = 0, *getstate_func = 0, *class_args = 0; - char *module_str, *name_str; - int module_size, name_size, res = -1; - - static char inst = INST, obj = OBJ, build = BUILD; - - if (self->fast && !fast_save_enter(self, args)) - goto finally; - - if (self->write_func(self, &MARKv, 1) < 0) - goto finally; - - if (!( class = PyObject_GetAttr(args, __class___str))) - goto finally; - - if (self->bin) { - if (save(self, class, 0) < 0) - goto finally; - } - - if ((getinitargs_func = PyObject_GetAttr(args, __getinitargs___str))) { - PyObject *element = 0; - int i, len; - - if (!( class_args = - PyObject_Call(getinitargs_func, empty_tuple, NULL))) - goto finally; - - if ((len = PyObject_Size(class_args)) < 0) - goto finally; - - for (i = 0; i < len; i++) { - if (!( element = PySequence_GetItem(class_args, i))) - goto finally; - - if (save(self, element, 0) < 0) { - Py_DECREF(element); - goto finally; - } - - Py_DECREF(element); - } - } - else { - if (PyErr_ExceptionMatches(PyExc_AttributeError)) - PyErr_Clear(); - else - goto finally; - } - - if (!self->bin) { - if (!( name = ((PyClassObject *)class)->cl_name )) { - PyErr_SetString(PicklingError, "class has no name"); - goto finally; - } - - if (!( module = whichmodule(class, name))) - goto finally; - - - if ((module_size = PyString_Size(module)) < 0 || - (name_size = PyString_Size(name)) < 0) - goto finally; - - module_str = PyString_AS_STRING((PyStringObject *)module); - name_str = PyString_AS_STRING((PyStringObject *)name); - - if (self->write_func(self, &inst, 1) < 0) - goto finally; - - if (self->write_func(self, module_str, module_size) < 0) - goto finally; - - if (self->write_func(self, "\n", 1) < 0) - goto finally; - - if (self->write_func(self, name_str, name_size) < 0) - goto finally; - - if (self->write_func(self, "\n", 1) < 0) - goto finally; - } - else if (self->write_func(self, &obj, 1) < 0) { - goto finally; - } - - if ((getstate_func = PyObject_GetAttr(args, __getstate___str))) { - state = PyObject_Call(getstate_func, empty_tuple, NULL); - if (!state) - goto finally; - } - else { - if (PyErr_ExceptionMatches(PyExc_AttributeError)) - PyErr_Clear(); - else - goto finally; - - if (!( state = PyObject_GetAttr(args, __dict___str))) { - if (PyErr_ExceptionMatches(PyExc_AttributeError)) - PyErr_Clear(); - else - goto finally; - res = 0; - goto finally; - } - } - - if (!PyDict_Check(state)) { - if (put2(self, args) < 0) - goto finally; - } - else { - if (put(self, args) < 0) - goto finally; - } - - if (save(self, state, 0) < 0) - goto finally; - - if (self->write_func(self, &build, 1) < 0) - goto finally; - - res = 0; - - finally: - if (self->fast && !fast_save_leave(self, args)) - res = -1; - - Py_XDECREF(module); - Py_XDECREF(class); - Py_XDECREF(state); - Py_XDECREF(getinitargs_func); - Py_XDECREF(getstate_func); - Py_XDECREF(class_args); - - return res; -} - static int save_global(Picklerobject *self, PyObject *args, PyObject *name) @@ -2420,20 +2278,6 @@ save(Picklerobject *self, PyObject *args, int pers_save) } break; - case 'i': - if (type == &PyInstance_Type) { - res = save_inst(self, args); - goto finally; - } - break; - - case 'c': - if (type == &PyClass_Type) { - res = save_global(self, args, NULL); - goto finally; - } - break; - case 'f': if (type == &PyFunction_Type) { res = save_global(self, args, NULL); @@ -3594,57 +3438,6 @@ load_dict(Unpicklerobject *self) return 0; } -static PyObject * -Instance_New(PyObject *cls, PyObject *args) -{ - PyObject *r = 0; - - if (PyClass_Check(cls)) { - int l; - - if ((l=PyObject_Size(args)) < 0) goto err; - if (!( l )) { - PyObject *__getinitargs__; - - __getinitargs__ = PyObject_GetAttr(cls, - __getinitargs___str); - if (!__getinitargs__) { - /* We have a class with no __getinitargs__, - so bypass usual construction */ - PyObject *inst; - - PyErr_Clear(); - if (!( inst=PyInstance_NewRaw(cls, NULL))) - goto err; - return inst; - } - Py_DECREF(__getinitargs__); - } - - if ((r=PyInstance_New(cls, args, NULL))) return r; - else goto err; - } - - if ((r=PyObject_CallObject(cls, args))) return r; - - err: - { - PyObject *tp, *v, *tb, *tmp_value; - - PyErr_Fetch(&tp, &v, &tb); - tmp_value = v; - /* NULL occurs when there was a KeyboardInterrupt */ - if (tmp_value == NULL) - tmp_value = Py_None; - if ((r = PyTuple_Pack(3, tmp_value, cls, args))) { - Py_XDECREF(v); - v=r; - } - PyErr_Restore(tp,v,tb); - } - return NULL; -} - static int load_obj(Unpicklerobject *self) @@ -3655,10 +3448,6 @@ load_obj(Unpicklerobject *self) if ((i = marker(self)) < 0) return -1; if (!( tup=Pdata_popTuple(self->stack, i+1))) return -1; PDATA_POP(self->stack, class); - if (class) { - obj = Instance_New(class, tup); - Py_DECREF(class); - } Py_DECREF(tup); if (! obj) return -1; @@ -3694,8 +3483,8 @@ load_inst(Unpicklerobject *self) if (! class) return -1; if ((tup=Pdata_popTuple(self->stack, i))) { - obj = Instance_New(class, tup); - Py_DECREF(tup); + PyErr_SetString(UnpicklingError, "it's dead, Jim"); + return -1; } Py_DECREF(class); @@ -4388,10 +4177,6 @@ load_reduce(Unpicklerobject *self) PDATA_POP(self->stack, arg_tup); if (! arg_tup) return -1; PDATA_POP(self->stack, callable); - if (callable) { - ob = Instance_New(callable, arg_tup); - Py_DECREF(callable); - } Py_DECREF(arg_tup); if (! ob) return -1; diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c index 872727d..5c2f381 100644 --- a/Modules/gcmodule.c +++ b/Modules/gcmodule.c @@ -66,12 +66,10 @@ static PyObject *delstr = NULL; #define DEBUG_STATS (1<<0) /* print collection statistics */ #define DEBUG_COLLECTABLE (1<<1) /* print collectable objects */ #define DEBUG_UNCOLLECTABLE (1<<2) /* print uncollectable objects */ -#define DEBUG_INSTANCES (1<<3) /* print instances */ #define DEBUG_OBJECTS (1<<4) /* print other objects */ #define DEBUG_SAVEALL (1<<5) /* save all garbage in gc.garbage */ #define DEBUG_LEAK DEBUG_COLLECTABLE | \ DEBUG_UNCOLLECTABLE | \ - DEBUG_INSTANCES | \ DEBUG_OBJECTS | \ DEBUG_SAVEALL static int debug; @@ -410,13 +408,7 @@ move_unreachable(PyGC_Head *young, PyGC_Head *unreachable) static int has_finalizer(PyObject *op) { - if (PyInstance_Check(op)) { - assert(delstr != NULL); - return _PyInstance_Lookup(op, delstr) != NULL; - } - else if (PyType_HasFeature(op->ob_type, Py_TPFLAGS_HEAPTYPE)) - return op->ob_type->tp_del != NULL; - else if (PyGen_CheckExact(op)) + if (PyGen_CheckExact(op)) return PyGen_NeedsFinalizing((PyGenObject *)op); else return 0; @@ -633,26 +625,9 @@ handle_weakrefs(PyGC_Head *unreachable, PyGC_Head *old) } static void -debug_instance(char *msg, PyInstanceObject *inst) -{ - char *cname; - /* simple version of instance_repr */ - PyObject *classname = inst->in_class->cl_name; - if (classname != NULL && PyString_Check(classname)) - cname = PyString_AsString(classname); - else - cname = "?"; - PySys_WriteStderr("gc: %.100s <%.100s instance at %p>\n", - msg, cname, inst); -} - -static void debug_cycle(char *msg, PyObject *op) { - if ((debug & DEBUG_INSTANCES) && PyInstance_Check(op)) { - debug_instance(msg, (PyInstanceObject *)op); - } - else if (debug & DEBUG_OBJECTS) { + if (debug & DEBUG_OBJECTS) { PySys_WriteStderr("gc: %.100s <%.100s %p>\n", msg, op->ob_type->tp_name, op); } @@ -983,7 +958,6 @@ PyDoc_STRVAR(gc_set_debug__doc__, " DEBUG_STATS - Print statistics during collection.\n" " DEBUG_COLLECTABLE - Print collectable objects found.\n" " DEBUG_UNCOLLECTABLE - Print unreachable but uncollectable objects found.\n" -" DEBUG_INSTANCES - Print instance objects.\n" " DEBUG_OBJECTS - Print objects other than instances.\n" " DEBUG_SAVEALL - Save objects to gc.garbage rather than freeing them.\n" " DEBUG_LEAK - Debug leaking programs (everything but STATS).\n"); @@ -1244,7 +1218,6 @@ initgc(void) ADD_INT(DEBUG_STATS); ADD_INT(DEBUG_COLLECTABLE); ADD_INT(DEBUG_UNCOLLECTABLE); - ADD_INT(DEBUG_INSTANCES); ADD_INT(DEBUG_OBJECTS); ADD_INT(DEBUG_SAVEALL); ADD_INT(DEBUG_LEAK); |