I have code like the following:
PyObject *callback;
PyObject *paths;
// Process and convert arguments
if (!PyArg_ParseTuple(args, "OO:schedule", &paths, &callback))
return NULL;
What exactly happens inside PyArg_ParseTuple? My guess is that callback gets the function pointer I passed to args (also PyObject*). How does PyArg_ParseTuple convert the function pointer to PyObject*?
What I want to know is what happens if I pass in the same callback function pointer twice. I think callback gets allocated a new PyObject inside PyArg_ParseTuple, so it will get a different memory address each time, but will contain the same callback function pointer.
But if I PyObject_Hash callback, it will produce a different value each time, right? (since address is different each time..)
PyArg_ParseTuple
doesn't care about the type of an "O" arg. No conversion is done. No new object is created. The address of the object is dropped into the PyObject *
C variable that you have specified. It does exactly the same to each of your two args.
I can't imagine what is the relevance of PyObject_Hash
. If you want to compare two incarnations of your callback arg, just use ==
on the addresses.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With