]> granicus.if.org Git - python/commitdiff
Simplify and speedup uses of Py_BuildValue():
authorRaymond Hettinger <python@rcn.com>
Sun, 12 Oct 2003 19:09:37 +0000 (19:09 +0000)
committerRaymond Hettinger <python@rcn.com>
Sun, 12 Oct 2003 19:09:37 +0000 (19:09 +0000)
* 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)

25 files changed:
Modules/_sre.c
Modules/almodule.c
Modules/arraymodule.c
Modules/cPickle.c
Modules/cStringIO.c
Modules/datetimemodule.c
Modules/flmodule.c
Modules/mathmodule.c
Modules/posixmodule.c
Modules/pyexpat.c
Modules/regexmodule.c
Modules/selectmodule.c
Modules/socketmodule.c
Modules/svmodule.c
Modules/symtablemodule.c
Objects/classobject.c
Objects/complexobject.c
Objects/fileobject.c
Objects/typeobject.c
Python/bltinmodule.c
Python/ceval.c
Python/compile.c
Python/errors.c
Python/exceptions.c
Python/pythonrun.c

index a8a97748b197372a18d4222f2c25cedc2ec5dca9..5490bdc5bddfda717d3cdb88b2bce95fc55c1a92 100644 (file)
@@ -1907,7 +1907,7 @@ deepcopy(PyObject** object, PyObject* memo)
 
     copy = call(
         "copy", "deepcopy",
-        Py_BuildValue("OO", *object, memo)
+        PyTuple_Pack(2, *object, memo)
         );
     if (!copy)
         return 0;
@@ -1968,7 +1968,7 @@ join_list(PyObject* list, PyObject* pattern)
 #else
     result = call(
         "string", "join",
-        Py_BuildValue("OO", list, joiner)
+        PyTuple_Pack(2, list, joiner)
         );
 #endif
     Py_DECREF(joiner);
@@ -2255,7 +2255,7 @@ pattern_subx(PatternObject* self, PyObject* template, PyObject* string,
             /* not a literal; hand it over to the template compiler */
             filter = call(
                 SRE_MODULE, "_subx",
-                Py_BuildValue("OO", self, template)
+                PyTuple_Pack(2, self, template)
                 );
             if (!filter)
                 return NULL;
@@ -2321,7 +2321,7 @@ pattern_subx(PatternObject* self, PyObject* template, PyObject* string,
             match = pattern_new_match(self, &state, 1);
             if (!match)
                 goto error;
-            args = Py_BuildValue("(O)", match);
+            args = PyTuple_Pack(1, match);
             if (!args) {
                 Py_DECREF(match);
                 goto error;
@@ -2610,7 +2610,7 @@ match_expand(MatchObject* self, PyObject* args)
     /* delegate to Python code */
     return call(
         SRE_MODULE, "_expand",
-        Py_BuildValue("OOO", self->pattern, self, template)
+        PyTuple_Pack(3, self->pattern, self, template)
         );
 }
 
index 64306002729f8476304db662e7d4eae503734159..12b265e90ece7d82998e328074a12902ed016171 100644 (file)
@@ -901,7 +901,7 @@ alp_GetFrameTime(alpobject *self, PyObject *args)
                Py_XDECREF(v1);
                return NULL;
        }
-       ret = Py_BuildValue("(OO)", v0, v1);
+       ret = PyTuple_Pack(2, v0, v1);
        Py_DECREF(v0);
        Py_DECREF(v1);
        return ret;
index 228c8f4c6989a31ca08cb8f6db74ce40a31dbf43..938292734b52f15ec4718e2655d7e47cea01edf7 100644 (file)
@@ -1770,7 +1770,7 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
                                        Py_DECREF(v);
                                }
                        } else if (initial != NULL && PyString_Check(initial)) {
-                               PyObject *t_initial = Py_BuildValue("(O)",
+                               PyObject *t_initial = PyTuple_Pack(1,
                                                                    initial);
                                PyObject *v =
                                        array_fromstring((arrayobject *)a,
index c452dc126d0d68d7019b1fe261086c1f2ee4e350..4961c3b36beb893c19ad4d78eb3e256eafe4986c 100644 (file)
@@ -3627,7 +3627,7 @@ Instance_New(PyObject *cls, PyObject *args)
                PyObject *tp, *v, *tb;
 
                PyErr_Fetch(&tp, &v, &tb);
-               if ((r=Py_BuildValue("OOO",v,cls,args))) {
+               if ((r=PyTuple_Pack(3,v,cls,args))) {
                        Py_XDECREF(v);
                        v=r;
                }
index ac84ab0c51b01f5d4a6039449d85c92991852d14..ee11878730c0357965053f3584b7a24b369f1069 100644 (file)
@@ -439,7 +439,7 @@ O_writelines(Oobject *self, PyObject *args) {
         tmp = PyObject_CallFunction(joiner, "O", args);
         UNLESS (tmp) return NULL;
 
-        args = Py_BuildValue("(O)", tmp);
+        args = PyTuple_Pack(1, tmp);
         Py_DECREF(tmp);
         UNLESS (args) return NULL;
 
index d8aed17f32e9675734584988efe784ddff04067c..0d553d4e752e20d57e5c9eedf3dc4a7a846bca38 100644 (file)
@@ -3372,9 +3372,9 @@ time_getstate(PyDateTime_Time *self)
                                                _PyDateTime_TIME_DATASIZE);
        if (basestate != NULL) {
                if (! HASTZINFO(self) || self->tzinfo == Py_None)
-                       result = Py_BuildValue("(O)", basestate);
+                       result = PyTuple_Pack(1, basestate);
                else
-                       result = Py_BuildValue("OO", basestate, self->tzinfo);
+                       result = PyTuple_Pack(2, basestate, self->tzinfo);
                Py_DECREF(basestate);
        }
        return result;
@@ -4350,9 +4350,9 @@ datetime_getstate(PyDateTime_DateTime *self)
                                          _PyDateTime_DATETIME_DATASIZE);
        if (basestate != NULL) {
                if (! HASTZINFO(self) || self->tzinfo == Py_None)
-                       result = Py_BuildValue("(O)", basestate);
+                       result = PyTuple_Pack(1, basestate);
                else
-                       result = Py_BuildValue("OO", basestate, self->tzinfo);
+                       result = PyTuple_Pack(2, basestate, self->tzinfo);
                Py_DECREF(basestate);
        }
        return result;
index 2fe118d629f44cb462796deecc373fb3f951c8e9..1ae2dc85bbd260b4d24f806792a371bac2530dc1 100644 (file)
@@ -1714,7 +1714,7 @@ forms_do_or_check_forms(PyObject *dummy, FL_OBJECT *(*func)(void))
                        Py_INCREF(g);
                        return ((PyObject *) g);
                }
-               arg = Py_BuildValue("(OO)", (PyObject *)g, g->ob_callback_arg);
+               arg = PyTuple_Pack(2, (PyObject *)g, g->ob_callback_arg);
                if (arg == NULL)
                        return NULL;
                res = PyEval_CallObject(g->ob_callback, arg);
index 44c6abbd5368838d6b564b657b01a1ece0ea103a..54152538aad7e82599b595ff6eac733d2ba53610 100644 (file)
@@ -259,23 +259,19 @@ math_log(PyObject *self, PyObject *args)
        if (base == NULL)
                return loghelper(args, log, "d:log", arg);
 
-       newargs = PyTuple_New(1);
+       newargs = PyTuple_Pack(1, arg);
        if (newargs == NULL)
                return NULL;
-       Py_INCREF(arg);
-       PyTuple_SET_ITEM(newargs, 0, arg);
        num = loghelper(newargs, log, "d:log", arg);
        Py_DECREF(newargs);
        if (num == NULL)
                return NULL;
 
-       newargs = PyTuple_New(1);
+       newargs = PyTuple_Pack(1, base);
        if (newargs == NULL) {
                Py_DECREF(num);
                return NULL;
        }
-       Py_INCREF(base);
-       PyTuple_SET_ITEM(newargs, 0, base);
        den = loghelper(newargs, log, "d:log", base);
        Py_DECREF(newargs);
        if (den == NULL) {
index fa8215a468e018b1df518b32728c50bfb7d263f3..f5787c393eea9f8f2a2db6ab2603e75b3de467d0 100644 (file)
@@ -3376,10 +3376,10 @@ _PyPopen(char *cmdstring, int mode, int n, int bufsize)
        {
                if ((p_f[2] = PyFile_FromFile(p_s[2], cmdstring, rd_mode, _PyPclose)) != NULL)
                        PyFile_SetBufSize(p_f[0], bufsize);
-               f = Py_BuildValue("OOO", p_f[0], p_f[1], p_f[2]);
+               f = PyTuple_Pack(3, p_f[0], p_f[1], p_f[2]);
        }
        else
-               f = Py_BuildValue("OO", p_f[0], p_f[1]);
+               f = PyTuple_Pack(2, p_f[0], p_f[1]);
 
        /*
         * Insert the files we've created into the process dictionary
@@ -4069,7 +4069,7 @@ _PyPopen(char *cmdstring, int mode, int n)
                 if (n != 4)
                         CloseHandle(hChildStderrRdDup);
 
-                f = Py_BuildValue("OO",p1,p2);
+                f = PyTuple_Pack(2,p1,p2);
                 Py_XDECREF(p1);
                 Py_XDECREF(p2);
                 file_count = 2;
@@ -4101,7 +4101,7 @@ _PyPopen(char *cmdstring, int mode, int n)
                 PyFile_SetBufSize(p1, 0);
                 PyFile_SetBufSize(p2, 0);
                 PyFile_SetBufSize(p3, 0);
-                f = Py_BuildValue("OOO",p1,p2,p3);
+                f = PyTuple_Pack(3,p1,p2,p3);
                 Py_XDECREF(p1);
                 Py_XDECREF(p2);
                 Py_XDECREF(p3);
index 6c408938ffca11508cbc001bc9e8302cfc3a699b..c1662fc296d1eafedc8461747e784685f59c967a 100644 (file)
@@ -336,7 +336,7 @@ trace_frame_exc(PyThreadState *tstate, 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 0;
index db541612e282787d3b2a0675833991efa3a5e408..9f84032e4d46377c453bf3edc6ce1a2baeb3227c 100644 (file)
@@ -551,7 +551,7 @@ static PyObject *cache_prog;
 static int
 update_cache(PyObject *pat)
 {
-       PyObject *tuple = Py_BuildValue("(O)", pat);
+       PyObject *tuple = PyTuple_Pack(1, pat);
        int status = 0;
 
        if (!tuple)
index 2b2d6a90e805441701c9fec0976b345c3b65bccb..989885a255865f58b120a1ac06469f223ee5bbf9 100644 (file)
@@ -284,7 +284,7 @@ select_select(PyObject *self, PyObject *args)
                 /* optimization */
                ifdlist = PyList_New(0);
                if (ifdlist) {
-                       ret = Py_BuildValue("OOO", ifdlist, ifdlist, ifdlist);
+                       ret = PyTuple_Pack(3, ifdlist, ifdlist, ifdlist);
                        Py_DECREF(ifdlist);
                }
        }
@@ -299,7 +299,7 @@ select_select(PyObject *self, PyObject *args)
                if (PyErr_Occurred())
                        ret = NULL;
                else
-                       ret = Py_BuildValue("OOO", ifdlist, ofdlist, efdlist);
+                       ret = PyTuple_Pack(3, ifdlist, ofdlist, efdlist);
 
                Py_DECREF(ifdlist);
                Py_DECREF(ofdlist);
index a2a692ad8eca0f41ab5ebff908ff9b1bee7ca0bc..4a2fb583e8c3047f22bc280a814b8754de1405fc 100644 (file)
@@ -1161,7 +1161,7 @@ sock_accept(PySocketSockObject *s)
        if (addr == NULL)
                goto finally;
 
-       res = Py_BuildValue("OO", sock, addr);
+       res = PyTuple_Pack(2, sock, addr);
 
 finally:
        Py_XDECREF(sock);
@@ -1911,7 +1911,7 @@ sock_recvfrom(PySocketSockObject *s, PyObject *args)
                                  addrlen)))
                goto finally;
 
