Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
pybind11
Commits
5ef1af13
Commit
5ef1af13
authored
May 06, 2018
by
Naotoshi Seo
Committed by
Jason Rhinelander
May 06, 2018
Browse files
Fix SEGV to create empty shaped numpy array (#1371)
Fix a segfault when creating a 0-dimension, c-strides array.
parent
4b874616
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
2 deletions
+10
-2
include/pybind11/numpy.h
include/pybind11/numpy.h
+3
-2
tests/test_numpy_array.cpp
tests/test_numpy_array.cpp
+3
-0
tests/test_numpy_array.py
tests/test_numpy_array.py
+4
-0
No files found.
include/pybind11/numpy.h
View file @
5ef1af13
...
@@ -758,6 +758,7 @@ protected:
...
@@ -758,6 +758,7 @@ protected:
static
std
::
vector
<
ssize_t
>
c_strides
(
const
std
::
vector
<
ssize_t
>
&
shape
,
ssize_t
itemsize
)
{
static
std
::
vector
<
ssize_t
>
c_strides
(
const
std
::
vector
<
ssize_t
>
&
shape
,
ssize_t
itemsize
)
{
auto
ndim
=
shape
.
size
();
auto
ndim
=
shape
.
size
();
std
::
vector
<
ssize_t
>
strides
(
ndim
,
itemsize
);
std
::
vector
<
ssize_t
>
strides
(
ndim
,
itemsize
);
if
(
ndim
>
0
)
for
(
size_t
i
=
ndim
-
1
;
i
>
0
;
--
i
)
for
(
size_t
i
=
ndim
-
1
;
i
>
0
;
--
i
)
strides
[
i
-
1
]
=
strides
[
i
]
*
shape
[
i
];
strides
[
i
-
1
]
=
strides
[
i
]
*
shape
[
i
];
return
strides
;
return
strides
;
...
...
tests/test_numpy_array.cpp
View file @
5ef1af13
...
@@ -102,6 +102,9 @@ TEST_SUBMODULE(numpy_array, sm) {
...
@@ -102,6 +102,9 @@ TEST_SUBMODULE(numpy_array, sm) {
sm
.
def
(
"make_f_array"
,
[]
{
return
py
::
array_t
<
float
>
({
2
,
2
},
{
4
,
8
});
});
sm
.
def
(
"make_f_array"
,
[]
{
return
py
::
array_t
<
float
>
({
2
,
2
},
{
4
,
8
});
});
sm
.
def
(
"make_c_array"
,
[]
{
return
py
::
array_t
<
float
>
({
2
,
2
},
{
8
,
4
});
});
sm
.
def
(
"make_c_array"
,
[]
{
return
py
::
array_t
<
float
>
({
2
,
2
},
{
8
,
4
});
});
// test_empty_shaped_array
sm
.
def
(
"make_empty_shaped_array"
,
[]
{
return
py
::
array
(
py
::
dtype
(
"f"
),
{},
{});
});
// test_wrap
// test_wrap
sm
.
def
(
"wrap"
,
[](
py
::
array
a
)
{
sm
.
def
(
"wrap"
,
[](
py
::
array
a
)
{
return
py
::
array
(
return
py
::
array
(
...
...
tests/test_numpy_array.py
View file @
5ef1af13
...
@@ -135,6 +135,10 @@ def test_make_c_f_array():
...
@@ -135,6 +135,10 @@ def test_make_c_f_array():
assert
not
m
.
make_f_array
().
flags
.
c_contiguous
assert
not
m
.
make_f_array
().
flags
.
c_contiguous
def
test_make_empty_shaped_array
():
m
.
make_empty_shaped_array
()
def
test_wrap
():
def
test_wrap
():
def
assert_references
(
a
,
b
,
base
=
None
):
def
assert_references
(
a
,
b
,
base
=
None
):
from
distutils.version
import
LooseVersion
from
distutils.version
import
LooseVersion
...
...
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