Message27266
This is happening on OSX, Python 2.4.2:
ralf@mini:~/Python-2.4.2$ cat ~/t.py
#! /usr/bin/env python
import sys
print sys.version
import mmap
mmap.mmap(-1, 4096)
ralf@mini:~/Python-2.4.2$ ./python ~/t.py
2.4.2 (#1, Jan 11 2006, 00:58:35)
[GCC 4.0.1 (Apple Computer, Inc. build 5247)]
Segmentation fault
The following one line diff solves that problem (mmap's data member
is otherwise uninitialized...)
ralf@mini:~/Python-2.4.2$ diff -u Modules/mmapmodule.c-orig
Modules/mmapmodule.c--- Modules/mmapmodule.c-orig
2006-01-11 01:12:32.000000000 +0100
+++ Modules/mmapmodule.c 2006-01-11 01:13:06.000000000
+0100
@@ -910,6 +910,7 @@
#endif
m_obj = PyObject_New (mmap_object, &mmap_object_type);
if (m_obj == NULL) {return NULL;}
+ m_obj->data = NULL;
m_obj->size = (size_t) map_size;
m_obj->pos = (size_t) 0;
m_obj->fd = dup(fd);
However, the problem is that passing -1 as filedescriptor to mmap
is perfectly ok when one wants to mmap anonymous memory (at least
on FreeeBSD and OS X). The following patch also solves that problem.
[mmap.mmap(-1, 4096, mmap.MAP_ANON) now works...]
Any chance to get this included? Passing -1 to mmap should not hurt
anybody, as systems which do not support it, should then return an
error from mmap.
ralf@mini:~/Python-2.4.2$ diff -u Modules/mmapmodule.c-orig
Modules/mmapmodule.c--- Modules/mmapmodule.c-orig
2006-01-11 01:12:32.000000000 +0100
+++ Modules/mmapmodule.c 2006-01-11 01:23:52.000000000
+0100
@@ -910,10 +910,12 @@
#endif
m_obj = PyObject_New (mmap_object, &mmap_object_type);
if (m_obj == NULL) {return NULL;}
+ m_obj->data = NULL;
m_obj->size = (size_t) map_size;
m_obj->pos = (size_t) 0;
- m_obj->fd = dup(fd);
- if (m_obj->fd == -1) {
+ if (fd == -1) {
+ m_obj->fd = -1;
+ } else if ((m_obj->fd = dup(fd)) == -1) {
Py_DECREF(m_obj);
PyErr_SetFromErrno(mmap_module_error);
return NULL;
|
|
Date |
User |
Action |
Args |
2007-08-23 14:37:13 | admin | link | issue1402308 messages |
2007-08-23 14:37:13 | admin | create | |
|