~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_static_tuple_c.c

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-10-23 18:40:24 UTC
  • mfrom: (4759.2.20 statictuple-pickling)
  • Revision ID: pqm@pqm.ubuntu.com-20091023184024-igfxawbh4tkag0ui
(Matt Nordhoff) Add Pickle support to the StaticTuple class.

Show diffs side-by-side

added added

removed removed

Lines of Context:
304
304
    if (tuple_repr == NULL) {
305
305
        return NULL;
306
306
    }
307
 
    result = PyString_FromFormat("%s%s", Py_TYPE(self)->tp_name,
308
 
                                         PyString_AsString(tuple_repr));
 
307
    result = PyString_FromFormat("StaticTuple%s",
 
308
                                 PyString_AsString(tuple_repr));
309
309
    return result;
310
310
}
311
311
 
574
574
 
575
575
 
576
576
static PyObject *
 
577
StaticTuple_reduce(StaticTuple *self)
 
578
{
 
579
    PyObject *result = NULL, *as_tuple = NULL;
 
580
 
 
581
    result = PyTuple_New(2);
 
582
    if (!result) {
 
583
        return NULL;
 
584
    }
 
585
    as_tuple = StaticTuple_as_tuple(self);
 
586
    if (as_tuple == NULL) {
 
587
        Py_DECREF(result);
 
588
        return NULL;
 
589
    }
 
590
    Py_INCREF(&StaticTuple_Type);
 
591
    PyTuple_SET_ITEM(result, 0, (PyObject *)&StaticTuple_Type);
 
592
    PyTuple_SET_ITEM(result, 1, as_tuple);
 
593
    return result;
 
594
}
 
595
 
 
596
static char StaticTuple_reduce_doc[] = "__reduce__() => tuple\n";
 
597
 
 
598
 
 
599
static PyObject *
577
600
StaticTuple_add(PyObject *v, PyObject *w)
578
601
{
579
602
    Py_ssize_t i, len_v, len_w;
688
711
     METH_STATIC | METH_VARARGS,
689
712
     "Create a StaticTuple from a given sequence. This functions"
690
713
     " the same as the tuple() constructor."},
 
714
    {"__reduce__", (PyCFunction)StaticTuple_reduce, METH_NOARGS, StaticTuple_reduce_doc},
691
715
    {NULL, NULL} /* sentinel */
692
716
};
693
717
 
735
759
PyTypeObject StaticTuple_Type = {
736
760
    PyObject_HEAD_INIT(NULL)
737
761
    0,                                           /* ob_size */
738
 
    "StaticTuple",                               /* tp_name */
 
762
    "bzrlib._static_tuple_c.StaticTuple",        /* tp_name */
739
763
    sizeof(StaticTuple),                         /* tp_basicsize */
740
764
    sizeof(PyObject *),                          /* tp_itemsize */
741
765
    (destructor)StaticTuple_dealloc,             /* tp_dealloc */