summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>2023-05-19 16:23:57 (GMT)
committerGitHub <noreply@github.com>2023-05-19 16:23:57 (GMT)
commitac56a854b418d35ad3838f3072604227dc718fca (patch)
tree6715faabb8a875be6cc917e15218d85d01326287
parent8f1f3b9abdaa3e9d19aad22d6c310eb1f05ae5c2 (diff)
downloadcpython-ac56a854b418d35ad3838f3072604227dc718fca.zip
cpython-ac56a854b418d35ad3838f3072604227dc718fca.tar.gz
cpython-ac56a854b418d35ad3838f3072604227dc718fca.tar.bz2
gh-104645: fix error handling in marshal tests (#104646)
-rw-r--r--Modules/_testcapimodule.c32
1 files changed, 14 insertions, 18 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index 1be1dd6..aff09aa 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -1808,10 +1808,9 @@ pymarshal_write_long_to_file(PyObject* self, PyObject *args)
}
PyMarshal_WriteLongToFile(value, fp, version);
+ assert(!PyErr_Occurred());
fclose(fp);
- if (PyErr_Occurred())
- return NULL;
Py_RETURN_NONE;
}
@@ -1834,10 +1833,9 @@ pymarshal_write_object_to_file(PyObject* self, PyObject *args)
}
PyMarshal_WriteObjectToFile(obj, fp, version);
+ assert(!PyErr_Occurred());
fclose(fp);
- if (PyErr_Occurred())
- return NULL;
Py_RETURN_NONE;
}
@@ -1895,48 +1893,46 @@ pymarshal_read_long_from_file(PyObject* self, PyObject *args)
static PyObject*
pymarshal_read_last_object_from_file(PyObject* self, PyObject *args)
{
- PyObject *obj;
- long pos;
PyObject *filename;
- FILE *fp;
-
if (!PyArg_ParseTuple(args, "O:pymarshal_read_last_object_from_file", &filename))
return NULL;
- fp = _Py_fopen_obj(filename, "rb");
+ FILE *fp = _Py_fopen_obj(filename, "rb");
if (fp == NULL) {
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}
- obj = PyMarshal_ReadLastObjectFromFile(fp);
- pos = ftell(fp);
+ PyObject *obj = PyMarshal_ReadLastObjectFromFile(fp);
+ long pos = ftell(fp);
fclose(fp);
+ if (obj == NULL) {
+ return NULL;
+ }
return Py_BuildValue("Nl", obj, pos);
}
static PyObject*
pymarshal_read_object_from_file(PyObject* self, PyObject *args)
{
- PyObject *obj;
- long pos;
PyObject *filename;
- FILE *fp;
-
if (!PyArg_ParseTuple(args, "O:pymarshal_read_object_from_file", &filename))
return NULL;
- fp = _Py_fopen_obj(filename, "rb");
+ FILE *fp = _Py_fopen_obj(filename, "rb");
if (fp == NULL) {
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}
- obj = PyMarshal_ReadObjectFromFile(fp);
- pos = ftell(fp);
+ PyObject *obj = PyMarshal_ReadObjectFromFile(fp);
+ long pos = ftell(fp);
fclose(fp);
+ if (obj == NULL) {
+ return NULL;
+ }
return Py_BuildValue("Nl", obj, pos);
}