diff options
author | Jeffrey Yasskin <jyasskin@gmail.com> | 2009-05-08 21:51:06 (GMT) |
---|---|---|
committer | Jeffrey Yasskin <jyasskin@gmail.com> | 2009-05-08 21:51:06 (GMT) |
commit | 1aa4700234aa0657ee8cb12cfd9b615fef9e0300 (patch) | |
tree | 6a480c31e4b83218ae9412f7ab2e9d41b34f8fd0 /Modules/pyexpat.c | |
parent | 083d1f9f9a26486cf9f0d85fb0e76e6cf9474b0c (diff) | |
download | cpython-1aa4700234aa0657ee8cb12cfd9b615fef9e0300.zip cpython-1aa4700234aa0657ee8cb12cfd9b615fef9e0300.tar.gz cpython-1aa4700234aa0657ee8cb12cfd9b615fef9e0300.tar.bz2 |
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.
Diffstat (limited to 'Modules/pyexpat.c')
-rw-r--r-- | Modules/pyexpat.c | 43 |
1 files changed, 1 insertions, 42 deletions
diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c index 01971b7..47ef186 100644 --- a/Modules/pyexpat.c +++ b/Modules/pyexpat.c @@ -261,52 +261,11 @@ flag_error(xmlparseobject *self) static PyCodeObject* getcode(enum HandlerTypes slot, char* func_name, int lineno) { - PyObject *code = NULL; - PyObject *name = NULL; - PyObject *nulltuple = NULL; - PyObject *filename = NULL; - if (handler_info[slot].tb_code == NULL) { - code = PyString_FromString(""); - if (code == NULL) - goto failed; - name = PyString_FromString(func_name); - if (name == NULL) - goto failed; - nulltuple = PyTuple_New(0); - if (nulltuple == NULL) - goto failed; - filename = PyString_FromString(__FILE__); handler_info[slot].tb_code = - PyCode_New(0, /* argcount */ - 0, /* nlocals */ - 0, /* stacksize */ - 0, /* flags */ - code, /* code */ - nulltuple, /* consts */ - nulltuple, /* names */ - nulltuple, /* varnames */ -#if PYTHON_API_VERSION >= 1010 - nulltuple, /* freevars */ - nulltuple, /* cellvars */ -#endif - filename, /* filename */ - name, /* name */ - lineno, /* firstlineno */ - code /* lnotab */ - ); - if (handler_info[slot].tb_code == NULL) - goto failed; - Py_DECREF(code); - Py_DECREF(nulltuple); - Py_DECREF(filename); - Py_DECREF(name); + PyCode_NewEmpty(__FILE__, func_name, lineno); } return handler_info[slot].tb_code; - failed: - Py_XDECREF(code); - Py_XDECREF(name); - return NULL; } #ifdef FIX_TRACE |