[Pyrex] Interpreting error messages

Matthias Baas baas at ira.uka.de
Sun Apr 27 20:46:35 CEST 2003


At 10:17 27.04.2003 -0400, Edward C. Jones wrote:
>The program is:
>
>#include <stdio.h>

Remember that you're writing a Pyrex program, not a C program, so the above 
line is a comment and is ignored by Pyrex.

>cdef tostring(void* p):
>     cdef char* s
>     s = <char*> malloc(50*sizeof(char))
>     sprintf(s, c"%p", p)
>     return s
>
>The error messages are:
>
>/.../silly.pyx:5:8: Casting temporary Python object to non-Python type
>/.../silly.pyx:6:22: Cannot convert 'void (*)' to Python object

Since the "#include <stdio.h>" was just a comment and you didn't declare 
malloc() and sprintf() Pyrex treats them as Python functions.
Pyrex isn't able to read C header files yet, so you have to declare the 
functions yourself, something like:

cdef extern from "stdio.h":
    void* malloc(int)
    ...

- Matthias -





More information about the Pyrex mailing list