-       ret = Py_BuildValue("OO", buf, addr);
+       ret = PyTuple_Pack(2, buf, addr);
 
 finally:
        Py_XDECREF(addr);
index d66f1cfe41b182f8df1cd0ec6b765059ab180d2a..9bd79686c4ecac59b9a83995c9c1bb48e32c4682 100644 (file)
@@ -157,7 +157,7 @@ svc_GetFields(captureobject *self, PyObject *args)
        if (!(f2 = PyString_FromStringAndSize(obcapture + fieldsize,
                                              fieldsize)))
                goto finally;
-       ret = Py_BuildValue("(OO)", f1, f2);
+       ret = PyTuple_Pack(2, f1, f2);
 
   finally:
        Py_XDECREF(f1);
index f605c2276c3080d574ef166c605f2e7cdd059d2d..909a404fdc5fa55d2d9fb553f2adadf85722f225 100644 (file)
@@ -31,7 +31,8 @@ symtable_symtable(PyObject *self, PyObject *args)
        st = Py_SymtableString(str, filename, start);
        if (st == NULL)
                return NULL;
-       t = Py_BuildValue("O", st->st_symbols);
+       t = st->st_symbols;
+       Py_INCREF(t);
        PyMem_Free((void *)st->st_future);
        PySymtable_Free(st);
        return t;
