This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: subclassable mmap
Type: enhancement Stage:
Components: Library (Lib) Versions:
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: Nosy List: georg.brandl, josiahcarlson, nnorwitz, schmir
Priority: normal Keywords:

Created on 2004-12-19 00:16 by josiahcarlson, last changed 2022-04-11 14:56 by admin. This issue is now closed.

File name Uploaded Description Edit
mmapclass.txt schmir, 2008-01-21 09:30 make mmap.mmap the class itself.
subclass_mmap_patch.txt schmir, 2008-01-22 13:34 fix mmap_object_dealloc function.
Messages (9)
msg54340 - (view) Author: Josiah Carlson (josiahcarlson) * (Python triager) Date: 2004-12-19 00:16
As the subject says, it would be nice if mmaps were nearly every other Python object type.

Note that pseudo-subclasses (copying the instance
methods to a different class (not necessarily of the
same type) instance) don't work completely due to , and is probably a Python
msg54341 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2007-03-16 06:17
Josiah, care to work up a patch?
msg54342 - (view) Author: Josiah Carlson (josiahcarlson) * (Python triager) Date: 2007-03-16 06:27
I honestly wouldn't know where to start.  I don't know what the differences are between the currently un-subclassable mmap, and something like int/list/dict.
msg61378 - (view) Author: Ralf Schmitt (schmir) Date: 2008-01-21 09:30
I'm attaching a patch, which makes mmap.mmap the mmap class itself and
also makes it subclassable. It also contains changes to the documentation.
This is against revision 60148 of trunk.
msg61396 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008-01-21 14:16
Reviewed and committed in r60152.
msg61397 - (view) Author: Ralf Schmitt (schmir) Date: 2008-01-21 14:22
Many thanks for handling it immediately.
msg61503 - (view) Author: Ralf Schmitt (schmir) Date: 2008-01-22 13:25
sorry, I somehow managed to introduce a segfault: 

~/pydev/trunk/ cat                                                
            ralf@red ok
from mmap import mmap

class anon_mmap(mmap):
    def __new__(klass, *args, **kwargs):
        res = mmap.__new__(klass, -1, *args, **kwargs)
        print "NEW:", res
        return res

~/pydev/trunk/ ./python                                           
            ralf@red ok
NEW: <__main__.anon_mmap object at 0x866b10>
Debug memory block at address p=0x866b10:
    18374686479671623679 bytes originally requested
    The 8 pad bytes at p-8 are not all FORBIDDENBYTE (0xfb):
        at p-8: 0xcb *** OUCH
        at p-7: 0xcb *** OUCH
        at p-6: 0xcb *** OUCH
        at p-5: 0xcb *** OUCH
        at p-4: 0xcb *** OUCH
        at p-3: 0xcb *** OUCH
        at p-2: 0xcb *** OUCH
        at p-1: 0xcb *** OUCH
    Because memory is corrupted at the start, the count of bytes requested
       may be bogus, and checking the trailing pad bytes may segfault.
    The 8 pad bytes at tail=0xff00000000866b0f are zsh: segmentation
fault  ./python

The following fixes it for me:

~/pydev/trunk/ cat patch                                               
    ralf@red failed 139
diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c
--- a/Modules/mmapmodule.c
+++ b/Modules/mmapmodule.c
@@ -129,7 +129,7 @@ mmap_object_dealloc(mmap_object *m_obj)
 #endif /* UNIX */
-       PyObject_Del(m_obj);
+       m_obj->ob_type->tp_free((PyObject*)m_obj);
 static PyObject *

I'll write a test for this issue and will attach a complete patch.
Sorry again.
msg61504 - (view) Author: Ralf Schmitt (schmir) Date: 2008-01-22 13:35
./python Lib/test/ works with a debug build with this patch.
msg61528 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008-01-22 19:56
Committed as r60202. Thanks for the care!
Date User Action Args
2022-04-11 14:56:08adminsetgithub: 41341
2008-01-22 19:56:27georg.brandlsetmessages: + msg61528
2008-01-22 13:35:35schmirsetmessages: + msg61504
2008-01-22 13:34:12schmirsetfiles: + subclass_mmap_patch.txt
2008-01-22 13:25:28schmirsetmessages: + msg61503
2008-01-21 14:22:27schmirsetmessages: + msg61397
2008-01-21 14:16:56georg.brandlsetstatus: open -> closed
nosy: + georg.brandl
resolution: accepted
messages: + msg61396
2008-01-21 09:30:53schmirsetfiles: + mmapclass.txt
nosy: + schmir
messages: + msg61378
2004-12-19 00:16:54josiahcarlsoncreate