Skip to content

Commit 20fe532

Browse files
authored
[3.9] Fix MSVC warnings in pythonrun.c (GH-20587) (GH-20592)
(cherry picked from commit 90d2970)
1 parent ff442f3 commit 20fe532

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

Python/pythonrun.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -478,9 +478,9 @@ PyRun_SimpleStringFlags(const char *command, PyCompilerFlags *flags)
478478

479479
static int
480480
parse_syntax_error(PyObject *err, PyObject **message, PyObject **filename,
481-
int *lineno, int *offset, PyObject **text)
481+
Py_ssize_t *lineno, Py_ssize_t *offset, PyObject **text)
482482
{
483-
int hold;
483+
Py_ssize_t hold;
484484
PyObject *v;
485485
_Py_IDENTIFIER(msg);
486486
_Py_IDENTIFIER(filename);
@@ -513,7 +513,7 @@ parse_syntax_error(PyObject *err, PyObject **message, PyObject **filename,
513513
v = _PyObject_GetAttrId(err, &PyId_lineno);
514514
if (!v)
515515
goto finally;
516-
hold = _PyLong_AsInt(v);
516+
hold = PyLong_AsSsize_t(v);
517517
Py_DECREF(v);
518518
if (hold < 0 && PyErr_Occurred())
519519
goto finally;
@@ -526,7 +526,7 @@ parse_syntax_error(PyObject *err, PyObject **message, PyObject **filename,
526526
*offset = -1;
527527
Py_DECREF(v);
528528
} else {
529-
hold = _PyLong_AsInt(v);
529+
hold = PyLong_AsSsize_t(v);
530530
Py_DECREF(v);
531531
if (hold < 0 && PyErr_Occurred())
532532
goto finally;
@@ -552,7 +552,7 @@ parse_syntax_error(PyObject *err, PyObject **message, PyObject **filename,
552552
}
553553

554554
static void
555-
print_error_text(PyObject *f, int offset, PyObject *text_obj)
555+
print_error_text(PyObject *f, Py_ssize_t offset, PyObject *text_obj)
556556
{
557557
/* Convert text to a char pointer; return if error */
558558
const char *text = PyUnicode_AsUTF8(text_obj);
@@ -586,7 +586,7 @@ print_error_text(PyObject *f, int offset, PyObject *text_obj)
586586
break;
587587
}
588588
Py_ssize_t inl = nl - text;
589-
if (inl >= (Py_ssize_t)offset) {
589+
if (inl >= offset) {
590590
break;
591591
}
592592
inl += 1;
@@ -833,7 +833,7 @@ print_exception(PyObject *f, PyObject *value)
833833
_PyObject_HasAttrId(value, &PyId_print_file_and_line))
834834
{
835835
PyObject *message, *filename, *text;
836-
int lineno, offset;
836+
Py_ssize_t lineno, offset;
837837
if (!parse_syntax_error(value, &message, &filename,
838838
&lineno, &offset, &text))
839839
PyErr_Clear();
@@ -843,7 +843,7 @@ print_exception(PyObject *f, PyObject *value)
843843
Py_DECREF(value);
844844
value = message;
845845

846-
line = PyUnicode_FromFormat(" File \"%S\", line %d\n",
846+
line = PyUnicode_FromFormat(" File \"%S\", line %zd\n",
847847
filename, lineno);
848848
Py_DECREF(filename);
849849
if (line != NULL) {

0 commit comments

Comments
 (0)