~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: 2010-02-11 04:02:41 UTC
  • mfrom: (5017.2.2 tariff)
  • Revision ID: pqm@pqm.ubuntu.com-20100211040241-w6n021dz0uus341n
(mbp) add import-tariff tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2009, 2010 Canonical Ltd
 
1
/* Copyright (C) 2009 Canonical Ltd
2
2
 * 
3
3
 * This program is free software; you can redistribute it and/or modify
4
4
 * it under the terms of the GNU General Public License as published by
140
140
StaticTuple_New(Py_ssize_t size)
141
141
{
142
142
    StaticTuple *stuple;
 
143
    if (size < 0) {
 
144
        PyErr_BadInternalCall();
 
145
        return NULL;
 
146
    }
143
147
 
144
148
    if (size < 0 || size > 255) {
145
149
        /* Too big or too small */
276
280
        return NULL;
277
281
    }
278
282
    len = PyTuple_GET_SIZE(args);
279
 
    if (len < 0 || len > 255) {
280
 
        /* Check the length here so we can raise a TypeError instead of
281
 
         * StaticTuple_New's ValueError.
282
 
         */
283
 
        PyErr_SetString(PyExc_TypeError, "StaticTuple(...)"
284
 
            " takes from 0 to 255 items");
285
 
        return NULL;
286
 
    }
287
283
    self = (StaticTuple *)StaticTuple_New(len);
288
284
    if (self == NULL) {
289
285
        return NULL;
703
699
    return 0;
704
700
}
705
701
 
706
 
 
707
 
static PyObject *
708
 
StaticTuple_sizeof(StaticTuple *self)
709
 
{
710
 
        Py_ssize_t res;
711
 
 
712
 
        res = _PyObject_SIZE(&StaticTuple_Type) + (int)self->size * sizeof(void*);
713
 
        return PyInt_FromSsize_t(res);
714
 
}
715
 
 
716
 
 
717
 
 
718
702
static char StaticTuple_doc[] =
719
703
    "C implementation of a StaticTuple structure."
720
704
    "\n This is used as StaticTuple(item1, item2, item3)"
734
718
     "Create a StaticTuple from a given sequence. This functions"
735
719
     " the same as the tuple() constructor."},
736
720
    {"__reduce__", (PyCFunction)StaticTuple_reduce, METH_NOARGS, StaticTuple_reduce_doc},
737
 
    {"__sizeof__",  (PyCFunction)StaticTuple_sizeof, METH_NOARGS}, 
738
721
    {NULL, NULL} /* sentinel */
739
722
};
740
723