mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-22 13:15:12 +00:00
don't allow registering a class twice (fixes #218)
This commit is contained in:
parent
5eda97d7e4
commit
38d8b8cfe2
@ -8,10 +8,11 @@ Changelog
|
|||||||
* Redesigned virtual call mechanism and user-facing syntax (breaking change!)
|
* Redesigned virtual call mechanism and user-facing syntax (breaking change!)
|
||||||
* Prevent implicit conversion of floating point values to integral types in
|
* Prevent implicit conversion of floating point values to integral types in
|
||||||
function arguments
|
function arguments
|
||||||
* Transparent conversion of sparse and dense Eigen data types
|
* Transparent conversion of sparse and dense Eigen matrices and vectors
|
||||||
* ``std::vector<>`` type bindings analogous to Boost.Python's ``indexing_suite``
|
* ``std::vector<>`` type bindings analogous to Boost.Python's ``indexing_suite``
|
||||||
* Fixed incorrect default return value policy for functions returning a shared
|
* Fixed incorrect default return value policy for functions returning a shared
|
||||||
pointer
|
pointer
|
||||||
|
* Don't allow registering a type via ``class_`` twice
|
||||||
* Don't allow casting a ``None`` value into a C++ lvalue reference
|
* 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
|
* 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
|
* Improved detection of whether or not custom C++ types can be copy/move-constructed
|
||||||
|
@ -131,4 +131,11 @@ void init_issues(py::module &m) {
|
|||||||
.def("f", &A::f);
|
.def("f", &A::f);
|
||||||
|
|
||||||
m2.def("call_f", call_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 */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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 type_holder(PyType_Type.tp_alloc(&PyType_Type, 0), false);
|
||||||
object name(PYBIND11_FROM_STRING(rec->name), false);
|
object name(PYBIND11_FROM_STRING(rec->name), false);
|
||||||
auto type = (PyHeapTypeObject*) type_holder.ptr();
|
auto type = (PyHeapTypeObject*) type_holder.ptr();
|
||||||
@ -528,12 +536,11 @@ protected:
|
|||||||
pybind11_fail("generic_type: unable to create type object!");
|
pybind11_fail("generic_type: unable to create type object!");
|
||||||
|
|
||||||
/* Register supplemental type information in C++ dict */
|
/* Register supplemental type information in C++ dict */
|
||||||
auto &internals = get_internals();
|
|
||||||
detail::type_info *tinfo = new detail::type_info();
|
detail::type_info *tinfo = new detail::type_info();
|
||||||
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[std::type_index(*(rec->type))] = tinfo;
|
internals.registered_types_cpp[tindex] = tinfo;
|
||||||
internals.registered_types_py[type] = tinfo;
|
internals.registered_types_py[type] = tinfo;
|
||||||
|
|
||||||
object scope_module;
|
object scope_module;
|
||||||
|
Loading…
Reference in New Issue
Block a user