~ubuntu-branches/ubuntu/oneiric/python2.5/oneiric

« back to all changes in this revision

Viewing changes to Modules/cPickle.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2008-12-21 08:57:49 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20081221085749-bijjr25h8na5jdsu
Tags: 2.5.3-0ubuntu1
* New upstream version.
* Regenerate the included documentation.
* Add an option --install-layout=deb, which is ignored for 2.5.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2141
2141
 * appropriate __reduce__ method for ob.
2142
2142
 */
2143
2143
static int
2144
 
save_reduce(Picklerobject *self, PyObject *args, PyObject *ob)
 
2144
save_reduce(Picklerobject *self, PyObject *args, PyObject *fn, PyObject *ob)
2145
2145
{
2146
2146
        PyObject *callable;
2147
2147
        PyObject *argtup;
2148
 
        PyObject *state = NULL;
2149
 
        PyObject *listitems = NULL;
2150
 
        PyObject *dictitems = NULL;
 
2148
        PyObject *state = NULL;
 
2149
        PyObject *listitems = Py_None;
 
2150
        PyObject *dictitems = Py_None;
 
2151
        Py_ssize_t size;
2151
2152
 
2152
2153
        int use_newobj = self->proto >= 2;
2153
2154
 
2155
2156
        static char build = BUILD;
2156
2157
        static char newobj = NEWOBJ;
2157
2158
 
 
2159
        size = PyTuple_Size(args);
 
2160
        if (size < 2 || size > 5) {
 
2161
                cPickle_ErrFormat(PicklingError, "tuple returned by "
 
2162
                        "%s must contain 2 through 5 elements",
 
2163
                        "O", fn);
 
2164
                return -1;
 
2165
        }
 
2166
 
2158
2167
        if (! PyArg_UnpackTuple(args, "save_reduce", 2, 5,
2159
2168
                                &callable,
2160
2169
                                &argtup,
2164
2173
                return -1;
2165
2174
 
2166
2175
        if (!PyTuple_Check(argtup)) {
2167
 
                PyErr_SetString(PicklingError,
2168
 
                                "args from reduce() should be a tuple");
 
2176
                cPickle_ErrFormat(PicklingError, "Second element of "
 
2177
                        "tuple returned by %s must be a tuple",
 
2178
                        "O", fn);
2169
2179
                return -1;
2170
2180
        }
2171
2181
 
2172
2182
        if (state == Py_None)
2173
2183
                state = NULL;
 
2184
 
2174
2185
        if (listitems == Py_None)
2175
2186
                listitems = NULL;
 
2187
        else if (!PyIter_Check(listitems)) {
 
2188
                cPickle_ErrFormat(PicklingError, "Fourth element of "
 
2189
                        "tuple returned by %s must be an iterator, not %s",
 
2190
                        "Os", fn, listitems->ob_type->tp_name);
 
2191
                return -1;
 
2192
        }
 
2193
 
2176
2194
        if (dictitems == Py_None)
2177
2195
                dictitems = NULL;
 
2196
        else if (!PyIter_Check(dictitems)) {
 
2197
                cPickle_ErrFormat(PicklingError, "Fifth element of "
 
2198
                        "tuple returned by %s must be an iterator, not %s",
 
2199
                        "Os", fn, dictitems->ob_type->tp_name);
 
2200
                return -1;
 
2201
        }
2178
2202
 
2179
2203
        /* Protocol 2 special case: if callable's name is __newobj__, use
2180
2204
         * NEWOBJ.  This consumes a lot of code.
2298
2322
{
2299
2323
        PyTypeObject *type;
2300
2324
        PyObject *py_ob_id = 0, *__reduce__ = 0, *t = 0;
2301
 
        PyObject *arg_tup;
2302
2325
        int res = -1;
2303
 
        int tmp, size;
 
2326
        int tmp;
2304
2327
 
2305
2328
        if (self->nesting++ > Py_GetRecursionLimit()){
2306
2329
                PyErr_SetString(PyExc_RuntimeError,
2527
2550
                goto finally;
2528
2551
        }
2529
2552
 
2530
 
        if (! PyTuple_Check(t)) {
 
2553
        if (!PyTuple_Check(t)) {
2531
2554
                cPickle_ErrFormat(PicklingError, "Value returned by "
2532
2555
                                "%s must be string or tuple",
2533
2556
                                "O", __reduce__);
2534
2557
                goto finally;
2535
2558
        }
2536
2559
 
2537
 
        size = PyTuple_Size(t);
2538
 
        if (size < 2 || size > 5) {
2539
 
                cPickle_ErrFormat(PicklingError, "tuple returned by "
2540
 
                        "%s must contain 2 through 5 elements",
2541
 
                        "O", __reduce__);
2542
 
                goto finally;
2543
 
        }
2544
 
 
2545
 
        arg_tup = PyTuple_GET_ITEM(t, 1);
2546
 
        if (!(PyTuple_Check(arg_tup) || arg_tup == Py_None))  {
2547
 
                cPickle_ErrFormat(PicklingError, "Second element of "
2548
 
                        "tuple returned by %s must be a tuple",
2549
 
                        "O", __reduce__);
2550
 
                goto finally;
2551
 
        }
2552
 
 
2553
 
        res = save_reduce(self, t, args);
 
2560
        res = save_reduce(self, t, __reduce__, args);
2554
2561
 
2555
2562
  finally:
2556
2563
        self->nesting--;