Property transfer ownership of schema from py to c++ upon register_schema()

This commit is contained in:
Thomas Krijnen
2023-04-10 22:01:53 +02:00
parent 352d6b5ef9
commit 8a4a42777f
2 changed files with 8 additions and 5 deletions
@@ -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)
@@ -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):