diff options
author | Tristan Gingold <tgingold@free.fr> | 2021-06-16 21:16:50 +0200 |
---|---|---|
committer | Tristan Gingold <tgingold@free.fr> | 2021-06-16 21:16:50 +0200 |
commit | 17ddaa0d211903e9e07cf26b0c7d23dee47fae99 (patch) | |
tree | c3f4fb71cec7b942ad9525ecc1cfdf5b8da53eb1 /pyGHDL/libghdl | |
parent | 4c0f9967e541b914a207bd4419d62d00d3e1745c (diff) | |
download | ghdl-17ddaa0d211903e9e07cf26b0c7d23dee47fae99.tar.gz ghdl-17ddaa0d211903e9e07cf26b0c7d23dee47fae99.tar.bz2 ghdl-17ddaa0d211903e9e07cf26b0c7d23dee47fae99.zip |
pyGHDL: add Get_Character to name_table.py
Diffstat (limited to 'pyGHDL/libghdl')
-rw-r--r-- | pyGHDL/libghdl/name_table.py | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/pyGHDL/libghdl/name_table.py b/pyGHDL/libghdl/name_table.py index 7dd5165a8..2e912d741 100644 --- a/pyGHDL/libghdl/name_table.py +++ b/pyGHDL/libghdl/name_table.py @@ -32,7 +32,7 @@ # SPDX-License-Identifier: GPL-2.0-or-later # ============================================================================ -from ctypes import c_char_p +from ctypes import c_char_p, c_char from pydecor import export @@ -58,7 +58,7 @@ def Get_Name_Length(Id: NameId) -> int: @export def Get_Name_Ptr(Id: NameId) -> str: """ - Get the address of the first character of ID. The address is valid until + Get the string corresponding to identifier ID. The address is valid until the next call to Get_Identifier (which may reallocate the string table). The string is NUL-terminated (this is done by get_identifier). @@ -72,6 +72,19 @@ def Get_Name_Ptr(Id: NameId) -> str: @export +def Get_Character(Id: NameId) -> str: + """ + Get the string corresponding to character identifier ID. + + :param Id: NameId for the identifier to query. + :return: + """ + func = libghdl.name_table__get_character + func.restype = c_char + + return func(Id).decode("utf-8") + +@export def Get_Identifier(string: str) -> NameId: """ Get or create an entry in the name table. |