8000 [3.10] Add more const modifiers. (GH-26691). (GH-26692) · python/cpython@c43317d · GitHub
[go: up one dir, main page]

Skip to content

Commit c43317d

Browse files
[3.10] Add more const modifiers. (GH-26691). (GH-26692)
(cherry picked from commit be8b631) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
1 parent b441e99 commit c43317d

File tree

7 files changed

+24
-24
lines changed

7 files changed

+24
-24
lines changed

Include/cpython/code.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ PyAPI_FUNC(int) PyCode_Addr2Line(PyCodeObject *, int);
137137
/* for internal use only */
138138
struct _opaque {
139139
int computed_line;
140-
char *lo_next;
141-
char *limit;
140+
const char *lo_next;
141+
const char *limit;
142142
};
143143

144144
typedef struct _line_offsets {
@@ -175,7 +175,7 @@ PyAPI_FUNC(int) _PyCode_SetExtra(PyObject *code, Py_ssize_t index,
175175
int _PyCode_InitAddressRange(PyCodeObject* co, PyCodeAddressRange *bounds);
176176

177177
/** Out of process API for initializing the line number table. */
178-
void PyLineTable_InitAddressRange(char *linetable, Py_ssize_t length, int firstlineno, PyCodeAddressRange *range);
178+
void PyLineTable_InitAddressRange(const char *linetable, Py_ssize_t length, int firstlineno, PyCodeAddressRange *range);
179179

180180
/** API for traversing the line number table. */
181181
int PyLineTable_NextAddressRange(PyCodeAddressRange *range);

Modules/_zoneinfo.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,11 +1468,11 @@ parse_tz_str(PyObject *tz_str_obj, _tzrule *out)
14681468
long std_offset = 1 << 20;
14691469
long dst_offset = 1 << 20;
14701470

1471-
char *tz_str = PyBytes_AsString(tz_str_obj);
1471+
const char *tz_str = PyBytes_AsString(tz_str_obj);
14721472
if (tz_str == NULL) {
14731473
return -1;
14741474
}
1475-
char *p = tz_str;
1475+
const char *p = tz_str;
14761476

14771477
// Read the `std` abbreviation, which must be at least 3 characters long.
14781478
Py_ssize_t num_chars = parse_abbr(p, &std_abbr);

Objects/codeobject.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ _PyCode_InitOpcache(PyCodeObject *co)
294294
return -1;
295295
}
296296

297-
_Py_CODEUNIT *opcodes = (_Py_CODEUNIT*)PyBytes_AS_STRING(co->co_code);
297+
const _Py_CODEUNIT *opcodes = (_Py_CODEUNIT*)PyBytes_AS_STRING(co->co_code);
298298
Py_ssize_t opts = 0;
299299

300300
for (Py_ssize_t i = 0; i < co_size;) {
@@ -1255,7 +1255,7 @@ PyCode_Addr2Line(PyCodeObject *co, int addrq)
12551255
}
12561256

12571257
void
1258-
PyLineTable_InitAddressRange(char *linetable, Py_ssize_t length, int firstlineno, PyCodeAddressRange *range)
1258+
PyLineTable_InitAddressRange(const char *linetable, Py_ssize_t length, int firstlineno, PyCodeAddressRange *range)
12591259
{
12601260
range->opaque.lo_next = linetable;
12611261
range->opaque.limit = range->opaque.lo_next + length;
@@ -1268,7 +1268,7 @@ PyLineTable_InitAddressRange(char *linetable, Py_ssize_t length, int firstlineno
12681268
int
12691269
_PyCode_InitAddressRange(PyCodeObject* co, PyCodeAddressRange *bounds)
12701270
{
1271-
char *linetable = PyBytes_AS_STRING(co->co_linetable);
1271+
const char *linetable = PyBytes_AS_STRING(co->co_linetable);
12721272
Py_ssize_t length = PyBytes_GET_SIZE(co->co_linetable);
12731273
PyLineTable_InitAddressRange(linetable, length, co->co_firstlineno, bounds);
12741274
return bounds->ar_line;

Objects/unicodeobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ unicode_result_ready(PyObject *unicode)
658658
if (length == 1) {
659659
int kind = PyUnicode_KIND(unicode);
660660
if (kind == PyUnicode_1BYTE_KIND) {
661-
Py_UCS1 *data = PyUnicode_1BYTE_DATA(unicode);
661+
const Py_UCS1 *data = PyUnicode_1BYTE_DATA(unicode);
662662
Py_UCS1 ch = data[0];
663663
struct _Py_unicode_state *state = get_unicode_state();
664664
PyObject *latin1_char = state->latin1[ch];

Parser/pegen.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include "string_parser.h"
88

99
PyObject *
10-
_PyPegen_new_type_comment(Parser *p, char *s)
10+
_PyPegen_new_type_comment(Parser *p, const char *s)
1111
{
1212
PyObject *res = PyUnicode_DecodeUTF8(s, strlen(s), NULL);
1313
if (res == NULL) {
@@ -26,7 +26,7 @@ _PyPegen_add_type_comment_to_arg(Parser *p, arg_ty a, Token *tc)
2626
if (tc == NULL) {
2727
return a;
2828
}
29-
char *bytes = PyBytes_AsString(tc->bytes);
29+
const char *bytes = PyBytes_AsString(tc->bytes);
3030
if (bytes == NULL) {
3131
return NULL;
3232
}
@@ -66,7 +66,7 @@ _PyPegen_check_barry_as_flufl(Parser *p, Token* t) {
6666
assert(t->bytes != NULL);
6767
assert(t->type == NOTEQUAL);
6868

69-
char* tok_str = PyBytes_AS_STRING(t->bytes);
69+
const char* tok_str = PyBytes_AS_STRING(t->bytes);
7070
if (p->flags & PyPARSE_BARRY_AS_BDFL && strcmp(tok_str, "<>") != 0) {
7171
RAISE_SYNTAX_ERROR("with Barry as BDFL, use '<>' instead of '!='");
7272
return -1;
@@ -78,7 +78,7 @@ _PyPegen_check_barry_as_flufl(Parser *p, Token* t) {
7878
}
7979

8080
PyObject *
81-
_PyPegen_new_identifier(Parser *p, char *n)
81+
_PyPegen_new_identifier(Parser *p, const char *n)
8282
{
8383
PyObject *id = PyUnicode_DecodeUTF8(n, strlen(n), NULL);
8484
if (!id) {
@@ -911,7 +911,7 @@ _PyPegen_expect_soft_keyword(Parser *p, const char *keyword)
911911
if (t->type != NAME) {
912912
return NULL;
913913
}
914-
char *s = PyBytes_AsString(t->bytes);
914+
const char *s = PyBytes_AsString(t->bytes);
915915
if (!s) {
916916
p->error_indicator = 1;
917917
return NULL;
@@ -942,7 +942,7 @@ _PyPegen_name_from_token(Parser *p, Token* t)
942942
if (t == NULL) {
943943
return NULL;
944944
}
945-
char* s = PyBytes_AsString(t->bytes);
945+
const char *s = PyBytes_AsString(t->bytes);
946946
if (!s) {
947947
p->error_indicator = 1;
948948
return NULL;
@@ -1068,7 +1068,7 @@ _PyPegen_number_token(Parser *p)
10681068
return NULL;
10691069
}
10701070

1071-
char *num_raw = PyBytes_AsString(t->bytes);
1071+
const char *num_raw = PyBytes_AsString(t->bytes);
10721072
if (num_raw == NULL) {
10731073
p->error_indicator = 1;
10741074
return NULL;

Parser/pegen.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,15 @@ CHECK_CALL_NULL_ALLOWED(Parser *p, void *result)
202202
#define CHECK(type, result) ((type) CHECK_CALL(p, result))
203203
#define CHECK_NULL_ALLOWED(type, result) ((type) CHECK_CALL_NULL_ALLOWED(p, result))
204204

205-
PyObject *_PyPegen_new_type_comment(Parser *, char *);
205+
PyObject *_PyPegen_new_type_comment(Parser *, const char *);
206206

207207
Py_LOCAL_INLINE(PyObject *)
208208
NEW_TYPE_COMMENT(Parser *p, Token *tc)
209209
{
210210
if (tc == NULL) {
211211
return NULL;
212212
}
213-
char *bytes = PyBytes_AsString(tc->bytes);
213+
const char *bytes = PyBytes_AsString(tc->bytes);
214214
if (bytes == NULL) {
215215
goto error;
216216
}
@@ -242,7 +242,7 @@ INVALID_VERSION_CHECK(Parser *p, int version, char *msg, void *node)
242242
#define CHECK_VERSION(type, version, msg, node) ((type) INVALID_VERSION_CHECK(p, version, msg, node))
243243

244244
arg_ty _PyPegen_add_type_comment_to_arg(Parser *, arg_ty, Token *);
245-
PyObject *_PyPegen_new_identifier(Parser *, char *);
245+
PyObject *_PyPegen_new_identifier(Parser *, const char *);
246246
Parser *_PyPegen_Parser_New(struct tok_state *, int, int, int, int *, PyArena *);
247247
void _PyPegen_Parser_Free(Parser *);
248248
mod_ty _PyPegen_run_parser_from_file_pointer(FILE *, int, PyObject *, const char *,

Parser/string_parser.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ decode_unicode_with_escapes(Parser *parser, const char *s, size_t len, Token *t)
8787
if (*s & 0x80) {
8888
PyObject *w;
8989
int kind;
90-
void *data;
90+
const void *data;
9191
Py_ssize_t w_len;
9292
Py_ssize_t i;
9393
w = decode_utf8(&s, end);
@@ -288,17 +288,17 @@ fstring_find_expr_location(Token *parent, char *expr_str, int *p_lines, int *p_c
288288
*p_lines = 0;
289289
*p_cols = 0;
290290
if (parent && parent->bytes) {
291-
char *parent_str = PyBytes_AsString(parent->bytes);
291+
const char *parent_str = PyBytes_AsString(parent->bytes);
292292
if (!parent_str) {
293293
return false;
294294
}
295-
char *substr = strstr(parent_str, expr_str);
295+
const char *substr = strstr(parent_str, expr_str);
296296
if (substr) {
297297
// The following is needed, in order to correctly shift the column
298298
// offset, in the case that (disregarding any whitespace) a newline
299299
// immediately follows the opening curly brace of the fstring expression.
300300
bool newline_after_brace = 1;
301-
char *start = substr + 1;
301+
const char *start = substr + 1;
302302
while (start && *start != '}' && *start != '\n') {
303303
if (*start != ' ' && *start != '\t' && *start != '\f') {
304304
newline_after_brace = 0;
@@ -318,7 +318,7 @@ fstring_find_expr_location(Token *parent, char *expr_str, int *p_lines, int *p_c
318318
}
319319
/* adjust the start based on the number of newlines encountered
320320
before the f-string expression */
321-
for (char* p = parent_str; p < substr; p++) {
321+
for (const char *p = parent_str; p < substr; p++) {
322322
if (*p == '\n') {
323323
(*p_lines)++;
324324
}

0 commit comments

Comments
 (0)
0