Commit 13229158 authored by Marius Wachtler's avatar Marius Wachtler

file: support close function pointer

parent 02c39c34
...@@ -824,8 +824,7 @@ extern "C" void PyFile_SetFP(PyObject* _f, FILE* fp) noexcept { ...@@ -824,8 +824,7 @@ extern "C" void PyFile_SetFP(PyObject* _f, FILE* fp) noexcept {
} }
extern "C" PyObject* PyFile_FromFile(FILE* fp, char* name, char* mode, int (*close)(FILE*)) noexcept { extern "C" PyObject* PyFile_FromFile(FILE* fp, char* name, char* mode, int (*close)(FILE*)) noexcept {
RELEASE_ASSERT(close == fclose, "unsupported"); return new BoxedFile(fp, name, mode, close);
return new BoxedFile(fp, name, mode);
} }
extern "C" FILE* PyFile_AsFile(PyObject* f) noexcept { extern "C" FILE* PyFile_AsFile(PyObject* f) noexcept {
...@@ -1082,8 +1081,8 @@ void fileDestructor(Box* b) { ...@@ -1082,8 +1081,8 @@ void fileDestructor(Box* b) {
assert(isSubclass(b->cls, file_cls)); assert(isSubclass(b->cls, file_cls));
BoxedFile* self = static_cast<BoxedFile*>(b); BoxedFile* self = static_cast<BoxedFile*>(b);
if (self->f_fp) if (self->f_fp && self->f_close)
fclose(self->f_fp); self->f_close(self->f_fp);
self->f_fp = NULL; self->f_fp = NULL;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment