Bug in PyCallable_Check

Arkon arkon at ragestorm.net
Mon May 3 07:39:41 EDT 2004


Hello,
 I encountered in a bug (or so I think) in the function
 PyCallable_Check, Python C API.

The problem is that in Python code you can pass to a function that
requests a function(pointer), types.FunctionType (Maybe other types
too, didn't try though) which is in fact a type-type.

And then the PyCallable_Check won't *detect* that it's not a real
function(pointer) passed...then later when you intend to run that
function, you get an error.

Python:
import types
func(types.FunctionType)

# instead of
def f():
 print "bug?!"
func(f)

C:
PyObject* module_func(PyObject* pSelf, PyObject* pArgs)
{
 PyObject* CallbackFunction = NULL;
 if (!PyArg_ParseTuple(pArgs, "O", &CallbackFunction)) return NULL;
 // FLAW: NEXT IF STATEMENT WON'T DETECT IT'S A TYPE-TYPE AND NOT A
REAL  FUNCTION!
 if (!PyCallable_Check(CallbackFunction)) ...
...
...
...
}

I hope I made myself clear with this point.
Let me know what you think.
Arkon,
 http://www.ragestorm.net



More information about the Python-list mailing list