Skip to content

Commit

Permalink
Fix the macros
Browse files Browse the repository at this point in the history
  • Loading branch information
amontoison committed Jun 13, 2024
1 parent 81f4e6d commit baf046f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ project(
default_options: [
'buildtype=release',
'libdir=lib',
'default_library=static',
'default_library=shared',
'warning_level=0',
],
)
Expand Down
24 changes: 12 additions & 12 deletions src/tools/cutest_delegate.f90
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
#endif

#ifdef _WIN32
#define DLOPEN_BIND_NAME LoadLibrary
#define DLSYM_BIND_NAME GetProcAddress
#define DLOPEN_BIND_NAME "LoadLibrary"
#define DLSYM_BIND_NAME "GetProcAddress"
#else
#define DLOPEN_BIND_NAME dlopen
#define DLSYM_BIND_NAME dlsym
#define DLOPEN_BIND_NAME "dlopen"
#define DLSYM_BIND_NAME "dlsym"
#endif

module cutest_delegate_r
Expand All @@ -32,22 +32,22 @@ module cutest_delegate_r

! Interface for dlopen / LoadLibrary
interface
function cutest_dlopen(name, mode) bind(C, name=DLOPEN_BIND_NAME)
function dlopen(name, mode) bind(C, name=DLOPEN_BIND_NAME)
use iso_c_binding, only: c_ptr, c_int, c_char
type(c_ptr) :: dlopen
character(kind=c_char), dimension(*) :: name
integer(kind=c_int) :: mode
end function cutest_dlopen
end function dlopen
end interface

! Interface for dlsym / GetProcAddress
interface
function cutest_dlsym(handle, symbol) bind(C, name=DLSYM_BIND_NAME)
function dlsym(handle, symbol) bind(C, name=DLSYM_BIND_NAME)
use iso_c_binding, only: c_funptr, c_ptr, c_char
type(c_funptr) :: dlsym
type(c_ptr), value :: handle
character(kind=c_char), dimension(*) :: symbol
end function cutest_dlsym
end function dlsym
end interface

! Constantes pour les modes d'ouverture de bibliothèques
Expand All @@ -73,15 +73,15 @@ subroutine load_routines(libname) bind(C, name=LOAD_ROUTINE_NAME)
character(kind=c_char), dimension(*), intent(in) :: libname

! Charge la bibliothèque dynamique
lib_handle = cutest_dlopen(libname, RTLD_LAZY)
lib_handle = dlopen(libname, RTLD_LAZY)
if (.not. c_associated(lib_handle)) then
stop "Unable to load library"
end if

! Récupère les adresses des fonctions
ptr_elfun = cutest_dlsym(lib_handle, ELFUN_BIND_NAME//c_null_char)
ptr_group = cutest_dlsym(lib_handle, GROUP_BIND_NAME//c_null_char)
ptr_range = cutest_dlsym(lib_handle, RANGE_BIND_NAME//c_null_char)
ptr_elfun = dlsym(lib_handle, ELFUN_BIND_NAME//c_null_char)
ptr_group = dlsym(lib_handle, GROUP_BIND_NAME//c_null_char)
ptr_range = dlsym(lib_handle, RANGE_BIND_NAME//c_null_char)

! Associe les pointeurs de procédure Fortran avec les adresses obtenues
call c_f_procpointer(ptr_elfun, fun_elfun)
Expand Down

0 comments on commit baf046f

Please sign in to comment.