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
d2dff6c7
Commit
d2dff6c7
authored
Feb 01, 2015
by
Stefan Krah
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #23370: Fix off-by-one error for non-contiguous buffers.
parent
a73df809
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
2 deletions
+55
-2
Modules/_testcapimodule.c
Modules/_testcapimodule.c
+53
-0
Objects/abstract.c
Objects/abstract.c
+2
-2
No files found.
Modules/_testcapimodule.c
View file @
d2dff6c7
...
...
@@ -424,6 +424,58 @@ test_to_contiguous(PyObject* self, PyObject *noargs)
Py_RETURN_NONE
;
}
static
PyObject
*
test_from_contiguous
(
PyObject
*
self
,
PyObject
*
noargs
)
{
int
data
[
9
]
=
{
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
};
int
init
[
5
]
=
{
0
,
1
,
2
,
3
,
4
};
Py_ssize_t
itemsize
=
sizeof
(
int
);
Py_ssize_t
shape
=
5
;
Py_ssize_t
strides
=
2
*
itemsize
;
Py_buffer
view
=
{
data
,
NULL
,
5
*
itemsize
,
itemsize
,
1
,
1
,
NULL
,
&
shape
,
&
strides
,
NULL
,
{
0
,
0
},
NULL
};
int
*
ptr
;
int
i
;
PyBuffer_FromContiguous
(
&
view
,
init
,
view
.
len
,
'C'
);
ptr
=
view
.
buf
;
for
(
i
=
0
;
i
<
5
;
i
++
)
{
if
(
ptr
[
2
*
i
]
!=
i
)
{
PyErr_SetString
(
TestError
,
"test_from_contiguous: incorrect result"
);
return
NULL
;
}
}
view
.
buf
=
&
data
[
8
];
view
.
strides
[
0
]
=
-
2
*
itemsize
;
PyBuffer_FromContiguous
(
&
view
,
init
,
view
.
len
,
'C'
);
ptr
=
view
.
buf
;
for
(
i
=
0
;
i
<
5
;
i
++
)
{
if
(
*
(
ptr
-
2
*
i
)
!=
i
)
{
PyErr_SetString
(
TestError
,
"test_from_contiguous: incorrect result"
);
return
NULL
;
}
}
Py_RETURN_NONE
;
}
/* Tests of PyLong_{As, From}{Unsigned,}Long(), and (#ifdef HAVE_LONG_LONG)
PyLong_{As, From}{Unsigned,}LongLong().
...
...
@@ -1833,6 +1885,7 @@ static PyMethodDef TestMethods[] = {
{
"test_lazy_hash_inheritance"
,
(
PyCFunction
)
test_lazy_hash_inheritance
,
METH_NOARGS
},
{
"test_broken_memoryview"
,
(
PyCFunction
)
test_broken_memoryview
,
METH_NOARGS
},
{
"test_to_contiguous"
,
(
PyCFunction
)
test_to_contiguous
,
METH_NOARGS
},
{
"test_from_contiguous"
,
(
PyCFunction
)
test_from_contiguous
,
METH_NOARGS
},
{
"test_long_api"
,
(
PyCFunction
)
test_long_api
,
METH_NOARGS
},
{
"test_long_and_overflow"
,
(
PyCFunction
)
test_long_and_overflow
,
METH_NOARGS
},
...
...
Objects/abstract.c
View file @
d2dff6c7
...
...
@@ -550,7 +550,7 @@ PyBuffer_FromContiguous(Py_buffer *view, void *buf, Py_ssize_t len, char fort)
/* Otherwise a more elaborate scheme is needed */
/*
XXX(nnorwitz): need to check for overflow!
*/
/*
view->ndim <= 64
*/
indices
=
(
Py_ssize_t
*
)
PyMem_Malloc
(
sizeof
(
Py_ssize_t
)
*
(
view
->
ndim
));
if
(
indices
==
NULL
)
{
PyErr_NoMemory
();
...
...
@@ -572,10 +572,10 @@ PyBuffer_FromContiguous(Py_buffer *view, void *buf, Py_ssize_t len, char fort)
*/
elements
=
len
/
view
->
itemsize
;
while
(
elements
--
)
{
addone
(
view
->
ndim
,
indices
,
view
->
shape
);
ptr
=
PyBuffer_GetPointer
(
view
,
indices
);
memcpy
(
ptr
,
src
,
view
->
itemsize
);
src
+=
view
->
itemsize
;
addone
(
view
->
ndim
,
indices
,
view
->
shape
);
}
PyMem_Free
(
indices
);
...
...
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