473,804 Members | 2,962 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[PATCH] add offset argument to mmap

I am surprised to find out the mmap module in python always
mmap from offset 0. So I just hack up some patch to allow it
accept offset arguments.

So here it is.

Chris
Add optional offset argument to mmap module.

Test on linux with Python 2.4.
The windows code is totally untested.

Signed-Off-by: Christopher Li <py****@chrisli .org>

Index: Modules/mmapmodule.c
=============== =============== =============== =============== =======
--- Modules.orig/mmapmodule.c 2004-05-19 10:39:08.000000 000 -0400
+++ Modules/mmapmodule.c 2005-05-26 10:01:51.000000 000 -0400
@@ -853,14 +853,17 @@
mmap_object *m_obj;
PyObject *map_size_obj = NULL;
int map_size;
+ unsigned long offset = 0;
int fd, flags = MAP_SHARED, prot = PROT_WRITE | PROT_READ;
access_mode access = ACCESS_DEFAULT;
char *keywords[] = {"fileno", "length",
"flags", "prot",
- "access", NULL};
+ "access", "offset",
+ NULL};

- if (!PyArg_ParseTu pleAndKeywords( args, kwdict, "iO|iii", keywords,
- &fd, &map_size_ob j, &flags, &prot, &access))
+ if (!PyArg_ParseTu pleAndKeywords( args, kwdict, "iO|iiil", keywords,
+ &fd, &map_size_ob j, &flags, &prot,
+ &access, &offset))
return NULL;
map_size = _GetMapSize(map _size_obj);
if (map_size < 0)
@@ -910,7 +913,7 @@
m_obj->fd = fd;
m_obj->data = mmap(NULL, map_size,
prot, flags,
- fd, 0);
+ fd, offset);
if (m_obj->data == (char *)-1) {
m_obj->data = NULL;
Py_DECREF(m_obj );
@@ -929,6 +932,7 @@
mmap_object *m_obj;
PyObject *map_size_obj = NULL;
int map_size;
+ unsigned long offset = 0;
char *tagname = "";
DWORD dwErr = 0;
int fileno;
@@ -939,9 +943,9 @@
"tagname",
"access", NULL };

- if (!PyArg_ParseTu pleAndKeywords( args, kwdict, "iO|zi", keywords,
+ if (!PyArg_ParseTu pleAndKeywords( args, kwdict, "iO|zil", keywords,
&fileno, &map_size_ob j,
- &tagname, &access)) {
+ &tagname, &access, &offset)) {
return NULL;
}

@@ -1040,8 +1044,8 @@
if (m_obj->map_handle != NULL) {
m_obj->data = (char *) MapViewOfFile (m_obj->map_handle,
dwDesiredAccess ,
- 0,
- 0,
+ offset>>32,
+ (unsigned int)offset,
0);
if (m_obj->data != NULL) {
return ((PyObject *) m_obj);
Jul 19 '05 #1
0 1614

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1582
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 391 open ( +7) / 3028 closed (+12) / 3419 total (+19) Bugs : 906 open ( -3) / 5519 closed (+19) / 6425 total (+16) RFE : 207 open ( -1) / 197 closed ( +1) / 404 total ( +0) New / Reopened Patches ______________________
0
222
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 420 open ( +6) / 3510 closed (+12) / 3930 total (+18) Bugs : 944 open ( -5) / 6391 closed (+15) / 7335 total (+10) RFE : 249 open ( +2) / 245 closed ( +0) / 494 total ( +2) New / Reopened Patches ______________________
0
1987
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 385 open (+21) / 3790 closed (+21) / 4175 total (+42) Bugs : 1029 open (+43) / 6744 closed (+43) / 7773 total (+86) RFE : 262 open ( +4) / 291 closed ( +4) / 553 total ( +8) New / Reopened Patches ______________________
1
1123
by: Travis Oliphant | last post by:
Hi all, I think the latest patch for fixing Issue 708374 (adding offset to mmap) should be committed to SVN. I will do it, if nobody opposes the plan. I think it is a very important addition and greatly increases the capability of the mmap module. Thanks,
0
9704
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10302
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6845
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5505
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5639
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4277
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2976
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.