mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
* 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.
This commit is contained in:
parent
88b78d8cd4
commit
967aa8b349
1 changed files with 9 additions and 3 deletions
|
@ -214,7 +214,13 @@ gen_throw(PyGenObject *gen, PyObject *args)
|
||||||
if (!PyArg_ParseTuple(args, "O|OO:throw", &typ, &val, &tb))
|
if (!PyArg_ParseTuple(args, "O|OO:throw", &typ, &val, &tb))
|
||||||
return NULL;
|
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,
|
PyErr_SetString(PyExc_TypeError,
|
||||||
"throw() third argument must be a traceback object");
|
"throw() third argument must be a traceback object");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -237,14 +243,14 @@ gen_throw(PyGenObject *gen, PyObject *args)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* Normalize to raise <class>, <instance> */
|
/* Normalize to raise <class>, <instance> */
|
||||||
|
Py_XDECREF(val);
|
||||||
val = typ;
|
val = typ;
|
||||||
typ = (PyObject*) ((PyInstanceObject*)typ)->in_class;
|
typ = (PyObject*) ((PyInstanceObject*)typ)->in_class;
|
||||||
Py_INCREF(typ);
|
Py_INCREF(typ);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* Not something you can raise. You get an exception
|
/* Not something you can raise. throw() fails. */
|
||||||
anyway, just not what you specified :-) */
|
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"exceptions must be classes, or instances, not %s",
|
"exceptions must be classes, or instances, not %s",
|
||||||
typ->ob_type->tp_name);
|
typ->ob_type->tp_name);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue