PyCode_NewEmpty:
Most uses of PyCode_New found by http://www.google.com/codesearch?q=PyCode_New
are trying to build an empty code object, usually to put it in a dummy frame
object. This patch adds a PyCode_NewEmpty wrapper which lets the user specify
just the filename, function name, and first line number, instead of also
requiring lots of code internals.
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index 0cccca3..fb5cf73 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -988,6 +988,21 @@
Py_RETURN_NONE;
}
+/* To test that the result of PyCode_NewEmpty has the right members. */
+static PyObject *
+code_newempty(PyObject *self, PyObject *args)
+{
+ const char *filename;
+ const char *funcname;
+ int firstlineno;
+
+ if (!PyArg_ParseTuple(args, "ssi:code_newempty",
+ &filename, &funcname, &firstlineno))
+ return NULL;
+
+ return (PyObject *)PyCode_NewEmpty(filename, funcname, firstlineno);
+}
+
static PyMethodDef TestMethods[] = {
{"raise_exception", raise_exception, METH_VARARGS},
{"test_config", (PyCFunction)test_config, METH_NOARGS},
@@ -1033,6 +1048,7 @@
{"_pending_threadfunc", pending_threadfunc, METH_VARARGS},
#endif
{"traceback_print", traceback_print, METH_VARARGS},
+ {"code_newempty", code_newempty, METH_VARARGS},
{NULL, NULL} /* sentinel */
};