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
fe40dfe6
Commit
fe40dfe6
authored
Nov 07, 2016
by
Wenzel Jakob
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
address number caster regression (fixes #484)
parent
c07ec31e
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
7 deletions
+33
-7
include/pybind11/cast.h
+7
-2
tests/test_issues.cpp
+6
-4
tests/test_issues.py
+20
-1
No files found.
include/pybind11/cast.h
View file @
fe40dfe6
...
@@ -449,8 +449,13 @@ public:
...
@@ -449,8 +449,13 @@ public:
bool
type_error
=
PyErr_ExceptionMatches
(
PyExc_TypeError
);
bool
type_error
=
PyErr_ExceptionMatches
(
PyExc_TypeError
);
#endif
#endif
PyErr_Clear
();
PyErr_Clear
();
if
(
type_error
&&
PyNumber_Check
(
src
.
ptr
()))
if
(
type_error
&&
PyNumber_Check
(
src
.
ptr
()))
{
return
load
(
object
(
PyNumber_Long
(
src
.
ptr
()),
true
),
false
);
object
tmp
(
std
::
is_floating_point
<
T
>::
value
?
PyNumber_Float
(
src
.
ptr
())
:
PyNumber_Long
(
src
.
ptr
()),
true
);
PyErr_Clear
();
return
load
(
tmp
,
false
);
}
return
false
;
return
false
;
}
}
...
...
tests/test_issues.cpp
View file @
fe40dfe6
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
#include "constructor_stats.h"
#include "constructor_stats.h"
#include <pybind11/stl.h>
#include <pybind11/stl.h>
#include <pybind11/operators.h>
#include <pybind11/operators.h>
#include <pybind11/complex.h>
#define TRACKERS(CLASS) CLASS() { print_default_created(this); } ~CLASS() { print_destroyed(this); }
#define TRACKERS(CLASS) CLASS() { print_default_created(this); } ~CLASS() { print_destroyed(this); }
struct
NestABase
{
int
value
=
-
2
;
TRACKERS
(
NestABase
)
};
struct
NestABase
{
int
value
=
-
2
;
TRACKERS
(
NestABase
)
};
...
@@ -346,10 +346,12 @@ void init_issues(py::module &m) {
...
@@ -346,10 +346,12 @@ void init_issues(py::module &m) {
.
def
(
"child"
,
&
SpecialHolderObj
::
child
,
pybind11
::
return_value_policy
::
reference_internal
)
.
def
(
"child"
,
&
SpecialHolderObj
::
child
,
pybind11
::
return_value_policy
::
reference_internal
)
.
def_readwrite
(
"val"
,
&
SpecialHolderObj
::
val
)
.
def_readwrite
(
"val"
,
&
SpecialHolderObj
::
val
)
.
def_static
(
"holder_cstats"
,
&
ConstructorStats
::
get
<
custom_unique_ptr
<
SpecialHolderObj
>>
,
.
def_static
(
"holder_cstats"
,
&
ConstructorStats
::
get
<
custom_unique_ptr
<
SpecialHolderObj
>>
,
py
::
return_value_policy
::
reference
)
py
::
return_value_policy
::
reference
);
;
};
/// Issue #484: number conversion generates unhandled exceptions
m2
.
def
(
"test_complex"
,
[](
float
x
)
{
py
::
print
(
"{}"
_s
.
format
(
x
));
});
m2
.
def
(
"test_complex"
,
[](
std
::
complex
<
float
>
x
)
{
py
::
print
(
"({}, {})"
_s
.
format
(
x
.
real
(),
x
.
imag
()));
});
}
// MSVC workaround: trying to use a lambda here crashes MSCV
// MSVC workaround: trying to use a lambda here crashes MSCV
test_initializer
issues
(
&
init_issues
);
test_initializer
issues
(
&
init_issues
);
tests/test_issues.py
View file @
fe40dfe6
...
@@ -60,7 +60,7 @@ def test_shared_ptr_gc():
...
@@ -60,7 +60,7 @@ def test_shared_ptr_gc():
assert
i
==
v
.
value
()
assert
i
==
v
.
value
()
def
test_no_id
(
capture
,
msg
):
def
test_no_id
(
msg
):
from
pybind11_tests.issues
import
get_element
,
expect_float
,
expect_int
from
pybind11_tests.issues
import
get_element
,
expect_float
,
expect_int
with
pytest
.
raises
(
TypeError
)
as
excinfo
:
with
pytest
.
raises
(
TypeError
)
as
excinfo
:
...
@@ -147,6 +147,7 @@ def test_move_fallback():
...
@@ -147,6 +147,7 @@ def test_move_fallback():
m1
=
get_moveissue1
(
1
)
m1
=
get_moveissue1
(
1
)
assert
m1
.
value
==
1
assert
m1
.
value
==
1
def
test_override_ref
():
def
test_override_ref
():
from
pybind11_tests.issues
import
OverrideTest
from
pybind11_tests.issues
import
OverrideTest
o
=
OverrideTest
(
"asdf"
)
o
=
OverrideTest
(
"asdf"
)
...
@@ -162,6 +163,7 @@ def test_override_ref():
...
@@ -162,6 +163,7 @@ def test_override_ref():
a
.
value
=
"bye"
a
.
value
=
"bye"
assert
a
.
value
==
"bye"
assert
a
.
value
==
"bye"
def
test_operators_notimplemented
(
capture
):
def
test_operators_notimplemented
(
capture
):
from
pybind11_tests.issues
import
OpTest1
,
OpTest2
from
pybind11_tests.issues
import
OpTest1
,
OpTest2
with
capture
:
with
capture
:
...
@@ -175,6 +177,7 @@ Add OpTest2 with OpTest2
...
@@ -175,6 +177,7 @@ Add OpTest2 with OpTest2
Add OpTest2 with OpTest1
Add OpTest2 with OpTest1
Add OpTest2 with OpTest1"""
Add OpTest2 with OpTest1"""
def
test_iterator_rvpolicy
():
def
test_iterator_rvpolicy
():
""" Issue 388: Can't make iterators via make_iterator() with different r/v policies """
""" Issue 388: Can't make iterators via make_iterator() with different r/v policies """
from
pybind11_tests.issues
import
make_iterator_1
from
pybind11_tests.issues
import
make_iterator_1
...
@@ -184,6 +187,7 @@ def test_iterator_rvpolicy():
...
@@ -184,6 +187,7 @@ def test_iterator_rvpolicy():
assert
list
(
make_iterator_2
())
==
[
1
,
2
,
3
]
assert
list
(
make_iterator_2
())
==
[
1
,
2
,
3
]
assert
(
type
(
make_iterator_1
())
!=
type
(
make_iterator_2
()))
assert
(
type
(
make_iterator_1
())
!=
type
(
make_iterator_2
()))
def
test_dupe_assignment
():
def
test_dupe_assignment
():
""" Issue 461: overwriting a class with a function """
""" Issue 461: overwriting a class with a function """
from
pybind11_tests.issues
import
dupe_exception_failures
from
pybind11_tests.issues
import
dupe_exception_failures
...
@@ -202,6 +206,7 @@ def test_enable_shared_from_this_with_reference_rvp():
...
@@ -202,6 +206,7 @@ def test_enable_shared_from_this_with_reference_rvp():
del
child
,
parent
del
child
,
parent
assert
cstats
.
alive
()
==
0
assert
cstats
.
alive
()
==
0
def
test_non_destructed_holders
():
def
test_non_destructed_holders
():
""" Issue #478: unique ptrs constructed and freed without destruction """
""" Issue #478: unique ptrs constructed and freed without destruction """
from
pybind11_tests
import
SpecialHolderObj
from
pybind11_tests
import
SpecialHolderObj
...
@@ -218,3 +223,17 @@ def test_non_destructed_holders():
...
@@ -218,3 +223,17 @@ def test_non_destructed_holders():
assert
cstats
.
alive
()
==
1
assert
cstats
.
alive
()
==
1
del
a
del
a
assert
cstats
.
alive
()
==
0
assert
cstats
.
alive
()
==
0
def
test_complex_cast
(
capture
):
""" Issue #484: number conversion generates unhandled exceptions """
from
pybind11_tests.issues
import
test_complex
with
capture
:
test_complex
(
1
)
test_complex
(
2
j
)
assert
capture
==
"""
1.0
(0.0, 2.0)
"""
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