Skip to content

Commit

Permalink
Add magic number
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianDeconinck committed Apr 22, 2024
1 parent cae88fa commit 30f8c06
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/tcn/py_ftn_interface/example/bridge.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,5 +30,3 @@ end subroutine python_function_f
end interface

end module stub_interface_mod


2 changes: 2 additions & 0 deletions src/tcn/py_ftn_interface/example/data_desc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ class Data_py_t:
x: float
y: int
b: bool
# Magic number: see Fortran
i_am_123456789: int
2 changes: 2 additions & 0 deletions src/tcn/py_ftn_interface/example/data_to_be_transited.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ typedef struct
float x;
int y;
bool b;
// Magic number, see Fortran
int i_am_123456789;
} data_t;

typedef union
Expand Down
4 changes: 4 additions & 0 deletions src/tcn/py_ftn_interface/example/runtime_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 30f8c06

Please sign in to comment.