Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ac56a85

Browse filesBrowse files
authored
gh-104645: fix error handling in marshal tests (#104646)
1 parent 8f1f3b9 commit ac56a85
Copy full SHA for ac56a85

File tree

Expand file treeCollapse file tree

1 file changed

+14
-18
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+14
-18
lines changed

‎Modules/_testcapimodule.c

Copy file name to clipboardExpand all lines: Modules/_testcapimodule.c
+14-18Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1808,10 +1808,9 @@ pymarshal_write_long_to_file(PyObject* self, PyObject *args)
18081808
}
18091809

18101810
PyMarshal_WriteLongToFile(value, fp, version);
1811+
assert(!PyErr_Occurred());
18111812

18121813
fclose(fp);
1813-
if (PyErr_Occurred())
1814-
return NULL;
18151814
Py_RETURN_NONE;
18161815
}
18171816

@@ -1834,10 +1833,9 @@ pymarshal_write_object_to_file(PyObject* self, PyObject *args)
18341833
}
18351834

18361835
PyMarshal_WriteObjectToFile(obj, fp, version);
1836+
assert(!PyErr_Occurred());
18371837

18381838
fclose(fp);
1839-
if (PyErr_Occurred())
1840-
return NULL;
18411839
Py_RETURN_NONE;
18421840
}
18431841

@@ -1895,48 +1893,46 @@ pymarshal_read_long_from_file(PyObject* self, PyObject *args)
18951893
static PyObject*
18961894
pymarshal_read_last_object_from_file(PyObject* self, PyObject *args)
18971895
{
1898-
PyObject *obj;
1899-
long pos;
19001896
PyObject *filename;
1901-
FILE *fp;
1902-
19031897
if (!PyArg_ParseTuple(args, "O:pymarshal_read_last_object_from_file", &filename))
19041898
return NULL;
19051899

1906-
fp = _Py_fopen_obj(filename, "rb");
1900+
FILE *fp = _Py_fopen_obj(filename, "rb");
19071901
if (fp == NULL) {
19081902
PyErr_SetFromErrno(PyExc_OSError);
19091903
return NULL;
19101904
}
19111905

1912-
obj = PyMarshal_ReadLastObjectFromFile(fp);
1913-
pos = ftell(fp);
1906+
PyObject *obj = PyMarshal_ReadLastObjectFromFile(fp);
1907+
long pos = ftell(fp);
19141908

19151909
fclose(fp);
1910+
if (obj == NULL) {
1911+
return NULL;
1912+
}
19161913
return Py_BuildValue("Nl", obj, pos);
19171914
}
19181915

19191916
static PyObject*
19201917
pymarshal_read_object_from_file(PyObject* self, PyObject *args)
19211918
{
1922-
PyObject *obj;
1923-
long pos;
19241919
PyObject *filename;
1925-
FILE *fp;
1926-
19271920
if (!PyArg_ParseTuple(args, "O:pymarshal_read_object_from_file", &filename))
19281921
return NULL;
19291922

1930-
fp = _Py_fopen_obj(filename, "rb");
1923+
FILE *fp = _Py_fopen_obj(filename, "rb");
19311924
if (fp == NULL) {
19321925
PyErr_SetFromErrno(PyExc_OSError);
19331926
return NULL;
19341927
}
19351928

1936-
obj = PyMarshal_ReadObjectFromFile(fp);
1937-
pos = ftell(fp);
1929+
PyObject *obj = PyMarshal_ReadObjectFromFile(fp);
1930+
long pos = ftell(fp);
19381931

19391932
fclose(fp);
1933+
if (obj == NULL) {
1934+
return NULL;
1935+
}
19401936
return Py_BuildValue("Nl", obj, pos);
19411937
}
19421938

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.