houbaastef . schrieb am 21.08.2015 um 03:15:
> 2015-08-20 23:56 GMT+02:00 houbaastef:
>> i need to call some functions from the pthread library.
>>
>> eg : int pthread_mutex_init (pthread_mutex_t *__mutex, const pthread_mutexattr_t
>> *__mutexattr)
>>
>> so i have to declare the opaque pthread_mutex_t and pthread_mutexattr_t
>>
>> by reading some headers, pthread_mutex_t looks implemented as a struct on
>> OSX, as a union on Linux, and maybe as pointers on some BSDs.
>>
>> Is there a way to properly declare that in cython, without explicite and
>> painful conditional compilation for each system ?
>
> After digging a bit, it seems that when in cython we declare something like
>
> cdef extern from "pthread.h" nogil:
> ctypedef struct pthread_t:
> pass
>
> In fact the struct nature of pthread_t does not really appear in the
> generated C code.
>
> So i guess the answer for my previous question is: just pretend
> pthread_mutex_t is an opaque struct in cython, and don't care if it's in
> fact an union. Is that right ?
Right. In fact, you can even remove the "pass" and shorten it to
ctypedef struct pthread_t
to make it clearer that there really is nothing interesting in it.
BTW, we don't currently ship declarations for the pthreads library. If
someone could come up with a .pxd file for it, I'd appreciate a pull
request for the Cython/Includes/ directory.
Stefan