From 8a4a42777f42cd81671cc41d7c14c40cff507047 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Mon, 10 Apr 2023 22:01:53 +0200 Subject: [PATCH] Property transfer ownership of schema from py to c++ upon register_schema() --- src/ifcopenshell-python/ifcopenshell/__init__.py | 6 ++---- .../ifcopenshell/express/schema_class.py | 7 ++++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/__init__.py b/src/ifcopenshell-python/ifcopenshell/__init__.py index 962a75a483..4b08dc3907 100644 --- a/src/ifcopenshell-python/ifcopenshell/__init__.py +++ b/src/ifcopenshell-python/ifcopenshell/__init__.py @@ -160,9 +160,6 @@ def create_entity(type, schema="IFC4", *args, **kwargs): return e -gcroot = [] - - def register_schema(schema): """Registers a custom IFC schema @@ -177,7 +174,8 @@ def register_schema(schema): ifcopenshell.register_schema(schema) ifcopenshell.file(schema="IFC_CUSTOM") """ - gcroot.append(schema) + schema.schema.this.disown() + schema.disown() ifcopenshell_wrapper.register_schema(schema.schema) register_schema_attributes(schema.schema) diff --git a/src/ifcopenshell-python/ifcopenshell/express/schema_class.py b/src/ifcopenshell-python/ifcopenshell/express/schema_class.py index e6e4b1aeef..583a8e5bd7 100644 --- a/src/ifcopenshell-python/ifcopenshell/express/schema_class.py +++ b/src/ifcopenshell-python/ifcopenshell/express/schema_class.py @@ -84,7 +84,7 @@ class LateBoundSchemaInstantiator: for attr_name, decl_type, optional in attribute_definitions: attributes.append(w.attribute(attr_name, decl_type, optional)) self.declarations[str(name)].set_attributes(attributes, is_derived) - self.cache.append(attributes) + self.cache.extend(attributes) def inverse_attributes(self, name, inv_attrs): attributes = [] @@ -100,6 +100,7 @@ class LateBoundSchemaInstantiator: en.attributes()[attribute_entity_index], ) ) + self.cache.extend(attributes) self.declarations[str(name)].set_inverse_attributes(attributes) def entity_subtypes(self, name, tys): @@ -110,6 +111,10 @@ class LateBoundSchemaInstantiator: override_schema_name or self.schema_name, list(self.declarations.values()), None ) + def disown(self): + for elem in self.cache + list(self.declarations.values()): + elem.this.disown() + class EarlyBoundCodeWriter: def __init__(self, schema_name):