Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
65d3b977
Commit
65d3b977
authored
Dec 10, 2014
by
Lars Buitinck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix shrinking and overflow in cpython.array
parent
16f809e6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
6 deletions
+18
-6
Cython/Utility/arrayarray.h
Cython/Utility/arrayarray.h
+8
-6
tests/run/pyarray.pyx
tests/run/pyarray.pyx
+10
-0
No files found.
Cython/Utility/arrayarray.h
View file @
65d3b977
...
@@ -121,13 +121,15 @@ static CYTHON_INLINE int resize(arrayobject *self, Py_ssize_t n) {
...
@@ -121,13 +121,15 @@ static CYTHON_INLINE int resize(arrayobject *self, Py_ssize_t n) {
static
CYTHON_INLINE
int
resize_smart
(
arrayobject
*
self
,
Py_ssize_t
n
)
{
static
CYTHON_INLINE
int
resize_smart
(
arrayobject
*
self
,
Py_ssize_t
n
)
{
void
*
items
=
(
void
*
)
self
->
data
.
ob_item
;
void
*
items
=
(
void
*
)
self
->
data
.
ob_item
;
Py_ssize_t
newsize
;
Py_ssize_t
newsize
;
if
(
n
<
self
->
allocated
)
{
if
(
n
<
self
->
ob_size
)
{
if
(
n
*
4
>
self
->
allocated
)
{
self
->
ob_size
=
n
;
self
->
ob_size
=
n
;
return
0
;
return
0
;
}
}
newsize
=
n
+
(
n
/
2
)
+
1
;
if
(
newsize
<=
self
->
allocated
)
{
/* overflow */
PyErr_NoMemory
();
return
-
1
;
}
}
newsize
=
n
*
3
/
2
+
1
;
PyMem_Resize
(
items
,
char
,
(
size_t
)(
newsize
*
self
->
ob_descr
->
itemsize
));
PyMem_Resize
(
items
,
char
,
(
size_t
)(
newsize
*
self
->
ob_descr
->
itemsize
));
if
(
items
==
NULL
)
{
if
(
items
==
NULL
)
{
PyErr_NoMemory
();
PyErr_NoMemory
();
...
...
tests/run/pyarray.pyx
View file @
65d3b977
...
@@ -105,6 +105,16 @@ def test_resize(a):
...
@@ -105,6 +105,16 @@ def test_resize(a):
assert
len
(
cb
)
==
10
assert
len
(
cb
)
==
10
assert
cb
[
9
]
==
cb
[
-
1
]
==
cb
.
data
.
as_floats
[
9
]
==
9
assert
cb
[
9
]
==
cb
[
-
1
]
==
cb
.
data
.
as_floats
[
9
]
==
9
def
test_resize_smart
(
a
):
"""
>>> a = array.array('d', [1, 2, 3])
>>> test_resize_smart(a)
2
"""
cdef
array
.
array
cb
=
array
.
copy
(
a
)
array
.
resize_smart
(
cb
,
2
)
return
len
(
cb
)
def
test_buffer
():
def
test_buffer
():
"""
"""
>>> test_buffer()
>>> test_buffer()
...
...
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