#include "pycore_pylifecycle.h" // _Py_IsInterpreterFinalizing()
#include "pycore_pystate.h" // _PyThreadState_GET()
#include "pycore_runtime_init.h" // _Py_ID()
+#include "pycore_tuple.h" // _PyTuple_FromPair
#include <stddef.h> // offsetof()
fut->fut_context0 = Py_NewRef(ctx);
}
else {
- PyObject *tup = PyTuple_New(2);
+ PyObject *tup = _PyTuple_FromPair(arg, (PyObject *)ctx);
if (tup == NULL) {
return NULL;
}
- Py_INCREF(arg);
- PyTuple_SET_ITEM(tup, 0, arg);
- Py_INCREF(ctx);
- PyTuple_SET_ITEM(tup, 1, (PyObject *)ctx);
if (fut->fut_callbacks != NULL) {
int err = PyList_Append(fut->fut_callbacks, tup);
Py_ssize_t i = 0;
if (self->fut_callback0 != NULL) {
- PyObject *tup0 = PyTuple_New(2);
+ assert(self->fut_context0 != NULL);
+ PyObject *tup0 = _PyTuple_FromPair(self->fut_callback0, self->fut_context0);
if (tup0 == NULL) {
Py_DECREF(callbacks);
return NULL;
}
- PyTuple_SET_ITEM(tup0, 0, Py_NewRef(self->fut_callback0));
- assert(self->fut_context0 != NULL);
- PyTuple_SET_ITEM(tup0, 1, Py_NewRef(self->fut_context0));
PyList_SET_ITEM(callbacks, i, tup0);
i++;
}
#include <Python.h>
#include "pycore_object.h" // _PyObject_VisitType()
#include "pycore_pystate.h" // _PyThreadState_GET()
+#include "pycore_tuple.h" // _PyTuple_FromPair
#include "pycore_typeobject.h"
#include <mpdecimal.h>
PyObject *numerator = NULL;
PyObject *denominator = NULL;
PyObject *exponent = NULL;
- PyObject *result = NULL;
PyObject *tmp;
mpd_ssize_t exp;
PyObject *context;
if (exp >= 0) {
Py_SETREF(numerator, state->_py_long_multiply(numerator, exponent));
+ Py_CLEAR(exponent);
if (numerator == NULL) {
goto error;
}
goto error;
}
}
-
- result = PyTuple_Pack(2, numerator, denominator);
-
+ return _PyTuple_FromPairSteal(numerator, denominator);
error:
Py_XDECREF(exponent);
Py_XDECREF(denominator);
Py_XDECREF(numerator);
- return result;
+ return NULL;
}
/*[clinic input]
PyObject *q, *r;
PyObject *context;
uint32_t status = 0;
- PyObject *ret;
decimal_state *state = find_state_left_or_right(v, w);
CURRENT_CONTEXT(state, context);
return NULL;
}
- ret = PyTuple_Pack(2, q, r);
- Py_DECREF(r);
- Py_DECREF(q);
- return ret;
+ return _PyTuple_FromPairSteal(q, r);
}
static PyObject *
PyObject *a, *b;
PyObject *q, *r;
uint32_t status = 0;
- PyObject *ret;
CONVERT_BINOP_RAISE(&a, &b, x, y, context);
decimal_state *state = get_module_state_from_ctx(context);
return NULL;
}
- ret = PyTuple_Pack(2, q, r);
- Py_DECREF(r);
- Py_DECREF(q);
- return ret;
+ return _PyTuple_FromPairSteal(q, r);
}
/* Binary or ternary arithmetic functions */
switch (cm->flag) {
case MPD_Float_operation:
- base = PyTuple_Pack(2, state->DecimalException, PyExc_TypeError);
+ base = _PyTuple_FromPair(state->DecimalException, PyExc_TypeError);
break;
case MPD_Division_by_zero:
- base = PyTuple_Pack(2, state->DecimalException,
- PyExc_ZeroDivisionError);
+ base = _PyTuple_FromPair(state->DecimalException,
+ PyExc_ZeroDivisionError);
break;
case MPD_Overflow:
- base = PyTuple_Pack(2, state->signal_map[INEXACT].ex,
- state->signal_map[ROUNDED].ex);
+ base = _PyTuple_FromPair(state->signal_map[INEXACT].ex,
+ state->signal_map[ROUNDED].ex);
break;
case MPD_Underflow:
base = PyTuple_Pack(3, state->signal_map[INEXACT].ex,
for (cm = state->cond_map+1; cm->name != NULL; cm++) {
PyObject *base;
if (cm->flag == MPD_Division_undefined) {
- base = PyTuple_Pack(2, state->signal_map[0].ex, PyExc_ZeroDivisionError);
+ base = _PyTuple_FromPair(state->signal_map[0].ex, PyExc_ZeroDivisionError);
}
else {
base = PyTuple_Pack(1, state->signal_map[0].ex);
#include "Python.h"
#include "pycore_dict.h" // _PyDict_CopyAsDict()
#include "pycore_pyhash.h" // _Py_HashSecret
+#include "pycore_tuple.h" // _PyTuple_FromPair
#include "pycore_weakref.h" // FT_CLEAR_WEAKREFS()
#include <stddef.h> // offsetof()
return NULL;
}
- old = PyTuple_Pack(2,
+ old = _PyTuple_FromPair(
st->comment_factory ? st->comment_factory : Py_None,
st->pi_factory ? st->pi_factory : Py_None);
{
if (action != NULL) {
PyObject *res;
- PyObject *event = PyTuple_Pack(2, action, node);
+ PyObject *event = _PyTuple_FromPair(action, node);
if (event == NULL)
return -1;
res = PyObject_CallOneArg(self->events_append, event);
Py_XSETREF(self->last_for_tail, Py_NewRef(pi));
}
} else {
- pi = PyTuple_Pack(2, target, text);
+ pi = _PyTuple_FromPair(target, text);
if (!pi) {
return NULL;
}
PyObject* parcel;
if (self->events_append && self->start_ns_event_obj) {
- parcel = PyTuple_Pack(2, prefix, uri);
+ parcel = _PyTuple_FromPair(prefix, uri);
if (!parcel) {
return NULL;
}
#include "pycore_global_strings.h" // _Py_ID()
#include "pycore_pyerrors.h" // _PyErr_FormatNote
#include "pycore_runtime.h" // _PyRuntime
+#include "pycore_tuple.h" // _PyTuple_FromPair
#include "pycore_unicodeobject.h" // _PyUnicode_CheckConsistency()
#include <stdbool.h> // bool
static PyObject *
_build_rval_index_tuple(PyObject *rval, Py_ssize_t idx) {
/* return (rval, idx) tuple, stealing reference to rval */
- PyObject *tpl;
PyObject *pyidx;
/*
steal a reference to rval, returns (rval, idx)
Py_DECREF(rval);
return NULL;
}
- tpl = PyTuple_New(2);
- if (tpl == NULL) {
- Py_DECREF(pyidx);
- Py_DECREF(rval);
- return NULL;
- }
- PyTuple_SET_ITEM(tpl, 0, rval);
- PyTuple_SET_ITEM(tpl, 1, pyidx);
- return tpl;
+ return _PyTuple_FromPairSteal(rval, pyidx);
}
static PyObject *
goto bail;
if (has_pairs_hook) {
- PyObject *item = PyTuple_Pack(2, key, val);
+ PyObject *item = _PyTuple_FromPairSteal(key, val);
+ key = val = NULL;
if (item == NULL)
goto bail;
- Py_CLEAR(key);
- Py_CLEAR(val);
if (PyList_Append(rval, item) == -1) {
Py_DECREF(item);
goto bail;
itemgetterobject *ig = itemgetterobject_CAST(op);
if (ig->nitems == 1)
return Py_BuildValue("O(O)", Py_TYPE(ig), ig->item);
- return PyTuple_Pack(2, Py_TYPE(ig), ig->item);
+ return _PyTuple_FromPair((PyObject *)Py_TYPE(ig), ig->item);
}
PyDoc_STRVAR(reduce_doc, "Return state information for pickling");
#include "pycore_setobject.h" // _PySet_NextEntry()
#include "pycore_symtable.h" // _Py_Mangle()
#include "pycore_sysmodule.h" // _PySys_GetSizeOf()
+#include "pycore_tuple.h" // _PyTuple_FromPair
#include "pycore_unicodeobject.h" // _PyUnicode_EqualToASCIIString()
#include <stdlib.h> // strtol()
PyObject *key;
PyObject *item;
- key = PyTuple_Pack(2, *module_name, *global_name);
+ key = _PyTuple_FromPair(*module_name, *global_name);
if (key == NULL)
return -1;
item = PyDict_GetItemWithError(st->name_mapping_3to2, key);
char pdata[5];
Py_ssize_t n;
- extension_key = PyTuple_Pack(2, module_name, global_name);
+ extension_key = _PyTuple_FromPair(module_name, global_name);
if (extension_key == NULL) {
goto error;
}
_pickle_PicklerMemoProxy___reduce___impl(PicklerMemoProxyObject *self)
/*[clinic end generated code: output=bebba1168863ab1d input=2f7c540e24b7aae4]*/
{
- PyObject *reduce_value, *dict_args;
+ PyObject *dict_args;
PyObject *contents = _pickle_PicklerMemoProxy_copy_impl(self);
if (contents == NULL)
return NULL;
- reduce_value = PyTuple_New(2);
- if (reduce_value == NULL) {
- Py_DECREF(contents);
- return NULL;
- }
dict_args = PyTuple_New(1);
if (dict_args == NULL) {
Py_DECREF(contents);
- Py_DECREF(reduce_value);
return NULL;
}
PyTuple_SET_ITEM(dict_args, 0, contents);
- PyTuple_SET_ITEM(reduce_value, 0, Py_NewRef(&PyDict_Type));
- PyTuple_SET_ITEM(reduce_value, 1, dict_args);
- return reduce_value;
+
+ return _PyTuple_FromPairSteal(Py_NewRef(&PyDict_Type), dict_args);
}
static PyMethodDef picklerproxy_methods[] = {
/* Check if the global (i.e., a function or a class) was renamed
or moved to another module. */
- key = PyTuple_Pack(2, module_name, global_name);
+ key = _PyTuple_FromPair(module_name, global_name);
if (key == NULL)
return NULL;
item = PyDict_GetItemWithError(st->name_mapping_2to3, key);
_pickle_UnpicklerMemoProxy___reduce___impl(UnpicklerMemoProxyObject *self)
/*[clinic end generated code: output=6da34ac048d94cca input=6920862413407199]*/
{
- PyObject *reduce_value;
PyObject *constructor_args;
PyObject *contents = _pickle_UnpicklerMemoProxy_copy_impl(self);
if (contents == NULL)
return NULL;
- reduce_value = PyTuple_New(2);
- if (reduce_value == NULL) {
- Py_DECREF(contents);
- return NULL;
- }
constructor_args = PyTuple_New(1);
if (constructor_args == NULL) {
Py_DECREF(contents);
- Py_DECREF(reduce_value);
return NULL;
}
PyTuple_SET_ITEM(constructor_args, 0, contents);
- PyTuple_SET_ITEM(reduce_value, 0, Py_NewRef(&PyDict_Type));
- PyTuple_SET_ITEM(reduce_value, 1, constructor_args);
- return reduce_value;
+
+ return _PyTuple_FromPairSteal(Py_NewRef(&PyDict_Type), constructor_args);
}
static PyMethodDef unpicklerproxy_methods[] = {
#include "pycore_dict.h" // _PyDict_Next()
#include "pycore_long.h" // _PyLong_GetZero()
#include "pycore_moduleobject.h" // _PyModule_GetState()
+#include "pycore_tuple.h" // _PyTuple_FromPairSteal
#include "pycore_unicodeobject.h" // _PyUnicode_Copy
#include "pycore_weakref.h" // FT_CLEAR_WEAKREFS()
LOCAL(PyObject*)
_pair(Py_ssize_t i1, Py_ssize_t i2)
{
- PyObject* pair;
- PyObject* item;
-
- pair = PyTuple_New(2);
- if (!pair)
+ PyObject* item1 = PyLong_FromSsize_t(i1);
+ if (!item1) {
return NULL;
+ }
+ PyObject* item2 = PyLong_FromSsize_t(i2);
+ if(!item2) {
+ Py_DECREF(item1);
+ return NULL;
+ }
- item = PyLong_FromSsize_t(i1);
- if (!item)
- goto error;
- PyTuple_SET_ITEM(pair, 0, item);
-
- item = PyLong_FromSsize_t(i2);
- if (!item)
- goto error;
- PyTuple_SET_ITEM(pair, 1, item);
-
- return pair;
-
- error:
- Py_DECREF(pair);
- return NULL;
+ return _PyTuple_FromPairSteal(item1, item2);
}
/*[clinic input]
#include "pycore_pylifecycle.h"
#include "pycore_pystate.h" // _PyThreadState_SetCurrent()
#include "pycore_time.h" // _PyTime_FromSeconds()
+#include "pycore_tuple.h" // _PyTuple_FromPairSteal
#include "pycore_weakref.h" // _PyWeakref_GET_REF()
#include <stddef.h> // offsetof()
return NULL;
}
- PyObject *args = PyTuple_New(2);
+ PyObject *args = _PyTuple_FromPairSteal(self_wr,
+ Py_NewRef(tstate->threading_local_key));
if (args == NULL) {
- Py_DECREF(self_wr);
return NULL;
}
- PyTuple_SET_ITEM(args, 0, self_wr);
- PyTuple_SET_ITEM(args, 1, Py_NewRef(tstate->threading_local_key));
PyObject *cb = PyCFunction_New(&wr_callback_def, args);
Py_DECREF(args);
#include "pycore_floatobject.h" // _PY_FLOAT_BIG_ENDIAN
#include "pycore_modsupport.h" // _PyArg_NoKeywords()
#include "pycore_moduleobject.h" // _PyModule_GetState()
+#include "pycore_tuple.h" // _PyTuple_FromPairSteal
#include "pycore_weakref.h" // FT_CLEAR_WEAKREFS()
#include <stddef.h> // offsetof()
array_array_buffer_info_impl(arrayobject *self)
/*[clinic end generated code: output=9b2a4ec3ae7e98e7 input=63d9ad83ba60cda8]*/
{
- PyObject *retval = NULL, *v;
-
- retval = PyTuple_New(2);
- if (!retval)
- return NULL;
-
- v = PyLong_FromVoidPtr(self->ob_item);
- if (v == NULL) {
- Py_DECREF(retval);
+ PyObject* item1 = PyLong_FromVoidPtr(self->ob_item);
+ if (item1 == NULL) {
return NULL;
}
- PyTuple_SET_ITEM(retval, 0, v);
-
- v = PyLong_FromSsize_t(Py_SIZE(self));
- if (v == NULL) {
- Py_DECREF(retval);
+ PyObject* item2 = PyLong_FromSsize_t(Py_SIZE(self));
+ if (item2 == NULL) {
+ Py_DECREF(item1);
return NULL;
}
- PyTuple_SET_ITEM(retval, 1, v);
- return retval;
+ return _PyTuple_FromPairSteal(item1, item2);
}
/*[clinic input]
if (typecode_obj == NULL)
return NULL;
- new_args = PyTuple_New(2);
+ new_args = _PyTuple_FromPairSteal(typecode_obj, Py_NewRef(items));
if (new_args == NULL) {
- Py_DECREF(typecode_obj);
return NULL;
}
- PyTuple_SET_ITEM(new_args, 0, typecode_obj);
- PyTuple_SET_ITEM(new_args, 1, Py_NewRef(items));
array_obj = array_new(arraytype, new_args, NULL);
Py_DECREF(new_args);
}
po->it = it;
po->old = NULL;
- po->result = PyTuple_Pack(2, Py_None, Py_None);
+ po->result = _PyTuple_FromPairSteal(Py_None, Py_None);
if (po->result == NULL) {
Py_DECREF(po);
return NULL;
_PyTuple_Recycle(result);
}
else {
- result = PyTuple_New(2);
- if (result != NULL) {
- PyTuple_SET_ITEM(result, 0, Py_NewRef(old));
- PyTuple_SET_ITEM(result, 1, Py_NewRef(new));
- }
+ result = _PyTuple_FromPair(old, new);
}
Py_XSETREF(po->old, new);
static PyObject *
groupby_next(PyObject *op)
{
- PyObject *r, *grouper;
+ PyObject *grouper;
groupbyobject *gbo = groupbyobject_CAST(op);
gbo->currgrouper = NULL;
if (grouper == NULL)
return NULL;
- r = PyTuple_Pack(2, gbo->currkey, grouper);
- Py_DECREF(grouper);
- return r;
+ return _PyTuple_FromPairSteal(Py_NewRef(gbo->currkey), grouper);
}
static PyType_Slot groupby_slots[] = {
#include "pycore_pylifecycle.h" // _Py_PreInitializeFromPyArgv()
#include "pycore_pystate.h" // _PyInterpreterState_GET()
#include "pycore_pythonrun.h" // _PyRun_AnyFileObject()
+#include "pycore_tuple.h" // _PyTuple_FromPair
#include "pycore_unicodeobject.h" // _PyUnicode_Dedent()
/* Includes for exit_sigint() */
Py_DECREF(runmodule);
return pymain_exit_err_print();
}
- runargs = PyTuple_Pack(2, module, set_argv0 ? Py_True : Py_False);
+ runargs = _PyTuple_FromPair(module, set_argv0 ? Py_True : Py_False);
if (runargs == NULL) {
fprintf(stderr,
"Could not create arguments for runpy._run_module_as_main\n");