Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
cfe7e091
Commit
cfe7e091
authored
Feb 17, 2006
by
Martin v. Löwis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove size restrictions.
parent
f2882957
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
29 deletions
+19
-29
Modules/mmapmodule.c
Modules/mmapmodule.c
+19
-29
No files found.
Modules/mmapmodule.c
View file @
cfe7e091
...
...
@@ -18,6 +18,7 @@
/ ftp://squirl.nightmare.com/pub/python/python-ext.
*/
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#ifndef MS_WINDOWS
...
...
@@ -242,7 +243,7 @@ mmap_find_method(mmap_object *self,
{
Py_ssize_t
start
=
self
->
pos
;
char
*
needle
;
in
t
len
;
Py_ssize_
t
len
;
CHECK_VALID
(
NULL
);
if
(
!
PyArg_ParseTuple
(
args
,
"s#|n:find"
,
&
needle
,
&
len
,
&
start
))
{
...
...
@@ -259,16 +260,14 @@ mmap_find_method(mmap_object *self,
start
=
self
->
size
;
for
(
p
=
self
->
data
+
start
;
p
+
len
<=
e
;
++
p
)
{
in
t
i
;
Py_ssize_
t
i
;
for
(
i
=
0
;
i
<
len
&&
needle
[
i
]
==
p
[
i
];
++
i
)
/* nothing */
;
if
(
i
==
len
)
{
return
Py_BuildValue
(
"l"
,
(
long
)
(
p
-
self
->
data
));
return
PyInt_FromSsize_t
(
p
-
self
->
data
);
}
}
return
Py
_BuildValue
(
"l"
,
(
long
)
-
1
);
return
Py
Int_FromLong
(
-
1
);
}
}
...
...
@@ -296,7 +295,7 @@ static PyObject *
mmap_write_method
(
mmap_object
*
self
,
PyObject
*
args
)
{
in
t
length
;
Py_ssize_
t
length
;
char
*
data
;
CHECK_VALID
(
NULL
);
...
...
@@ -377,9 +376,9 @@ static PyObject *
mmap_resize_method
(
mmap_object
*
self
,
PyObject
*
args
)
{
unsigned
long
new_size
;
Py_ssize_t
new_size
;
CHECK_VALID
(
NULL
);
if
(
!
PyArg_ParseTuple
(
args
,
"
k
:resize"
,
&
new_size
)
||
if
(
!
PyArg_ParseTuple
(
args
,
"
n
:resize"
,
&
new_size
)
||
!
is_resizeable
(
self
))
{
return
NULL
;
#ifdef MS_WINDOWS
...
...
@@ -498,10 +497,10 @@ mmap_flush_method(mmap_object *self, PyObject *args)
static
PyObject
*
mmap_seek_method
(
mmap_object
*
self
,
PyObject
*
args
)
{
in
t
dist
;
Py_ssize_
t
dist
;
int
how
=
0
;
CHECK_VALID
(
NULL
);
if
(
!
PyArg_ParseTuple
(
args
,
"
i
|i:seek"
,
&
dist
,
&
how
))
if
(
!
PyArg_ParseTuple
(
args
,
"
n
|i:seek"
,
&
dist
,
&
how
))
return
NULL
;
else
{
size_t
where
;
...
...
@@ -512,12 +511,12 @@ mmap_seek_method(mmap_object *self, PyObject *args)
where
=
dist
;
break
;
case
1
:
/* relative to current position */
if
((
in
t
)
self
->
pos
+
dist
<
0
)
if
((
Py_ssize_
t
)
self
->
pos
+
dist
<
0
)
goto
onoutofrange
;
where
=
self
->
pos
+
dist
;
break
;
case
2
:
/* relative to end */
if
((
in
t
)
self
->
size
+
dist
<
0
)
if
((
Py_ssize_
t
)
self
->
size
+
dist
<
0
)
goto
onoutofrange
;
where
=
self
->
size
+
dist
;
break
;
...
...
@@ -802,14 +801,9 @@ static PyTypeObject mmap_object_type = {
/* extract the map size from the given PyObject
The map size is restricted to [0, INT_MAX] because this is the current
Python limitation on object sizes. Although the mmap object *could* handle
a larger map size, there is no point because all the useful operations
(len(), slicing(), sequence indexing) are limited by a C int.
Returns -1 on error, with an appropriate Python exception raised. On
success, the map size is returned. */
static
in
t
static
Py_ssize_
t
_GetMapSize
(
PyObject
*
o
)
{
if
(
PyInt_Check
(
o
))
{
...
...
@@ -818,12 +812,10 @@ _GetMapSize(PyObject *o)
return
-
1
;
if
(
i
<
0
)
goto
onnegoverflow
;
if
(
i
>
INT_MAX
)
goto
onposoverflow
;
return
(
int
)
i
;
return
i
;
}
else
if
(
PyLong_Check
(
o
))
{
long
i
=
PyLong_AsLong
(
o
);
Py_ssize_t
i
=
PyInt_AsSsize_t
(
o
);
if
(
PyErr_Occurred
())
{
/* yes negative overflow is mistaken for positive overflow
but not worth the trouble to check sign of 'i' */
...
...
@@ -834,9 +826,7 @@ _GetMapSize(PyObject *o)
}
if
(
i
<
0
)
goto
onnegoverflow
;
if
(
i
>
INT_MAX
)
goto
onposoverflow
;
return
(
int
)
i
;
return
i
;
}
else
{
PyErr_SetString
(
PyExc_TypeError
,
...
...
@@ -864,7 +854,7 @@ new_mmap_object(PyObject *self, PyObject *args, PyObject *kwdict)
#endif
mmap_object
*
m_obj
;
PyObject
*
map_size_obj
=
NULL
;
in
t
map_size
;
Py_ssize_
t
map_size
;
int
fd
,
flags
=
MAP_SHARED
,
prot
=
PROT_WRITE
|
PROT_READ
;
int
devzero
=
-
1
;
int
access
=
(
int
)
ACCESS_DEFAULT
;
...
...
@@ -912,7 +902,7 @@ new_mmap_object(PyObject *self, PyObject *args, PyObject *kwdict)
# endif
if
(
fstat
(
fd
,
&
st
)
==
0
&&
S_ISREG
(
st
.
st_mode
))
{
if
(
map_size
==
0
)
{
map_size
=
(
int
)
st
.
st_size
;
map_size
=
st
.
st_size
;
}
else
if
((
size_t
)
map_size
>
st
.
st_size
)
{
PyErr_SetString
(
PyExc_ValueError
,
"mmap length is greater than file size"
);
...
...
@@ -977,7 +967,7 @@ new_mmap_object(PyObject *self, PyObject *args, PyObject *kwdict)
{
mmap_object
*
m_obj
;
PyObject
*
map_size_obj
=
NULL
;
in
t
map_size
;
Py_ssize_
t
map_size
;
DWORD
size_hi
;
/* upper 32 bits of m_obj->size */
DWORD
size_lo
;
/* lower 32 bits of m_obj->size */
char
*
tagname
=
""
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment