mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-13 02:47:48 +00:00
register_schema: use ref to avoid segfaults
E.g. `register_schema(None)` from Python was resulting in a segfault
This commit is contained in:
@@ -173,7 +173,7 @@ ifcopenshell::schema_definition::schema_definition(const std::string& name, cons
|
||||
ent->all_attributes();
|
||||
}
|
||||
|
||||
register_schema(this);
|
||||
register_schema(*this);
|
||||
}
|
||||
|
||||
ifcopenshell::schema_definition::~schema_definition() {
|
||||
@@ -182,7 +182,7 @@ ifcopenshell::schema_definition::~schema_definition() {
|
||||
}
|
||||
}
|
||||
|
||||
void ifcopenshell::register_schema(schema_definition* schema) {
|
||||
void ifcopenshell::register_schema(schema_definition& schema) {
|
||||
schema_registry_instance().bind(schema);
|
||||
}
|
||||
|
||||
@@ -244,10 +244,10 @@ void ifcopenshell::schema_registry::bind(const std::string& schema_name, get_sch
|
||||
entry.module_ = module;
|
||||
}
|
||||
|
||||
void ifcopenshell::schema_registry::bind(schema_definition* schema) {
|
||||
void ifcopenshell::schema_registry::bind(schema_definition& schema) {
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
auto& entry = entries_[schema_key(schema->name())];
|
||||
entry.schema_ = schema;
|
||||
auto& entry = entries_[schema_key(schema.name())];
|
||||
entry.schema_ = &schema;
|
||||
}
|
||||
|
||||
const ifcopenshell::schema_definition* ifcopenshell::schema_registry::get(const std::string& schema_name) {
|
||||
|
||||
@@ -510,7 +510,7 @@ class IFC_PARSE_API schema_registry {
|
||||
typedef void register_schema_plugin_fn(schema_registry&, const ifcopenshell::plugin::module&);
|
||||
|
||||
void bind(const std::string& schema_name, get_schema_fn get, clear_schema_fn clear, const ifcopenshell::plugin::module& module = ifcopenshell::plugin::module());
|
||||
void bind(schema_definition* schema);
|
||||
void bind(schema_definition& schema);
|
||||
const schema_definition* get(const std::string& schema_name);
|
||||
std::vector<std::string> names();
|
||||
void clear();
|
||||
@@ -548,7 +548,7 @@ IFC_PARSE_API const schema_definition* schema_by_name(const std::string& schema_
|
||||
|
||||
IFC_PARSE_API std::vector<std::string> schema_names();
|
||||
|
||||
IFC_PARSE_API void register_schema(schema_definition* schema);
|
||||
IFC_PARSE_API void register_schema(schema_definition& schema);
|
||||
|
||||
IFC_PARSE_API void clear_schemas();
|
||||
} // namespace ifcopenshell
|
||||
|
||||
Reference in New Issue
Block a user