summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2003-10-12 19:09:37 (GMT)
committerRaymond Hettinger <python@rcn.com>2003-10-12 19:09:37 (GMT)
commit8ae468965700fd9900efc28bff8fa2015dae2bef (patch)
tree1f3545b2d2a3ad8b7d5692a7f84daa88d850b29c /Python
parentcb2da43db8943e9e7b1d900bce1d6416339d6f64 (diff)
downloadcpython-8ae468965700fd9900efc28bff8fa2015dae2bef.zip
cpython-8ae468965700fd9900efc28bff8fa2015dae2bef.tar.gz
cpython-8ae468965700fd9900efc28bff8fa2015dae2bef.tar.bz2
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)
Diffstat (limited to 'Python')
-rw-r--r--Python/bltinmodule.c8
-rw-r--r--Python/ceval.c6
-rw-r--r--Python/compile.c4
-rw-r--r--Python/errors.c6
-rw-r--r--Python/exceptions.c2
-rw-r--r--Python/pythonrun.c2
6 files changed, 14 insertions, 14 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 5e74929..29804f5 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -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;
diff --git a/Python/ceval.c b/Python/ceval.c
index 035520a..e6b7424 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -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;
diff --git a/Python/compile.c b/Python/compile.c
index 73d9742..02c7873 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -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);
diff --git a/Python/errors.c b/Python/errors.c
index a40844e..1788cdd 100644
--- a/Python/errors.c
+++ b/Python/errors.c
@@ -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);
diff --git a/Python/exceptions.c b/Python/exceptions.c
index d489aa6..4642046 100644
--- a/Python/exceptions.c
+++ b/Python/exceptions.c
@@ -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)))
{
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 018400c..21c2cac 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -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) {