diff options
author | René 'Necoro' Neumann <necoro@necoro.net> | 2010-04-14 22:17:53 +0200 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.net> | 2010-04-14 22:17:53 +0200 |
commit | 208c4adfbdf7b82cc40da873ed185f3e29880cfa (patch) | |
tree | 6c374e4c7e7480496602e38a275bd42d70aa4fe7 /portato/ipc.pyx | |
parent | 0f19f73c55ea8c8188aec7426ea94bfb7a823720 (diff) | |
download | portato-208c4adfbdf7b82cc40da873ed185f3e29880cfa.tar.gz portato-208c4adfbdf7b82cc40da873ed185f3e29880cfa.tar.bz2 portato-208c4adfbdf7b82cc40da873ed185f3e29880cfa.zip |
Improve the C modules
Diffstat (limited to '')
-rw-r--r-- | portato/ipc.pyx | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/portato/ipc.pyx b/portato/ipc.pyx index abb26fe..7dcf949 100644 --- a/portato/ipc.pyx +++ b/portato/ipc.pyx @@ -70,7 +70,7 @@ cdef class MessageQueue (object): elif errno == ENOENT: raise MessageQueueError("Queue does not exist and 'create' is not set.") elif errno == ENOMEM or errno == ENOSPC: - raise MemoryError("Insufficient ressources.") + PyErr_NoMemory() else: raise OSError(errno, strerror(errno)) @@ -111,7 +111,7 @@ cdef class MessageQueue (object): msg = <msg_data*>PyMem_Malloc(sizeof(msg_data) + size) if msg is NULL: - raise MemoryError("Out of memory") + PyErr_NoMemory() memcpy(msg.mtext, <char*>message, size) msg.mtype = type @@ -119,18 +119,17 @@ cdef class MessageQueue (object): with nogil: ret = msgsnd(self.msgid, msg, size, 0) - try: - if ret == -1: - if errno == EIDRM or errno == EINVAL: - raise MessageQueueRemovedError("Queue was removed.") - elif errno == EINTR: - raise MessageQueueError("Signaled while waiting.") - elif errno == EACCES: - raise MessageQueueError("Permission denied.") - else: - raise OSError(errno, strerror(errno)) - finally: - PyMem_Free(msg) + PyMem_Free(msg) + + if ret == -1: + if errno == EIDRM or errno == EINVAL: + raise MessageQueueRemovedError("Queue was removed.") + elif errno == EINTR: + raise MessageQueueError("Signaled while waiting.") + elif errno == EACCES: + raise MessageQueueError("Permission denied.") + else: + raise OSError(errno, strerror(errno)) def receive (self): """ @@ -145,7 +144,7 @@ cdef class MessageQueue (object): msg = <msg_data*>PyMem_Malloc(sizeof(msg_data) + MAX_MESSAGE_SIZE) if msg is NULL: - raise MemoryError("Out of memory") + PyErr_NoMemory() msg.mtype = 0 @@ -162,12 +161,11 @@ cdef class MessageQueue (object): raise MessageQueueError("Permission denied.") else: raise OSError(errno, strerror(errno)) - - retTuple = (PyString_FromStringAndSize(msg.mtext, ret), msg.mtype) + else: + return (PyString_FromStringAndSize(msg.mtext, ret), msg.mtype) + finally: PyMem_Free(msg) - return retTuple - cdef inline key_t random_key (self): return <int>(<double>rand() / (<double>RAND_MAX + 1) * INT_MAX) |