Skip to content

Commit b63a793

Browse files
serhiy-storchakajdevries3133
authored andcommitted
Add more const modifiers. (pythonGH-26691)
1 parent 29584b7 commit b63a793

File tree

9 files changed

+27
-27
lines changed

9 files changed

+27
-27
lines changed

Include/cpython/code.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ PyAPI_FUNC(int) PyCode_Addr2Line(PyCodeObject *, int);
196196
/* for internal use only */
197197
struct _opaque {
198198
int computed_line;
199-
char *lo_next;
200-
char *limit;
199+
const char *lo_next;
200+
const char *limit;
201201
};
202202

203203
typedef struct _line_offsets {
@@ -234,7 +234,7 @@ PyAPI_FUNC(int) _PyCode_SetExtra(PyObject *code, Py_ssize_t index,
234234
int _PyCode_InitAddressRange(PyCodeObject* co, PyCodeAddressRange *bounds);
235235

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

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

Include/internal/pycore_code.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ typedef union _cache_or_instruction {
7979
* The zeroth entry immediately precedes the instructions.
8080
*/
8181
static inline SpecializedCacheEntry *
82-
_GetSpecializedCacheEntry(_Py_CODEUNIT *first_instr, Py_ssize_t n)
82+
_GetSpecializedCacheEntry(const _Py_CODEUNIT *first_instr, Py_ssize_t n)
8383
{
8484
SpecializedCacheOrInstruction *last_cache_plus_one = (SpecializedCacheOrInstruction *)first_instr;
8585
assert(&last_cache_plus_one->code[0] == first_instr);
@@ -126,7 +126,7 @@ offset_from_oparg_and_nexti(int oparg, int nexti)
126126
* nexti is used as it corresponds to the instruction pointer in the interpreter.
127127
* This doesn't check that an entry has been allocated for that instruction. */
128128
static inline SpecializedCacheEntry *
129-
_GetSpecializedCacheEntryForInstruction(_Py_CODEUNIT *first_instr, int nexti, int oparg)
129+
_GetSpecializedCacheEntryForInstruction(const _Py_CODEUNIT *first_instr, int nexti, int oparg)
130130
{
131131
return _GetSpecializedCacheEntry(
132132
first_instr,

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
@@ -627,7 +627,7 @@ PyCode_Addr2Line(PyCodeObject *co, int addrq)
627627
}
628628

629629
void
630-
PyLineTable_InitAddressRange(char *linetable, Py_ssize_t length, int firstlineno, PyCodeAddressRange *range)
630+
PyLineTable_InitAddressRange(const char *linetable, Py_ssize_t length, int firstlineno, PyCodeAddressRange *range)
631631
{
632632
range->opaque.lo_next = linetable;
633633
range->opaque.limit = range->opaque.lo_next + length;
@@ -640,7 +640,7 @@ PyLineTable_InitAddressRange(char *linetable, Py_ssize_t length, int firstlineno
640640
int
641641
_PyCode_InitAddressRange(PyCodeObject* co, PyCodeAddressRange *bounds)
642642
{
643-
char *linetable = PyBytes_AS_STRING(co->co_linetable);
643+
const char *linetable = PyBytes_AS_STRING(co->co_linetable);
644644
Py_ssize_t length = PyBytes_GET_SIZE(co->co_linetable);
645645
PyLineTable_InitAddressRange(linetable, length, co->co_firstlineno, bounds);
646646
return bounds->ar_line;
@@ -926,7 +926,7 @@ _PyCode_InitOpcache(PyCodeObject *co)
926926
return -1;
927927
}
928928

929-
_Py_CODEUNIT *opcodes = (_Py_CODEUNIT*)PyBytes_AS_STRING(co->co_code);
929+
const _Py_CODEUNIT *opcodes = (const _Py_CODEUNIT*)PyBytes_AS_STRING(co->co_code);
930930
Py_ssize_t opts = 0;
931931

932932
for (Py_ssize_t i = 0; i < co_size;) {

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
}

Python/specialize.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ oparg_from_instruction_and_update_offset(int index, int opcode, int original_opa
120120
}
121121

122122
static int
123-
entries_needed(_Py_CODEUNIT *code, int len)
123+
entries_needed(const _Py_CODEUNIT *code, int len)
124124
{
125125
int cache_offset = 0;
126126
int previous_opcode = -1;

0 commit comments

Comments
 (0)