Py_ssize_t
_PyPegen_byte_offset_to_character_offset_line(PyObject *line, Py_ssize_t col_offset, Py_ssize_t end_col_offset)
{
- const char *data = PyUnicode_AsUTF8(line);
+ const unsigned char *data = (const unsigned char*)PyUnicode_AsUTF8(line);
Py_ssize_t len = 0;
while (col_offset < end_col_offset) {
Py_ssize_t
_PyPegen_byte_offset_to_character_offset_raw(const char* str, Py_ssize_t col_offset)
{
- Py_ssize_t len = strlen(str);
+ Py_ssize_t len = (Py_ssize_t)strlen(str);
if (col_offset > len + 1) {
col_offset = len + 1;
}
static int
_get_keyword_or_name_type(Parser *p, struct token *new_token)
{
- int name_len = new_token->end_col_offset - new_token->col_offset;
+ Py_ssize_t name_len = new_token->end_col_offset - new_token->col_offset;
assert(name_len > 0);
if (name_len >= p->n_keyword_lists ||
return NAME;
}
for (KeywordToken *k = p->keywords[name_len]; k != NULL && k->type != -1; k++) {
- if (strncmp(k->str, new_token->start, name_len) == 0) {
+ if (strncmp(k->str, new_token->start, (size_t)name_len) == 0) {
return k->type;
}
}
static int
_resize_tokens_array(Parser *p) {
int newsize = p->size * 2;
- Token **new_tokens = PyMem_Realloc(p->tokens, newsize * sizeof(Token *));
+ Token **new_tokens = PyMem_Realloc(p->tokens, (size_t)newsize * sizeof(Token *));
if (new_tokens == NULL) {
PyErr_NoMemory();
return -1;
// Record and skip '# type: ignore' comments
while (type == TYPE_IGNORE) {
Py_ssize_t len = new_token.end_col_offset - new_token.col_offset;
- char *tag = PyMem_Malloc(len + 1);
+ char *tag = PyMem_Malloc((size_t)len + 1);
if (tag == NULL) {
PyErr_NoMemory();
goto error;
}
- strncpy(tag, new_token.start, len);
+ strncpy(tag, new_token.start, (size_t)len);
tag[len] = '\0';
// Ownership of tag passes to the growable array
if (!growable_comment_array_add(&p->type_ignore_comments, p->tok->lineno, tag)) {
PyObject *
_PyPegen_new_identifier(Parser *p, const char *n)
{
- PyObject *id = PyUnicode_DecodeUTF8(n, strlen(n), NULL);
+ PyObject *id = PyUnicode_DecodeUTF8(n, (Py_ssize_t)strlen(n), NULL);
if (!id) {
goto error;
}
Py_ssize_t size;
PyBytes_AsStringAndSize(t->bytes, &the_token, &size);
for (char **keyword = p->soft_keywords; *keyword != NULL; keyword++) {
- if (strncmp(*keyword, the_token, size) == 0) {
+ if (strncmp(*keyword, the_token, (size_t)size) == 0) {
return _PyPegen_name_from_token(p, t);
}
}