|
28 | 28 | #include "pycore_fileutils.h" // _Py_stat_struct |
29 | 29 | #include "pycore_weakref.h" // FT_CLEAR_WEAKREFS() |
30 | 30 |
|
31 | | -/*[clinic input] |
32 | | -module mmap |
33 | | -class mmap.mmap "mmap_object *" "mmap_object_type" |
34 | | -[clinic start generated code]*/ |
35 | | -/*[clinic end generated code: output=da39a3ee5e6b4b0d input=4ebde54549b9daa7]*/ |
36 | | - |
37 | 31 | #include <stddef.h> // offsetof() |
38 | 32 | #ifndef MS_WINDOWS |
39 | 33 | # include <unistd.h> // close() |
@@ -135,15 +129,6 @@ typedef struct { |
135 | 129 |
|
136 | 130 | #define mmap_object_CAST(op) ((mmap_object *)(op)) |
137 | 131 |
|
138 | | -#include "clinic/mmapmodule.c.h" |
139 | | - |
140 | | -static int |
141 | | -mmap_object_traverse(PyObject *op, visitproc visit, void *arg) |
142 | | -{ |
143 | | - Py_VISIT(Py_TYPE(op)); |
144 | | - return 0; |
145 | | -} |
146 | | - |
147 | 132 | static void |
148 | 133 | mmap_object_dealloc(PyObject *op) |
149 | 134 | { |
@@ -942,31 +927,19 @@ mmap_tell_method(PyObject *op, PyObject *Py_UNUSED(ignored)) |
942 | 927 | return PyLong_FromSize_t(self->pos); |
943 | 928 | } |
944 | 929 |
|
945 | | -/*[clinic input] |
946 | | -mmap.mmap.flush |
947 | | -
|
948 | | - offset: Py_ssize_t = 0 |
949 | | - size: Py_ssize_t(c_default="-1") = None |
950 | | - / |
951 | | -
|
952 | | -Flushes changes made to the in-memory copy of a file back to disk. |
953 | | -
|
954 | | -If offset and size are specified, only the specified range will |
955 | | -be flushed. If not specified, the entire mapped region will be |
956 | | -flushed. |
957 | | -[clinic start generated code]*/ |
958 | | - |
959 | 930 | static PyObject * |
960 | | -mmap_mmap_flush_impl(mmap_object *self, Py_ssize_t offset, Py_ssize_t size) |
961 | | -/*[clinic end generated code: output=956ced67466149cf input=07c2c6d4e69263a4]*/ |
| 931 | +mmap_flush_method(PyObject *op, PyObject *args) |
962 | 932 | { |
| 933 | + Py_ssize_t offset = 0; |
| 934 | + Py_ssize_t size = -1; |
| 935 | + mmap_object *self = mmap_object_CAST(op); |
963 | 936 | CHECK_VALID(NULL); |
964 | | - |
965 | | - // If size is -1 (default), calculate size from offset to end. |
| 937 | + if (!PyArg_ParseTuple(args, "|nn:flush", &offset, &size)) { |
| 938 | + return NULL; |
| 939 | + } |
966 | 940 | if (size == -1) { |
967 | 941 | size = self->size - offset; |
968 | 942 | } |
969 | | - |
970 | 943 | if (size < 0 || offset < 0 || self->size - offset < size) { |
971 | 944 | PyErr_SetString(PyExc_ValueError, "flush values out of range"); |
972 | 945 | return NULL; |
@@ -1228,7 +1201,7 @@ static struct PyMethodDef mmap_object_methods[] = { |
1228 | 1201 | {"close", mmap_close_method, METH_NOARGS}, |
1229 | 1202 | {"find", mmap_find_method, METH_VARARGS}, |
1230 | 1203 | {"rfind", mmap_rfind_method, METH_VARARGS}, |
1231 | | - MMAP_MMAP_FLUSH_METHODDEF |
| 1204 | + {"flush", mmap_flush_method, METH_VARARGS}, |
1232 | 1205 | #ifdef HAVE_MADVISE |
1233 | 1206 | {"madvise", mmap_madvise_method, METH_VARARGS}, |
1234 | 1207 | #endif |
|
0 commit comments