8000 gh-124064: Fix -Wconversion warnings in Parser/pegen.c (#124181) · python/cpython@3aff1d0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3aff1d0

Browse files
authored
gh-124064: Fix -Wconversion warnings in Parser/pegen.c (#124181)
1 parent ec08aa1 commit 3aff1d0

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

Parser/pegen.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ _PyPegen_interactive_exit(Parser *p)
2222
Py_ssize_t
2323
_PyPegen_byte_offset_to_character_offset_line(PyObject *line, Py_ssize_t col_offset, Py_ssize_t end_col_offset)
2424
{
25-
const char *data = PyUnicode_AsUTF8(line);
25+
const unsigned char *data = (const unsigned char*)PyUnicode_AsUTF8(line);
2626

2727
Py_ssize_t len = 0;
2828
while (col_offset < end_col_offset) {
@@ -47,7 +47,7 @@ _PyPegen_byte_offset_to_character_offset_line(PyObject *line, Py_ssize_t col_off
4747
Py_ssize_t
4848
_PyPegen_byte_offset_to_character_offset_raw(const char* str, Py_ssize_t col_offset)
4949
{
50-
Py_ssize_t len = strlen(str);
50+
Py_ssize_t len = (Py_ssize_t)strlen(str);
5151
if (col_offset > len + 1) {
5252
col_offset = len + 1;
5353
}
@@ -158,7 +158,7 @@ growable_comment_array_deallocate(growable_comment_array *arr) {
158158
static int
159159
_get_keyword_or_name_type(Parser *p, struct token *new_token)
160160
{
161-
int name_len = new_token->end_col_offset - new_token->col_offset;
161+
Py_ssize_t name_len = new_token->end_col_offset - new_token->col_offset;
162162
assert(name_len > 0);
163163

164164
if (name_len >= p->n_keyword_lists ||
@@ -167,7 +167,7 @@ _get_keyword_or_name_type(Parser *p, struct token *new_token)
167167
return NAME;
168168
}
169169
for (KeywordToken *k = p->keywords[name_len]; k != NULL && k->type != -1; k++) {
170-
if (strncmp(k->str, new_token->start, name_len) == 0) {
170+
if (strncmp(k->str, new_token->start, (size_t)name_len) == 0) {
171171
return k->type;
172172
}
173173
}
@@ -218,7 +218,7 @@ initialize_token(Parser *p, Token *parser_token, struct token *new_token, int to
218218
static int
219219
_resize_tokens_array(Parser *p) {
220220
int newsize = p->size * 2;
221-
Token **new_tokens = PyMem_Realloc(p->tokens, newsize * sizeof(Token *));
221+
Token **new_tokens = PyMem_Realloc(p->tokens, (size_t)newsize * sizeof(Token *));
222222
if (new_tokens == NULL) {
223223
PyErr_NoMemory();
224224
return -1;
@@ -247,12 +247,12 @@ _PyPegen_fill_token(Parser *p)
247247
// Record and skip '# type: ignore' comments
248248
while (type == TYPE_IGNORE) {
249249
Py_ssize_t len = new_token.end_col_offset - new_token.col_offset;
250-
char *tag = PyMem_Malloc(len + 1);
250+
char *tag = PyMem_Malloc((size_t)len + 1);
251251
if (tag == NULL) {
252252
PyErr_NoMemory();
253253
goto error;
254254
}
255-
strncpy(tag, new_token.start, len);
255+
strncpy(tag, new_token.start, (size_t)len);
256256
tag[len] = '\0';
257257
// Ownership of tag passes to the growable array
258258
if (!growable_comment_array_add(&p->type_ignore_comments, p->tok->lineno, tag)) {
@@ -505,7 +505,7 @@ _PyPegen_get_last_nonnwhitespace_token(Parser *p)
505505
PyObject *
506506
_PyPegen_new_identifier(Parser *p, const char *n)
507507
{
508-
PyObject *id = PyUnicode_DecodeUTF8(n, strlen(n), NULL);
508+
PyObject *id = PyUnicode_DecodeUTF8(n, (Py_ssize_t)strlen(n), NULL);
509509
if (!id) {
510510
goto error;
511511
}
@@ -601,7 +601,7 @@ expr_ty _PyPegen_soft_keyword_token(Parser *p) {
601601
Py_ssize_t size;
602602
PyBytes_AsStringAndSize(t->bytes, &the_token, &size);
603603
for (char **keyword = p->soft_keywords; *keyword != NULL; keyword++) {
604-
if (strncmp(*keyword, the_token, size) == 0) {
604+
if (strncmp(*keyword, the_token, (size_t)size) == 0) {
605605
return _PyPegen_name_from_token(p, t);
606606
}
607607
}

Tools/build/.warningignore_macos

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ Parser/action_helpers.c 4
173173
Parser/lexer/buffer.c 1
174174
Parser/lexer/lexer.c 12
175175
Parser/parser.c 116
176-
Parser/pegen.c 7
177176
Parser/string_parser.c 7
178177
Parser/tokenizer/file_tokenizer.c 8
179178
Parser/tokenizer/helpers.c 7

Tools/build/.warningignore_ubuntu

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@ Parser/action_helpers.c 3
199199
Parser/lexer/buffer.c 1
200200
Parser/lexer/lexer.c 14
201201
Parser/parser.c 116
202-
Parser/pegen.c 8
203202
Parser/string_parser.c 7
204203
Parser/tokenizer/file_tokenizer.c 9
205204
Parser/tokenizer/helpers.c 7

0 commit comments

Comments
 (0)
0