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
85e16262
"git@developer.sourcefind.cn:gaoqiong/pybind11.git" did not exist on "14e70650fe097923354e64c88bb40a583c6dc488"
Commit
85e16262
authored
Oct 20, 2016
by
Ivan Smirnov
Browse files
Enable direct conversions with no typeinfo present
parent
7bf90e80
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
11 deletions
+20
-11
include/pybind11/cast.h
include/pybind11/cast.h
+20
-11
No files found.
include/pybind11/cast.h
View file @
85e16262
...
@@ -166,12 +166,14 @@ public:
...
@@ -166,12 +166,14 @@ public:
}
}
bool
load
(
handle
src
,
bool
convert
,
PyTypeObject
*
tobj
)
{
bool
load
(
handle
src
,
bool
convert
,
PyTypeObject
*
tobj
)
{
if
(
!
src
||
!
typeinfo
)
if
(
!
src
)
return
false
;
return
false
;
if
(
src
.
is_none
())
{
if
(
src
.
is_none
())
{
value
=
nullptr
;
value
=
nullptr
;
return
true
;
return
true
;
}
}
if
(
!
typeinfo
)
return
load_direct
(
src
,
convert
);
if
(
typeinfo
->
simple_type
)
{
/* Case 1: no multiple inheritance etc. involved */
if
(
typeinfo
->
simple_type
)
{
/* Case 1: no multiple inheritance etc. involved */
/* Check if we can safely perform a reinterpret-style cast */
/* Check if we can safely perform a reinterpret-style cast */
...
@@ -208,23 +210,16 @@ public:
...
@@ -208,23 +210,16 @@ public:
}
}
}
}
/* Perform an implicit
or a direct
conversion */
/* Perform an implicit conversion */
if
(
convert
)
{
if
(
convert
)
{
for
(
auto
&
converter
:
typeinfo
->
implicit_conversions
)
{
for
(
auto
&
converter
:
typeinfo
->
implicit_conversions
)
{
temp
=
object
(
converter
(
src
.
ptr
(),
typeinfo
->
type
),
false
);
temp
=
object
(
converter
(
src
.
ptr
(),
typeinfo
->
type
),
false
);
if
(
load
(
temp
,
false
))
if
(
load
(
temp
,
false
))
return
true
;
return
true
;
}
}
auto
&
direct
=
get_internals
().
direct_conversions
;
auto
it
=
direct
.
find
(
tindex
);
if
(
it
!=
direct
.
end
())
{
for
(
auto
&
converter
:
it
->
second
)
{
if
(
converter
(
src
.
ptr
(),
value
))
return
true
;
}
}
}
}
return
false
;
return
load_direct
(
src
,
convert
);
}
}
PYBIND11_NOINLINE
static
handle
cast
(
const
void
*
_src
,
return_value_policy
policy
,
handle
parent
,
PYBIND11_NOINLINE
static
handle
cast
(
const
void
*
_src
,
return_value_policy
policy
,
handle
parent
,
...
@@ -305,6 +300,20 @@ protected:
...
@@ -305,6 +300,20 @@ protected:
std
::
type_index
tindex
;
std
::
type_index
tindex
;
void
*
value
=
nullptr
;
void
*
value
=
nullptr
;
object
temp
;
object
temp
;
bool
load_direct
(
handle
src
,
bool
convert
)
{
if
(
convert
)
{
auto
&
direct
=
get_internals
().
direct_conversions
;
auto
it
=
direct
.
find
(
tindex
);
if
(
it
!=
direct
.
end
())
{
for
(
auto
&
converter
:
it
->
second
)
{
if
(
converter
(
src
.
ptr
(),
value
))
return
true
;
}
}
}
return
false
;
}
};
};
/* Determine suitable casting operator */
/* Determine suitable casting operator */
...
...
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