Skip to content
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

bpo-36876: Make some static string literal arrays constant. #15760

Closed
Closed
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
2 changes: 1 addition & 1 deletion Doc/includes/custom2.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Custom_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
static int
Custom_init(CustomObject *self, PyObject *args, PyObject *kwds)
{
static char *kwlist[] = {"first", "last", "number", NULL};
static const char *kwlist[] = {"first", "last", "number", NULL};
PyObject *first = NULL, *last = NULL, *tmp;

if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOi", kwlist,
Expand Down
2 changes: 1 addition & 1 deletion Doc/includes/custom3.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Custom_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
static int
Custom_init(CustomObject *self, PyObject *args, PyObject *kwds)
{
static char *kwlist[] = {"first", "last", "number", NULL};
static const char *kwlist[] = {"first", "last", "number", NULL};
PyObject *first = NULL, *last = NULL, *tmp;

if (!PyArg_ParseTupleAndKeywords(args, kwds, "|UUi", kwlist,
Expand Down
2 changes: 1 addition & 1 deletion Doc/includes/custom4.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Custom_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
static int
Custom_init(CustomObject *self, PyObject *args, PyObject *kwds)
{
static char *kwlist[] = {"first", "last", "number", NULL};
static const char *kwlist[] = {"first", "last", "number", NULL};
PyObject *first = NULL, *last = NULL, *tmp;

if (!PyArg_ParseTupleAndKeywords(args, kwds, "|UUi", kwlist,
Expand Down
8 changes: 4 additions & 4 deletions Modules/_bisectmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ bisect_right(PyObject *self, PyObject *args, PyObject *kw)
Py_ssize_t lo = 0;
Py_ssize_t hi = -1;
Py_ssize_t index;
static char *keywords[] = {"a", "x", "lo", "hi", NULL};
static const char *keywords[] = {"a", "x", "lo", "hi", NULL};

if (kw == NULL && PyTuple_GET_SIZE(args) == 2) {
list = PyTuple_GET_ITEM(args, 0);
Expand Down Expand Up @@ -87,7 +87,7 @@ insort_right(PyObject *self, PyObject *args, PyObject *kw)
Py_ssize_t lo = 0;
Py_ssize_t hi = -1;
Py_ssize_t index;
static char *keywords[] = {"a", "x", "lo", "hi", NULL};
static const char *keywords[] = {"a", "x", "lo", "hi", NULL};

if (kw == NULL && PyTuple_GET_SIZE(args) == 2) {
list = PyTuple_GET_ITEM(args, 0);
Expand Down Expand Up @@ -168,7 +168,7 @@ bisect_left(PyObject *self, PyObject *args, PyObject *kw)
Py_ssize_t lo = 0;
Py_ssize_t hi = -1;
Py_ssize_t index;
static char *keywords[] = {"a", "x", "lo", "hi", NULL};
static const char *keywords[] = {"a", "x", "lo", "hi", NULL};

if (kw == NULL && PyTuple_GET_SIZE(args) == 2) {
list = PyTuple_GET_ITEM(args, 0);
Expand Down Expand Up @@ -204,7 +204,7 @@ insort_left(PyObject *self, PyObject *args, PyObject *kw)
Py_ssize_t lo = 0;
Py_ssize_t hi = -1;
Py_ssize_t index;
static char *keywords[] = {"a", "x", "lo", "hi", NULL};
static const char *keywords[] = {"a", "x", "lo", "hi", NULL};

if (kw == NULL && PyTuple_GET_SIZE(args) == 2) {
list = PyTuple_GET_ITEM(args, 0);
Expand Down
2 changes: 1 addition & 1 deletion Modules/_collectionsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1461,7 +1461,7 @@ deque_init(dequeobject *deque, PyObject *args, PyObject *kwdargs)
PyObject *iterable = NULL;
PyObject *maxlenobj = NULL;
Py_ssize_t maxlen = -1;
char *kwlist[] = {"iterable", "maxlen", 0};
static const char *kwlist[] = {"iterable", "maxlen", 0};

if (kwdargs == NULL && PyTuple_GET_SIZE(args) <= 2) {
if (PyTuple_GET_SIZE(args) > 0) {
Expand Down
2 changes: 1 addition & 1 deletion Modules/_csv.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ Dialect_dealloc(DialectObj *self)
Py_TYPE(self)->tp_free((PyObject *)self);
}

static char *dialect_kws[] = {
static const char *dialect_kws[] = {
"dialect",
"delimiter",
"doublequote",
Expand Down
28 changes: 14 additions & 14 deletions Modules/_datetimemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2434,7 +2434,7 @@ delta_new(PyTypeObject *type, PyObject *args, PyObject *kw)
PyObject *y = NULL; /* temp sum of microseconds */
double leftover_us = 0.0;

static char *keywords[] = {
static const char *keywords[] = {
"days", "seconds", "microseconds", "milliseconds",
"minutes", "hours", "weeks", NULL
};
Expand Down Expand Up @@ -2791,7 +2791,7 @@ static PyGetSetDef date_getset[] = {

/* Constructors. */

static char *date_kws[] = {"year", "month", "day", NULL};
static const char *date_kws[] = {"year", "month", "day", NULL};

static PyObject *
date_from_pickle(PyTypeObject *type, PyObject *state)
Expand Down Expand Up @@ -3008,7 +3008,7 @@ date_fromisoformat(PyObject *cls, PyObject *dtstr)
static PyObject *
date_fromisocalendar(PyObject *cls, PyObject *args, PyObject *kw)
{
static char *keywords[] = {
static const char *keywords[] = {
"year", "week", "day", NULL
};

Expand Down Expand Up @@ -3184,7 +3184,7 @@ date_strftime(PyDateTime_Date *self, PyObject *args, PyObject *kw)
PyObject *tuple;
PyObject *format;
_Py_IDENTIFIER(timetuple);
static char *keywords[] = {"format", NULL};
static const char *keywords[] = {"format", NULL};

if (! PyArg_ParseTupleAndKeywords(args, kw, "U:strftime", keywords,
&format))
Expand Down Expand Up @@ -3717,7 +3717,7 @@ static PyTypeObject PyDateTime_TZInfoType = {
0, /* tp_free */
};

static char *timezone_kws[] = {"offset", "name", NULL};
static const char *timezone_kws[] = {"offset", "name", NULL};

static PyObject *
timezone_new(PyTypeObject *type, PyObject *args, PyObject *kw)
Expand Down Expand Up @@ -4012,8 +4012,8 @@ static PyGetSetDef time_getset[] = {
* Constructors.
*/

static char *time_kws[] = {"hour", "minute", "second", "microsecond",
"tzinfo", "fold", NULL};
static const char *time_kws[] = {"hour", "minute", "second", "microsecond",
"tzinfo", "fold", NULL};

static PyObject *
time_from_pickle(PyTypeObject *type, PyObject *state, PyObject *tzinfo)
Expand Down Expand Up @@ -4181,7 +4181,7 @@ time_isoformat(PyDateTime_Time *self, PyObject *args, PyObject *kw)
{
char buf[100];
char *timespec = NULL;
static char *keywords[] = {"timespec", NULL};
static const char *keywords[] = {"timespec", NULL};
PyObject *result;
int us = TIME_GET_MICROSECOND(self);
static char *specs[][2] = {
Expand Down Expand Up @@ -4247,7 +4247,7 @@ time_strftime(PyDateTime_Time *self, PyObject *args, PyObject *kw)
PyObject *result;
PyObject *tuple;
PyObject *format;
static char *keywords[] = {"format", NULL};
static const char *keywords[] = {"format", NULL};

if (! PyArg_ParseTupleAndKeywords(args, kw, "U:strftime", keywords,
&format))
Expand Down Expand Up @@ -4676,7 +4676,7 @@ static PyGetSetDef datetime_getset[] = {
* Constructors.
*/

static char *datetime_kws[] = {
static const char *datetime_kws[] = {
"year", "month", "day", "hour", "minute", "second",
"microsecond", "tzinfo", "fold", NULL
};
Expand Down Expand Up @@ -4981,7 +4981,7 @@ datetime_fromtimestamp(PyObject *cls, PyObject *args, PyObject *kw)
PyObject *self;
PyObject *timestamp;
PyObject *tzinfo = Py_None;
static char *keywords[] = {"timestamp", "tz", NULL};
static const char *keywords[] = {"timestamp", "tz", NULL};

if (! PyArg_ParseTupleAndKeywords(args, kw, "O|O:fromtimestamp",
keywords, &timestamp, &tzinfo))
Expand Down Expand Up @@ -5038,7 +5038,7 @@ datetime_strptime(PyObject *cls, PyObject *args)
static PyObject *
datetime_combine(PyObject *cls, PyObject *args, PyObject *kw)
{
static char *keywords[] = {"date", "time", "tzinfo", NULL};
static const char *keywords[] = {"date", "time", "tzinfo", NULL};
PyObject *date;
PyObject *time;
PyObject *tzinfo = NULL;
Expand Down Expand Up @@ -5412,7 +5412,7 @@ datetime_isoformat(PyDateTime_DateTime *self, PyObject *args, PyObject *kw)
{
int sep = 'T';
char *timespec = NULL;
static char *keywords[] = {"sep", "timespec", NULL};
static const char *keywords[] = {"sep", "timespec", NULL};
char buffer[100];
PyObject *result = NULL;
int us = DATE_GET_MICROSECOND(self);
Expand Down Expand Up @@ -5868,7 +5868,7 @@ datetime_astimezone(PyDateTime_DateTime *self, PyObject *args, PyObject *kw)
PyObject *temp;
PyObject *self_tzinfo;
PyObject *tzinfo = Py_None;
static char *keywords[] = {"tz", NULL};
static const char *keywords[] = {"tz", NULL};

if (! PyArg_ParseTupleAndKeywords(args, kw, "|O:astimezone", keywords,
&tzinfo))
Expand Down
32 changes: 16 additions & 16 deletions Modules/_decimal/_decimal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,7 @@ context_dealloc(PyDecContextObject *self)
static int
context_init(PyObject *self, PyObject *args, PyObject *kwds)
{
static char *kwlist[] = {
static const char *kwlist[] = {
"prec", "rounding", "Emin", "Emax", "capitals", "clamp",
"flags", "traps", NULL
};
Expand Down Expand Up @@ -1577,7 +1577,7 @@ PyDec_SetCurrentContext(PyObject *self UNUSED, PyObject *v)
static PyObject *
ctxmanager_new(PyTypeObject *type UNUSED, PyObject *args, PyObject *kwds)
{
static char *kwlist[] = {"ctx", NULL};
static const char *kwlist[] = {"ctx", NULL};
PyDecContextManagerObject *self;
PyObject *local = Py_None;
PyObject *global;
Expand Down Expand Up @@ -2641,7 +2641,7 @@ PyDec_FromObject(PyObject *v, PyObject *context)
static PyObject *
dec_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
static char *kwlist[] = {"value", "context", NULL};
static const char *kwlist[] = {"value", "context", NULL};
PyObject *v = NULL;
PyObject *context = Py_None;

Expand Down Expand Up @@ -3364,7 +3364,7 @@ dec_as_integer_ratio(PyObject *self, PyObject *args UNUSED)
static PyObject *
PyDec_ToIntegralValue(PyObject *dec, PyObject *args, PyObject *kwds)
{
static char *kwlist[] = {"rounding", "context", NULL};
static const char *kwlist[] = {"rounding", "context", NULL};
PyObject *result;
PyObject *rounding = Py_None;
PyObject *context = Py_None;
Expand Down Expand Up @@ -3405,7 +3405,7 @@ PyDec_ToIntegralValue(PyObject *dec, PyObject *args, PyObject *kwds)
static PyObject *
PyDec_ToIntegralExact(PyObject *dec, PyObject *args, PyObject *kwds)
{
static char *kwlist[] = {"rounding", "context", NULL};
static const char *kwlist[] = {"rounding", "context", NULL};
PyObject *result;
PyObject *rounding = Py_None;
PyObject *context = Py_None;
Expand Down Expand Up @@ -3689,7 +3689,7 @@ dec_##MPDFUNC(PyObject *self, PyObject *dummy UNUSED) \
static PyObject * \
dec_##MPDFUNC(PyObject *self, PyObject *args, PyObject *kwds) \
{ \
static char *kwlist[] = {"context", NULL}; \
static const char *kwlist[] = {"context", NULL}; \
PyObject *context = Py_None; \
\
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O", kwlist, \
Expand All @@ -3706,7 +3706,7 @@ dec_##MPDFUNC(PyObject *self, PyObject *args, PyObject *kwds) \
static PyObject * \
dec_##MPDFUNC(PyObject *self, PyObject *args, PyObject *kwds) \
{ \
static char *kwlist[] = {"context", NULL}; \
static const char *kwlist[] = {"context", NULL}; \
PyObject *result; \
PyObject *context = Py_None; \
uint32_t status = 0; \
Expand Down Expand Up @@ -3735,7 +3735,7 @@ dec_##MPDFUNC(PyObject *self, PyObject *args, PyObject *kwds) \
static PyObject * \
dec_##MPDFUNC(PyObject *self, PyObject *args, PyObject *kwds) \
{ \
static char *kwlist[] = {"other", "context", NULL}; \
static const char *kwlist[] = {"other", "context", NULL}; \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few other alignment issues like the ones above - probably best to align the newline escapes as above.

PyObject *other; \
PyObject *a, *b; \
PyObject *result; \
Expand Down Expand Up @@ -3773,7 +3773,7 @@ dec_##MPDFUNC(PyObject *self, PyObject *args, PyObject *kwds) \
static PyObject * \
dec_##MPDFUNC(PyObject *self, PyObject *args, PyObject *kwds) \
{ \
static char *kwlist[] = {"other", "context", NULL}; \
static const char *kwlist[] = {"other", "context", NULL}; \
PyObject *context = Py_None; \
PyObject *other; \
PyObject *a, *b; \
Expand Down Expand Up @@ -3804,7 +3804,7 @@ dec_##MPDFUNC(PyObject *self, PyObject *args, PyObject *kwds) \
static PyObject * \
dec_##MPDFUNC(PyObject *self, PyObject *args, PyObject *kwds) \
{ \
static char *kwlist[] = {"other", "third", "context", NULL}; \
static const char *kwlist[] = {"other", "third", "context", NULL}; \
PyObject *other, *third; \
PyObject *a, *b, *c; \
PyObject *result; \
Expand Down Expand Up @@ -4087,7 +4087,7 @@ Dec_UnaryFuncVA(mpd_qlogb)
static PyObject *
dec_mpd_class(PyObject *self, PyObject *args, PyObject *kwds)
{
static char *kwlist[] = {"context", NULL};
static const char *kwlist[] = {"context", NULL};
PyObject *context = Py_None;
const char *cp;

Expand All @@ -4104,7 +4104,7 @@ dec_mpd_class(PyObject *self, PyObject *args, PyObject *kwds)
static PyObject *
dec_mpd_to_eng(PyObject *self, PyObject *args, PyObject *kwds)
{
static char *kwlist[] = {"context", NULL};
static const char *kwlist[] = {"context", NULL};
PyObject *result;
PyObject *context = Py_None;
mpd_ssize_t size;
Expand Down Expand Up @@ -4135,7 +4135,7 @@ Dec_BinaryFuncVA_NO_CTX(mpd_compare_total_mag)
static PyObject *
dec_mpd_qcopy_sign(PyObject *self, PyObject *args, PyObject *kwds)
{
static char *kwlist[] = {"other", "context", NULL};
static const char *kwlist[] = {"other", "context", NULL};
PyObject *other;
PyObject *a, *b;
PyObject *result;
Expand Down Expand Up @@ -4170,7 +4170,7 @@ dec_mpd_qcopy_sign(PyObject *self, PyObject *args, PyObject *kwds)
static PyObject *
dec_mpd_same_quantum(PyObject *self, PyObject *args, PyObject *kwds)
{
static char *kwlist[] = {"other", "context", NULL};
static const char *kwlist[] = {"other", "context", NULL};
PyObject *other;
PyObject *a, *b;
PyObject *result;
Expand Down Expand Up @@ -4202,7 +4202,7 @@ Dec_BinaryFuncVA(mpd_qshift)
static PyObject *
dec_mpd_qquantize(PyObject *v, PyObject *args, PyObject *kwds)
{
static char *kwlist[] = {"exp", "rounding", "context", NULL};
static const char *kwlist[] = {"exp", "rounding", "context", NULL};
PyObject *rounding = Py_None;
PyObject *context = Py_None;
PyObject *w, *a, *b;
Expand Down Expand Up @@ -4975,7 +4975,7 @@ ctx_mpd_qdivmod(PyObject *context, PyObject *args)
static PyObject *
ctx_mpd_qpow(PyObject *context, PyObject *args, PyObject *kwds)
{
static char *kwlist[] = {"a", "b", "modulo", NULL};
static const char *kwlist[] = {"a", "b", "modulo", NULL};
PyObject *base, *exp, *mod = Py_None;
PyObject *a, *b, *c = NULL;
PyObject *result;
Expand Down
2 changes: 1 addition & 1 deletion Modules/_elementtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -1090,7 +1090,7 @@ element_setstate_from_attributes(ElementObject *self,
static PyObject *
element_setstate_from_Python(ElementObject *self, PyObject *state)
{
static char *kwlist[] = {PICKLED_TAG, PICKLED_ATTRIB, PICKLED_TEXT,
static const char *kwlist[] = {PICKLED_TAG, PICKLED_ATTRIB, PICKLED_TEXT,
PICKLED_TAIL, PICKLED_CHILDREN, 0};
PyObject *args;
PyObject *tag, *attrib, *text, *tail, *children;
Expand Down
6 changes: 3 additions & 3 deletions Modules/_functoolsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ keyobject_call(keyobject *ko, PyObject *args, PyObject *kwds)
{
PyObject *object;
keyobject *result;
static char *kwargs[] = {"obj", NULL};
static const char *kwargs[] = {"obj", NULL};

if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:K", kwargs, &object))
return NULL;
Expand Down Expand Up @@ -598,7 +598,7 @@ static PyObject *
functools_cmp_to_key(PyObject *self, PyObject *args, PyObject *kwds)
{
PyObject *cmp;
static char *kwargs[] = {"mycmp", NULL};
static const char *kwargs[] = {"mycmp", NULL};
keyobject *object;

if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:cmp_to_key", kwargs, &cmp))
Expand Down Expand Up @@ -1131,7 +1131,7 @@ lru_cache_new(PyTypeObject *type, PyObject *args, PyObject *kw)
lru_cache_object *obj;
Py_ssize_t maxsize;
PyObject *(*wrapper)(lru_cache_object *, PyObject *, PyObject *);
static char *keywords[] = {"user_function", "maxsize", "typed",
static const char *keywords[] = {"user_function", "maxsize", "typed",
"cache_info_type", NULL};

if (!PyArg_ParseTupleAndKeywords(args, kw, "OOpO:lru_cache", keywords,
Expand Down
Loading