Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Modules/_ctypes/_ctypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ bytes(cdata)
#include "pycore_unicodeobject.h" // _PyUnicode_EqualToASCIIString()
#include "pycore_pyatomic_ft_wrappers.h"
#include "pycore_object.h"
#include "pycore_tuple.h" // _PyTuple_FromPair
#ifdef MS_WIN32
# include "pycore_modsupport.h" // _PyArg_NoKeywords()
#endif
Expand Down Expand Up @@ -3511,7 +3512,7 @@ _PyCData_set(ctypes_state *st,
only it's object list. So we create a tuple, containing
b_objects list PLUS the array itself, and return that!
*/
return PyTuple_Pack(2, keep, value);
return _PyTuple_FromPair(keep, value);
}
PyErr_Format(PyExc_TypeError,
"incompatible types, %s instance instead of %s instance",
Expand Down Expand Up @@ -5332,8 +5333,7 @@ PyCArrayType_from_ctype(ctypes_state *st, PyObject *itemtype, Py_ssize_t length)
len = PyLong_FromSsize_t(length);
if (len == NULL)
return NULL;
key = PyTuple_Pack(2, itemtype, len);
Py_DECREF(len);
key = _PyTuple_FromPairSteal(Py_NewRef(itemtype), len);
if (!key)
return NULL;

Expand Down
9 changes: 5 additions & 4 deletions Modules/_datetimemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "pycore_long.h" // _PyLong_GetOne()
#include "pycore_object.h" // _PyObject_Init()
#include "pycore_time.h" // _PyTime_ObjectToTime_t()
#include "pycore_tuple.h" // _PyTuple_FromPair
#include "pycore_unicodeobject.h" // _PyUnicode_Copy()
#include "pycore_initconfig.h" // _PyStatus_OK()
#include "pycore_pyatomic_ft_wrappers.h"
Expand Down Expand Up @@ -2692,7 +2693,7 @@ delta_divmod(PyObject *left, PyObject *right)
Py_DECREF(divmod);
return NULL;
}
result = PyTuple_Pack(2, PyTuple_GET_ITEM(divmod, 0), delta);
result = _PyTuple_FromPair(PyTuple_GET_ITEM(divmod, 0), delta);
Py_DECREF(delta);
Py_DECREF(divmod);
return result;
Expand Down Expand Up @@ -4496,7 +4497,7 @@ timezone_getinitargs(PyObject *op, PyObject *Py_UNUSED(dummy))
PyDateTime_TimeZone *self = PyTimeZone_CAST(op);
if (self->name == NULL)
return PyTuple_Pack(1, self->offset);
return PyTuple_Pack(2, self->offset, self->name);
return _PyTuple_FromPair(self->offset, self->name);
}

static PyMethodDef timezone_methods[] = {
Expand Down Expand Up @@ -5247,7 +5248,7 @@ time_getstate(PyDateTime_Time *self, int proto)
if (! HASTZINFO(self) || self->tzinfo == Py_None)
result = PyTuple_Pack(1, basestate);
else
result = PyTuple_Pack(2, basestate, self->tzinfo);
result = _PyTuple_FromPair(basestate, self->tzinfo);
Py_DECREF(basestate);
}
return result;
Expand Down Expand Up @@ -7169,7 +7170,7 @@ datetime_getstate(PyDateTime_DateTime *self, int proto)
if (! HASTZINFO(self) || self->tzinfo == Py_None)
result = PyTuple_Pack(1, basestate);
else
result = PyTuple_Pack(2, basestate, self->tzinfo);
result = _PyTuple_FromPair(basestate, self->tzinfo);
Py_DECREF(basestate);
}
return result;
Expand Down
6 changes: 2 additions & 4 deletions Modules/_interpretersmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "pycore_pybuffer.h" // _PyBuffer_ReleaseInInterpreterAndRawFree()
#include "pycore_pylifecycle.h" // _PyInterpreterConfig_AsDict()
#include "pycore_pystate.h" // _PyInterpreterState_IsRunningMain()
#include "pycore_tuple.h" // _PyTuple_FromPairSteal

#include "marshal.h" // PyMarshal_ReadObjectFromString()

Expand Down Expand Up @@ -796,10 +797,7 @@ get_summary(PyInterpreterState *interp)
Py_DECREF(idobj);
return NULL;
}
PyObject *res = PyTuple_Pack(2, idobj, whenceobj);
Py_DECREF(idobj);
Py_DECREF(whenceobj);
return res;
return _PyTuple_FromPairSteal(idobj, whenceobj);
}


