diff options
author | Armin Rigo <arigo@tunes.org> | 2006-02-14 15:50:44 (GMT) |
---|---|---|
committer | Armin Rigo <arigo@tunes.org> | 2006-02-14 15:50:44 (GMT) |
commit | 967aa8b3496df29f03895b5e30a590d77d337167 (patch) | |
tree | 12178e032c4e78a7ef46c3719bb0e08236bd2bbc /Objects/genobject.c | |
parent | 88b78d8cd4a9231b62e4c91f48143c7a67384379 (diff) | |
download | cpython-967aa8b3496df29f03895b5e30a590d77d337167.zip cpython-967aa8b3496df29f03895b5e30a590d77d337167.tar.gz cpython-967aa8b3496df29f03895b5e30a590d77d337167.tar.bz2 |
* Refcount leak. It was just a reference to Py_None, but still.
* Allow the 3rd argument to generator.throw() to be None.
The 'raise' statement does the same, and anyway it follows the
general policy that optional arguments of built-ins should, when
reasonable, have a default value specifiable from Python.
Diffstat (limited to 'Objects/genobject.c')
-rw-r--r-- | Objects/genobject.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/Objects/genobject.c b/Objects/genobject.c index b001b01..8b84e2e 100644 --- a/Objects/genobject.c +++ b/Objects/genobject.c @@ -214,7 +214,13 @@ gen_throw(PyGenObject *gen, PyObject *args) if (!PyArg_ParseTuple(args, "O|OO:throw", &typ, &val, &tb)) return NULL; - if (tb && !PyTraceBack_Check(tb)) { + /* First, check the traceback argument, replacing None with + NULL. */ + if (tb == Py_None) { + Py_DECREF(tb); + tb = NULL; + } + else if (tb != NULL && !PyTraceBack_Check(tb)) { PyErr_SetString(PyExc_TypeError, "throw() third argument must be a traceback object"); return NULL; @@ -237,14 +243,14 @@ gen_throw(PyGenObject *gen, PyObject *args) } else { /* Normalize to raise <class>, <instance> */ + Py_XDECREF(val); val = typ; typ = (PyObject*) ((PyInstanceObject*)typ)->in_class; Py_INCREF(typ); } } else { - /* Not something you can raise. You get an exception - anyway, just not what you specified :-) */ + /* Not something you can raise. throw() fails. */ PyErr_Format(PyExc_TypeError, "exceptions must be classes, or instances, not %s", typ->ob_type->tp_name); |