Skip to content

Commit

Permalink
merge 3.4-slp (Stackless #127, use C-Python pickling)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anselm Kruis committed Apr 14, 2017
2 parents 785c16c + 43b9010 commit 1a49b66
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 110 deletions.
10 changes: 7 additions & 3 deletions Stackless/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ What's New in Stackless 3.X.X?
*Release date: 20XX-XX-XX*

- https://bitbucket.org/stackless-dev/stackless/issues/127
Fix pickling of 'callable-iterator' and 'method-wrapper' objects.
Fix copy.copy() for 'callable-iterator', 'method', 'dict_keys', 'dict_values'
and 'dict_items' objects.
Disable the Stackless specific code for pickling 'iterator' and
'callable_iterator' objects. C-Python 3.3 already pickles them. Stackless-3.5
can't read pickles of 'iterator' or 'callable_iterator' objects created with
Stackless 3.4.2 or older versions.
Fix pickling of 'method-wrapper' objects.
Fix copy.copy() for 'method', 'dict_keys', 'dict_values' and 'dict_items'
objects.

- https://bitbucket.org/stackless-dev/stackless/issues/126
Load the module stackless early in all C-Python tests. This ensures a defined
Expand Down
99 changes: 0 additions & 99 deletions Stackless/pickling/prickelpit.c
Original file line number Diff line number Diff line change
Expand Up @@ -1427,105 +1427,6 @@ static int init_moduletype(void)
#define initchain init_moduletype


/******************************************************
pickling of iterators
******************************************************/

/* XXX make sure this copy is always up to date */
typedef struct {
PyObject_HEAD
long it_index;
PyObject *it_seq;
} seqiterobject;

static PyTypeObject wrap_PySeqIter_Type;

static PyObject *
iter_reduce(seqiterobject *iterator)
{
PyObject *tup;
tup = Py_BuildValue("(O(Ol)())",
&wrap_PySeqIter_Type,
iterator->it_seq,
iterator->it_index);
return tup;
}

static PyObject *
iter_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
PyObject *iter, *seq;
long index;

if (is_wrong_type(type)) return NULL;
if (!PyArg_ParseTuple(args, "Ol:iter", &seq, &index)) return NULL;
iter = PySeqIter_New(seq);
if (iter != NULL) {
((seqiterobject *) iter)->it_index = index;
iter->ob_type = type;
}
return iter;
}

MAKE_WRAPPERTYPE(PySeqIter_Type, iter, "iterator", iter_reduce, iter_new,
generic_setstate)

/* XXX make sure this copy is always up to date */
typedef struct {
PyObject_HEAD
PyObject *it_callable; /* Set to NULL when iterator is exhausted */
PyObject *it_sentinel; /* Set to NULL when iterator is exhausted */
} calliterobject;

static PyTypeObject wrap_PyCallIter_Type;
static PyObject *
calliter_reduce(calliterobject *iterator)
{
PyObject *tup;
tup = Py_BuildValue("(O(OO)" NO_STATE_FORMAT ")",
&wrap_PyCallIter_Type,
iterator->it_callable ? iterator->it_callable : Py_None,
iterator->it_sentinel ? iterator->it_sentinel : Py_None
NO_STATE_ARG);
return tup;
}

static
PyObject *
calliter_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
calliterobject *it;
PyObject *it_callable;
PyObject *it_sentinel;

if (is_wrong_type(type)) return NULL;
if (!PyArg_ParseTuple(args, "OO:calliter", &it_callable,
&it_sentinel))
return NULL;

if (it_callable == Py_None) it_callable = NULL;
if (it_sentinel == Py_None) it_sentinel = NULL;

it = (calliterobject *) PyCallIter_New(it_callable, it_sentinel);
if (it != NULL)
Py_TYPE(it) = type;
return (PyObject *) it;
}

MAKE_WRAPPERTYPE(PyCallIter_Type, calliter, "callable_iterator",
calliter_reduce, calliter_new, generic_setstate)

static int init_itertype(void)
{
return init_type(&wrap_PySeqIter_Type, NULL)
|| init_type(&wrap_PyCallIter_Type, initchain);
}
#undef initchain
#define initchain init_itertype


/******************************************************
pickling of class/instance methods (PyMethod)
Expand Down
8 changes: 0 additions & 8 deletions Stackless/unittests/test_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,14 +690,6 @@ def test_module(self):
import tabnanny as obj
self._test(obj, '__name__', '__dict__')

def test_iterator(self):
obj = iter("abc")
self._test(obj)

def test_callable_iterator(self):
obj = iter(lambda: None, None)
self._test(obj)

def test_method(self):
obj = self.id
self._test(obj, '__func__', '__self__')
Expand Down

0 comments on commit 1a49b66

Please sign in to comment.