Skip to content

Commit 9a75d56

Browse files
authored
gh-118379: Use PyTuple_Pack instead of Py_BuildValue if possible (GH-118381)
1 parent 17a8af9 commit 9a75d56

File tree

6 files changed

+9
-9
lines changed

6 files changed

+9
-9
lines changed

Modules/_decimal/_decimal.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -4287,7 +4287,7 @@ nm_mpd_qdivmod(PyObject *v, PyObject *w)
42874287
return NULL;
42884288
}
42894289

4290-
ret = Py_BuildValue("(OO)", q, r);
4290+
ret = PyTuple_Pack(2, q, r);
42914291
Py_DECREF(r);
42924292
Py_DECREF(q);
42934293
return ret;
@@ -5312,7 +5312,7 @@ ctx_mpd_qdivmod(PyObject *context, PyObject *args)
53125312
return NULL;
53135313
}
53145314

5315-
ret = Py_BuildValue("(OO)", q, r);
5315+
ret = PyTuple_Pack(2, q, r);
53165316
Py_DECREF(r);
53175317
Py_DECREF(q);
53185318
return ret;

Modules/_testbuffer.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1217,7 +1217,7 @@ init_ndbuf(PyObject *items, PyObject *shape, PyObject *strides,
12171217

12181218
/* convert scalar to list */
12191219
if (ndim == 0) {
1220-
items = Py_BuildValue("(O)", items);
1220+
items = PyTuple_Pack(1, items);
12211221
if (items == NULL)
12221222
return NULL;
12231223
}

Modules/_testcapimodule.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -2475,7 +2475,7 @@ get_basic_static_type(PyObject *self, PyObject *args)
24752475
PyTypeObject *cls = &BasicStaticTypes[num_basic_static_types_used++];
24762476

24772477
if (base != NULL) {
2478-
cls->tp_bases = Py_BuildValue("(O)", base);
2478+
cls->tp_bases = PyTuple_Pack(1, base);
24792479
if (cls->tp_bases == NULL) {
24802480
return NULL;
24812481
}
@@ -3474,7 +3474,7 @@ typedef struct {
34743474
static PyObject *
34753475
ipowType_ipow(PyObject *self, PyObject *other, PyObject *mod)
34763476
{
3477-
return Py_BuildValue("OO", other, mod);
3477+
return PyTuple_Pack(2, other, mod);
34783478
}
34793479

34803480
static PyNumberMethods ipowType_as_number = {

Modules/_testclinic.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1243,7 +1243,7 @@ _testclinic_TestClass_get_defining_class_arg_impl(PyObject *self,
12431243
PyObject *arg)
12441244
/*[clinic end generated code: output=fe7e49d96cbb7718 input=d1b83d3b853af6d9]*/
12451245
{
1246-
return Py_BuildValue("(OO)", cls, arg);
1246+
return PyTuple_Pack(2, cls, arg);
12471247
}
12481248

12491249
static struct PyMethodDef test_class_methods[] = {

Modules/posixmodule.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -5500,7 +5500,7 @@ os__path_splitroot_ex_impl(PyObject *module, PyObject *path)
55005500
if (tail == NULL) {
55015501
goto exit;
55025502
}
5503-
result = Py_BuildValue("(OOO)", drv, root, tail);
5503+
result = PyTuple_Pack(3, drv, root, tail);
55045504
exit:
55055505
PyMem_Free(buffer);
55065506
Py_XDECREF(drv);

Python/errors.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -632,8 +632,8 @@ _PyErr_StackItemToExcInfoTuple(_PyErr_StackItem *err_info)
632632
PyObject *exc_type = get_exc_type(exc_value);
633633
PyObject *exc_traceback = get_exc_traceback(exc_value);
634634

635-
return Py_BuildValue(
636-
"(OOO)",
635+
return PyTuple_Pack(
636+
3,
637637
exc_type ? exc_type : Py_None,
638638
exc_value ? exc_value : Py_None,
639639
exc_traceback ? exc_traceback : Py_None);

0 commit comments

Comments
 (0)