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
b6cf75d6
Commit
b6cf75d6
authored
Jan 29, 2016
by
Wenzel Jakob
Browse files
address issue with std::type_info across module boundaries (fixes #86)
parent
2547ca46
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
22 deletions
+12
-22
include/pybind11/cast.h
include/pybind11/cast.h
+3
-14
include/pybind11/common.h
include/pybind11/common.h
+4
-3
include/pybind11/pybind11.h
include/pybind11/pybind11.h
+5
-5
No files found.
include/pybind11/cast.h
View file @
b6cf75d6
...
@@ -59,20 +59,9 @@ PYBIND11_NOINLINE inline detail::type_info* get_type_info(PyTypeObject *type) {
...
@@ -59,20 +59,9 @@ PYBIND11_NOINLINE inline detail::type_info* get_type_info(PyTypeObject *type) {
PYBIND11_NOINLINE
inline
detail
::
type_info
*
get_type_info
(
const
std
::
type_info
&
tp
)
{
PYBIND11_NOINLINE
inline
detail
::
type_info
*
get_type_info
(
const
std
::
type_info
&
tp
)
{
auto
&
types
=
get_internals
().
registered_types_cpp
;
auto
&
types
=
get_internals
().
registered_types_cpp
;
auto
it
=
types
.
find
(
&
tp
);
auto
it
=
types
.
find
(
std
::
type_index
(
tp
)
);
if
(
it
!=
types
.
end
())
{
if
(
it
!=
types
.
end
())
return
(
detail
::
type_info
*
)
it
->
second
;
return
(
detail
::
type_info
*
)
it
->
second
;
}
else
{
/* Unknown type?! Since std::type_info* often varies across
module boundaries, the following does an explicit check */
for
(
auto
const
&
type
:
types
)
{
auto
*
first
=
(
const
std
::
type_info
*
)
type
.
first
;
if
(
strcmp
(
first
->
name
(),
tp
.
name
())
==
0
)
{
types
[
&
tp
]
=
type
.
second
;
return
(
detail
::
type_info
*
)
type
.
second
;
}
}
}
return
nullptr
;
return
nullptr
;
}
}
...
@@ -144,7 +133,7 @@ public:
...
@@ -144,7 +133,7 @@ public:
if
(
it_instance
!=
internals
.
registered_instances
.
end
()
&&
!
dont_cache
)
if
(
it_instance
!=
internals
.
registered_instances
.
end
()
&&
!
dont_cache
)
return
handle
((
PyObject
*
)
it_instance
->
second
).
inc_ref
();
return
handle
((
PyObject
*
)
it_instance
->
second
).
inc_ref
();
auto
it
=
internals
.
registered_types_cpp
.
find
(
type_info
);
auto
it
=
internals
.
registered_types_cpp
.
find
(
std
::
type_index
(
*
type_info
)
)
;
if
(
it
==
internals
.
registered_types_cpp
.
end
())
{
if
(
it
==
internals
.
registered_types_cpp
.
end
())
{
std
::
string
tname
=
type_info
->
name
();
std
::
string
tname
=
type_info
->
name
();
detail
::
clean_type_id
(
tname
);
detail
::
clean_type_id
(
tname
);
...
...
include/pybind11/common.h
View file @
b6cf75d6
...
@@ -71,6 +71,7 @@
...
@@ -71,6 +71,7 @@
#include <unordered_set>
#include <unordered_set>
#include <unordered_map>
#include <unordered_map>
#include <memory>
#include <memory>
#include <typeindex>
#if PY_MAJOR_VERSION >= 3 /// Compatibility macros for various Python versions
#if PY_MAJOR_VERSION >= 3 /// Compatibility macros for various Python versions
#define PYBIND11_INSTANCE_METHOD_NEW(ptr, class_) PyInstanceMethod_New(ptr)
#define PYBIND11_INSTANCE_METHOD_NEW(ptr, class_) PyInstanceMethod_New(ptr)
...
@@ -216,9 +217,9 @@ struct overload_hash {
...
@@ -216,9 +217,9 @@ struct overload_hash {
/// Internal data struture used to track registered instances and types
/// Internal data struture used to track registered instances and types
struct
internals
{
struct
internals
{
std
::
unordered_map
<
const
void
*
,
void
*>
registered_types_cpp
;
// std::type_in
fo*
-> type_info
std
::
unordered_map
<
std
::
type_index
,
void
*>
registered_types_cpp
;
// std::type_in
dex
-> type_info
std
::
unordered_map
<
const
void
*
,
void
*>
registered_types_py
;
// PyTypeObject* -> type_info
std
::
unordered_map
<
const
void
*
,
void
*>
registered_types_py
;
// PyTypeObject* -> type_info
std
::
unordered_map
<
const
void
*
,
void
*>
registered_instances
;
// void * -> PyObject*
std
::
unordered_map
<
const
void
*
,
void
*>
registered_instances
;
// void * -> PyObject*
std
::
unordered_set
<
std
::
pair
<
const
PyObject
*
,
const
char
*>
,
overload_hash
>
inactive_overload_cache
;
std
::
unordered_set
<
std
::
pair
<
const
PyObject
*
,
const
char
*>
,
overload_hash
>
inactive_overload_cache
;
};
};
...
...
include/pybind11/pybind11.h
View file @
b6cf75d6
...
@@ -204,7 +204,7 @@ protected:
...
@@ -204,7 +204,7 @@ protected:
const
std
::
type_info
*
t
=
types
[
type_index
++
];
const
std
::
type_info
*
t
=
types
[
type_index
++
];
if
(
!
t
)
if
(
!
t
)
pybind11_fail
(
"Internal error while parsing type signature (1)"
);
pybind11_fail
(
"Internal error while parsing type signature (1)"
);
auto
it
=
registered_types
.
find
(
t
);
auto
it
=
registered_types
.
find
(
std
::
type_index
(
*
t
)
);
if
(
it
!=
registered_types
.
end
())
{
if
(
it
!=
registered_types
.
end
())
{
signature
+=
((
const
detail
::
type_info
*
)
it
->
second
)
->
type
->
tp_name
;
signature
+=
((
const
detail
::
type_info
*
)
it
->
second
)
->
type
->
tp_name
;
}
else
{
}
else
{
...
@@ -524,7 +524,7 @@ protected:
...
@@ -524,7 +524,7 @@ protected:
tinfo
->
type
=
(
PyTypeObject
*
)
type
;
tinfo
->
type
=
(
PyTypeObject
*
)
type
;
tinfo
->
type_size
=
rec
->
type_size
;
tinfo
->
type_size
=
rec
->
type_size
;
tinfo
->
init_holder
=
rec
->
init_holder
;
tinfo
->
init_holder
=
rec
->
init_holder
;
internals
.
registered_types_cpp
[
rec
->
type
]
=
tinfo
;
internals
.
registered_types_cpp
[
std
::
type_index
(
*
(
rec
->
type
))
]
=
tinfo
;
internals
.
registered_types_py
[
type
]
=
tinfo
;
internals
.
registered_types_py
[
type
]
=
tinfo
;
auto
scope_module
=
(
object
)
rec
->
scope
.
attr
(
"__module__"
);
auto
scope_module
=
(
object
)
rec
->
scope
.
attr
(
"__module__"
);
...
@@ -844,7 +844,7 @@ public:
...
@@ -844,7 +844,7 @@ public:
template
<
typename
target
>
class_
alias
()
{
template
<
typename
target
>
class_
alias
()
{
auto
&
instances
=
pybind11
::
detail
::
get_internals
().
registered_types_cpp
;
auto
&
instances
=
pybind11
::
detail
::
get_internals
().
registered_types_cpp
;
instances
[
&
typeid
(
target
)]
=
instances
[
&
typeid
(
type
)];
instances
[
std
::
type_index
(
typeid
(
target
)
)
]
=
instances
[
std
::
type_index
(
typeid
(
type
)
)];
return
*
this
;
return
*
this
;
}
}
private:
private:
...
@@ -976,8 +976,8 @@ template <typename InputType, typename OutputType> void implicitly_convertible()
...
@@ -976,8 +976,8 @@ template <typename InputType, typename OutputType> void implicitly_convertible()
PyErr_Clear
();
PyErr_Clear
();
return
result
;
return
result
;
};
};
auto
&
registered_types
=
detail
::
get_internals
().
registered_types_cpp
;
auto
&
registered_types
=
detail
::
get_internals
().
registered_types_cpp
;
auto
it
=
registered_types
.
find
(
&
typeid
(
OutputType
));
auto
it
=
registered_types
.
find
(
std
::
type_index
(
typeid
(
OutputType
))
)
;
if
(
it
==
registered_types
.
end
())
if
(
it
==
registered_types
.
end
())
pybind11_fail
(
"implicitly_convertible: Unable to find type "
+
type_id
<
OutputType
>
());
pybind11_fail
(
"implicitly_convertible: Unable to find type "
+
type_id
<
OutputType
>
());
((
detail
::
type_info
*
)
it
->
second
)
->
implicit_conversions
.
push_back
(
implicit_caster
);
((
detail
::
type_info
*
)
it
->
second
)
->
implicit_conversions
.
push_back
(
implicit_caster
);
...
...
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