mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Switch mmap from old Py_FindMethod to new PyObject_GenericGetAttr attribute access.
Fixes #1087735.
This commit is contained in:
parent
6f7e2d0a30
commit
ef92802f73
1 changed files with 36 additions and 10 deletions
|
@ -687,12 +687,6 @@ mmap_buffer_getcharbuffer(mmap_object *self, Py_ssize_t index, const void **ptr)
|
||||||
return self->size;
|
return self->size;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
|
||||||
mmap_object_getattr(mmap_object *self, char *name)
|
|
||||||
{
|
|
||||||
return Py_FindMethod(mmap_object_methods, (PyObject *)self, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
static Py_ssize_t
|
static Py_ssize_t
|
||||||
mmap_length(mmap_object *self)
|
mmap_length(mmap_object *self)
|
||||||
{
|
{
|
||||||
|
@ -980,6 +974,30 @@ static PyBufferProcs mmap_as_buffer = {
|
||||||
(charbufferproc)mmap_buffer_getcharbuffer,
|
(charbufferproc)mmap_buffer_getcharbuffer,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
PyDoc_STRVAR(mmap_doc,
|
||||||
|
"Windows: mmap(fileno, length[, tagname[, access[, offset]]])\n\
|
||||||
|
\n\
|
||||||
|
Maps length bytes from the file specified by the file handle fileno,\n\
|
||||||
|
and returns a mmap object. If length is larger than the current size\n\
|
||||||
|
of the file, the file is extended to contain length bytes. If length\n\
|
||||||
|
is 0, the maximum length of the map is the current size of the file,\n\
|
||||||
|
except that if the file is empty Windows raises an exception (you cannot\n\
|
||||||
|
create an empty mapping on Windows).\n\
|
||||||
|
\n\
|
||||||
|
Unix: mmap(fileno, length[, flags[, prot[, access[, offset]]]])\n\
|
||||||
|
\n\
|
||||||
|
Maps length bytes from the file specified by the file descriptor fileno,\n\
|
||||||
|
and returns a mmap object. If length is 0, the maximum length of the map\n\
|
||||||
|
will be the current size of the file when mmap is called.\n\
|
||||||
|
flags specifies the nature of the mapping. MAP_PRIVATE creates a\n\
|
||||||
|
private copy-on-write mapping, so changes to the contents of the mmap\n\
|
||||||
|
object will be private to this process, and MAP_SHARED`creates a mapping\n\
|
||||||
|
that's shared with all other processes mapping the same areas of the file.\n\
|
||||||
|
The default value is MAP_SHARED.\n\
|
||||||
|
\n\
|
||||||
|
To map anonymous memory, pass -1 as the fileno (both versions).");
|
||||||
|
|
||||||
|
|
||||||
static PyTypeObject mmap_object_type = {
|
static PyTypeObject mmap_object_type = {
|
||||||
PyVarObject_HEAD_INIT(0, 0) /* patched in module init */
|
PyVarObject_HEAD_INIT(0, 0) /* patched in module init */
|
||||||
"mmap.mmap", /* tp_name */
|
"mmap.mmap", /* tp_name */
|
||||||
|
@ -988,7 +1006,7 @@ static PyTypeObject mmap_object_type = {
|
||||||
/* methods */
|
/* methods */
|
||||||
(destructor) mmap_object_dealloc, /* tp_dealloc */
|
(destructor) mmap_object_dealloc, /* tp_dealloc */
|
||||||
0, /* tp_print */
|
0, /* tp_print */
|
||||||
(getattrfunc) mmap_object_getattr, /* tp_getattr */
|
0, /* tp_getattr */
|
||||||
0, /* tp_setattr */
|
0, /* tp_setattr */
|
||||||
0, /* tp_compare */
|
0, /* tp_compare */
|
||||||
0, /* tp_repr */
|
0, /* tp_repr */
|
||||||
|
@ -998,11 +1016,19 @@ static PyTypeObject mmap_object_type = {
|
||||||
0, /*tp_hash*/
|
0, /*tp_hash*/
|
||||||
0, /*tp_call*/
|
0, /*tp_call*/
|
||||||
0, /*tp_str*/
|
0, /*tp_str*/
|
||||||
0, /*tp_getattro*/
|
PyObject_GenericGetAttr, /*tp_getattro*/
|
||||||
0, /*tp_setattro*/
|
0, /*tp_setattro*/
|
||||||
&mmap_as_buffer, /*tp_as_buffer*/
|
&mmap_as_buffer, /*tp_as_buffer*/
|
||||||
Py_TPFLAGS_HAVE_GETCHARBUFFER, /*tp_flags*/
|
Py_TPFLAGS_HAVE_GETCHARBUFFER, /*tp_flags*/
|
||||||
0, /*tp_doc*/
|
mmap_doc, /*tp_doc*/
|
||||||
|
0, /* tp_traverse */
|
||||||
|
0, /* tp_clear */
|
||||||
|
0, /* tp_richcompare */
|
||||||
|
0, /* tp_weaklistoffset */
|
||||||
|
0, /* tp_iter */
|
||||||
|
0, /* tp_iternext */
|
||||||
|
mmap_object_methods, /* tp_methods */
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -1341,7 +1367,7 @@ new_mmap_object(PyObject *self, PyObject *args, PyObject *kwdict)
|
||||||
/* List of functions exported by this module */
|
/* List of functions exported by this module */
|
||||||
static struct PyMethodDef mmap_functions[] = {
|
static struct PyMethodDef mmap_functions[] = {
|
||||||
{"mmap", (PyCFunction) new_mmap_object,
|
{"mmap", (PyCFunction) new_mmap_object,
|
||||||
METH_VARARGS|METH_KEYWORDS},
|
METH_VARARGS|METH_KEYWORDS, mmap_doc},
|
||||||
{NULL, NULL} /* Sentinel */
|
{NULL, NULL} /* Sentinel */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue