aboutsummaryrefslogtreecommitdiffstats
path: root/pyGHDL/libghdl
diff options
context:
space:
mode:
authorPatrick Lehmann <Patrick.Lehmann@plc2.de>2021-01-06 11:27:59 +0100
committertgingold <tgingold@users.noreply.github.com>2021-01-10 10:14:16 +0100
commit0de91f9313a4c76445ada1617fff69d97fe12217 (patch)
tree1e5074682a4996db4d54ac9b6c92e8745f05d753 /pyGHDL/libghdl
parent015adfc69e63e46c7823524032636faa99106c1f (diff)
downloadghdl-0de91f9313a4c76445ada1617fff69d97fe12217.tar.gz
ghdl-0de91f9313a4c76445ada1617fff69d97fe12217.tar.bz2
ghdl-0de91f9313a4c76445ada1617fff69d97fe12217.zip
Make API more pythonic be replacing C-like byte arrays with str. Abstracted utf-8 encoding/decoding.
Diffstat (limited to 'pyGHDL/libghdl')
-rw-r--r--pyGHDL/libghdl/errorout_memory.py5
-rw-r--r--pyGHDL/libghdl/name_table.py14
2 files changed, 10 insertions, 9 deletions
diff --git a/pyGHDL/libghdl/errorout_memory.py b/pyGHDL/libghdl/errorout_memory.py
index f9977ec27..444c53e80 100644
--- a/pyGHDL/libghdl/errorout_memory.py
+++ b/pyGHDL/libghdl/errorout_memory.py
@@ -79,13 +79,12 @@ def Get_Error_Record(Idx: ErrorIndex): # FIXME: returns Error_Message
@export
-def Get_Error_Message(Idx: ErrorIndex) -> str: # FIXME: check '*_addr' vs string return value
+def Get_Error_Message(Idx: ErrorIndex) -> str:
func = libghdl.errorout__memory__get_error_message_addr
func.argstype = [c_int32]
func.restype = c_char_p
- # FIXME: don't we need to encode to utf-8?
- return func(Idx)
+ return func(Idx).decode("utf-8")
@export
diff --git a/pyGHDL/libghdl/name_table.py b/pyGHDL/libghdl/name_table.py
index b82207fb3..72b6dfd8c 100644
--- a/pyGHDL/libghdl/name_table.py
+++ b/pyGHDL/libghdl/name_table.py
@@ -56,7 +56,7 @@ def Get_Name_Length(Id: NameId) -> int:
@export
-def Get_Name_Ptr(Id: NameId) -> bytes:
+def Get_Name_Ptr(Id: NameId) -> str:
"""
Get the address of the first character of ID. The address is valid until
the next call to Get_Identifier (which may reallocate the string table).
@@ -67,8 +67,8 @@ def Get_Name_Ptr(Id: NameId) -> bytes:
"""
func = libghdl.name_table__get_name_ptr
func.restype = c_char_p
- # FIXME: don't we need to encode to utf-8?
- return func(Id)
+
+ return func(Id).decode("utf-8")
@export
@@ -76,9 +76,11 @@ def Get_Identifier(string: str) -> NameId:
"""
Get or create an entry in the name table.
- Note:
- * an identifier is represented in all lower case letter,
- * an extended identifier is represented in backslashes, double internal backslashes are simplified.
+ .. note::
+
+ * an identifier is represented in all lower case letter,
+ * an extended identifier is represented in backslashes, double internal
+ backslashes are simplified.
:param string: String to create or lookup.
:return: Id in name table.