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
38d8b8cf
Commit
38d8b8cf
authored
May 31, 2016
by
Wenzel Jakob
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
don't allow registering a class twice (fixes #218)
parent
5eda97d7
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
3 deletions
+18
-3
docs/changelog.rst
+2
-1
example/issues.cpp
+7
-0
include/pybind11/pybind11.h
+9
-2
No files found.
docs/changelog.rst
View file @
38d8b8cf
...
...
@@ -8,10 +8,11 @@ Changelog
* Redesigned virtual call mechanism and user-facing syntax (breaking change!)
* Prevent implicit conversion of floating point values to integral types in
function arguments
* Transparent conversion of sparse and dense Eigen
data type
s
* Transparent conversion of sparse and dense Eigen
matrices and vector
s
* ``std::vector<>`` type bindings analogous to Boost.Python's ``indexing_suite``
* Fixed incorrect default return value policy for functions returning a shared
pointer
* Don't allow registering a type via ``class_`` twice
* Don't allow casting a ``None`` value into a C++ lvalue reference
* Fixed a crash in ``enum_::operator==`` that was triggered by the ``help()`` command
* Improved detection of whether or not custom C++ types can be copy/move-constructed
...
...
example/issues.cpp
View file @
38d8b8cf
...
...
@@ -131,4 +131,11 @@ void init_issues(py::module &m) {
.
def
(
"f"
,
&
A
::
f
);
m2
.
def
(
"call_f"
,
call_f
);
try
{
py
::
class_
<
Placeholder
>
(
m2
,
"Placeholder"
);
throw
std
::
logic_error
(
"Expected an exception!"
);
}
catch
(
std
::
runtime_error
&
e
)
{
/* All good */
}
}
include/pybind11/pybind11.h
View file @
38d8b8cf
...
...
@@ -520,6 +520,14 @@ protected:
}
}
auto
&
internals
=
get_internals
();
auto
tindex
=
std
::
type_index
(
*
(
rec
->
type
));
if
(
internals
.
registered_types_cpp
.
find
(
tindex
)
!=
internals
.
registered_types_cpp
.
end
())
pybind11_fail
(
"generic_type: type
\"
"
+
std
::
string
(
rec
->
name
)
+
"
\"
is already registered!"
);
object
type_holder
(
PyType_Type
.
tp_alloc
(
&
PyType_Type
,
0
),
false
);
object
name
(
PYBIND11_FROM_STRING
(
rec
->
name
),
false
);
auto
type
=
(
PyHeapTypeObject
*
)
type_holder
.
ptr
();
...
...
@@ -528,12 +536,11 @@ protected:
pybind11_fail
(
"generic_type: unable to create type object!"
);
/* Register supplemental type information in C++ dict */
auto
&
internals
=
get_internals
();
detail
::
type_info
*
tinfo
=
new
detail
::
type_info
();
tinfo
->
type
=
(
PyTypeObject
*
)
type
;
tinfo
->
type_size
=
rec
->
type_size
;
tinfo
->
init_holder
=
rec
->
init_holder
;
internals
.
registered_types_cpp
[
std
::
type_index
(
*
(
rec
->
type
))
]
=
tinfo
;
internals
.
registered_types_cpp
[
tindex
]
=
tinfo
;
internals
.
registered_types_py
[
type
]
=
tinfo
;
object
scope_module
;
...
...
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