From 30f8c0653f56b2202e9105ba3071dd168b16ae34 Mon Sep 17 00:00:00 2001 From: Florian Deconinck Date: Mon, 22 Apr 2024 14:36:26 -0400 Subject: [PATCH] Add magic number --- src/tcn/py_ftn_interface/example/bridge.f90 | 5 +++-- src/tcn/py_ftn_interface/example/data_desc.py | 2 ++ src/tcn/py_ftn_interface/example/data_to_be_transited.h | 2 ++ src/tcn/py_ftn_interface/example/runtime_code.py | 4 ++++ 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/tcn/py_ftn_interface/example/bridge.f90 b/src/tcn/py_ftn_interface/example/bridge.f90 index ffe546b..23e7f12 100644 --- a/src/tcn/py_ftn_interface/example/bridge.f90 +++ b/src/tcn/py_ftn_interface/example/bridge.f90 @@ -11,6 +11,9 @@ module stub_interface_mod real(c_float) :: x integer(c_int) :: y logical(c_bool) :: b + ! Magic number: help guaranteeing layout is kept + ! consistant through the interface. Imperfect. + integer(c_int) :: i_am_123456789 = 123456789 end type interface @@ -27,5 +30,3 @@ end subroutine python_function_f end interface end module stub_interface_mod - - diff --git a/src/tcn/py_ftn_interface/example/data_desc.py b/src/tcn/py_ftn_interface/example/data_desc.py index d326d9b..70454fa 100644 --- a/src/tcn/py_ftn_interface/example/data_desc.py +++ b/src/tcn/py_ftn_interface/example/data_desc.py @@ -6,3 +6,5 @@ class Data_py_t: x: float y: int b: bool + # Magic number: see Fortran + i_am_123456789: int diff --git a/src/tcn/py_ftn_interface/example/data_to_be_transited.h b/src/tcn/py_ftn_interface/example/data_to_be_transited.h index e155a12..b616411 100644 --- a/src/tcn/py_ftn_interface/example/data_to_be_transited.h +++ b/src/tcn/py_ftn_interface/example/data_to_be_transited.h @@ -6,6 +6,8 @@ typedef struct float x; int y; bool b; + // Magic number, see Fortran + int i_am_123456789; } data_t; typedef union diff --git a/src/tcn/py_ftn_interface/example/runtime_code.py b/src/tcn/py_ftn_interface/example/runtime_code.py index 5c070da..a33ad3f 100644 --- a/src/tcn/py_ftn_interface/example/runtime_code.py +++ b/src/tcn/py_ftn_interface/example/runtime_code.py @@ -3,6 +3,10 @@ def check_function(data: Data_py_t): + # Check the magic number + if data.i_am_123456789 != 123456789: + raise ValueError("Magic number failure") + print(f"Data comes as {data} of type {type(data)}") members = inspect.getmembers(Data_py_t) keys = list(