[Pyrex] Interpreting error messages
Edward C. Jones
edcjones at erols.com
Mon Apr 28 02:39:08 CEST 2003
Matthias Baas wrote:
> 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.
If I am thinking C-like things, I tend to C-like programming. In Python
I think Pythonically.
It is not easy to adopt a world view between the two. It would be easier
if Pyrex was an extension of Python with optional strong typing which
could read C header files and libraries.
>> 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
>
Not very useful error messages. I would prefer the Python "undefined
global variable" error.
>
> 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)
> ...
This worked. Here is a trick I got from one of your recent postings:
cdef tostring(void* p):
# Ugly. Cast a pointer to an int. Not portable.
i = <int> p
return "%x" % i
More information about the Pyrex
mailing list