diff options
author | Patrick Lehmann <Patrick.Lehmann@plc2.de> | 2021-06-19 02:23:16 +0200 |
---|---|---|
committer | Patrick Lehmann <Patrick.Lehmann@plc2.de> | 2021-06-19 15:25:07 +0200 |
commit | 35673cc2ec1b572379396ca5f3e35939a99c3a31 (patch) | |
tree | f22a78924a7de3cd4a50e7307199230f26783b34 /pyGHDL/libghdl | |
parent | d9a096facfde93a78f1ce7546bb4f34f4e3cbde1 (diff) | |
download | ghdl-35673cc2ec1b572379396ca5f3e35939a99c3a31.tar.gz ghdl-35673cc2ec1b572379396ca5f3e35939a99c3a31.tar.bz2 ghdl-35673cc2ec1b572379396ca5f3e35939a99c3a31.zip |
Added handling of new types to the decorator for the Python-C/Ada binding.
Diffstat (limited to 'pyGHDL/libghdl')
-rw-r--r-- | pyGHDL/libghdl/_decorator.py | 43 |
1 files changed, 37 insertions, 6 deletions
diff --git a/pyGHDL/libghdl/_decorator.py b/pyGHDL/libghdl/_decorator.py index ffec1f497..2001cb37e 100644 --- a/pyGHDL/libghdl/_decorator.py +++ b/pyGHDL/libghdl/_decorator.py @@ -31,7 +31,18 @@ # SPDX-License-Identifier: GPL-2.0-or-later # ============================================================================ # -from ctypes import c_int32, c_uint32, c_char_p, c_bool, c_double, Structure, c_char +from ctypes import ( + c_int32, + c_uint32, + c_char_p, + c_bool, + c_double, + Structure, + c_char, + c_uint64, + c_int64, +) +from enum import IntEnum from functools import wraps from typing import Callable, List, Dict, Any, TypeVar @@ -94,9 +105,20 @@ def BindToLibGHDL(subprogramName): # Humm, recurse ? if typ.__bound__ is int: return c_int32 - if typ.__bound__ in (c_uint32, c_int32, c_double): + if typ.__bound__ is float: + return c_double + if typ.__bound__ in ( + c_bool, + c_uint32, + c_int32, + c_uint64, + c_int64, + c_double, + ): return typ.__bound__ raise TypeError("Unsupported typevar bound to {!s}".format(typ.__bound__)) + elif issubclass(typ, IntEnum): + return c_int32 elif issubclass(typ, Structure): return typ raise TypeError @@ -155,10 +177,19 @@ def BindToLibGHDL(subprogramName): functionPointer.parameterTypes = parameterTypes functionPointer.restype = resultType - @wraps(func) - def inner(*args): - return functionPointer(*args) + if isinstance(returnType, type) and issubclass(returnType, IntEnum): + + @wraps(func) + def inner(*args): + return returnType(functionPointer(*args)) + + return inner + else: + + @wraps(func) + def inner(*args): + return functionPointer(*args) - return inner + return inner return wrapper |