diff options
| author | 2010-04-30 13:35:57 -0500 | |
|---|---|---|
| committer | 2012-03-20 23:25:55 +0100 | |
| commit | 3877711296cbfa4a0bcafc3c5560609a1ce2d079 (patch) | |
| tree | 751f1fd27ce3ee5d8dd9d748600381c0d2e5d6bd /cython/imobiledevice.pyx | |
| parent | 74943414c8e04a92f42dcbc4fac1599c7f9deed2 (diff) | |
| download | libimobiledevice-3877711296cbfa4a0bcafc3c5560609a1ce2d079.tar.gz libimobiledevice-3877711296cbfa4a0bcafc3c5560609a1ce2d079.tar.bz2 | |
More memory leak plugging. Some code cleanup too.
Diffstat (limited to 'cython/imobiledevice.pyx')
| -rw-r--r-- | cython/imobiledevice.pyx | 55 |
1 files changed, 35 insertions, 20 deletions
diff --git a/cython/imobiledevice.pyx b/cython/imobiledevice.pyx index bde43d0..7898290 100644 --- a/cython/imobiledevice.pyx +++ b/cython/imobiledevice.pyx | |||
| @@ -102,13 +102,16 @@ def event_unsubscribe(): | |||
| 102 | 102 | ||
| 103 | def get_device_list(): | 103 | def get_device_list(): |
| 104 | cdef: | 104 | cdef: |
| 105 | char** devices | 105 | char** devices = NULL |
| 106 | int count | 106 | int count |
| 107 | list result | 107 | list result |
| 108 | bytes device | 108 | bytes device |
| 109 | iDeviceError err = iDeviceError(idevice_get_device_list(&devices, &count)) | 109 | iDeviceError err = iDeviceError(idevice_get_device_list(&devices, &count)) |
| 110 | 110 | ||
| 111 | if err: raise err | 111 | if err: |
| 112 | if devices != NULL: | ||
| 113 | idevice_device_list_free(devices) | ||
| 114 | raise err | ||
| 112 | 115 | ||
| 113 | result = [] | 116 | result = [] |
| 114 | for i from 0 <= i < count: | 117 | for i from 0 <= i < count: |
| @@ -131,15 +134,16 @@ cdef class iDeviceConnection(Base): | |||
| 131 | cdef inline BaseError _error(self, int16_t ret): | 134 | cdef inline BaseError _error(self, int16_t ret): |
| 132 | return iDeviceError(ret) | 135 | return iDeviceError(ret) |
| 133 | 136 | ||
| 137 | cimport stdlib | ||
| 138 | |||
| 134 | cdef class iDevice(Base): | 139 | cdef class iDevice(Base): |
| 135 | def __cinit__(self, uuid=None, *args, **kwargs): | 140 | def __cinit__(self, object uuid=None, *args, **kwargs): |
| 136 | cdef: | 141 | cdef char* c_uuid = NULL |
| 137 | char* c_uuid = NULL | 142 | if isinstance(uuid, basestring): |
| 138 | idevice_error_t err | 143 | c_uuid = <bytes>uuid |
| 139 | if uuid is not None: | 144 | elif uuid is not None: |
| 140 | c_uuid = uuid | 145 | raise TypeError("iDevice's constructor takes a string or None as the uuid argument") |
| 141 | err = idevice_new(&self._c_dev, c_uuid) | 146 | self.handle_error(idevice_new(&self._c_dev, c_uuid)) |
| 142 | self.handle_error(err) | ||
| 143 | 147 | ||
| 144 | def __dealloc__(self): | 148 | def __dealloc__(self): |
| 145 | if self._c_dev is not NULL: | 149 | if self._c_dev is not NULL: |
| @@ -151,10 +155,19 @@ cdef class iDevice(Base): | |||
| 151 | cpdef iDeviceConnection connect(self, uint16_t port): | 155 | cpdef iDeviceConnection connect(self, uint16_t port): |
| 152 | cdef: | 156 | cdef: |
| 153 | idevice_error_t err | 157 | idevice_error_t err |
| 154 | iDeviceConnection conn = iDeviceConnection.__new__(iDeviceConnection) | 158 | idevice_connection_t c_conn = NULL |
| 155 | err = idevice_connect(self._c_dev, port, &conn._c_connection) | 159 | iDeviceConnection conn |
| 156 | self.handle_error(err) | 160 | err = idevice_connect(self._c_dev, port, &c_conn) |
| 157 | return conn | 161 | try: |
| 162 | self.handle_error(err) | ||
| 163 | |||
| 164 | conn = iDeviceConnection.__new__(iDeviceConnection) | ||
| 165 | conn._c_connection = c_conn | ||
| 166 | |||
| 167 | return conn | ||
| 168 | except Exception, e: | ||
| 169 | if c_conn != NULL: | ||
| 170 | idevice_disconnect(c_conn) | ||
| 158 | 171 | ||
| 159 | property uuid: | 172 | property uuid: |
| 160 | def __get__(self): | 173 | def __get__(self): |
| @@ -162,8 +175,12 @@ cdef class iDevice(Base): | |||
| 162 | char* uuid | 175 | char* uuid |
| 163 | idevice_error_t err | 176 | idevice_error_t err |
| 164 | err = idevice_get_uuid(self._c_dev, &uuid) | 177 | err = idevice_get_uuid(self._c_dev, &uuid) |
| 165 | self.handle_error(err) | 178 | try: |
| 166 | return uuid | 179 | self.handle_error(err) |
| 180 | return uuid | ||
| 181 | except Exception, e: | ||
| 182 | if uuid != NULL: | ||
| 183 | stdlib.free(uuid) | ||
| 167 | property handle: | 184 | property handle: |
| 168 | def __get__(self): | 185 | def __get__(self): |
| 169 | cdef uint32_t handle | 186 | cdef uint32_t handle |
| @@ -173,8 +190,6 @@ cdef class iDevice(Base): | |||
| 173 | cdef extern from *: | 190 | cdef extern from *: |
| 174 | ctypedef char* const_char_ptr "const char*" | 191 | ctypedef char* const_char_ptr "const char*" |
| 175 | 192 | ||
| 176 | cimport stdlib | ||
| 177 | |||
| 178 | cdef class BaseService(Base): | 193 | cdef class BaseService(Base): |
| 179 | __service_name__ = None | 194 | __service_name__ = None |
| 180 | 195 | ||
| @@ -189,13 +204,13 @@ cdef class PropertyListService(BaseService): | |||
| 189 | err = self._receive(&c_node) | 204 | err = self._receive(&c_node) |
| 190 | try: | 205 | try: |
| 191 | self.handle_error(err) | 206 | self.handle_error(err) |
| 207 | |||
| 208 | return plist.plist_t_to_node(c_node) | ||
| 192 | except BaseError, e: | 209 | except BaseError, e: |
| 193 | if c_node != NULL: | 210 | if c_node != NULL: |
| 194 | plist.plist_free(c_node) | 211 | plist.plist_free(c_node) |
| 195 | raise | 212 | raise |
| 196 | 213 | ||
| 197 | return plist.plist_t_to_node(c_node) | ||
| 198 | |||
| 199 | cdef inline int16_t _send(self, plist.plist_t node): | 214 | cdef inline int16_t _send(self, plist.plist_t node): |
| 200 | raise NotImplementedError("send is not implemented") | 215 | raise NotImplementedError("send is not implemented") |
| 201 | 216 | ||
