bus error/segfault from PyArg_ParseTuple in initproc with incorrect arg number

Miles Lubin miles at lubin.us
Fri Feb 22 13:20:14 EST 2008


I am using PyArg_ParseTuple to parse the arguments (ignoring the keyword 
arguments) to my initproc for a type I define.
It seems that something goes wrong inside PyArg_ParseTuple when it gets 
the wrong number of arguments (my format string is "OO");
if the function isn't given exactly two arguments, I get a bus error on 
OS X and a segfault on Linux.
If two arguments are given, the code runs as expected.
This does not occur when using PyArg_ParseTuple in a normal method.
Am I not using PyArg_ParseTuple correctly?

Here's the relevant code:
PyObject *a, *b;
if (!PyArg_ParseTuple(args, "OO", &a, &b))
	return -1;

The segfault occurs on this line, not on any line after.

Thanks in advance,
Miles



More information about the Python-list mailing list