mirror of https://github.com/python/cpython
Add more const modifiers. (GH-26691)
This commit is contained in:
parent
9f1c5f6e8a
commit
be8b631b7a
|
@ -196,8 +196,8 @@ PyAPI_FUNC(int) PyCode_Addr2Line(PyCodeObject *, int);
|
||||||
/* for internal use only */
|
/* for internal use only */
|
||||||
struct _opaque {
|
struct _opaque {
|
||||||
int computed_line;
|
int computed_line;
|
||||||
char *lo_next;
|
const char *lo_next;
|
||||||
char *limit;
|
const char *limit;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct _line_offsets {
|
typedef struct _line_offsets {
|
||||||
|
@ -234,7 +234,7 @@ PyAPI_FUNC(int) _PyCode_SetExtra(PyObject *code, Py_ssize_t index,
|
||||||
int _PyCode_InitAddressRange(PyCodeObject* co, PyCodeAddressRange *bounds);
|
int _PyCode_InitAddressRange(PyCodeObject* co, PyCodeAddressRange *bounds);
|
||||||
|
|
||||||
/** Out of process API for initializing the line number table. */
|
/** Out of process API for initializing the line number table. */
|
||||||
void PyLineTable_InitAddressRange(char *linetable, Py_ssize_t length, int firstlineno, PyCodeAddressRange *range);
|
void PyLineTable_InitAddressRange(const char *linetable, Py_ssize_t length, int firstlineno, PyCodeAddressRange *range);
|
||||||
|
|
||||||
/** API for traversing the line number table. */
|
/** API for traversing the line number table. */
|
||||||
int PyLineTable_NextAddressRange(PyCodeAddressRange *range);
|
int PyLineTable_NextAddressRange(PyCodeAddressRange *range);
|
||||||
|
|
|
@ -79,7 +79,7 @@ typedef union _cache_or_instruction {
|
||||||
* The zeroth entry immediately precedes the instructions.
|
* The zeroth entry immediately precedes the instructions.
|
||||||
*/
|
*/
|
||||||
static inline SpecializedCacheEntry *
|
static inline SpecializedCacheEntry *
|
||||||
_GetSpecializedCacheEntry(_Py_CODEUNIT *first_instr, Py_ssize_t n)
|
_GetSpecializedCacheEntry(const _Py_CODEUNIT *first_instr, Py_ssize_t n)
|
||||||
{
|
{
|
||||||
SpecializedCacheOrInstruction *last_cache_plus_one = (SpecializedCacheOrInstruction *)first_instr;
|
SpecializedCacheOrInstruction *last_cache_plus_one = (SpecializedCacheOrInstruction *)first_instr;
|
||||||
assert(&last_cache_plus_one->code[0] == first_instr);
|
assert(&last_cache_plus_one->code[0] == first_instr);
|
||||||
|
@ -126,7 +126,7 @@ offset_from_oparg_and_nexti(int oparg, int nexti)
|
||||||
* nexti is used as it corresponds to the instruction pointer in the interpreter.
|
* nexti is used as it corresponds to the instruction pointer in the interpreter.
|
||||||
* This doesn't check that an entry has been allocated for that instruction. */
|
* This doesn't check that an entry has been allocated for that instruction. */
|
||||||
static inline SpecializedCacheEntry *
|
static inline SpecializedCacheEntry *
|
||||||
_GetSpecializedCacheEntryForInstruction(_Py_CODEUNIT *first_instr, int nexti, int oparg)
|
_GetSpecializedCacheEntryForInstruction(const _Py_CODEUNIT *first_instr, int nexti, int oparg)
|
||||||
{
|
{
|
||||||
return _GetSpecializedCacheEntry(
|
return _GetSpecializedCacheEntry(
|
||||||
first_instr,
|
first_instr,
|
||||||
|
|
|
@ -1468,11 +1468,11 @@ parse_tz_str(PyObject *tz_str_obj, _tzrule *out)
|
||||||
long std_offset = 1 << 20;
|
long std_offset = 1 << 20;
|
||||||
long dst_offset = 1 << 20;
|
long dst_offset = 1 << 20;
|
||||||
|
|
||||||
char *tz_str = PyBytes_AsString(tz_str_obj);
|
const char *tz_str = PyBytes_AsString(tz_str_obj);
|
||||||
if (tz_str == NULL) {
|
if (tz_str == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
char *p = tz_str;
|
const char *p = tz_str;
|
||||||
|
|
||||||
// Read the `std` abbreviation, which must be at least 3 characters long.
|
// Read the `std` abbreviation, which must be at least 3 characters long.
|
||||||
Py_ssize_t num_chars = parse_abbr(p, &std_abbr);
|
Py_ssize_t num_chars = parse_abbr(p, &std_abbr);
|
||||||
|
|
|
@ -627,7 +627,7 @@ PyCode_Addr2Line(PyCodeObject *co, int addrq)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PyLineTable_InitAddressRange(char *linetable, Py_ssize_t length, int firstlineno, PyCodeAddressRange *range)
|
PyLineTable_InitAddressRange(const char *linetable, Py_ssize_t length, int firstlineno, PyCodeAddressRange *range)
|
||||||
{
|
{
|
||||||
range->opaque.lo_next = linetable;
|
range->opaque.lo_next = linetable;
|
||||||
range->opaque.limit = range->opaque.lo_next + length;
|
range->opaque.limit = range->opaque.lo_next + length;
|
||||||
|
@ -640,7 +640,7 @@ PyLineTable_InitAddressRange(char *linetable, Py_ssize_t length, int firstlineno
|
||||||
int
|
int
|
||||||
_PyCode_InitAddressRange(PyCodeObject* co, PyCodeAddressRange *bounds)
|
_PyCode_InitAddressRange(PyCodeObject* co, PyCodeAddressRange *bounds)
|
||||||
{
|
{
|
||||||
char *linetable = PyBytes_AS_STRING(co->co_linetable);
|
const char *linetable = PyBytes_AS_STRING(co->co_linetable);
|
||||||
Py_ssize_t length = PyBytes_GET_SIZE(co->co_linetable);
|
Py_ssize_t length = PyBytes_GET_SIZE(co->co_linetable);
|
||||||
PyLineTable_InitAddressRange(linetable, length, co->co_firstlineno, bounds);
|
PyLineTable_InitAddressRange(linetable, length, co->co_firstlineno, bounds);
|
||||||
return bounds->ar_line;
|
return bounds->ar_line;
|
||||||
|
@ -926,7 +926,7 @@ _PyCode_InitOpcache(PyCodeObject *co)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
_Py_CODEUNIT *opcodes = (_Py_CODEUNIT*)PyBytes_AS_STRING(co->co_code);
|
const _Py_CODEUNIT *opcodes = (const _Py_CODEUNIT*)PyBytes_AS_STRING(co->co_code);
|
||||||
Py_ssize_t opts = 0;
|
Py_ssize_t opts = 0;
|
||||||
|
|
||||||
for (Py_ssize_t i = 0; i < co_size;) {
|
for (Py_ssize_t i = 0; i < co_size;) {
|
||||||
|
|
|
@ -658,7 +658,7 @@ unicode_result_ready(PyObject *unicode)
|
||||||
if (length == 1) {
|
if (length == 1) {
|
||||||
int kind = PyUnicode_KIND(unicode);
|
int kind = PyUnicode_KIND(unicode);
|
||||||
if (kind == PyUnicode_1BYTE_KIND) {
|
if (kind == PyUnicode_1BYTE_KIND) {
|
||||||
Py_UCS1 *data = PyUnicode_1BYTE_DATA(unicode);
|
const Py_UCS1 *data = PyUnicode_1BYTE_DATA(unicode);
|
||||||
Py_UCS1 ch = data[0];
|
Py_UCS1 ch = data[0];
|
||||||
struct _Py_unicode_state *state = get_unicode_state();
|
struct _Py_unicode_state *state = get_unicode_state();
|
||||||
PyObject *latin1_char = state->latin1[ch];
|
PyObject *latin1_char = state->latin1[ch];
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
#include "string_parser.h"
|
#include "string_parser.h"
|
||||||
|
|
||||||
PyObject *
|
PyObject *
|
||||||
_PyPegen_new_type_comment(Parser *p, char *s)
|
_PyPegen_new_type_comment(Parser *p, const char *s)
|
||||||
{
|
{
|
||||||
PyObject *res = PyUnicode_DecodeUTF8(s, strlen(s), NULL);
|
PyObject *res = PyUnicode_DecodeUTF8(s, strlen(s), NULL);
|
||||||
if (res == NULL) {
|
if (res == NULL) {
|
||||||
|
@ -26,7 +26,7 @@ _PyPegen_add_type_comment_to_arg(Parser *p, arg_ty a, Token *tc)
|
||||||
if (tc == NULL) {
|
if (tc == NULL) {
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
char *bytes = PyBytes_AsString(tc->bytes);
|
const char *bytes = PyBytes_AsString(tc->bytes);
|
||||||
if (bytes == NULL) {
|
if (bytes == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ _PyPegen_check_barry_as_flufl(Parser *p, Token* t) {
|
||||||
assert(t->bytes != NULL);
|
assert(t->bytes != NULL);
|
||||||
assert(t->type == NOTEQUAL);
|
assert(t->type == NOTEQUAL);
|
||||||
|
|
||||||
char* tok_str = PyBytes_AS_STRING(t->bytes);
|
const char* tok_str = PyBytes_AS_STRING(t->bytes);
|
||||||
if (p->flags & PyPARSE_BARRY_AS_BDFL && strcmp(tok_str, "<>") != 0) {
|
if (p->flags & PyPARSE_BARRY_AS_BDFL && strcmp(tok_str, "<>") != 0) {
|
||||||
RAISE_SYNTAX_ERROR("with Barry as BDFL, use '<>' instead of '!='");
|
RAISE_SYNTAX_ERROR("with Barry as BDFL, use '<>' instead of '!='");
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -78,7 +78,7 @@ _PyPegen_check_barry_as_flufl(Parser *p, Token* t) {
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject *
|
PyObject *
|
||||||
_PyPegen_new_identifier(Parser *p, char *n)
|
_PyPegen_new_identifier(Parser *p, const char *n)
|
||||||
{
|
{
|
||||||
PyObject *id = PyUnicode_DecodeUTF8(n, strlen(n), NULL);
|
PyObject *id = PyUnicode_DecodeUTF8(n, strlen(n), NULL);
|
||||||
if (!id) {
|
if (!id) {
|
||||||
|
@ -911,7 +911,7 @@ _PyPegen_expect_soft_keyword(Parser *p, const char *keyword)
|
||||||
if (t->type != NAME) {
|
if (t->type != NAME) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
char *s = PyBytes_AsString(t->bytes);
|
const char *s = PyBytes_AsString(t->bytes);
|
||||||
if (!s) {
|
if (!s) {
|
||||||
p->error_indicator = 1;
|
p->error_indicator = 1;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -942,7 +942,7 @@ _PyPegen_name_from_token(Parser *p, Token* t)
|
||||||
if (t == NULL) {
|
if (t == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
char* s = PyBytes_AsString(t->bytes);
|
const char *s = PyBytes_AsString(t->bytes);
|
||||||
if (!s) {
|
if (!s) {
|
||||||
p->error_indicator = 1;
|
p->error_indicator = 1;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -1068,7 +1068,7 @@ _PyPegen_number_token(Parser *p)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *num_raw = PyBytes_AsString(t->bytes);
|
const char *num_raw = PyBytes_AsString(t->bytes);
|
||||||
if (num_raw == NULL) {
|
if (num_raw == NULL) {
|
||||||
p->error_indicator = 1;
|
p->error_indicator = 1;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -202,7 +202,7 @@ CHECK_CALL_NULL_ALLOWED(Parser *p, void *result)
|
||||||
#define CHECK(type, result) ((type) CHECK_CALL(p, result))
|
#define CHECK(type, result) ((type) CHECK_CALL(p, result))
|
||||||
#define CHECK_NULL_ALLOWED(type, result) ((type) CHECK_CALL_NULL_ALLOWED(p, result))
|
#define CHECK_NULL_ALLOWED(type, result) ((type) CHECK_CALL_NULL_ALLOWED(p, result))
|
||||||
|
|
||||||
PyObject *_PyPegen_new_type_comment(Parser *, char *);
|
PyObject *_PyPegen_new_type_comment(Parser *, const char *);
|
||||||
|
|
||||||
Py_LOCAL_INLINE(PyObject *)
|
Py_LOCAL_INLINE(PyObject *)
|
||||||
NEW_TYPE_COMMENT(Parser *p, Token *tc)
|
NEW_TYPE_COMMENT(Parser *p, Token *tc)
|
||||||
|
@ -210,7 +210,7 @@ NEW_TYPE_COMMENT(Parser *p, Token *tc)
|
||||||
if (tc == NULL) {
|
if (tc == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
char *bytes = PyBytes_AsString(tc->bytes);
|
const char *bytes = PyBytes_AsString(tc->bytes);
|
||||||
if (bytes == NULL) {
|
if (bytes == NULL) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
@ -242,7 +242,7 @@ INVALID_VERSION_CHECK(Parser *p, int version, char *msg, void *node)
|
||||||
#define CHECK_VERSION(type, version, msg, node) ((type) INVALID_VERSION_CHECK(p, version, msg, node))
|
#define CHECK_VERSION(type, version, msg, node) ((type) INVALID_VERSION_CHECK(p, version, msg, node))
|
||||||
|
|
||||||
arg_ty _PyPegen_add_type_comment_to_arg(Parser *, arg_ty, Token *);
|
arg_ty _PyPegen_add_type_comment_to_arg(Parser *, arg_ty, Token *);
|
||||||
PyObject *_PyPegen_new_identifier(Parser *, char *);
|
PyObject *_PyPegen_new_identifier(Parser *, const char *);
|
||||||
Parser *_PyPegen_Parser_New(struct tok_state *, int, int, int, int *, PyArena *);
|
Parser *_PyPegen_Parser_New(struct tok_state *, int, int, int, int *, PyArena *);
|
||||||
void _PyPegen_Parser_Free(Parser *);
|
void _PyPegen_Parser_Free(Parser *);
|
||||||
mod_ty _PyPegen_run_parser_from_file_pointer(FILE *, int, PyObject *, const char *,
|
mod_ty _PyPegen_run_parser_from_file_pointer(FILE *, int, PyObject *, const char *,
|
||||||
|
|
|
@ -87,7 +87,7 @@ decode_unicode_with_escapes(Parser *parser, const char *s, size_t len, Token *t)
|
||||||
if (*s & 0x80) {
|
if (*s & 0x80) {
|
||||||
PyObject *w;
|
PyObject *w;
|
||||||
int kind;
|
int kind;
|
||||||
void *data;
|
const void *data;
|
||||||
Py_ssize_t w_len;
|
Py_ssize_t w_len;
|
||||||
Py_ssize_t i;
|
Py_ssize_t i;
|
||||||
w = decode_utf8(&s, end);
|
w = decode_utf8(&s, end);
|
||||||
|
@ -288,17 +288,17 @@ fstring_find_expr_location(Token *parent, char *expr_str, int *p_lines, int *p_c
|
||||||
*p_lines = 0;
|
*p_lines = 0;
|
||||||
*p_cols = 0;
|
*p_cols = 0;
|
||||||
if (parent && parent->bytes) {
|
if (parent && parent->bytes) {
|
||||||
char *parent_str = PyBytes_AsString(parent->bytes);
|
const char *parent_str = PyBytes_AsString(parent->bytes);
|
||||||
if (!parent_str) {
|
if (!parent_str) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
char *substr = strstr(parent_str, expr_str);
|
const char *substr = strstr(parent_str, expr_str);
|
||||||
if (substr) {
|
if (substr) {
|
||||||
// The following is needed, in order to correctly shift the column
|
// The following is needed, in order to correctly shift the column
|
||||||
// offset, in the case that (disregarding any whitespace) a newline
|
// offset, in the case that (disregarding any whitespace) a newline
|
||||||
// immediately follows the opening curly brace of the fstring expression.
|
// immediately follows the opening curly brace of the fstring expression.
|
||||||
bool newline_after_brace = 1;
|
bool newline_after_brace = 1;
|
||||||
char *start = substr + 1;
|
const char *start = substr + 1;
|
||||||
while (start && *start != '}' && *start != '\n') {
|
while (start && *start != '}' && *start != '\n') {
|
||||||
if (*start != ' ' && *start != '\t' && *start != '\f') {
|
if (*start != ' ' && *start != '\t' && *start != '\f') {
|
||||||
newline_after_brace = 0;
|
newline_after_brace = 0;
|
||||||
|
@ -318,7 +318,7 @@ fstring_find_expr_location(Token *parent, char *expr_str, int *p_lines, int *p_c
|
||||||
}
|
}
|
||||||
/* adjust the start based on the number of newlines encountered
|
/* adjust the start based on the number of newlines encountered
|
||||||
before the f-string expression */
|
before the f-string expression */
|
||||||
for (char* p = parent_str; p < substr; p++) {
|
for (const char *p = parent_str; p < substr; p++) {
|
||||||
if (*p == '\n') {
|
if (*p == '\n') {
|
||||||
(*p_lines)++;
|
(*p_lines)++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,7 +120,7 @@ oparg_from_instruction_and_update_offset(int index, int opcode, int original_opa
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
entries_needed(_Py_CODEUNIT *code, int len)
|
entries_needed(const _Py_CODEUNIT *code, int len)
|
||||||
{
|
{
|
||||||
int cache_offset = 0;
|
int cache_offset = 0;
|
||||||
int previous_opcode = -1;
|
int previous_opcode = -1;
|
||||||
|
|
Loading…
Reference in New Issue