mirror of
https://github.com/python/cpython.git
synced 2026-04-13 23:31:02 +00:00
GH-145247: Use _PyTuple_FromPair in Parser and Python (#145842)
Use _PyTuple_FromPair in Parser and Python
This commit is contained in:
parent
f062014d38
commit
d19de375a2
8 changed files with 16 additions and 11 deletions
|
|
@ -1,6 +1,7 @@
|
|||
#include "Python.h"
|
||||
#include "errcode.h"
|
||||
#include "internal/pycore_critical_section.h" // Py_BEGIN_CRITICAL_SECTION
|
||||
#include "internal/pycore_tuple.h" // _PyTuple_FromPair
|
||||
#include "../Parser/lexer/state.h"
|
||||
#include "../Parser/lexer/lexer.h"
|
||||
#include "../Parser/tokenizer/tokenizer.h"
|
||||
|
|
@ -164,7 +165,7 @@ _tokenizer_error(tokenizeriterobject *it)
|
|||
goto exit;
|
||||
}
|
||||
|
||||
value = PyTuple_Pack(2, errstr, tmp);
|
||||
value = _PyTuple_FromPair(errstr, tmp);
|
||||
if (!value) {
|
||||
result = -1;
|
||||
goto exit;
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
#include "pycore_pylifecycle.h" // _Py_IsInterpreterFinalizing()
|
||||
#include "pycore_pystate.h" // _PyThreadState_GET()
|
||||
#include "pycore_traceback.h" // _Py_DisplaySourceLine()
|
||||
#include "pycore_tuple.h" // _PyTuple_FromPair
|
||||
#include "pycore_unicodeobject.h" // _PyUnicode_EqualToASCIIString()
|
||||
|
||||
#include <stdbool.h>
|
||||
|
|
@ -634,7 +635,7 @@ update_registry(PyInterpreterState *interp, PyObject *registry, PyObject *text,
|
|||
if (add_zero)
|
||||
altkey = PyTuple_Pack(3, text, category, _PyLong_GetZero());
|
||||
else
|
||||
altkey = PyTuple_Pack(2, text, category);
|
||||
altkey = _PyTuple_FromPair(text, category);
|
||||
|
||||
rc = already_warned(interp, registry, altkey, 1);
|
||||
Py_XDECREF(altkey);
|
||||
|
|
|
|||
|
|
@ -3341,7 +3341,7 @@ zip_reduce(PyObject *self, PyObject *Py_UNUSED(ignored))
|
|||
if (lz->strict) {
|
||||
return PyTuple_Pack(3, Py_TYPE(lz), lz->ittuple, Py_True);
|
||||
}
|
||||
return PyTuple_Pack(2, Py_TYPE(lz), lz->ittuple);
|
||||
return _PyTuple_FromPair((PyObject *)Py_TYPE(lz), lz->ittuple);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
#include "pycore_runtime.h" // _Py_ID()
|
||||
#include "pycore_setobject.h" // _PySet_NextEntry()
|
||||
#include "pycore_stats.h"
|
||||
#include "pycore_tuple.h" // _PyTuple_FromPair
|
||||
#include "pycore_unicodeobject.h" // _PyUnicode_EqualToASCIIString()
|
||||
|
||||
#include "cpython/code.h"
|
||||
|
|
@ -1697,7 +1698,7 @@ _PyCompile_CodeGen(PyObject *ast, PyObject *filename, PyCompilerFlags *pflags,
|
|||
return NULL;
|
||||
}
|
||||
/* Allocate a copy of the instruction sequence on the heap */
|
||||
res = PyTuple_Pack(2, _PyCompile_InstrSequence(c), metadata);
|
||||
res = _PyTuple_FromPair((PyObject *)_PyCompile_InstrSequence(c), metadata);
|
||||
|
||||
finally:
|
||||
Py_XDECREF(metadata);
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#include "pycore_initconfig.h" // _PyStatus_OK()
|
||||
#include "pycore_long.h" // _PyLong_Format()
|
||||
#include "pycore_object.h" // _PyObject_GC_TRACK()
|
||||
#include "pycore_tuple.h" // _PyTuple_FromPair
|
||||
|
||||
#include <stddef.h> // offsetof()
|
||||
|
||||
|
|
@ -2542,7 +2543,7 @@ PyTypeObject _PyHamtItems_Type = {
|
|||
static PyObject *
|
||||
hamt_iter_yield_items(PyObject *key, PyObject *val)
|
||||
{
|
||||
return PyTuple_Pack(2, key, val);
|
||||
return _PyTuple_FromPair(key, val);
|
||||
}
|
||||
|
||||
PyObject *
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
#include "pycore_object.h" // _PyObject_IsUniquelyReferenced
|
||||
#include "pycore_pystate.h" // _PyInterpreterState_GET()
|
||||
#include "pycore_setobject.h" // _PySet_NextEntryRef()
|
||||
#include "pycore_tuple.h" // _PyTuple_FromPairSteal
|
||||
#include "pycore_unicodeobject.h" // _PyUnicode_InternImmortal()
|
||||
|
||||
#include "marshal.h" // Py_MARSHAL_VERSION
|
||||
|
|
@ -629,9 +630,7 @@ w_complex_object(PyObject *v, char flag, WFILE *p)
|
|||
Py_DECREF(value);
|
||||
break;
|
||||
}
|
||||
PyObject *pair = PyTuple_Pack(2, dump, value);
|
||||
Py_DECREF(dump);
|
||||
Py_DECREF(value);
|
||||
PyObject *pair = _PyTuple_FromPairSteal(dump, value);
|
||||
if (pair == NULL) {
|
||||
p->error = WFERR_NOMEMORY;
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@
|
|||
#include "pycore_stats.h" // _PyStats_InterpInit()
|
||||
#include "pycore_sysmodule.h" // _PySys_ClearAttrString()
|
||||
#include "pycore_traceback.h" // _Py_DumpTracebackThreads()
|
||||
#include "pycore_tuple.h" // _PyTuple_FromPair
|
||||
#include "pycore_typeobject.h" // _PyTypes_InitTypes()
|
||||
#include "pycore_typevarobject.h" // _Py_clear_generic_types()
|
||||
#include "pycore_unicodeobject.h" // _PyUnicode_InitTypes()
|
||||
|
|
@ -1613,7 +1614,7 @@ finalize_remove_modules(PyObject *modules, int verbose)
|
|||
if (weaklist != NULL) { \
|
||||
PyObject *wr = PyWeakref_NewRef(mod, NULL); \
|
||||
if (wr) { \
|
||||
PyObject *tup = PyTuple_Pack(2, name, wr); \
|
||||
PyObject *tup = _PyTuple_FromPair(name, wr); \
|
||||
if (!tup || PyList_Append(weaklist, tup) < 0) { \
|
||||
PyErr_FormatUnraisable("Exception ignored while removing modules"); \
|
||||
} \
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue