? stackless2.3_iterators.patch ? Lib/distutils/__init__.pyc ? Lib/distutils/archive_util.pyc ? Lib/distutils/ccompiler.pyc ? Lib/distutils/cmd.pyc ? Lib/distutils/core.pyc ? Lib/distutils/debug.pyc ? Lib/distutils/dep_util.pyc ? Lib/distutils/dir_util.pyc ? Lib/distutils/dist.pyc ? Lib/distutils/errors.pyc ? Lib/distutils/extension.pyc ? Lib/distutils/fancy_getopt.pyc ? Lib/distutils/file_util.pyc ? Lib/distutils/log.pyc ? Lib/distutils/spawn.pyc ? Lib/distutils/sysconfig.pyc ? Lib/distutils/text_file.pyc ? Lib/distutils/unixccompiler.pyc ? Lib/distutils/util.pyc ? Lib/distutils/command/__init__.pyc ? Lib/distutils/command/build.pyc ? Lib/distutils/command/build_ext.pyc ? Lib/distutils/command/build_scripts.pyc ? Lib/distutils/command/install.pyc ? Lib/distutils/command/install_lib.pyc ? Lib/distutils/command/install_scripts.pyc ? Lib/encodings/__init__.pyc ? Lib/encodings/aliases.pyc ? Lib/encodings/ascii.pyc ? Lib/encodings/string_escape.pyc ? Objects/.rangeobject.c.swp ? Stackless/.prickelpit.c.swp ? Stackless/.prickelpit.h.swp ? Stackless/test/.gdb_history Index: Stackless/prickelpit.c =================================================================== RCS file: /home/cvs/slpdev/src/2.3/src/Stackless/prickelpit.c,v retrieving revision 1.36 diff -u -r1.36 prickelpit.c --- Stackless/prickelpit.c 14 Jan 2004 18:48:33 -0000 1.36 +++ Stackless/prickelpit.c 25 Jan 2004 17:24:51 -0000 @@ -205,7 +205,7 @@ char msg[500]; PyErr_Clear(); sprintf(msg, "frame exec function at %08x is not registered!", - (void *)f->f_execute); + (unsigned int)(void *)f->f_execute); PyErr_SetString(PyExc_ValueError, msg); valid = 0; } @@ -1206,6 +1206,329 @@ return init_type(PyGenerator_Type, generator_methods, generator_new); } +/****************************************************** + + pickling of dictiter + + ******************************************************/ + +/* + * unfortunately we have to copy here. + * XXX automate checking such situations. + */ + +typedef struct { + PyObject_HEAD + PyDictObject *di_dict; /* Set to NULL when iterator is exhausted */ + int di_used; + int di_pos; + binaryfunc di_select; +} dictiterobject; +/* + binaryfunc is a big problem. we don't have access to the + function pointers, so what we have to do is exhaust the + dictionary iterator by copying it. + + when we unpickle, we return an entirely different kind of object. +*/ + +static PyObject * +dictiter_reduce(dictiterobject *di) +{ + PyObject *tup, *list, *key, *value, *res; + int i; + + /* Make a list big enough to exhaust the dict */ + list = PyList_New(0); + if (list == NULL) + return PyErr_NoMemory(); + + /* is this dictiter is already exhausted? */ + if (di->di_dict != NULL) { + if (di->di_used != di->di_dict->ma_used) { + PyErr_SetString(PyExc_RuntimeError, + "dictionary changed size during iteration"); + di->di_used = -1; /* Make this state sticky */ + return NULL; + } + i = di->di_pos; + while (PyDict_Next((PyObject *)di->di_dict, &i, &key, &value)) { + res = (*di->di_select)(key, value); + if (res == NULL) { + Py_DECREF(list); + return NULL; + } + if (PyList_Append(list, res) == -1) { + return NULL; + } + } + } + /* masquerade as a PySeqIter */ + tup = Py_BuildValue("(O(lO))", + &PySeqIter_Type, + 0, + list + ); + Py_DECREF(list); + return tup; +} + + +static struct PyMethodDef dictiter_methods[] = { + {"__reduce__", (PyCFunction)dictiter_reduce, METH_NOARGS, + "di.__reduce__() -- reduce dictionary-iterator for pickling"}, + {NULL, NULL} /* Sentinel */ +}; + +static int init_dictitertype(void) +{ + PyTypeObject *t; + PyObject *dct, *iter; + int rval; + dct = PyDict_New(); + if (dct == NULL) + return -1; + iter = PyObject_GetIter(dct); + Py_DECREF(dct); + if (iter == NULL) + return -1; + t = (PyTypeObject *)PyObject_Type(iter); + Py_DECREF(iter); + if (t == NULL) + return -1; + rval = init_type(t, dictiter_methods, NULL); + Py_DECREF(t); + return rval; +} + + +/****************************************************** + + pickling of listiter + + ******************************************************/ + +/* + * unfortunately we have to copy here. + * XXX automate checking such situations. + */ + +typedef struct { + PyObject_HEAD + long it_index; + PyListObject *it_seq; /* Set to NULL when iterator is exhausted */ +} listiterobject; + +static PyObject * +listiter_reduce(listiterobject *it) +{ + PyObject *tup, *list; + + /* it's finished or exhausted */ + if (it->it_seq == NULL || it->it_index >= PyList_GET_SIZE(it->it_seq)) { + list = PyList_New(0); + if (list == NULL) + return PyErr_NoMemory(); + } else { + list = PyList_GetSlice( + (PyObject *)it->it_seq, + it->it_index, + PyList_Size((PyObject *)it->it_seq)); + } + /* masquerade as a PySeqIter */ + tup = Py_BuildValue("(O(lO))", + &PySeqIter_Type, + 0, + list + ); + Py_DECREF(list); + return tup; +} + + +static struct PyMethodDef listiter_methods[] = { + {"__reduce__", (PyCFunction)listiter_reduce, METH_NOARGS, + "it.__reduce__() -- reduce listiterator for pickling"}, + {NULL, NULL} /* Sentinel */ +}; + +static int init_listitertype(void) +{ + PyTypeObject *t; + PyObject *lst, *iter; + int rval; + lst = PyList_New(0); + if (lst == NULL) + return -1; + iter = PyObject_GetIter(lst); + Py_DECREF(lst); + if (iter == NULL) + return -1; + t = (PyTypeObject *)PyObject_Type(iter); + Py_DECREF(iter); + if (t == NULL) + return -1; + rval = init_type(t, listiter_methods, NULL); + Py_DECREF(t); + return rval; +} + +/****************************************************** + + pickling of rangeiter + + ******************************************************/ + +/* + * unfortunately we have to copy here. + * XXX automate checking such situations. + */ + +typedef struct { + PyObject_HEAD + long index; + long start; + long step; + long len; +} rangeiterobject; + +static PyObject * +rangeiter_reduce(rangeiterobject *it) +{ + PyObject *tup, *typ; + + typ = PyObject_Type((PyObject *)it); + /* masquerade as a PySeqIter */ + tup = Py_BuildValue("(O(llll))", + typ, + it->index, + it->start, + it->step, + it->len + ); + Py_DECREF(typ); + return tup; +} + +static +PyObject * +rangeiter_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + rangeiterobject *it; + if (kwds != NULL) { + PyErr_SetString(PyExc_ValueError, "Keyword parameters not supported for rangeiter_new"); + return NULL; + } + it = PyObject_New(rangeiterobject, type); + if (it == NULL) + return NULL; + if (!PyArg_ParseTuple(args, "iiii:rangeiterator", + &it->index, + &it->start, + &it->step, + &it->len)) + return NULL; + return (PyObject *)it; +} + +static struct PyMethodDef rangeiter_methods[] = { + {"__reduce__", (PyCFunction)rangeiter_reduce, METH_NOARGS, + "it.__reduce__() -- reduce rangeiterator for pickling"}, + {NULL, NULL} /* Sentinel */ +}; + +static int init_rangeitertype(void) +{ + PyTypeObject *t; + PyObject *xrange, *iter; + int rval; + xrange = PyRange_New(0,0,1,1); + if (xrange == NULL) + return -1; + iter = PyObject_GetIter(xrange); + Py_DECREF(xrange); + if (iter == NULL) + return -1; + t = (PyTypeObject *)PyObject_Type(iter); + Py_DECREF(iter); + if (t == NULL) + return -1; + rval = init_type(t, rangeiter_methods, rangeiter_new); + Py_DECREF(t); + return rval; +} + +/****************************************************** + + pickling of tupleiter + + ******************************************************/ + +/* + * unfortunately we have to copy here. + * XXX automate checking such situations. + */ + +typedef struct { + PyObject_HEAD + long it_index; + PyListObject *it_seq; /* Set to NULL when iterator is exhausted */ +} tupleiterobject; + +static PyObject * +tupleiter_reduce(tupleiterobject *it) +{ + PyObject *tup, *tuple; + + /* it's finished or exhausted */ + if (it->it_seq == NULL || it->it_index >= PyTuple_GET_SIZE(it->it_seq)) { + tuple = PyTuple_New(0); + if (tuple == NULL) + return PyErr_NoMemory(); + } else { + tuple = PyTuple_GetSlice( + (PyObject *)it->it_seq, + it->it_index, + PyList_Size((PyObject *)it->it_seq)); + } + /* masquerade as a PySeqIter */ + tup = Py_BuildValue("(O(lO))", + &PySeqIter_Type, + 0, + tuple + ); + Py_DECREF(tuple); + return tup; +} + + +static struct PyMethodDef tupleiter_methods[] = { + {"__reduce__", (PyCFunction)tupleiter_reduce, METH_NOARGS, + "it.__reduce__() -- reduce tupleiterator for pickling"}, + {NULL, NULL} /* Sentinel */ +}; + +static int init_tupleitertype(void) +{ + PyTypeObject *t; + PyObject *tup, *iter; + int rval; + tup = PyTuple_New(0); + if (tup == NULL) + return -1; + iter = PyObject_GetIter(tup); + Py_DECREF(tup); + if (iter == NULL) + return -1; + t = (PyTypeObject *)PyObject_Type(iter); + Py_DECREF(iter); + if (t == NULL) + return -1; + rval = init_type(t, tupleiter_methods, NULL); + Py_DECREF(t); + return rval; +} + /****************************************************** @@ -1227,6 +1550,10 @@ || init_methtype() || init_methodtype() || init_generatortype() + || init_dictitertype() + || init_listitertype() + || init_rangeitertype() + || init_tupleitertype() ) return -1; return 0; }