#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
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",
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;
#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"
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;
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[] = {
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;
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;
#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()
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);
}
#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"
}
/* 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;
}
#include "multibytecodec.h"
#include "clinic/multibytecodec.c.h"
+#include "pycore_tuple.h" // _PyTuple_FromPairSteal
#include <stddef.h> // offsetof()
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);
- if (w == NULL) {
- Py_DECREF(v);
+ PyObject* len_obj = PyLong_FromSsize_t(len);
+ if (len_obj == NULL) {
+ Py_DECREF(object);
return NULL;
}
- PyTuple_SET_ITEM(v, 1, w);
- return v;
+ return _PyTuple_FromPairSteal(object, len_obj);
}
static PyObject *
#endif
#include "Python.h"
+#include "pycore_tuple.h" // _PyTuple_FromPairSteal
#define WINDOWS_LEAN_AND_MEAN
#include <winsock2.h>
BOOL ret;
DWORD err;
PyObject *addr;
+ PyObject *transferred_obj;
if (self->type == TYPE_NONE) {
PyErr_SetString(PyExc_ValueError, "operation not yet attempted");
}
// The result is a two item tuple: (message, address)
- self->read_from.result = PyTuple_New(2);
+ 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
return NULL;
}
+ transferred_obj = PyLong_FromUnsignedLong((unsigned long)transferred);
+ if (transferred_obj == NULL) {
+ Py_DECREF(addr);
+ return NULL;
+ }
+
// The result is a two item tuple: (number of bytes read, address)
- self->read_from_into.result = PyTuple_New(2);
+ self->read_from_into.result = _PyTuple_FromPairSteal(
+ transferred_obj, addr);
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);
#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
Py_DECREF(value);
return NULL;
}
- PyObject *tuple = PyTuple_Pack(2, value, interval);
- Py_DECREF(interval);
- Py_DECREF(value);
- return tuple;
+ return _PyTuple_FromPairSteal(value, interval);
}
static PyObject *
#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()
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);
#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()
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) {
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
#include "pycore_moduleobject.h" // _PyModule_GetState
#include "pycore_object.h" // _PyObject_VisitType()
#include "pycore_time.h" // _PyTime_AsMilliseconds()
+#include "pycore_tuple.h" // _PyTuple_FromPairSteal
#include "pycore_pystate.h" // _Py_AssertHoldsTstate()
#ifdef _Py_MEMORY_SANITIZER
socklen_t addrlen;
PyObject *sock = NULL;
PyObject *addr = NULL;
- PyObject *res = NULL;
struct sock_accept ctx;
if (!getsockaddrlen(s, &addrlen))
if (!SetHandleInformation((HANDLE)newfd, HANDLE_FLAG_INHERIT, 0)) {
PyErr_SetFromWindowsErr(0);
SOCKETCLOSE(newfd);
- goto finally;
+ goto error;
}
#endif
#else
{
if (_Py_set_inheritable(newfd, 0, NULL) < 0) {
SOCKETCLOSE(newfd);
- goto finally;
+ goto error;
}
}
#endif
sock = PyLong_FromSocket_t(newfd);
if (sock == NULL) {
SOCKETCLOSE(newfd);
- goto finally;
+ goto error;
}
addr = makesockaddr(get_sock_fd(s), SAS2SA(&addrbuf),
addrlen, s->sock_proto);
if (addr == NULL)
- goto finally;
+ goto error;
- res = PyTuple_Pack(2, sock, addr);
+ return _PyTuple_FromPairSteal(sock, addr);
-finally:
+error:
Py_XDECREF(sock);
Py_XDECREF(addr);
- return res;
+ return NULL;
}
PyDoc_STRVAR(accept_doc,
PySocketSockObject *s = _PySocketSockObject_CAST(self);
PyObject *addr = NULL;
- PyObject *ret = NULL;
int flags = 0;
Py_ssize_t recvlen, outlen;
recvlen, flags, &addr);
if (outlen < 0) {
PyBytesWriter_Discard(writer);
- goto finally;
+ goto error;
}
PyObject *buf = PyBytesWriter_FinishWithSize(writer, outlen);
if (buf == NULL) {
- goto finally;
+ goto error;
}
- ret = PyTuple_Pack(2, buf, addr);
- Py_DECREF(buf);
+ return _PyTuple_FromPairSteal(buf, addr);
-finally:
+error:
Py_XDECREF(addr);
- return ret;
+ return NULL;
}
PyDoc_STRVAR(recvfrom_doc,
PySocketSockObject *s0 = NULL, *s1 = NULL;
SOCKET_T sv[2];
int family, type = SOCK_STREAM, proto = 0;
- PyObject *res = NULL;
socket_state *state = get_module_state(self);
#ifdef SOCK_CLOEXEC
int *atomic_flag_works = &sock_cloexec_works;
return set_error();
if (_Py_set_inheritable(sv[0], 0, atomic_flag_works) < 0)
- goto finally;
+ goto error;
if (_Py_set_inheritable(sv[1], 0, atomic_flag_works) < 0)
- goto finally;
+ goto error;
s0 = new_sockobject(state, sv[0], family, type, proto);
if (s0 == NULL)
- goto finally;
+ goto error;
s1 = new_sockobject(state, sv[1], family, type, proto);
if (s1 == NULL)
- goto finally;
- res = PyTuple_Pack(2, s0, s1);
+ goto error;
+ return _PyTuple_FromPairSteal((PyObject *)s0, (PyObject *)s1);
-finally:
- if (res == NULL) {
- if (s0 == NULL)
- SOCKETCLOSE(sv[0]);
- if (s1 == NULL)
- SOCKETCLOSE(sv[1]);
- }
+error:
+ if (s0 == NULL)
+ SOCKETCLOSE(sv[0]);
+ if (s1 == NULL)
+ SOCKETCLOSE(sv[1]);
Py_XDECREF(s0);
Py_XDECREF(s1);
- return res;
+ return NULL;
}
PyDoc_STRVAR(socketpair_doc,