Fix MSVC warnings in pythonrun.c (#GH-0587)

This commit is contained in:
Ammar Askar 2020-06-02 08:17:24 +00:00 committed by GitHub
parent 8a3d2af997
commit 90d297012b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 8 deletions

View File

@ -478,9 +478,9 @@ PyRun_SimpleStringFlags(const char *command, PyCompilerFlags *flags)
static int static int
parse_syntax_error(PyObject *err, PyObject **message, PyObject **filename, parse_syntax_error(PyObject *err, PyObject **message, PyObject **filename,
int *lineno, int *offset, PyObject **text) Py_ssize_t *lineno, Py_ssize_t *offset, PyObject **text)
{ {
int hold; Py_ssize_t hold;
PyObject *v; PyObject *v;
_Py_IDENTIFIER(msg); _Py_IDENTIFIER(msg);
_Py_IDENTIFIER(filename); _Py_IDENTIFIER(filename);
@ -513,7 +513,7 @@ parse_syntax_error(PyObject *err, PyObject **message, PyObject **filename,
v = _PyObject_GetAttrId(err, &PyId_lineno); v = _PyObject_GetAttrId(err, &PyId_lineno);
if (!v) if (!v)
goto finally; goto finally;
hold = _PyLong_AsInt(v); hold = PyLong_AsSsize_t(v);
Py_DECREF(v); Py_DECREF(v);
if (hold < 0 && PyErr_Occurred()) if (hold < 0 && PyErr_Occurred())
goto finally; goto finally;
@ -526,7 +526,7 @@ parse_syntax_error(PyObject *err, PyObject **message, PyObject **filename,
*offset = -1; *offset = -1;
Py_DECREF(v); Py_DECREF(v);
} else { } else {
hold = _PyLong_AsInt(v); hold = PyLong_AsSsize_t(v);
Py_DECREF(v); Py_DECREF(v);
if (hold < 0 && PyErr_Occurred()) if (hold < 0 && PyErr_Occurred())
goto finally; goto finally;
@ -552,7 +552,7 @@ finally:
} }
static void static void
print_error_text(PyObject *f, int offset, PyObject *text_obj) print_error_text(PyObject *f, Py_ssize_t offset, PyObject *text_obj)
{ {
/* Convert text to a char pointer; return if error */ /* Convert text to a char pointer; return if error */
const char *text = PyUnicode_AsUTF8(text_obj); const char *text = PyUnicode_AsUTF8(text_obj);
@ -586,7 +586,7 @@ print_error_text(PyObject *f, int offset, PyObject *text_obj)
break; break;
} }
Py_ssize_t inl = nl - text; Py_ssize_t inl = nl - text;
if (inl >= (Py_ssize_t)offset) { if (inl >= offset) {
break; break;
} }
inl += 1; inl += 1;
@ -833,7 +833,7 @@ print_exception(PyObject *f, PyObject *value)
_PyObject_HasAttrId(value, &PyId_print_file_and_line)) _PyObject_HasAttrId(value, &PyId_print_file_and_line))
{ {
PyObject *message, *filename, *text; PyObject *message, *filename, *text;
int lineno, offset; Py_ssize_t lineno, offset;
if (!parse_syntax_error(value, &message, &filename, if (!parse_syntax_error(value, &message, &filename,
&lineno, &offset, &text)) &lineno, &offset, &text))
PyErr_Clear(); PyErr_Clear();
@ -843,7 +843,7 @@ print_exception(PyObject *f, PyObject *value)
Py_DECREF(value); Py_DECREF(value);
value = message; value = message;
line = PyUnicode_FromFormat(" File \"%S\", line %d\n", line = PyUnicode_FromFormat(" File \"%S\", line %zd\n",
filename, lineno); filename, lineno);
Py_DECREF(filename); Py_DECREF(filename);
if (line != NULL) { if (line != NULL) {