[Cython] getting rid of C' stlib strcmp() in generated sources

Lisandro Dalcin dalcinl at gmail.com
Sat Mar 7 19:37:48 CET 2009


On Sat, Mar 7, 2009 at 4:58 AM, Robert Bradshaw
<robertwb at math.washington.edu> wrote:
> On Mar 6, 2009, at 11:06 PM, Stefan Behnel wrote:
>
>>
>> That by itself is perfectly ok and makes sense (although I don't
>> know if
>> you can use PyMem_*() in nogil functions/blocks).
>
> I am pretty sure it's not treadsafe.
>

First of all, AFAIK Cython does not emit any malloc()/free() call, so
there are not issues regarding this.

If you look at core CPython sources, you will discover that
PyMem_Malloc() (implemented in "Objects/object.c") actually used the
macro PyMem_MALLOC(). This one is defined in "Include/pymem.h".

If "PYMALLOC_DEBUG" is not #define'd (should be the case for non-debug
Python builds, right?), then PyMem_MALLOC actually calls system
malloc(). So in this case using PyMem_Malloc() (note: the function,
not the macro) should be as thread-safe as the system malloc() is.

If "PYMALLOC_DEBUG" do is #define'd, then yes, propably PyMem_Malloc()
is not thread-safe



-- 
Lisandro Dalcín
---------------
Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
PTLC - Güemes 3450, (3000) Santa Fe, Argentina
Tel/Fax: +54-(0)342-451.1594


More information about the Cython-dev mailing list