diff options
author | tgingold <tgingold@users.noreply.github.com> | 2021-06-20 16:58:55 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-20 16:58:55 +0200 |
commit | 37920daab7a1cdcdb7f6b54c2799d73b58634524 (patch) | |
tree | 8b68056072cdd34e47efa55aa629143552a55ba8 /pyGHDL/libghdl/_decorator.py | |
parent | 603c44d06dd0b3f2f49af25045b46dd8aa72979a (diff) | |
parent | 3f3cf203c02671ab4d181d8d74aac2c3cc2c7c5c (diff) | |
download | ghdl-37920daab7a1cdcdb7f6b54c2799d73b58634524.tar.gz ghdl-37920daab7a1cdcdb7f6b54c2799d73b58634524.tar.bz2 ghdl-37920daab7a1cdcdb7f6b54c2799d73b58634524.zip |
Merge pull request #1798 from Paebbels/paebbels/aggregates
Python-C/Ada Bindings - Updated decorator
Diffstat (limited to 'pyGHDL/libghdl/_decorator.py')
-rw-r--r-- | pyGHDL/libghdl/_decorator.py | 46 |
1 files changed, 40 insertions, 6 deletions
diff --git a/pyGHDL/libghdl/_decorator.py b/pyGHDL/libghdl/_decorator.py index b3d17fd01..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, 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 @@ -82,6 +93,8 @@ def BindToLibGHDL(subprogramName): return None elif typ is int: return c_int32 + elif type is float: + return c_double elif typ is bool: return c_bool elif typ is bytes: @@ -92,8 +105,20 @@ def BindToLibGHDL(subprogramName): # Humm, recurse ? if typ.__bound__ is int: return c_int32 - if typ.__bound__ in (c_uint32, c_int32): + 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 @@ -152,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 |