Skip to content

bpo-35199: Add an internal _PyTuple_ITEMS() macro #10434

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 9, 2018
Merged
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
4 changes: 4 additions & 0 deletions Include/tupleobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ PyAPI_FUNC(void) _PyTuple_MaybeUntrack(PyObject *);
#define PyTuple_GET_ITEM(op, i) (((PyTupleObject *)(op))->ob_item[i])
#define PyTuple_GET_SIZE(op) (assert(PyTuple_Check(op)),Py_SIZE(op))

#ifdef Py_BUILD_CORE
# define _PyTuple_ITEMS(op) ((((PyTupleObject *)(op))->ob_item))
#endif

/* Macro, *only* to be used to fill in brand new tuples */
#define PyTuple_SET_ITEM(op, i, v) (((PyTupleObject *)(op))->ob_item[i] = v)
#endif
Expand Down
6 changes: 3 additions & 3 deletions Modules/_functoolsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ partial_fastcall(partialobject *pto, PyObject **args, Py_ssize_t nargs,
stack = args;
}
else if (nargs == 0) {
stack = &PyTuple_GET_ITEM(pto->args, 0);
stack = _PyTuple_ITEMS(pto->args);
}
else {
if (nargs2 <= (Py_ssize_t)Py_ARRAY_LENGTH(small_stack)) {
Expand All @@ -159,7 +159,7 @@ partial_fastcall(partialobject *pto, PyObject **args, Py_ssize_t nargs,

/* use borrowed references */
memcpy(stack,
&PyTuple_GET_ITEM(pto->args, 0),
_PyTuple_ITEMS(pto->args),
pto_nargs * sizeof(PyObject*));
memcpy(&stack[pto_nargs],
args,
Expand Down Expand Up @@ -222,7 +222,7 @@ partial_call(partialobject *pto, PyObject *args, PyObject *kwargs)

if (pto->use_fastcall) {
res = partial_fastcall(pto,
&PyTuple_GET_ITEM(args, 0),
_PyTuple_ITEMS(args),
PyTuple_GET_SIZE(args),
kwargs2);
}
Expand Down
2 changes: 1 addition & 1 deletion Modules/_testcapimodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -4361,7 +4361,7 @@ fastcall_args(PyObject *args, PyObject ***stack, Py_ssize_t *nargs)
*nargs = 0;
}
else if (PyTuple_Check(args)) {
*stack = &PyTuple_GET_ITEM(args, 0);
*stack = ((PyTupleObject *)args)->ob_item;
*nargs = PyTuple_GET_SIZE(args);
}
else {
Expand Down
22 changes: 11 additions & 11 deletions Objects/call.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ PyObject_Call(PyObject *callable, PyObject *args, PyObject *kwargs)

if (PyFunction_Check(callable)) {
return _PyFunction_FastCallDict(callable,
&PyTuple_GET_ITEM(args, 0),
_PyTuple_ITEMS(args),
PyTuple_GET_SIZE(args),
kwargs);
}
Expand Down Expand Up @@ -325,7 +325,7 @@ _PyFunction_FastCallDict(PyObject *func, PyObject *const *args, Py_ssize_t nargs
&& co->co_argcount == PyTuple_GET_SIZE(argdefs)) {
/* function called with no arguments, but all parameters have
a default value: use default values as arguments .*/
args = &PyTuple_GET_ITEM(argdefs, 0);
args = _PyTuple_ITEMS(argdefs);
return function_code_fastcall(co, args, PyTuple_GET_SIZE(argdefs),
globals);
}
Expand All @@ -342,7 +342,7 @@ _PyFunction_FastCallDict(PyObject *func, PyObject *const *args, Py_ssize_t nargs
return NULL;
}

k = &PyTuple_GET_ITEM(kwtuple, 0);
k = _PyTuple_ITEMS(kwtuple);
pos = i = 0;
while (PyDict_Next(kwargs, &pos, &k[i], &k[i+1])) {
/* We must hold strong references because keyword arguments can be
Expand All @@ -365,7 +365,7 @@ _PyFunction_FastCallDict(PyObject *func, PyObject *const *args, Py_ssize_t nargs
qualname = ((PyFunctionObject *)func) -> func_qualname;

if (argdefs != NULL) {
d = &PyTuple_GET_ITEM(argdefs, 0);
d = _PyTuple_ITEMS(argdefs);
nd = PyTuple_GET_SIZE(argdefs);
}
else {
Expand Down Expand Up @@ -411,7 +411,7 @@ _PyFunction_FastCallKeywords(PyObject *func, PyObject *const *stack,
&& co->co_argcount == PyTuple_GET_SIZE(argdefs)) {
/* function called with no arguments, but all parameters have
a default value: use default values as arguments .*/
stack = &PyTuple_GET_ITEM(argdefs, 0);
stack = _PyTuple_ITEMS(argdefs);
return function_code_fastcall(co, stack, PyTuple_GET_SIZE(argdefs),
globals);
}
Expand All @@ -423,7 +423,7 @@ _PyFunction_FastCallKeywords(PyObject *func, PyObject *const *stack,
qualname = ((PyFunctionObject *)func) -> func_qualname;

if (argdefs != NULL) {
d = &PyTuple_GET_ITEM(argdefs, 0);
d = _PyTuple_ITEMS(argdefs);
nd = PyTuple_GET_SIZE(argdefs);
}
else {
Expand All @@ -432,7 +432,7 @@ _PyFunction_FastCallKeywords(PyObject *func, PyObject *const *stack,
}
return _PyEval_EvalCodeWithName((PyObject*)co, globals, (PyObject *)NULL,
stack, nargs,
nkwargs ? &PyTuple_GET_ITEM(kwnames, 0) : NULL,
nkwargs ? _PyTuple_ITEMS(kwnames) : NULL,
stack + nargs,
nkwargs, 1,
d, (int)nd, kwdefs,
Expand Down Expand Up @@ -785,7 +785,7 @@ PyCFunction_Call(PyObject *func, PyObject *args, PyObject *kwargs)
}
else {
return _PyCFunction_FastCallDict(func,
&PyTuple_GET_ITEM(args, 0),
_PyTuple_ITEMS(args),
PyTuple_GET_SIZE(args),
kwargs);
}
Expand Down Expand Up @@ -898,8 +898,8 @@ _PyObject_Call_Prepend(PyObject *callable,
/* use borrowed references */
stack[0] = obj;
memcpy(&stack[1],
&PyTuple_GET_ITEM(args, 0),
argcount * sizeof(PyObject *));
_PyTuple_ITEMS(args),
argcount * sizeof(PyObject *));

result = _PyObject_FastCallDict(callable,
stack, argcount + 1,
Expand Down Expand Up @@ -950,7 +950,7 @@ _PyObject_CallFunctionVa(PyObject *callable, const char *format,
func(*(arg1, arg2, arg3)): func(arg1, arg2, arg3) */
PyObject *args = stack[0];
result = _PyObject_FastCall(callable,
&PyTuple_GET_ITEM(args, 0),
_PyTuple_ITEMS(args),
PyTuple_GET_SIZE(args));
}
else {
Expand Down
2 changes: 1 addition & 1 deletion Objects/codeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ intern_strings(PyObject *tuple)
if (v == NULL || !PyUnicode_CheckExact(v)) {
Py_FatalError("non-string found in code slot");
}
PyUnicode_InternInPlace(&PyTuple_GET_ITEM(tuple, i));
PyUnicode_InternInPlace(&_PyTuple_ITEMS(tuple)[i]);
}
}

Expand Down
4 changes: 2 additions & 2 deletions Objects/descrobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ methoddescr_call(PyMethodDescrObject *descr, PyObject *args, PyObject *kwargs)
}

result = _PyMethodDef_RawFastCallDict(descr->d_method, self,
&PyTuple_GET_ITEM(args, 1), nargs - 1,
&_PyTuple_ITEMS(args)[1], nargs - 1,
kwargs);
result = _Py_CheckFunctionResult((PyObject *)descr, result, NULL);
return result;
Expand Down Expand Up @@ -331,7 +331,7 @@ classmethoddescr_call(PyMethodDescrObject *descr, PyObject *args,
}

result = _PyMethodDef_RawFastCallDict(descr->d_method, self,
&PyTuple_GET_ITEM(args, 1), argc - 1,
&_PyTuple_ITEMS(args)[1], argc - 1,
kwds);
result = _Py_CheckFunctionResult((PyObject *)descr, result, NULL);
return result;
Expand Down
2 changes: 1 addition & 1 deletion Objects/funcobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ function_call(PyObject *func, PyObject *args, PyObject *kwargs)
PyObject **stack;
Py_ssize_t nargs;

stack = &PyTuple_GET_ITEM(args, 0);
stack = _PyTuple_ITEMS(args);
nargs = PyTuple_GET_SIZE(args);
return _PyFunction_FastCallDict(func, stack, nargs, kwargs);
}
Expand Down
2 changes: 1 addition & 1 deletion Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -4662,7 +4662,7 @@ do_call_core(PyObject *func, PyObject *callargs, PyObject *kwdict)
}

C_TRACE(result, _PyCFunction_FastCallDict(func,
&PyTuple_GET_ITEM(callargs, 1),
&_PyTuple_ITEMS(callargs)[1],
nargs - 1,
kwdict));
Py_DECREF(func);
Expand Down
6 changes: 3 additions & 3 deletions Python/getargs.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ vgetargs1(PyObject *args, const char *format, va_list *p_va, int flags)
return 0;
}

stack = &PyTuple_GET_ITEM(args, 0);
stack = _PyTuple_ITEMS(args);
nargs = PyTuple_GET_SIZE(args);
}
else {
Expand Down Expand Up @@ -2254,7 +2254,7 @@ vgetargskeywordsfast(PyObject *args, PyObject *keywords,
return 0;
}

stack = &PyTuple_GET_ITEM(args, 0);
stack = _PyTuple_ITEMS(args);
nargs = PyTuple_GET_SIZE(args);
return vgetargskeywordsfast_impl(stack, nargs, keywords, NULL,
parser, p_va, flags);
Expand Down Expand Up @@ -2461,7 +2461,7 @@ PyArg_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssize_t m
"PyArg_UnpackTuple() argument list is not a tuple");
return 0;
}
stack = &PyTuple_GET_ITEM(args, 0);
stack = _PyTuple_ITEMS(args);
nargs = PyTuple_GET_SIZE(args);

#ifdef HAVE_STDARG_PROTOTYPES
Expand Down