Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pybind11
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
pybind11
Commits
c9d32a81
Commit
c9d32a81
authored
Jul 27, 2019
by
Pauli Virtanen
Committed by
Wenzel Jakob
Jul 27, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
numpy: fix refcount leak to dtype singleton (#1860)
PyArray_DescrFromType returns a new reference, not borrowed one
parent
4a3464fd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
1 deletions
+12
-1
include/pybind11/numpy.h
+1
-1
tests/test_numpy_array.py
+11
-0
No files found.
include/pybind11/numpy.h
View file @
c9d32a81
...
@@ -1044,7 +1044,7 @@ public:
...
@@ -1044,7 +1044,7 @@ public:
static
pybind11
::
dtype
dtype
()
{
static
pybind11
::
dtype
dtype
()
{
if
(
auto
ptr
=
npy_api
::
get
().
PyArray_DescrFromType_
(
value
))
if
(
auto
ptr
=
npy_api
::
get
().
PyArray_DescrFromType_
(
value
))
return
reinterpret_
borrow
<
pybind11
::
dtype
>
(
ptr
);
return
reinterpret_
steal
<
pybind11
::
dtype
>
(
ptr
);
pybind11_fail
(
"Unsupported buffer format!"
);
pybind11_fail
(
"Unsupported buffer format!"
);
}
}
};
};
...
...
tests/test_numpy_array.py
View file @
c9d32a81
...
@@ -434,3 +434,14 @@ def test_array_create_and_resize(msg):
...
@@ -434,3 +434,14 @@ def test_array_create_and_resize(msg):
def
test_index_using_ellipsis
():
def
test_index_using_ellipsis
():
a
=
m
.
index_using_ellipsis
(
np
.
zeros
((
5
,
6
,
7
)))
a
=
m
.
index_using_ellipsis
(
np
.
zeros
((
5
,
6
,
7
)))
assert
a
.
shape
==
(
6
,)
assert
a
.
shape
==
(
6
,)
@pytest.unsupported_on_pypy
def
test_dtype_refcount_leak
():
from
sys
import
getrefcount
dtype
=
np
.
dtype
(
np
.
float_
)
a
=
np
.
array
([
1
],
dtype
=
dtype
)
before
=
getrefcount
(
dtype
)
m
.
ndim
(
a
)
after
=
getrefcount
(
dtype
)
assert
after
==
before
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