Skip to content

Commit

Permalink
Revert "pythongh-104645: fix error handling in marshal tests"
Browse files Browse the repository at this point in the history
This reverts commit 19b2600.
  • Loading branch information
iritkatriel committed May 19, 2023
1 parent 19b2600 commit e9978b8
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions Modules/_testcapimodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1808,9 +1808,10 @@ 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;
}

Expand All @@ -1833,9 +1834,10 @@ 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;
}

Expand Down Expand Up @@ -1893,46 +1895,48 @@ 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;

FILE *fp = _Py_fopen_obj(filename, "rb");
fp = _Py_fopen_obj(filename, "rb");
if (fp == NULL) {
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}

PyObject *obj = PyMarshal_ReadLastObjectFromFile(fp);
long pos = ftell(fp);
obj = PyMarshal_ReadLastObjectFromFile(fp);
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;

FILE *fp = _Py_fopen_obj(filename, "rb");
fp = _Py_fopen_obj(filename, "rb");
if (fp == NULL) {
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}

PyObject *obj = PyMarshal_ReadObjectFromFile(fp);
long pos = ftell(fp);
obj = PyMarshal_ReadObjectFromFile(fp);
pos = ftell(fp);

fclose(fp);
if (obj == NULL) {
return NULL;
}
return Py_BuildValue("Nl", obj, pos);
}

Expand Down

0 comments on commit e9978b8

Please sign in to comment.