diff options
| author | Antoine Pitrou <solipsis@pitrou.net> | 2013-05-13 22:35:38 +0200 |
|---|---|---|
| committer | Antoine Pitrou <solipsis@pitrou.net> | 2013-05-13 22:35:38 +0200 |
| commit | c15df25fef4ab764bf9ae2c0ca9453d0906037d8 (patch) | |
| tree | 02521ad7c223b54eb7a70faaa0cc4b1af5d6b932 /Python/bltinmodule.c | |
| parent | 724df745dd8de9a3b51199eb43ad01f9a0775d36 (diff) | |
| parent | 0c26f2f86d11bc675b918d6dafc7de7b982a10b5 (diff) | |
| download | cpython-c15df25fef4ab764bf9ae2c0ca9453d0906037d8.tar.gz | |
Fix ResourceWarnings in test_sax
Diffstat (limited to 'Python/bltinmodule.c')
| -rw-r--r-- | Python/bltinmodule.c | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 75afa860f1..5291565b81 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -659,7 +659,7 @@ builtin_compile(PyObject *self, PyObject *args, PyObject *kwds) goto finally; } - str = source_as_string(cmd, "compile", "string, bytes, AST or code", &cf); + str = source_as_string(cmd, "compile", "string, bytes or AST", &cf); if (str == NULL) goto error; @@ -1810,10 +1810,10 @@ For most object types, eval(repr(object)) == object."); static PyObject * builtin_round(PyObject *self, PyObject *args, PyObject *kwds) { - static PyObject *round_str = NULL; PyObject *ndigits = NULL; static char *kwlist[] = {"number", "ndigits", 0}; - PyObject *number, *round; + PyObject *number, *round, *result; + _Py_IDENTIFIER(__round__); if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O:round", kwlist, &number, &ndigits)) @@ -1824,24 +1824,21 @@ builtin_round(PyObject *self, PyObject *args, PyObject *kwds) return NULL; } - if (round_str == NULL) { - round_str = PyUnicode_InternFromString("__round__"); - if (round_str == NULL) - return NULL; - } - - round = _PyType_Lookup(Py_TYPE(number), round_str); + round = _PyObject_LookupSpecial(number, &PyId___round__); if (round == NULL) { - PyErr_Format(PyExc_TypeError, - "type %.100s doesn't define __round__ method", - Py_TYPE(number)->tp_name); + if (!PyErr_Occurred()) + PyErr_Format(PyExc_TypeError, + "type %.100s doesn't define __round__ method", + Py_TYPE(number)->tp_name); return NULL; } if (ndigits == NULL) - return PyObject_CallFunction(round, "O", number); + result = PyObject_CallFunctionObjArgs(round, NULL); else - return PyObject_CallFunction(round, "OO", number, ndigits); + result = PyObject_CallFunctionObjArgs(round, ndigits, NULL); + Py_DECREF(round); + return result; } PyDoc_STRVAR(round_doc, @@ -2408,6 +2405,12 @@ PyObject * _PyBuiltin_Init(void) { PyObject *mod, *dict, *debug; + + if (PyType_Ready(&PyFilter_Type) < 0 || + PyType_Ready(&PyMap_Type) < 0 || + PyType_Ready(&PyZip_Type) < 0) + return NULL; + mod = PyModule_Create(&builtinsmodule); if (mod == NULL) return NULL; |
