gh-104645: fix error handling in marshal tests (#104646)
This commit is contained in:
parent
8f1f3b9abd
commit
ac56a854b4
@ -1808,10 +1808,9 @@ pymarshal_write_long_to_file(PyObject* self, PyObject *args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
PyMarshal_WriteLongToFile(value, fp, version);
|
PyMarshal_WriteLongToFile(value, fp, version);
|
||||||
|
assert(!PyErr_Occurred());
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
if (PyErr_Occurred())
|
|
||||||
return NULL;
|
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1834,10 +1833,9 @@ pymarshal_write_object_to_file(PyObject* self, PyObject *args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
PyMarshal_WriteObjectToFile(obj, fp, version);
|
PyMarshal_WriteObjectToFile(obj, fp, version);
|
||||||
|
assert(!PyErr_Occurred());
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
if (PyErr_Occurred())
|
|
||||||
return NULL;
|
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1895,48 +1893,46 @@ pymarshal_read_long_from_file(PyObject* self, PyObject *args)
|
|||||||
static PyObject*
|
static PyObject*
|
||||||
pymarshal_read_last_object_from_file(PyObject* self, PyObject *args)
|
pymarshal_read_last_object_from_file(PyObject* self, PyObject *args)
|
||||||
{
|
{
|
||||||
PyObject *obj;
|
|
||||||
long pos;
|
|
||||||
PyObject *filename;
|
PyObject *filename;
|
||||||
FILE *fp;
|
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "O:pymarshal_read_last_object_from_file", &filename))
|
if (!PyArg_ParseTuple(args, "O:pymarshal_read_last_object_from_file", &filename))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
fp = _Py_fopen_obj(filename, "rb");
|
FILE *fp = _Py_fopen_obj(filename, "rb");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
PyErr_SetFromErrno(PyExc_OSError);
|
PyErr_SetFromErrno(PyExc_OSError);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
obj = PyMarshal_ReadLastObjectFromFile(fp);
|
PyObject *obj = PyMarshal_ReadLastObjectFromFile(fp);
|
||||||
pos = ftell(fp);
|
long pos = ftell(fp);
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
if (obj == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
return Py_BuildValue("Nl", obj, pos);
|
return Py_BuildValue("Nl", obj, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
pymarshal_read_object_from_file(PyObject* self, PyObject *args)
|
pymarshal_read_object_from_file(PyObject* self, PyObject *args)
|
||||||
{
|
{
|
||||||
PyObject *obj;
|
|
||||||
long pos;
|
|
||||||
PyObject *filename;
|
PyObject *filename;
|
||||||
FILE *fp;
|
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "O:pymarshal_read_object_from_file", &filename))
|
if (!PyArg_ParseTuple(args, "O:pymarshal_read_object_from_file", &filename))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
fp = _Py_fopen_obj(filename, "rb");
|
FILE *fp = _Py_fopen_obj(filename, "rb");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
PyErr_SetFromErrno(PyExc_OSError);
|
PyErr_SetFromErrno(PyExc_OSError);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
obj = PyMarshal_ReadObjectFromFile(fp);
|
PyObject *obj = PyMarshal_ReadObjectFromFile(fp);
|
||||||
pos = ftell(fp);
|
long pos = ftell(fp);
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
if (obj == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
return Py_BuildValue("Nl", obj, pos);
|
return Py_BuildValue("Nl", obj, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user