Author: ArcRiley Date: 2008-03-04 16:02:50 -0500 (Tue, 04 Mar 2008) New Revision: 1030
Modified: trunk/pysoy/src/_internals/Children.pxi trunk/pysoy/src/_internals/soy._internals.pxd Log: Ticket #901 : * Start of major API change for Children ''' THIS CHANGESET BREAKS EVERYTHING ''' Modified: trunk/pysoy/src/_internals/Children.pxi =================================================================== --- trunk/pysoy/src/_internals/Children.pxi 2008-03-04 20:20:25 UTC (rev 1029) +++ trunk/pysoy/src/_internals/Children.pxi 2008-03-04 21:02:50 UTC (rev 1030) @@ -29,85 +29,90 @@ ''' def __cinit__(self) : - self.size = 1 - self.current = 0 - self.list = <void **>py.PyMem_Malloc(sizeof(void *)) - self.mutex = py.PyThread_allocate_lock() + self._size = 1 + self._current = 0 + self._list = <void **>py.PyMem_Malloc(sizeof(void *)) + self._mutex = py.PyThread_allocate_lock() - cdef void lock(self) : - py.PyThread_acquire_lock(self.mutex,1) + def __dealloc__(self) : + py.PyMem_Free(self._list) + py.PyThread_free_lock(self._mutex) - cdef int trylock(self) : - return py.PyThread_acquire_lock(self.mutex,0) + cdef void _lock(self) : + py.PyThread_acquire_lock(self._mutex, 1) - cdef void unlock(self) : - py.PyThread_release_lock(self.mutex) + cdef int _trylock(self) : + return py.PyThread_acquire_lock(self._mutex, 0) - cdef void append(self, void *child) : - if self.size == self.current : - self.size = self.size * 2 - self.list = <void **>py.PyMem_Realloc(self.list, - sizeof(void *)*(self.size)) - self.list[self.current] = <void *>child - self.current = self.current + 1 + cdef void _unlock(self) : + py.PyThread_release_lock(self._mutex) - cdef int index(self, void *child) : - cdef int i - for i from 0 <= i < self.current : - if self.list[i] == child : - return i + cdef void _append(self, void* _child) : + self._lock() + if self._size == self._current : + self._size = self._size * 2 + self._list = <void **> py.PyMem_Realloc(self._list, + sizeof(void *) * (self._size)) + self._list[self._current] = <void *> _child + self._current = self._current + 1 + self._unlock() + + cdef int _index(self, void* _child) : + cdef int _i + self._lock() + for _i from 0 <= _i < self._current : + if self._list[_i] == _child : + return _i return -1 + self._unlock() - cdef void swap(self, int first, int second) : - cdef void *sibling - sibling = self.list[first] - self.list[first] = self.list[second] - self.list[second] = sibling + cdef void _swap(self, int _first, int _second) : + cdef void* _sibling + _sibling = self._list[_first] + self._list[_first] = self._list[_second] + self._list[_second] = _sibling - cdef void down(self, void *child) : - cdef int index - index = self.index(child) - if index > 0 : - self.swap(index, index-1) + cdef void _down(self, void* _child) : + cdef int _index + _index = self._index(_child) + if _index > 0 : + self._swap(_index, _index - 1) - cdef void up(self, void *child) : - cdef int index - index = self.index(child) - if index == -1 : + cdef void _up(self, void* _child) : + cdef int _index + _index = self._index(_child) + if _index == -1 : return - if index < self.current-1 : - self.swap(index, index+1) + if _index < self._current-1 : + self._swap(_index, _index + 1) - cdef void top(self, void *child) : - cdef int index - index = self.index(child) - if index == -1 : + cdef void _top(self, void* _child) : + cdef int _index + _index = self._index(_child) + if _index == -1 : return - if index < self.current-1 : - self.swap(index, self.current-1) + if _index < self._current - 1 : + self._swap(_index, self._current - 1) - cdef void bottom(self, void *child) : - cdef int index - index = self.index(child) - if index > 0 : - self.swap(index, 0) + cdef void _bottom(self, void* _child) : + cdef int _index + _index = self._index(_child) + if _index > 0 : + self._swap(_index, 0) - cdef void remove(self, void *child) : - cdef int i - cdef int index - index = self.index(child) - if index == -1 : + cdef void _remove(self, void* _child) : + cdef int _i, _index + self._lock() + _index = self._index(_child) + if _index == -1 : return - for i from index <= i < (self.current-1) : - self.list[i] = self.list[i+1] - self.current = self.current - 1 + for _i from _index <= _i < (self._current - 1) : + self._list[_i] = self._list[_i + 1] + self._current = self._current - 1 + self._unlock() - cdef void empty(self) : - py.PyMem_Free(self.list) - self.size = 1 - self.current = 0 - self.list = <void **>py.PyMem_Malloc(sizeof(void *)) - - def __dealloc__(self) : - py.PyMem_Free(self.list) - py.PyThread_free_lock(self.mutex) + cdef void _empty(self) : + py.PyMem_Free(self._list) + self._size = 1 + self._current = 0 + self._list = <void **>py.PyMem_Malloc(sizeof(void *)) Modified: trunk/pysoy/src/_internals/soy._internals.pxd =================================================================== --- trunk/pysoy/src/_internals/soy._internals.pxd 2008-03-04 20:20:25 UTC (rev 1029) +++ trunk/pysoy/src/_internals/soy._internals.pxd 2008-03-04 21:02:50 UTC (rev 1030) @@ -25,22 +25,22 @@ cdef object _pop(self) cdef class Children : - cdef int size - cdef int current - cdef void **list - cdef void *mutex - cdef void lock ( self ) - cdef int trylock ( self ) - cdef void unlock ( self ) - cdef void append ( self, void* ) - cdef int index ( self, void* ) - cdef void swap ( self, int, int ) - cdef void up ( self, void* ) - cdef void down ( self, void* ) - cdef void top ( self, void* ) - cdef void bottom ( self, void* ) - cdef void remove ( self, void* ) - cdef void empty ( self ) + cdef int _size + cdef int _current + cdef void** _list + cdef void* _mutex + cdef void _lock ( self ) + cdef int _trylock ( self ) + cdef void _unlock ( self ) + cdef void _append ( self, void* ) + cdef int _index ( self, void* ) + cdef void _swap ( self, int, int ) + cdef void _up ( self, void* ) + cdef void _down ( self, void* ) + cdef void _top ( self, void* ) + cdef void _bottom ( self, void* ) + cdef void _remove ( self, void* ) + cdef void _empty ( self ) cdef class Loadable : cdef object _source _______________________________________________ PySoy-SVN mailing list PySoy-SVN@pysoy.org http://www.pysoy.org/mailman/listinfo/pysoy-svn