~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_static_tuple_c.c

Add bzrlib.pyutils, which has get_named_object, a wrapper around __import__.

This is used to replace various ad hoc implementations of the same logic,
notably the version used in registry's _LazyObjectGetter which had a bug when
getting a module without also getting a member.  And of course, this new
function has unit tests, unlike the replaced code.

This also adds a KnownHooksRegistry subclass to provide a more natural home for
some other logic.

I'm not thrilled about the name of the new module or the new functions, but it's
hard to think of good names for such generic functionality.

Show diffs side-by-side

added added

removed removed

Lines of Context:
703
703
    return 0;
704
704
}
705
705
 
 
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
 
706
718
static char StaticTuple_doc[] =
707
719
    "C implementation of a StaticTuple structure."
708
720
    "\n This is used as StaticTuple(item1, item2, item3)"
722
734
     "Create a StaticTuple from a given sequence. This functions"
723
735
     " the same as the tuple() constructor."},
724
736
    {"__reduce__", (PyCFunction)StaticTuple_reduce, METH_NOARGS, StaticTuple_reduce_doc},
 
737
    {"__sizeof__",  (PyCFunction)StaticTuple_sizeof, METH_NOARGS}, 
725
738
    {NULL, NULL} /* sentinel */
726
739
};
727
740