[Pyrex] char * from python

Brent Pedersen bpederse at gmail.com
Fri Dec 1 21:45:59 UTC 2006


thanks, that does it.

-brent

On 12/1/06, Chris Perkins <chrisperkins99 at gmail.com> wrote:
>
> On 12/1/06, Brent Pedersen <bpederse at gmail.com> wrote:
> > hi, i've just been tinkering with pyrex, trying to do this (below).
> > but it segfaults on the sscanf line in pyscanf.
> > what am i doing wrong? is this more involved than my naive approach?
> >
> > thanks,
> > -brent
> >
> > ##############################
> > # pyscanf.pyx
> >
> > cdef extern from "stdio.h":
> >     int sscanf (char *,char *,...)
> >
> > def pyscanf(char * str):
> >     cdef char * q
> >     cdef char * s
> >     cdef int my_int
> >     cdef float my_float
> >     sscanf(str,"%s %s %i %f",q,s,&my_int,&my_float)
> >     return [q,s,my_int,my_float]
> >
> >
> > ####### run with ###########
> > from pyscanf import pyscanf
> > print pyscanf("asdf asdf 123 12.22")
>
> You need to allocate space for p and s.  sscanf tries to copy "asdf"
> in to the memory location that q points to, but you have left it
> uninitialized.  Same for s.
>
> Chris Perkins
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.copyleft.no/pipermail/pyrex/attachments/20061201/4a65d978/attachment.html 


More information about the Pyrex mailing list