summaryrefslogtreecommitdiff
path: root/src/scripts/pyolian/eolian.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/scripts/pyolian/eolian.py')
-rw-r--r--src/scripts/pyolian/eolian.py35
1 files changed, 22 insertions, 13 deletions
diff --git a/src/scripts/pyolian/eolian.py b/src/scripts/pyolian/eolian.py
index 645b463278..1b43d5e737 100644
--- a/src/scripts/pyolian/eolian.py
+++ b/src/scripts/pyolian/eolian.py
@@ -24,6 +24,7 @@ a way that this folder will be available on PYTHON_PATH, fe:
24 24
25""" 25"""
26from enum import IntEnum 26from enum import IntEnum
27import atexit
27from ctypes import cast, byref, c_char_p, c_void_p, c_int 28from ctypes import cast, byref, c_char_p, c_void_p, c_int
28import ctypes 29import ctypes
29 30
@@ -32,6 +33,7 @@ try:
32except ImportError: 33except ImportError:
33 from eolian_lib import lib 34 from eolian_lib import lib
34 35
36_already_halted = False
35 37
36### Eolian Enums ############################################################ 38### Eolian Enums ############################################################
37 39
@@ -303,13 +305,16 @@ class Eolian_Unit(EolianBaseObject):
303 @property 305 @property
304 def all_namespaces(self): 306 def all_namespaces(self):
305 # TODO find a better way to find namespaces (maybe inside eolian?) 307 # TODO find a better way to find namespaces (maybe inside eolian?)
306 nspaces = [] 308 nspaces = set()
307 for cls in self.all_classes: 309 for obj in self.all_classes:
308 ns = Namespace(self, cls.namespace) 310 nspaces.add(Namespace(self, obj.namespace))
309 if not ns in nspaces: 311 for obj in self.typedecl_all_aliases:
310 nspaces.append(ns) 312 nspaces.add(Namespace(self, obj.namespace))
311 nspaces.sort() 313 for obj in self.typedecl_all_structs:
312 return nspaces 314 nspaces.add(Namespace(self, obj.namespace))
315 for obj in self.typedecl_all_enums:
316 nspaces.add(Namespace(self, obj.namespace))
317 return sorted(nspaces)
313 318
314 def namespace_get_by_name(self, name): 319 def namespace_get_by_name(self, name):
315 return Namespace(self, name) 320 return Namespace(self, name)
@@ -392,10 +397,8 @@ class Eolian(Eolian_Unit):
392 self._obj = lib.eolian_new() # Eolian * 397 self._obj = lib.eolian_new() # Eolian *
393 398
394 def __del__(self): 399 def __del__(self):
395 # TODO I'm not sure about this, It is automatically called on gc, that 400 if not _already_halted: # do not free after eolian_shutdown
396 # is fired after atexit (eolian_shutdown). Thus causing a segfault 401 lib.eolian_free(self._obj)
397 # if the user do not call del before exit.
398 lib.eolian_free(self._obj)
399 402
400 def file_parse(self, filepath): 403 def file_parse(self, filepath):
401 c_unit = lib.eolian_file_parse(self._obj, _str_to_bytes(filepath)) 404 c_unit = lib.eolian_file_parse(self._obj, _str_to_bytes(filepath))
@@ -449,6 +452,9 @@ class Namespace(object):
449 def __gt__(self, other): 452 def __gt__(self, other):
450 return self.name > other.name 453 return self.name > other.name
451 454
455 def __hash__(self):
456 return hash(self._name)
457
452 @property 458 @property
453 def name(self): 459 def name(self):
454 return self._name 460 return self._name
@@ -1420,10 +1426,13 @@ def _str_to_py(s):
1420 1426
1421 1427
1422### module init/shutdown #################################################### 1428### module init/shutdown ####################################################
1429def _cleanup():
1430 global _already_halted
1431 lib.eolian_shutdown()
1432 _already_halted = True
1423 1433
1424import atexit
1425lib.eolian_init() 1434lib.eolian_init()
1426atexit.register(lambda: lib.eolian_shutdown()) 1435atexit.register(_cleanup)
1427 1436
1428 1437
1429### API coverage statistics ################################################# 1438### API coverage statistics #################################################