register_schema: use ref to avoid segfaults

E.g. `register_schema(None)` from Python was resulting in a segfault
This commit is contained in:
Andrej730
2026-07-24 16:52:32 +05:00
parent a954170927
commit 189eeae719
2 changed files with 7 additions and 7 deletions
+5 -5
View File
@@ -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) {
+2 -2
View File
@@ -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