1547
1546
/* proto > 0: write in batches of BATCHSIZE. */
1549
/* Get next group of (no more than) BATCHSIZE elements. */
1550
for (n = 0; n < BATCHSIZE; ++n) {
1548
/* Get first item */
1549
firstitem = PyIter_Next(iter);
1550
if (firstitem == NULL) {
1551
if (PyErr_Occurred())
1554
/* nothing more to add */
1558
/* Try to get a second item */
1559
obj = PyIter_Next(iter);
1561
if (PyErr_Occurred())
1564
/* Only one item to write */
1565
if (save(self, firstitem, 0) < 0)
1567
if (self->write_func(self, &append, 1) < 0)
1569
Py_CLEAR(firstitem);
1573
/* More than one item to write */
1575
/* Pump out MARK, items, APPENDS. */
1576
if (self->write_func(self, &MARKv, 1) < 0)
1579
if (save(self, firstitem, 0) < 0)
1581
Py_CLEAR(firstitem);
1584
/* Fetch and save up to BATCHSIZE items */
1586
if (save(self, obj, 0) < 0)
1551
1594
obj = PyIter_Next(iter);
1552
1595
if (obj == NULL) {
1553
1596
if (PyErr_Occurred())
1554
1597
goto BatchFailed;
1561
/* Pump out MARK, slice[0:n], APPENDS. */
1562
if (self->write_func(self, &MARKv, 1) < 0)
1564
for (i = 0; i < n; ++i) {
1565
if (save(self, slice[i], 0) < 0)
1568
if (self->write_func(self, &appends, 1) < 0)
1572
if (save(self, slice[0], 0) < 0)
1574
if (self->write_func(self, &append, 1) < 0)
1578
for (i = 0; i < n; ++i) {
1579
Py_DECREF(slice[i]);
1602
if (self->write_func(self, &appends, 1) < 0)
1581
1605
} while (n == BATCHSIZE);
1586
Py_DECREF(slice[n]);
1609
Py_XDECREF(firstitem);
1693
1721
/* proto > 0: write in batches of BATCHSIZE. */
1695
/* Get next group of (no more than) BATCHSIZE elements. */
1696
for (n = 0; n < BATCHSIZE; ++n) {
1697
p = PyIter_Next(iter);
1699
if (PyErr_Occurred())
1723
/* Get first item */
1724
firstitem = PyIter_Next(iter);
1725
if (firstitem == NULL) {
1726
if (PyErr_Occurred())
1729
/* nothing more to add */
1732
if (!PyTuple_Check(firstitem) || PyTuple_Size(firstitem) != 2) {
1733
PyErr_SetString(PyExc_TypeError, "dict items "
1734
"iterator must return 2-tuples");
1738
/* Try to get a second item */
1739
p = PyIter_Next(iter);
1741
if (PyErr_Occurred())
1744
/* Only one item to write */
1745
if (save(self, PyTuple_GET_ITEM(firstitem, 0), 0) < 0)
1747
if (save(self, PyTuple_GET_ITEM(firstitem, 1), 0) < 0)
1749
if (self->write_func(self, &setitem, 1) < 0)
1751
Py_CLEAR(firstitem);
1755
/* More than one item to write */
1757
/* Pump out MARK, items, SETITEMS. */
1758
if (self->write_func(self, &MARKv, 1) < 0)
1761
if (save(self, PyTuple_GET_ITEM(firstitem, 0), 0) < 0)
1763
if (save(self, PyTuple_GET_ITEM(firstitem, 1), 0) < 0)
1765
Py_CLEAR(firstitem);
1768
/* Fetch and save up to BATCHSIZE items */
1703
1770
if (!PyTuple_Check(p) || PyTuple_Size(p) != 2) {
1704
1771
PyErr_SetString(PyExc_TypeError, "dict items "
1705
1772
"iterator must return 2-tuples");
1706
1773
goto BatchFailed;
1712
/* Pump out MARK, slice[0:n], SETITEMS. */
1713
if (self->write_func(self, &MARKv, 1) < 0)
1715
for (i = 0; i < n; ++i) {
1717
if (save(self, PyTuple_GET_ITEM(p, 0), 0) < 0)
1719
if (save(self, PyTuple_GET_ITEM(p, 1), 0) < 0)
1722
if (self->write_func(self, &setitems, 1) < 0)
1727
1775
if (save(self, PyTuple_GET_ITEM(p, 0), 0) < 0)
1728
1776
goto BatchFailed;
1729
1777
if (save(self, PyTuple_GET_ITEM(p, 1), 0) < 0)
1730
1778
goto BatchFailed;
1731
if (self->write_func(self, &setitem, 1) < 0)
1735
for (i = 0; i < n; ++i) {
1736
Py_DECREF(slice[i]);
1785
p = PyIter_Next(iter);
1787
if (PyErr_Occurred())
1793
if (self->write_func(self, &setitems, 1) < 0)
1738
1796
} while (n == BATCHSIZE);
1743
Py_DECREF(slice[n]);
1800
Py_XDECREF(firstitem);
2309
if (self->nesting++ > Py_GetRecursionLimit()){
2310
PyErr_SetString(PyExc_RuntimeError,
2311
"maximum recursion depth exceeded");
2370
if (Py_EnterRecursiveCall(" while pickling an object"))
2315
2373
if (!pers_save && self->pers_func) {
2316
2374
if ((tmp = save_pers(self, args, self->pers_func)) != 0) {
3435
3494
if (self->read_func(self, &s, 4) < 0) return -1;
3437
3496
l = calc_binint(s, 4);
3498
/* Corrupt or hostile pickle -- we never write one like
3501
PyErr_SetString(UnpicklingError,
3502
"BINSTRING pickle has negative byte count");
3439
3506
if (self->read_func(self, &s, l) < 0)
3502
3569
if (self->read_func(self, &s, 4) < 0) return -1;
3504
3571
l = calc_binint(s, 4);
3573
/* Corrupt or hostile pickle -- we never write one like
3576
PyErr_SetString(UnpicklingError,
3577
"BINUNICODE pickle has negative byte count");
3506
3581
if (self->read_func(self, &s, l) < 0)