index 0df249de6ceafc9667409ae051c66bb435dede4c..b0e19347d44ca700dba7df60e773588e9a2642c5 100644 (file)
@@ -750,7 +750,7 @@ instance_getattr(register PyInstanceObject *inst, PyObject *name)
                if (!PyErr_ExceptionMatches(PyExc_AttributeError))
                        return NULL;
                PyErr_Clear();
-               args = Py_BuildValue("(OO)", inst, name);
+               args = PyTuple_Pack(2, inst, name);
                if (args == NULL)
                        return NULL;
                res = PyEval_CallObject(func, args);
@@ -847,9 +847,9 @@ instance_setattr(PyInstanceObject *inst, PyObject *name, PyObject *v)
        if (func == NULL)
                return instance_setattr1(inst, name, v);
        if (v == NULL)
-               args = Py_BuildValue("(OO)", inst, name);
+               args = PyTuple_Pack(2, inst, name);
        else
-               args = Py_BuildValue("(OOO)", inst, name, v);
+               args = PyTuple_Pack(3, inst, name, v);
        if (args == NULL)
                return -1;
        res = PyEval_CallObject(func, args);
@@ -1038,7 +1038,7 @@ instance_subscript(PyInstanceObject *inst, PyObject *key)
        func = instance_getattr(inst, getitemstr);
        if (func == NULL)
                return NULL;
