~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_simple_set_pyx.pyx

(jelmer) Use the absolute_import feature everywhere in bzrlib,
 and add a source test to make sure it's used everywhere. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009 Canonical Ltd
 
1
# Copyright (C) 2009, 2010 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
115
115
            raise MemoryError()
116
116
        memset(self._table, 0, n_bytes)
117
117
 
 
118
    def __sizeof__(self):
 
119
        # Note: Pyrex doesn't allow sizeof(class) so we re-implement it here.
 
120
        # Bits are:
 
121
        #   1: PyObject
 
122
        #   2: vtable *
 
123
        #   3: 3 Py_ssize_t
 
124
        #   4: PyObject**
 
125
        # Note that we might get alignment, etc, wrong, but at least this is
 
126
        # better than no estimate at all
 
127
        # return sizeof(SimpleSet) + (self._mask + 1) * (sizeof(PyObject*))
 
128
        return (sizeof(PyObject) + sizeof(void*)
 
129
                + 3*sizeof(Py_ssize_t) + sizeof(PyObject**)
 
130
                + (self._mask + 1) * sizeof(PyObject*))
 
131
 
118
132
    def __dealloc__(self):
119
133
        if self._table != NULL:
120
134
            PyMem_Free(self._table)
540
554
    return _check_self(self)._used
541
555
 
542
556
 
543
 
cdef api int SimpleSet_Next(object self, Py_ssize_t *pos, PyObject **key):
 
557
cdef api int SimpleSet_Next(object self, Py_ssize_t *pos,
 
558
                            PyObject **key) except -1:
544
559
    """Walk over items in a SimpleSet.
545
560
 
546
561
    :param pos: should be initialized to 0 by the caller, and will be updated
567
582
    return 1
568
583
 
569
584
 
570
 
cdef int SimpleSet_traverse(SimpleSet self, visitproc visit, void *arg):
 
585
cdef int SimpleSet_traverse(SimpleSet self, visitproc visit,
 
586
                            void *arg) except -1:
571
587
    """This is an implementation of 'tp_traverse' that hits the whole table.
572
588
 
573
589
    Cython/Pyrex don't seem to let you define a tp_traverse, and they only