From 44d410d007e88d794e35e322082bec3ec69d5fa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Sat, 15 Aug 2009 11:46:13 +0200 Subject: Finish mq module --- portato/mq.pxd | 3 ++- portato/mq.pyx | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) (limited to 'portato') diff --git a/portato/mq.pxd b/portato/mq.pxd index ab5cfbe..be7631b 100644 --- a/portato/mq.pxd +++ b/portato/mq.pxd @@ -10,7 +10,8 @@ # # Written by René 'Necoro' Neumann -from stdlib cimport * +from python_string cimport * +from python_mem cimport * cdef extern from "errno.h": int errno diff --git a/portato/mq.pyx b/portato/mq.pyx index a5d0745..e9ce464 100644 --- a/portato/mq.pyx +++ b/portato/mq.pyx @@ -84,7 +84,7 @@ cdef class MessageQueue (object): if size >= MAX_MESSAGE_SIZE: raise ValueError("Message must be smaller than %d", MAX_MESSAGE_SIZE) - msg = malloc(sizeof(msg_data) + size) + msg = PyMem_Malloc(sizeof(msg_data) + size) if msg is NULL: raise MemoryError("Out of memory") @@ -93,7 +93,7 @@ cdef class MessageQueue (object): msg.mtype = type with nogil: - ret = msgsnd(self.msgid, &msg, size, 0) + ret = msgsnd(self.msgid, msg, size, 0) try: if ret == -1: @@ -106,14 +106,14 @@ cdef class MessageQueue (object): else: raise OSError(errno, strerror(errno)) finally: - free(msg) + PyMem_Free(msg) def receive (self): cdef msg_data * msg cdef int ret cdef object retTuple - msg = malloc(sizeof(msg_data) + MAX_MESSAGE_SIZE) + msg = PyMem_Malloc(sizeof(msg_data) + MAX_MESSAGE_SIZE) if msg is NULL: raise MemoryError("Out of memory") @@ -134,9 +134,9 @@ cdef class MessageQueue (object): else: raise OSError(errno, strerror(errno)) - retTuple = (msg.mtext, msg.mtype) + retTuple = (PyString_FromStringAndSize(msg.mtext, ret), msg.mtype) finally: - free(msg) + PyMem_Free(msg) return retTuple -- cgit v1.2.3