~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_groupcompress_pyx.pyx

  • Committer: John Arbash Meinel
  • Date: 2010-08-02 17:08:29 UTC
  • mto: This revision was merged to the branch mainline in revision 5369.
  • Revision ID: john@arbash-meinel.com-20100802170829-l0ti5v5rvcua32ia
Pyrex doesn't allow sizeof(class), so we have to unroll it manually.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
 
24
24
cdef extern from "Python.h":
 
25
    ctypedef struct PyObject:
 
26
        pass
25
27
    ctypedef int Py_ssize_t # Required for older pyrex versions
26
28
    int PyString_CheckExact(object)
27
29
    char * PyString_AS_STRING(object)
92
94
    cdef readonly object _sources
93
95
    cdef source_info *_source_infos
94
96
    cdef delta_index *_index
 
97
    cdef public unsigned long _source_offset
95
98
    cdef readonly unsigned int _max_num_sources
96
 
    cdef public unsigned long _source_offset
97
99
 
98
100
    def __init__(self, source=None):
99
101
        self._sources = []
109
111
    def __sizeof__(self):
110
112
        # We want to track the _source_infos allocations, but the referenced
111
113
        # void* are actually tracked in _sources itself.
112
 
        return (sizeof(DeltaIndex)
113
 
            + (sizeof(source_info) * self._max_num_sources)
114
 
            + sizeof_delta_index(self._index))
 
114
        # XXX: Cython is capable of doing sizeof(class) and returning the size
 
115
        #      of the underlying struct. Pyrex (<= 0.9.9) refuses, so we need
 
116
        #      to do it manually. *sigh* Note that we might get it wrong
 
117
        #      because of alignment issues.
 
118
        cdef Py_ssize_t size
 
119
        # PyObject start, vtable *, 3 object pointers, 2 C ints
 
120
        size = ((sizeof(PyObject) + sizeof(void*) + 3*sizeof(PyObject*)
 
121
                 + sizeof(unsigned long)
 
122
                 + sizeof(unsigned int))
 
123
                + (sizeof(source_info) * self._max_num_sources)
 
124
                + sizeof_delta_index(self._index))
 
125
        return size
115
126
 
116
127
    def __repr__(self):
117
128
        return '%s(%d, %d)' % (self.__class__.__name__,