Expand Down
3 changes: 2 additions & 1 deletion Modules/_ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "pycore_long.h" // _PyLong_UnsignedLongLong_Converter()
#include "pycore_pyerrors.h" // _PyErr_ChainExceptions1()
#include "pycore_time.h" // _PyDeadline_Init()
#include "pycore_tuple.h" // _PyTuple_FromPair

/* Include symbols from _socket module */
#include "socketmodule.h"
Expand Down Expand Up @@ -6796,7 +6797,7 @@ do { \
}

/* ssl.CertificateError used to be a subclass of ValueError */
bases = PyTuple_Pack(2, state->PySSLErrorObject, PyExc_ValueError);
bases = _PyTuple_FromPair(state->PySSLErrorObject, PyExc_ValueError);
if (bases == NULL) {
goto error;
}
Expand Down
18 changes: 5 additions & 13 deletions Modules/cjkcodecs/multibytecodec.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "multibytecodec.h"
#include "clinic/multibytecodec.c.h"
#include "pycore_tuple.h" // _PyTuple_FromPairSteal

#include <stddef.h> // offsetof()

Expand Down Expand Up @@ -102,26 +103,17 @@ static PyObject *multibytecodec_encode(const MultibyteCodec *,
static PyObject *
make_tuple(PyObject *object, Py_ssize_t len)
{
PyObject *v, *w;

if (object == NULL)
return NULL;

v = PyTuple_New(2);
if (v == NULL) {
Py_DECREF(object);
if (object == NULL) {
return NULL;
}
PyTuple_SET_ITEM(v, 0, object);

w = PyLong_FromSsize_t(len);
PyObject* w = PyLong_FromSsize_t(len);
Comment thread
sergey-miryanov marked this conversation as resolved.
Outdated
if (w == NULL) {
Py_DECREF(v);
Py_DECREF(object);
return NULL;
}
PyTuple_SET_ITEM(v, 1, w);

return v;
return _PyTuple_FromPairSteal(object, w);
}

static PyObject *
Expand Down
25 changes: 9 additions & 16 deletions Modules/overlapped.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#endif

#include "Python.h"
#include "pycore_tuple.h" // _PyTuple_FromPairSteal

#define WINDOWS_LEAN_AND_MEAN
#include <winsock2.h>
Expand Down Expand Up @@ -964,18 +965,14 @@ _overlapped_Overlapped_getresult_impl(OverlappedObject *self, BOOL wait)
}

// The result is a two item tuple: (message, address)
self->read_from.result = PyTuple_New(2);
// first item: message
// second item: address
Comment thread
sergey-miryanov marked this conversation as resolved.
Outdated
self->read_from.result = _PyTuple_FromPairSteal(
Py_NewRef(self->read_from.allocated_buffer), addr);
if (self->read_from.result == NULL) {
Py_CLEAR(addr);
return NULL;
}

// first item: message
PyTuple_SET_ITEM(self->read_from.result, 0,
Py_NewRef(self->read_from.allocated_buffer));
// second item: address
PyTuple_SET_ITEM(self->read_from.result, 1, addr);

return Py_NewRef(self->read_from.result);
case TYPE_READ_FROM_INTO:
// unparse the address
Expand All @@ -987,18 +984,14 @@ _overlapped_Overlapped_getresult_impl(OverlappedObject *self, BOOL wait)
}

// The result is a two item tuple: (number of bytes read, address)
self->read_from_into.result = PyTuple_New(2);
// first item: number of bytes read
// second item: address
Comment thread
sergey-miryanov marked this conversation as resolved.
Outdated
self->read_from_into.result = _PyTuple_FromPairSteal(
PyLong_FromUnsignedLong((unsigned long)transferred), addr);
Comment thread
sergey-miryanov marked this conversation as resolved.
Outdated
if (self->read_from_into.result == NULL) {
Py_CLEAR(addr);
return NULL;
}

// first item: number of bytes read
PyTuple_SET_ITEM(self->read_from_into.result, 0,
PyLong_FromUnsignedLong((unsigned long)transferred));
// second item: address
PyTuple_SET_ITEM(self->read_from_into.result, 1, addr);

return Py_NewRef(self->read_from_into.result);
default:
return PyLong_FromUnsignedLong((unsigned long) transferred);
Expand Down
5 changes: 2 additions & 3 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "pycore_pystate.h" // _PyInterpreterState_GET()
#include "pycore_signal.h" // Py_NSIG
#include "pycore_time.h" // _PyLong_FromTime_t()
#include "pycore_tuple.h" // _PyTuple_FromPairSteal
#include "pycore_typeobject.h" // _PyType_AddMethod()

#ifndef MS_WINDOWS
Expand Down Expand Up @@ -11288,9 +11289,7 @@ build_itimerspec(const struct itimerspec* curr_value)
Py_DECREF(value);
return NULL;
}
PyObject *tuple = PyTuple_Pack(2, value, interval);
Py_DECREF(interval);
Py_DECREF(value);
PyObject *tuple = _PyTuple_FromPairSteal(value, interval);
return tuple;
Comment thread
sergey-miryanov marked this conversation as resolved.
Outdated
}

Expand Down
5 changes: 2 additions & 3 deletions Modules/selectmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "Python.h"
#include "pycore_fileutils.h" // _Py_set_inheritable()
#include "pycore_time.h" // _PyTime_FromSecondsObject()
#include "pycore_tuple.h" // _PyTuple_FromPairSteal

#include <stdbool.h>
#include <stddef.h> // offsetof()
Expand Down Expand Up @@ -1075,9 +1076,7 @@ select_devpoll_poll_impl(devpollObject *self, PyObject *timeout_obj)
Py_XDECREF(num2);
goto error;
}
value = PyTuple_Pack(2, num1, num2);
Py_DECREF(num1);
Py_DECREF(num2);
value = _PyTuple_FromPairSteal(num1, num2);
if (value == NULL)
goto error;
PyList_SET_ITEM(result_list, i, value);
Expand Down
24 changes: 7 additions & 17 deletions Modules/signalmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "pycore_pystate.h" // _PyThreadState_GET()
#include "pycore_signal.h" // _Py_RestoreSignals()
#include "pycore_time.h" // _PyTime_FromSecondsObject()
#include "pycore_tuple.h" // _PyTuple_FromPairSteal

#ifndef MS_WINDOWS
# include "posixmodule.h" // _PyLong_FromUid()
Expand Down Expand Up @@ -193,27 +194,16 @@
static PyObject *
itimer_retval(struct itimerval *iv)
{
PyObject *r, *v;

r = PyTuple_New(2);
if (r == NULL)
return NULL;

if(!(v = PyFloat_FromDouble(double_from_timeval(&iv->it_value)))) {
Py_DECREF(r);
PyObject *value = PyFloat_FromDouble(double_from_timeval(&iv->it_value))
if (value == NULL) {

Check failure on line 198 in Modules/signalmodule.c

View workflow job for this annotation

GitHub Actions / Hypothesis tests on Ubuntu

expected ‘,’ or ‘;’ before ‘if’

Check failure on line 198 in Modules/signalmodule.c

View workflow job for this annotation

GitHub Actions / Ubuntu (free-threading) / build and test (ubuntu-24.04)

expected ‘,’ or ‘;’ before ‘if’

Check failure on line 198 in Modules/signalmodule.c

View workflow job for this annotation

GitHub Actions / Cross build Linux

expected ‘,’ or ‘;’ before ‘if’

Check failure on line 198 in Modules/signalmodule.c

View workflow job for this annotation

GitHub Actions / Ubuntu (free-threading) / build and test (ubuntu-24.04-arm)

expected ‘,’ or ‘;’ before ‘if’

Check failure on line 198 in Modules/signalmodule.c

View workflow job for this annotation

GitHub Actions / Ubuntu / build and test (ubuntu-24.04-arm)

expected ‘,’ or ‘;’ before ‘if’

Check failure on line 198 in Modules/signalmodule.c

View workflow job for this annotation

GitHub Actions / Ubuntu / build and test (ubuntu-24.04)

expected ‘,’ or ‘;’ before ‘if’

Check failure on line 198 in Modules/signalmodule.c

View workflow job for this annotation

GitHub Actions / Address sanitizer (ubuntu-24.04)

expected ‘,’ or ‘;’ before ‘if’

Check failure on line 198 in Modules/signalmodule.c

View workflow job for this annotation

GitHub Actions / Ubuntu (bolt) / build and test (ubuntu-24.04)

expected ‘,’ or ‘;’ before ‘if’
return NULL;
}

PyTuple_SET_ITEM(r, 0, v);

if(!(v = PyFloat_FromDouble(double_from_timeval(&iv->it_interval)))) {
Py_DECREF(r);
PyObject *interval = PyFloat_FromDouble(double_from_timeval(&iv->it_interval));
if (interval == NULL) {
Py_DECREF(value);
return NULL;
}

PyTuple_SET_ITEM(r, 1, v);

return r;
return _PyTuple_FromPairSteal(value, interval);
}
#endif

Expand Down
Loading
Loading