En Tue, 10 Apr 2007 03:35:35 -0300, 7stud <[EMAIL PROTECTED]> 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 -- http://mail.python.org/mailman/listinfo/python-list