Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
gaoqiong
pybind11
Commits
3f200fab
Commit
3f200fab
authored
May 17, 2016
by
Wenzel Jakob
Browse files
don't implicitly convert doubles to ints
parent
a439ccaa
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
22 additions
and
0 deletions
+22
-0
docs/changelog.rst
docs/changelog.rst
+2
-0
example/issues.cpp
example/issues.cpp
+4
-0
example/issues.py
example/issues.py
+8
-0
example/issues.ref
example/issues.ref
+4
-0
include/pybind11/cast.h
include/pybind11/cast.h
+4
-0
No files found.
docs/changelog.rst
View file @
3f200fab
...
@@ -5,6 +5,8 @@ Changelog
...
@@ -5,6 +5,8 @@ Changelog
1.8 (Not yet released)
1.8 (Not yet released)
----------------------
----------------------
* Prevent implicit conversion of floating point values to integral types in
function arguments
* Transparent conversion of sparse and dense Eigen data types
* Transparent conversion of sparse and dense Eigen data types
* Fixed incorrect default return value policy for functions returning a shared
* Fixed incorrect default return value policy for functions returning a shared
pointer
pointer
...
...
example/issues.cpp
View file @
3f200fab
...
@@ -104,4 +104,8 @@ void init_issues(py::module &m) {
...
@@ -104,4 +104,8 @@ void init_issues(py::module &m) {
// (no id): should not be able to pass 'None' to a reference argument
// (no id): should not be able to pass 'None' to a reference argument
m2
.
def
(
"print_element"
,
[](
ElementA
&
el
)
{
std
::
cout
<<
el
.
value
()
<<
std
::
endl
;
});
m2
.
def
(
"print_element"
,
[](
ElementA
&
el
)
{
std
::
cout
<<
el
.
value
()
<<
std
::
endl
;
});
// (no id): don't cast doubles to ints
m2
.
def
(
"expect_float"
,
[](
float
f
)
{
return
f
;
});
m2
.
def
(
"expect_int"
,
[](
int
i
)
{
return
i
;
});
}
}
example/issues.py
View file @
3f200fab
...
@@ -8,6 +8,7 @@ from example.issues import DispatchIssue, dispatch_issue_go
...
@@ -8,6 +8,7 @@ from example.issues import DispatchIssue, dispatch_issue_go
from
example.issues
import
Placeholder
,
return_vec_of_reference_wrapper
from
example.issues
import
Placeholder
,
return_vec_of_reference_wrapper
from
example.issues
import
iterator_passthrough
from
example.issues
import
iterator_passthrough
from
example.issues
import
ElementList
,
ElementA
,
print_element
from
example.issues
import
ElementList
,
ElementA
,
print_element
from
example.issues
import
expect_float
,
expect_int
import
gc
import
gc
print_cchar
(
"const char *"
)
print_cchar
(
"const char *"
)
...
@@ -47,3 +48,10 @@ try:
...
@@ -47,3 +48,10 @@ try:
print_element
(
None
)
print_element
(
None
)
except
Exception
as
e
:
except
Exception
as
e
:
print
(
"Failed as expected: "
+
str
(
e
))
print
(
"Failed as expected: "
+
str
(
e
))
try
:
print
(
expect_int
(
5.2
))
except
Exception
as
e
:
print
(
"Failed as expected: "
+
str
(
e
))
print
(
expect_float
(
12
))
example/issues.ref
View file @
3f200fab
...
@@ -8,3 +8,7 @@ Yay..
...
@@ -8,3 +8,7 @@ Yay..
Failed as expected: Incompatible function arguments. The following argument types are supported:
Failed as expected: Incompatible function arguments. The following argument types are supported:
1. (example.issues.ElementA) -> NoneType
1. (example.issues.ElementA) -> NoneType
Failed as expected: Incompatible function arguments. The following argument types are supported:
1. (int) -> int
12.0
include/pybind11/cast.h
View file @
3f200fab
...
@@ -326,11 +326,15 @@ public:
...
@@ -326,11 +326,15 @@ public:
}
if
(
std
::
is_floating_point
<
T
>::
value
)
{
}
if
(
std
::
is_floating_point
<
T
>::
value
)
{
py_value
=
(
py_type
)
PyFloat_AsDouble
(
src
.
ptr
());
py_value
=
(
py_type
)
PyFloat_AsDouble
(
src
.
ptr
());
}
else
if
(
sizeof
(
T
)
<=
sizeof
(
long
))
{
}
else
if
(
sizeof
(
T
)
<=
sizeof
(
long
))
{
if
(
PyFloat_Check
(
src
.
ptr
()))
return
false
;
if
(
std
::
is_signed
<
T
>::
value
)
if
(
std
::
is_signed
<
T
>::
value
)
py_value
=
(
py_type
)
PyLong_AsLong
(
src
.
ptr
());
py_value
=
(
py_type
)
PyLong_AsLong
(
src
.
ptr
());
else
else
py_value
=
(
py_type
)
PyLong_AsUnsignedLong
(
src
.
ptr
());
py_value
=
(
py_type
)
PyLong_AsUnsignedLong
(
src
.
ptr
());
}
else
{
}
else
{
if
(
PyFloat_Check
(
src
.
ptr
()))
return
false
;
if
(
std
::
is_signed
<
T
>::
value
)
if
(
std
::
is_signed
<
T
>::
value
)
py_value
=
(
py_type
)
PYBIND11_LONG_AS_LONGLONG
(
src
.
ptr
());
py_value
=
(
py_type
)
PYBIND11_LONG_AS_LONGLONG
(
src
.
ptr
());
else
else
...
...
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