"bad argument type for built-in operation"
sjmachin at lexicon.net
Mon Jan 24 15:56:04 EST 2005
Gilles Arnaud wrote:
> I've got a nasty bug and no idea to deal with :
> here is the method :
Big snip. The Python code is unlikely to be your problem.
> and the trace
> in None [(-2.0, 2.0), (-2.0, 2.0)] [0.1385039192456847,
> 0.87787941093093491] 2 2 <function undo at 0x81ff94c>
> [0.1385039192456847, 0.87787941093093491]
That's a very mangled trace!
> the first call of the methode succeed
> all following call failed.
So the first call is leaving a bomb behind.
> I've got different scenario which call this low level methode,
> many succeed, some failed this way.
> what's happened ?
> If someone got an idea ?
> what can raise this exception ?
At this stage, without the benefit of look-ahead, one could only blame
gamma rays or pointy-eared aliens :-)
> My program is written partially in python and partially in C.
> the top level is in python which call a C optimisation routine
> which use a callback (PyObject_CallMethod) to evaluate the cost in
> python again.
Aha! *Now* you tell us. *You* have "denormalised" the stack. Read your
C code carefully. Use a debugger, or put some "printf()" in it. With
PyObject_CallMethod, do the format descriptors and the arguments match?
Are you testing the returned value for NULL and acting accordingly? Is
the called-from-C Python method ever executed? Try putting a print
statement (that shows the args) at the top. More generally, are you
testing the returned value from each and every C API call? Are you
testing for the correct error value (some return NULL, some -1, ...)?
Are you doing the right thing on error?
A catalogue of the different ways of messing things up using C would
take forever to write. If you can't find your problem, post the code,
either on the newsgroup or as a web page.
Hope this helps,
More information about the Python-list