Strange problem with C API

Amrit amrit040 at yahoo.com
Tue Feb 26 21:35:29 CET 2002


Thanx that fixes the problem. So basically i was trying to read one
more element than what the input had. This explains the bug but what i
don't understand is why does this thing alternate ! Shouldn't it be
consistent.

Amrit
Michael Hudson <mwh at python.net> wrote in message news:<usn7oxtpd.fsf at python.net>...
> amrit040 at yahoo.com (Amrit) writes:
> 
> > Hi 
> > 
> > I'm trying to write a C function callable from python. I'm getting
> > some strange results :
> > 
> > Here's a typical run:
> > """
> > Python 2.0 (#2, Jun 18 2001, 15:29:44) 
> > [GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2
> > Type "copyright", "credits" or "license" for more information.
> > >>> import lt
> > >>> lt.__file__
>  'lt.so'
> > >>> dir(lt)
>  ['__doc__', '__file__', '__name__', 'fmm']
> > >>> lt.fmm(range(15),-41)
>  (0.0, -1.0)
> > >>> lt.fmm(range(15),-41)
> > TypeError: function requires at least one argument
> > """
> > 
> > On calling the same function again with the same argument gives me a
> > type error. This alternates. I get a typeerror and then a correct
> > output and so on. Any ideas what could be wrong. My C code is pasted
> > below
> 
> This sort of thing usually means an exception happened and you didn't
> return NULL.
> 
> >   for (i = 0; i < n; i++)
> >     {
> >       obj[i] = PySequence_GetItem (vec, i+1);
> 
> This looks suspicious.
> 
> Cheers,
> M.



More information about the Python-list mailing list