-       arg = Py_BuildValue("(O)", key);
+       arg = PyTuple_Pack(1, key);
        if (arg == NULL) {
                Py_DECREF(func);
                return NULL;
@@ -1069,9 +1069,9 @@ instance_ass_subscript(PyInstanceObject *inst, PyObject *key, PyObject *value)
        if (func == NULL)
                return -1;
        if (value == NULL)
-               arg = Py_BuildValue("(O)", key);
+               arg = PyTuple_Pack(1, key);
        else
-               arg = Py_BuildValue("(OO)", key, value);
+               arg = PyTuple_Pack(2, key, value);
        if (arg == NULL) {
                Py_DECREF(func);
                return -1;
@@ -1281,7 +1281,7 @@ instance_contains(PyInstanceObject *inst, PyObject *member)
        if (func) {
                PyObject *res;
                int ret;
-               PyObject *arg = Py_BuildValue("(O)", member);
+               PyObject *arg = PyTuple_Pack(1, member);
                if(arg == NULL) {
                        Py_DECREF(func);
                        return -1;
@@ -1346,7 +1346,7 @@ generic_binary_op(PyObject *v, PyObject *w, char *opname)
                Py_INCREF(Py_NotImplemented);
                return Py_NotImplemented;
        }
-       args = Py_BuildValue("(O)", w);
+       args = PyTuple_Pack(1, w);
        if (args == NULL) {
                Py_DECREF(func);
                return NULL;
@@ -1389,7 +1389,7 @@ half_binop(PyObject *v, PyObject *w, char *opname, binaryfunc thisfunc,
                return generic_binary_op(v, w, opname);
        }
 
-       args = Py_BuildValue("(O)", w);
+       args = PyTuple_Pack(1, w);
        if (args == NULL) {
                Py_DECREF(coercefunc);
                return NULL;
@@ -1474,7 +1474,7 @@ instance_coerce(PyObject **pv, PyObject **pw)
                return 1;
        }
        /* Has __coerce__ method: call it */
-       args = Py_BuildValue("(O)", w);
+       args = PyTuple_Pack(1, w);
        if (args == NULL) {
                return -1;
        }
@@ -1587,7 +1587,7 @@ half_cmp(PyObject *v, PyObject *w)
                return 2;
        }
 
-       args = Py_BuildValue("(O)", w);
+       args = PyTuple_Pack(1, w);
        if (args == NULL) {
                Py_DECREF(cmp_func);
                return -2;
@@ -1747,7 +1747,7 @@ instance_pow(PyObject *v, PyObject *w, PyObject *z)
                func = PyObject_GetAttrString(v, "__pow__");
                if (func == NULL)
                        return NULL;
-               args = Py_BuildValue("(OO)", w, z);
+               args = PyTuple_Pack(2, w, z);
                if (args == NULL) {
                        Py_DECREF(func);
                        return NULL;
@@ -1786,7 +1786,7 @@ instance_ipow(PyObject *v, PyObject *w, PyObject *z)
                        PyErr_Clear();
                        return instance_pow(v, w, z);
                }
-               args = Py_BuildValue("(OO)", w, z);
+               args = PyTuple_Pack(2, w, z);
                if (args == NULL) {
                        Py_DECREF(func);
                        return NULL;
@@ -1859,7 +1859,7 @@ half_richcompare(PyObject *v, PyObject *w, int op)
                return res;
        }
 
-       args = Py_BuildValue("(O)", w);
+       args = PyTuple_Pack(1, w);
        if (args == NULL) {
                Py_DECREF(method);
                return NULL;
index 96fa33d38b52f5014e30b7861aae1793dc3b3e57..c29d48d0b934669a8782f351ea3c5ee48d7432b7 100644 (file)
@@ -439,7 +439,7 @@ complex_divmod(PyComplexObject *v, PyComplexObject *w)
        mod = c_diff(v->cval, c_prod(w->cval, div));
        d = PyComplex_FromCComplex(div);
        m = PyComplex_FromCComplex(mod);
-       z = Py_BuildValue("(OO)", d, m);
+       z = PyTuple_Pack(2, d, m);
        Py_XDECREF(d);
        Py_XDECREF(m);
        return z;
@@ -865,7 +865,7 @@ complex_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
        if (f == NULL)
                PyErr_Clear();
        else {
-               PyObject *args = Py_BuildValue("()");
+               PyObject *args = PyTuple_New(0);
                if (args == NULL)
                        return NULL;
                r = PyEval_CallObject(f, args);
index d7c9da5261d0355f555f9d50e63f8d2c56461b78..6f90fb9e84a14d97203c94065000263df30af1d4 100644 (file)
@@ -1227,7 +1227,7 @@ PyFile_GetLine(PyObject *f, int n)
                if (reader == NULL)
                        return NULL;
                if (n <= 0)
-                       args = Py_BuildValue("()");
+                       args = PyTuple_New(0);
                else
                        args = Py_BuildValue("(i)", n);
                if (args == NULL) {
@@ -2104,7 +2104,7 @@ PyFile_WriteObject(PyObject *v, PyObject *f, int flags)
                Py_DECREF(writer);
                return -1;
        }
-       args = Py_BuildValue("(O)", value);
+       args = PyTuple_Pack(1, value);
        if (args == NULL) {
                Py_DECREF(value);
                Py_DECREF(writer);
index bb498e4a4235a7c88a7dff972456a22e10f5f01a..dcb43e59e359ee9808b356a190aec0e62e351a36 100644 (file)
@@ -163,7 +163,7 @@ mro_subclasses(PyTypeObject *type, PyObject* temp)
                }
                else {
                        PyObject* tuple;
-                       tuple = Py_BuildValue("OO", subclass, old_mro);
+                       tuple = PyTuple_Pack(2, subclass, old_mro);
                        Py_DECREF(old_mro);
                        if (!tuple)
                                return -1;
@@ -258,8 +258,8 @@ type_set_bases(PyTypeObject *type, PyObject *value, void *context)
                for (i = 0; i < PyList_Size(temp); i++) {
                        PyTypeObject* cls;
                        PyObject* mro;
-                       PyArg_ParseTuple(PyList_GET_ITEM(temp, i),
-                                        "OO", &cls, &mro);
+                       PyArg_UnpackTuple(PyList_GET_ITEM(temp, i),
+                                        "", 2, 2, &cls, &mro);
                        Py_DECREF(cls->tp_mro);
                        cls->tp_mro = mro;
                        Py_INCREF(cls->tp_mro);
@@ -1606,7 +1606,7 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
 
        /* Adjust for empty tuple bases */
        if (nbases == 0) {
-               bases = Py_BuildValue("(O)", &PyBaseObject_Type);
+               bases = PyTuple_Pack(1, &PyBaseObject_Type);
                if (bases == NULL)
                        return NULL;
                nbases = 1;
@@ -1650,7 +1650,7 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
 
                /* Make it into a tuple */
                if (PyString_Check(slots))
-                       slots = Py_BuildValue("(O)", slots);
+                       slots = PyTuple_Pack(1, slots);
                else
                        slots = PySequence_Tuple(slots);
                if (slots == NULL) {
@@ -2644,8 +2644,7 @@ reduce_2(PyObject *obj)
                PyTuple_SET_ITEM(args2, i+1, v);
        }
 
-       res = Py_BuildValue("(OOOOO)",
-                           newobj, args2, state, listitems, dictitems);
+       res = PyTuple_Pack(5, newobj, args2, state, listitems, dictitems);
 
   end:
        Py_XDECREF(cls);
@@ -3142,7 +3141,7 @@ PyType_Ready(PyTypeObject *type)
                if (base == NULL)
                        bases = PyTuple_New(0);
                else
-                       bases = Py_BuildValue("(O)", base);
+                       bases = PyTuple_Pack(1, base);
                if (bases == NULL)
                        goto error;
                type->tp_bases = bases;
@@ -4127,7 +4126,7 @@ slot_sq_contains(PyObject *self, PyObject *value)
 
        func = lookup_maybe(self, "__contains__", &contains_str);
        if (func != NULL) {
-               args = Py_BuildValue("(O)", value);
+               args = PyTuple_Pack(1, value);
                if (args == NULL)
                        res = NULL;
                else {
@@ -4342,7 +4341,7 @@ half_compare(PyObject *self, PyObject *other)
                PyErr_Clear();
        }
        else {
-               args = Py_BuildValue("(O)", other);
+               args = PyTuple_Pack(1, other);
                if (args == NULL)
                        res = NULL;
                else {
@@ -4571,7 +4570,7 @@ half_richcompare(PyObject *self, PyObject *other, int op)
                Py_INCREF(Py_NotImplemented);
                return Py_NotImplemented;
        }
-       args = Py_BuildValue("(O)", other);
+       args = PyTuple_Pack(1, other);
        if (args == NULL)
                res = NULL;
        else {
index 5e74929e4ad9e81b2b9f3a5730fefc28701351d2..29804f5ede47d40845879713e87edc66c5953400 100644 (file)
@@ -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;
index 035520a593b5b14a6a9872ff2946cbb2a5276b60..e6b742499bad01d784933eb55134d0e29103c907 100644 (file)
@@ -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;
index 73d9742e1998576d1b06ab265cdca02648ee5c6b..02c7873a0741b345fc388d56349e5cf9b1113339 100644 (file)
@@ -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);
index a40844e7fe51c796b6349af2de52e22c4f8c65ca..1788cdd33f784434ece7b6c387e9fc3293ffc06c 100644 (file)
@@ -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);
index d489aa6efbe1503651274848d6312f1e88d09c8e..464204612540505e4fcae9c46c186e926a254186 100644 (file)
@@ -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)))
     {
index 018400cb9208d3e8f437e3a326e911f1ed372768..21c2cace8129bf832cf930bd6d228020ebb598a3 100644 (file)
@@ -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) {