mirror of
https://github.com/python/cpython.git
synced 2025-10-17 04:08:28 +00:00
Simplify and speedup uses of Py_BuildValue():
* Py_BuildValue("(OOO)",a,b,c) --> PyTuple_Pack(3,a,b,c) * Py_BuildValue("()",a) --> PyTuple_New(0) * Py_BuildValue("O", a) --> Py_INCREF(a)
This commit is contained in:
parent
cb2da43db8
commit
8ae4689657
25 changed files with 71 additions and 75 deletions
|
@ -323,7 +323,7 @@ builtin_coerce(PyObject *self, PyObject *args)
|
|||
return NULL;
|
||||
if (PyNumber_Coerce(&v, &w) < 0)
|
||||
return NULL;
|
||||
res = Py_BuildValue("(OO)", v, w);
|
||||
res = PyTuple_Pack(2, v, w);
|
||||
Py_DECREF(v);
|
||||
Py_DECREF(w);
|
||||
return res;
|
||||
|
@ -2185,7 +2185,7 @@ filtertuple(PyObject *func, PyObject *tuple)
|
|||
good = item;
|
||||
}
|
||||
else {
|
||||
PyObject *arg = Py_BuildValue("(O)", item);
|
||||
PyObject *arg = PyTuple_Pack(1, item);
|
||||
if (arg == NULL) {
|
||||
Py_DECREF(item);
|
||||
goto Fail_1;
|
||||
|
@ -2252,7 +2252,7 @@ filterstring(PyObject *func, PyObject *strobj)
|
|||
ok = 1;
|
||||
} else {
|
||||
PyObject *arg, *good;
|
||||
arg = Py_BuildValue("(O)", item);
|
||||
arg = PyTuple_Pack(1, item);
|
||||
if (arg == NULL) {
|
||||
Py_DECREF(item);
|
||||
goto Fail_1;
|
||||
|
@ -2346,7 +2346,7 @@ filterunicode(PyObject *func, PyObject *strobj)
|
|||
if (func == Py_None) {
|
||||
ok = 1;
|
||||
} else {
|
||||
arg = Py_BuildValue("(O)", item);
|
||||
arg = PyTuple_Pack(1, item);
|
||||
if (arg == NULL) {
|
||||
Py_DECREF(item);
|
||||
goto Fail_1;
|
||||
|
|
|
@ -1473,7 +1473,7 @@ eval_frame(PyFrameObject *f)
|
|||
x = NULL;
|
||||
}
|
||||
if (err == 0) {
|
||||
x = Py_BuildValue("(O)", v);
|
||||
x = PyTuple_Pack(1, v);
|
||||
if (x == NULL)
|
||||
err = -1;
|
||||
}
|
||||
|
@ -1981,7 +1981,7 @@ eval_frame(PyFrameObject *f)
|
|||
break;
|
||||
}
|
||||
u = TOP();
|
||||
w = Py_BuildValue("(OOOO)",
|
||||
w = PyTuple_Pack(4,
|
||||
w,
|
||||
f->f_globals,
|
||||
f->f_locals == NULL ?
|
||||
|
@ -2999,7 +2999,7 @@ call_exc_trace(Py_tracefunc func, PyObject *self, PyFrameObject *f)
|
|||
value = Py_None;
|
||||
Py_INCREF(value);
|
||||
}
|
||||
arg = Py_BuildValue("(OOO)", type, value, traceback);
|
||||
arg = PyTuple_Pack(3, type, value, traceback);
|
||||
if (arg == NULL) {
|
||||
PyErr_Restore(type, value, traceback);
|
||||
return;
|
||||
|
|
|
@ -610,7 +610,7 @@ com_error(struct compiling *c, PyObject *exc, char *msg)
|
|||
Py_None, line);
|
||||
if (t == NULL)
|
||||
goto exit;
|
||||
w = Py_BuildValue("(OO)", v, t);
|
||||
w = PyTuple_Pack(2, v, t);
|
||||
if (w == NULL)
|
||||
goto exit;
|
||||
PyErr_SetObject(exc, w);
|
||||
|
@ -969,7 +969,7 @@ com_add(struct compiling *c, PyObject *list, PyObject *dict, PyObject *v)
|
|||
PyObject *w, *t, *np=NULL;
|
||||
long n;
|
||||
|
||||
t = Py_BuildValue("(OO)", v, v->ob_type);
|
||||
t = PyTuple_Pack(2, v, v->ob_type);
|
||||
if (t == NULL)
|
||||
goto fail;
|
||||
w = PyDict_GetItem(dict, t);
|
||||
|
|
|
@ -159,13 +159,13 @@ PyErr_NormalizeException(PyObject **exc, PyObject **val, PyObject **tb)
|
|||
PyObject *args, *res;
|
||||
|
||||
if (value == Py_None)
|
||||
args = Py_BuildValue("()");
|
||||
args = PyTuple_New(0);
|
||||
else if (PyTuple_Check(value)) {
|
||||
Py_INCREF(value);
|
||||
args = value;
|
||||
}
|
||||
else
|
||||
args = Py_BuildValue("(O)", value);
|
||||
args = PyTuple_Pack(1, value);
|
||||
|
||||
if (args == NULL)
|
||||
goto finally;
|
||||
|
@ -560,7 +560,7 @@ PyErr_NewException(char *name, PyObject *base, PyObject *dict)
|
|||
classname = PyString_FromString(dot+1);
|
||||
if (classname == NULL)
|
||||
goto failure;
|
||||
bases = Py_BuildValue("(O)", base);
|
||||
bases = PyTuple_Pack(1, base);
|
||||
if (bases == NULL)
|
||||
goto failure;
|
||||
result = PyClass_New(bases, dict, classname);
|
||||
|
|
|
@ -1821,7 +1821,7 @@ _PyExc_Init(void)
|
|||
}
|
||||
|
||||
/* Now we need to pre-allocate a MemoryError instance */
|
||||
args = Py_BuildValue("()");
|
||||
args = PyTuple_New(0);
|
||||
if (!args ||
|
||||
!(PyExc_MemoryErrorInst = PyEval_CallObject(PyExc_MemoryError, args)))
|
||||
{
|
||||
|
|
|
@ -1037,7 +1037,7 @@ PyErr_PrintEx(int set_sys_last_vars)
|
|||
}
|
||||
hook = PySys_GetObject("excepthook");
|
||||
if (hook) {
|
||||
PyObject *args = Py_BuildValue("(OOO)",
|
||||
PyObject *args = PyTuple_Pack(3,
|
||||
exception, v ? v : Py_None, tb ? tb : Py_None);
|
||||
PyObject *result = PyEval_CallObject(hook, args);
|
||||
if (result == NULL) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue