Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions Include/tupleobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ PyAPI_FUNC(int) PyTuple_SetItem(PyObject *, Py_ssize_t, PyObject *);
PyAPI_FUNC(PyObject *) PyTuple_GetSlice(PyObject *, Py_ssize_t, Py_ssize_t);
PyAPI_FUNC(PyObject *) PyTuple_Pack(Py_ssize_t, ...);

PyAPI_FUNC(PyObject *) PyTuple_MakeSingle(PyObject *one);
PyAPI_FUNC(PyObject *) PyTuple_MakeSingleSteal(PyObject *one);
PyAPI_FUNC(PyObject *) PyTuple_MakePair(PyObject *one, PyObject *two);
PyAPI_FUNC(PyObject *) PyTuple_MakePairSteal(PyObject *one, PyObject *two);
PyAPI_FUNC(PyObject *) PyTuple_MakeTriplet(PyObject *one, PyObject *two, PyObject *three);


#ifndef Py_LIMITED_API
# define Py_CPYTHON_TUPLEOBJECT_H
# include "cpython/tupleobject.h"
Expand Down
12 changes: 3 additions & 9 deletions Modules/_asynciomodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -837,14 +837,10 @@ future_add_done_callback(asyncio_state *state, FutureObj *fut, PyObject *arg,
fut->fut_context0 = Py_NewRef(ctx);
}
else {
PyObject *tup = PyTuple_New(2);
PyObject *tup = PyTuple_MakePair(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);
Expand Down Expand Up @@ -1511,14 +1507,12 @@ _asyncio_Future__callbacks_get_impl(FutureObj *self)

Py_ssize_t i = 0;
if (self->fut_callback0 != NULL) {
PyObject *tup0 = PyTuple_New(2);
assert(self->fut_context0 != NULL);
PyObject *tup0 = PyTuple_MakePair(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++;
}
Expand Down
4 changes: 2 additions & 2 deletions Modules/_collectionsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2222,7 +2222,7 @@ defdict_missing(PyObject *op, PyObject *key)
if (factory == NULL || factory == Py_None) {
/* XXX Call dict.__missing__(key) */
PyObject *tup;
tup = PyTuple_Pack(1, key);
tup = PyTuple_MakeSingle(key);
if (!tup) return NULL;
PyErr_SetObject(PyExc_KeyError, tup);
Py_DECREF(tup);
Expand Down Expand Up @@ -2292,7 +2292,7 @@ defdict_reduce(PyObject *op, PyObject *Py_UNUSED(dummy))
if (dd->default_factory == NULL || dd->default_factory == Py_None)
args = PyTuple_New(0);
else
args = PyTuple_Pack(1, dd->default_factory);
args = PyTuple_MakeSingle(dd->default_factory);
if (args == NULL)
return NULL;
items = PyObject_CallMethodNoArgs(op, &_Py_ID(items));
Expand Down
2 changes: 1 addition & 1 deletion Modules/_csv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1787,7 +1787,7 @@ csv_exec(PyObject *module) {
}

/* Add the CSV exception object to the module. */
PyObject *bases = PyTuple_Pack(1, PyExc_Exception);
PyObject *bases = PyTuple_MakeSingle(PyExc_Exception);
if (bases == NULL) {
return -1;
}
Expand Down
4 changes: 2 additions & 2 deletions Modules/_ctypes/_ctypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -3510,7 +3510,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_MakePair(keep, value);
}
PyErr_Format(PyExc_TypeError,
"incompatible types, %s instance instead of %s instance",
Expand Down Expand Up @@ -5330,7 +5330,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);
key = PyTuple_MakePair(itemtype, len);
Py_DECREF(len);
if (!key)
return NULL;
Expand Down
5 changes: 1 addition & 4 deletions Modules/_ctypes/stgdict.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,7 @@ PyCStructUnionType_update_stginfo(PyObject *type, PyObject *fields, int isStruct
if (!layout_func) {
goto error;
}
kwnames = PyTuple_Pack(
2,
&_Py_ID(is_struct),
&_Py_ID(base));
kwnames = PyTuple_MakePair(&_Py_ID(is_struct), &_Py_ID(base));
if (!kwnames) {
goto error;
}
Expand Down
14 changes: 7 additions & 7 deletions Modules/_datetimemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2692,7 +2692,7 @@ delta_divmod(PyObject *left, PyObject *right)
Py_DECREF(divmod);
return NULL;
}
result = PyTuple_Pack(2, PyTuple_GET_ITEM(divmod, 0), delta);
result = PyTuple_MakePair(PyTuple_GET_ITEM(divmod, 0), delta);
Py_DECREF(delta);
Py_DECREF(divmod);
return result;
Expand Down Expand Up @@ -4478,8 +4478,8 @@ 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_MakeSingle(self->offset);
return PyTuple_MakePair(self->offset, self->name);
}

static PyMethodDef timezone_methods[] = {
Expand Down Expand Up @@ -5228,9 +5228,9 @@ time_getstate(PyDateTime_Time *self, int proto)
/* Set the first bit of the first byte */
PyBytes_AS_STRING(basestate)[0] |= (1 << 7);
if (! HASTZINFO(self) || self->tzinfo == Py_None)
result = PyTuple_Pack(1, basestate);
result = PyTuple_MakeSingle(basestate);
else
result = PyTuple_Pack(2, basestate, self->tzinfo);
result = PyTuple_MakePair(basestate, self->tzinfo);
Py_DECREF(basestate);
}
return result;
Expand Down Expand Up @@ -7165,9 +7165,9 @@ datetime_getstate(PyDateTime_DateTime *self, int proto)
/* Set the first bit of the third byte */
PyBytes_AS_STRING(basestate)[2] |= (1 << 7);
if (! HASTZINFO(self) || self->tzinfo == Py_None)
result = PyTuple_Pack(1, basestate);
result = PyTuple_MakeSingle(basestate);
else
result = PyTuple_Pack(2, basestate, self->tzinfo);
result = PyTuple_MakePair(basestate, self->tzinfo);
Py_DECREF(basestate);
}
return result;
Expand Down
28 changes: 14 additions & 14 deletions Modules/_decimal/_decimal.c
Original file line number Diff line number Diff line change
Expand Up @@ -4058,7 +4058,7 @@ _decimal_Decimal_as_integer_ratio_impl(PyObject *self, PyTypeObject *cls)
}
}

result = PyTuple_Pack(2, numerator, denominator);
result = PyTuple_MakePair(numerator, denominator);


error:
Expand Down Expand Up @@ -4638,7 +4638,7 @@ nm_mpd_qdivmod(PyObject *v, PyObject *w)
return NULL;
}

ret = PyTuple_Pack(2, q, r);
ret = PyTuple_MakePair(q, r);
Py_DECREF(r);
Py_DECREF(q);
return ret;
Expand Down Expand Up @@ -6689,7 +6689,7 @@ _decimal_Context_divmod_impl(PyObject *context, PyObject *x, PyObject *y)
return NULL;
}

ret = PyTuple_Pack(2, q, r);
ret = PyTuple_MakePair(q, r);
Py_DECREF(r);
Py_DECREF(q);
return ret;
Expand Down Expand Up @@ -7694,23 +7694,23 @@ _decimal_exec(PyObject *m)

switch (cm->flag) {
case MPD_Float_operation:
base = PyTuple_Pack(2, state->DecimalException, PyExc_TypeError);
base = PyTuple_MakePair(state->DecimalException, PyExc_TypeError);
break;
case MPD_Division_by_zero:
base = PyTuple_Pack(2, state->DecimalException,
PyExc_ZeroDivisionError);
base = PyTuple_MakePair(state->DecimalException,
PyExc_ZeroDivisionError);
break;
case MPD_Overflow:
base = PyTuple_Pack(2, state->signal_map[INEXACT].ex,
state->signal_map[ROUNDED].ex);
base = PyTuple_MakePair(state->signal_map[INEXACT].ex,
state->signal_map[ROUNDED].ex);
break;
case MPD_Underflow:
base = PyTuple_Pack(3, state->signal_map[INEXACT].ex,
state->signal_map[ROUNDED].ex,
state->signal_map[SUBNORMAL].ex);
base = PyTuple_MakeTriplet(state->signal_map[INEXACT].ex,
state->signal_map[ROUNDED].ex,
state->signal_map[SUBNORMAL].ex);
break;
default:
base = PyTuple_Pack(1, state->DecimalException);
base = PyTuple_MakeSingle(state->DecimalException);
break;
}

Expand Down Expand Up @@ -7741,10 +7741,10 @@ _decimal_exec(PyObject *m)
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_MakePair(state->signal_map[0].ex, PyExc_ZeroDivisionError);
}
else {
base = PyTuple_Pack(1, state->signal_map[0].ex);
base = PyTuple_MakeSingle(state->signal_map[0].ex);
}
if (base == NULL) {
goto error; /* GCOV_NOT_REACHED */
Expand Down
8 changes: 4 additions & 4 deletions Modules/_elementtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -2577,7 +2577,7 @@ _elementtree__set_factories_impl(PyObject *module, PyObject *comment_factory,
return NULL;
}

old = PyTuple_Pack(2,
old = PyTuple_MakePair(
st->comment_factory ? st->comment_factory : Py_None,
st->pi_factory ? st->pi_factory : Py_None);

Expand Down Expand Up @@ -2695,7 +2695,7 @@ treebuilder_append_event(TreeBuilderObject *self, PyObject *action,
{
if (action != NULL) {
PyObject *res;
PyObject *event = PyTuple_Pack(2, action, node);
PyObject *event = PyTuple_MakePair(action, node);
if (event == NULL)
return -1;
res = PyObject_CallOneArg(self->events_append, event);
Expand Down Expand Up @@ -2912,7 +2912,7 @@ treebuilder_handle_pi(TreeBuilderObject* self, PyObject* target, PyObject* text)
Py_XSETREF(self->last_for_tail, Py_NewRef(pi));
}
} else {
pi = PyTuple_Pack(2, target, text);
pi = PyTuple_MakePair(target, text);
if (!pi) {
return NULL;
}
Expand All @@ -2936,7 +2936,7 @@ treebuilder_handle_start_ns(TreeBuilderObject* self, PyObject* prefix, PyObject*
PyObject* parcel;

if (self->events_append && self->start_ns_event_obj) {
parcel = PyTuple_Pack(2, prefix, uri);
parcel = PyTuple_MakePair(prefix, uri);
if (!parcel) {
return NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion Modules/_interpretersmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ get_summary(PyInterpreterState *interp)
Py_DECREF(idobj);
return NULL;
}
PyObject *res = PyTuple_Pack(2, idobj, whenceobj);
PyObject *res = PyTuple_MakePair(idobj, whenceobj);
Py_DECREF(idobj);
Py_DECREF(whenceobj);
return res;
Expand Down
13 changes: 3 additions & 10 deletions Modules/_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,14 +450,7 @@ _build_rval_index_tuple(PyObject *rval, Py_ssize_t 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);
tpl = PyTuple_MakePairSteal(rval, pyidx);
return tpl;
}

Expand Down Expand Up @@ -826,7 +819,7 @@ _parse_object_unicode(PyScannerObject *s, PyObject *memo, PyObject *pystr, Py_ss
goto bail;

if (has_pairs_hook) {
PyObject *item = PyTuple_Pack(2, key, val);
PyObject *item = PyTuple_MakePair(key, val);
if (item == NULL)
goto bail;
Py_CLEAR(key);
Expand Down Expand Up @@ -1491,7 +1484,7 @@ encoder_call(PyObject *op, PyObject *args, PyObject *kwds)
if (str == NULL) {
return NULL;
}
PyObject *result = PyTuple_Pack(1, str);
PyObject *result = PyTuple_MakeSingle(str);
Py_DECREF(str);
return result;
}
Expand Down
2 changes: 1 addition & 1 deletion Modules/_operator.c
Original file line number Diff line number Diff line change
Expand Up @@ -1194,7 +1194,7 @@ itemgetter_reduce(PyObject *op, PyObject *Py_UNUSED(dummy))
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_MakePair((PyObject *)Py_TYPE(ig), ig->item);
}

PyDoc_STRVAR(reduce_doc, "Return state information for pickling");
Expand Down
32 changes: 7 additions & 25 deletions Modules/_pickle.c
Original file line number Diff line number Diff line change
Expand Up @@ -3609,7 +3609,7 @@ fix_imports(PickleState *st, PyObject **module_name, PyObject **global_name)
PyObject *key;
PyObject *item;

key = PyTuple_Pack(2, *module_name, *global_name);
key = PyTuple_MakePair(*module_name, *global_name);
if (key == NULL)
return -1;
item = PyDict_GetItemWithError(st->name_mapping_3to2, key);
Expand Down Expand Up @@ -3706,7 +3706,7 @@ save_global(PickleState *st, PicklerObject *self, PyObject *obj,
char pdata[5];
Py_ssize_t n;

extension_key = PyTuple_Pack(2, module_name, global_name);
extension_key = PyTuple_MakePair(module_name, global_name);
if (extension_key == NULL) {
goto error;
}
Expand Down Expand Up @@ -4958,20 +4958,11 @@ _pickle_PicklerMemoProxy___reduce___impl(PicklerMemoProxyObject *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);
dict_args = PyTuple_MakeSingleSteal(contents);
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);
reduce_value = PyTuple_MakePairSteal(Py_NewRef(&PyDict_Type), dict_args);
return reduce_value;
}

Expand Down Expand Up @@ -7123,7 +7114,7 @@ _pickle_Unpickler_find_class_impl(UnpicklerObject *self, PyTypeObject *cls,

/* 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_MakePair(module_name, global_name);
if (key == NULL)
return NULL;
item = PyDict_GetItemWithError(st->name_mapping_2to3, key);
Expand Down Expand Up @@ -7451,20 +7442,11 @@ _pickle_UnpicklerMemoProxy___reduce___impl(UnpicklerMemoProxyObject *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);
constructor_args = PyTuple_MakeSingleSteal(contents);
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);
reduce_value = PyTuple_MakePairSteal(Py_NewRef(&PyDict_Type), constructor_args);
return reduce_value;
}

Expand Down
4 changes: 2 additions & 2 deletions Modules/_sqlite/microprotocols.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pysqlite_microprotocols_add(pysqlite_state *state, PyTypeObject *type,

assert(type != NULL);
assert(proto != NULL);
key = PyTuple_Pack(2, (PyObject *)type, proto);
key = PyTuple_MakePair((PyObject *)type, proto);
if (!key) {
return -1;
}
Expand All @@ -81,7 +81,7 @@ pysqlite_microprotocols_adapt(pysqlite_state *state, PyObject *obj,
way to get a quotable object to be its instance */

/* look for an adapter in the registry */
key = PyTuple_Pack(2, (PyObject *)Py_TYPE(obj), proto);
key = PyTuple_MakePair((PyObject *)Py_TYPE(obj), proto);
if (!key) {
return NULL;
}
Expand Down
Loading