setup() and C extensions
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Tue Apr 10 08:03:09 EDT 2007
En Tue, 10 Apr 2007 03:35:35 -0300, 7stud <bbxx789_05ss at yahoo.com>
escribió:
> 1) When you create a C array to map python names to the C functions
> that you defined:
>
> static PyMethodDef MyFunctions[] =
> {
> {"my_calc", (PyCFunction)my_func, METH_VARARGS, "my very speedy c
> function"},
> {NULL, NULL, 0, NULL}
> };
>
> Why do you need to cast my_func to PyCFunction?
Because it does not *have* to be a PyCFunction; the ml_flags field is used
to indicate exactly what kind of function it is (METH_KEYWORDS indicating
a PyCFunctionWithKeywords, by example). But the C struct declaration
(PyMethodDef) has a fixed type. See
http://docs.python.org/api/common-structs.html
> 2) When returning None, why use the idiom:
>
> Py_INCREF(Py_None);
> return Py_None;
>
> instead of:
>
> return Py_BuildValue("");
Because it's a lot faster and clear?
--
Gabriel Genellina
More information about the Python-list
mailing list