Skip to content

Commit 3b2f018

Browse files
committed
Fix up location of manager and other bits
1 parent b267d06 commit 3b2f018

4 files changed

Lines changed: 67 additions & 43 deletions

File tree

meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ if pyprojectwheelbuild_enabled
5252
# Injected with `script/inject-srcs-into-meson-build.py`
5353
srcs = files(
5454
'src/example_fgen_basic/error_v/creation_wrapper.f90',
55+
'src/example_fgen_basic/error_v/error_v_wrapper.f90',
5556
'src/example_fgen_basic/get_wavelength_wrapper.f90',
5657
)
5758

src/example_fgen_basic/error_v/creation_wrapper.f90

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module m_error_v_creation_w
1717
implicit none
1818
private
1919

20-
public :: create_error, iget_code, iget_message
20+
public :: create_error
2121

2222
contains
2323

@@ -51,42 +51,4 @@ subroutine create_error(inv, res_instance_index)
5151

5252
end subroutine create_error
5353

54-
! Full set of wrapping strategies to pass different types in e.g.
55-
! https://gitlab.com/magicc/fgen/-/blob/switch-to-uv/tests/test-data/exposed_attrs/src/exposed_attrs/exposed_attrs_wrapped.f90
56-
! (we will do a full re-write of the code which generates this,
57-
! but the strategies will probably stay as they are)
58-
subroutine iget_code( &
59-
instance_index, &
60-
code &
61-
)
62-
63-
integer, intent(in) :: instance_index
64-
65-
integer, intent(out) :: code
66-
67-
type(ErrorV), pointer :: instance
68-
69-
call error_v_manager_associate_pointer_with_instance(instance_index, instance)
70-
71-
code = instance % code
72-
73-
end subroutine iget_code
74-
75-
subroutine iget_message( &
76-
instance_index, &
77-
message &
78-
)
79-
80-
integer, intent(in) :: instance_index
81-
82-
character(len=128), intent(out) :: message
83-
84-
type(ErrorV), pointer :: instance
85-
86-
call error_v_manager_associate_pointer_with_instance(instance_index, instance)
87-
88-
message = instance % message
89-
90-
end subroutine iget_message
91-
9254
end module m_error_v_creation_w

src/example_fgen_basic/error_v/error_v.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616

1717
try:
1818
from example_fgen_basic._lib import ( # type: ignore
19-
m_error_v_creation_w,
19+
m_error_v_w,
2020
)
2121
except (ModuleNotFoundError, ImportError) as exc: # pragma: no cover
22-
raise CompiledExtensionNotFoundError("example._lib.m_error_v_creation_w") from exc
22+
raise CompiledExtensionNotFoundError("example._lib.m_error_v_w") from exc
2323

2424

2525
@define
@@ -57,7 +57,7 @@ def code(self) -> int:
5757
:
5858
Error code, retrieved from Fortran
5959
"""
60-
code: int = m_error_v_creation_w.iget_code(instance_index=self.instance_index)
60+
code: int = m_error_v_w.iget_code(instance_index=self.instance_index)
6161

6262
return code
6363

@@ -72,7 +72,7 @@ def message(self) -> str:
7272
:
7373
Error message, retrieved from Fortran
7474
"""
75-
message: str = m_error_v_creation_w.iget_message(
75+
message: str = m_error_v_w.iget_message(
7676
instance_index=self.instance_index
7777
).decode()
7878

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
!> Wrapper for interfacing `m_error_v` with Python
2+
!>
3+
!> Written by hand here.
4+
!> Generation to be automated in future (including docstrings of some sort).
5+
module m_error_v_w
6+
7+
! => allows us to rename on import to avoid clashes
8+
use m_error_v, only: ErrorV
9+
10+
! The manager module, which makes this all work
11+
use m_error_v_manager, only: &
12+
get_free_instance_number, &
13+
error_v_manager_associate_pointer_with_instance => associate_pointer_with_instance
14+
! TODO: build and finalisation
15+
16+
implicit none
17+
private
18+
19+
public :: get_free_instance_number, iget_code, iget_message
20+
21+
contains
22+
23+
! Full set of wrapping strategies to pass different types in e.g.
24+
! https://gitlab.com/magicc/fgen/-/blob/switch-to-uv/tests/test-data/exposed_attrs/src/exposed_attrs/exposed_attrs_wrapped.f90
25+
! (we will do a full re-write of the code which generates this,
26+
! but the strategies will probably stay as they are)
27+
subroutine iget_code( &
28+
instance_index, &
29+
code &
30+
)
31+
32+
integer, intent(in) :: instance_index
33+
34+
integer, intent(out) :: code
35+
36+
type(ErrorV), pointer :: instance
37+
38+
call error_v_manager_associate_pointer_with_instance(instance_index, instance)
39+
40+
code = instance % code
41+
42+
end subroutine iget_code
43+
44+
subroutine iget_message( &
45+
instance_index, &
46+
message &
47+
)
48+
49+
integer, intent(in) :: instance_index
50+
51+
character(len=128), intent(out) :: message
52+
53+
type(ErrorV), pointer :: instance
54+
55+
call error_v_manager_associate_pointer_with_instance(instance_index, instance)
56+
57+
message = instance % message
58+
59+
end subroutine iget_message
60+
61+
end module m_error_v_w

0 commit comments

Comments
 (0)