Strange problem with C API

Michael Hudson mwh at python.net
Tue Feb 26 14:20:27 CET 2002


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.

-- 
  You have run into the classic Dmachine problem: your machine has
  become occupied by a malevolent spirit.  Replacing hardware or
  software will not fix this - you need an exorcist. 
                                       -- Tim Bradshaw, comp.lang.lisp



More information about the Python-list mailing list