Skip to content

Commit

Permalink
ENH: C API in the same file as the Fortran module.
Browse files Browse the repository at this point in the history
  • Loading branch information
MilanSkocic committed Jan 1, 2024
1 parent 6fd567c commit cd211a4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 36 deletions.
3 changes: 1 addition & 2 deletions src/codata.f90
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
module codata
!! Main module for CODATA library.
use codata__version
use codata__version_capi
use codata__constants
implicit none

end module
end module
23 changes: 22 additions & 1 deletion src/codata_version.f90
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
module codata__version
!! Version
use iso_fortran_env
use iso_c_binding
implicit none
private

character(len=*), parameter :: version = "0.9.0"
character(len=:), allocatable, target :: version_f

character(len=:), allocatable, target :: version_c

public :: get_version

Expand All @@ -28,4 +29,24 @@ function get_version()result(fptr)
fptr => version_f
end function

function capi_get_version()bind(c,name="codata_get_version")result(cptr)
!! Get the version.
implicit none

! Returns
type(c_ptr) :: cptr
!! Pointer to version string.

character(len=:), pointer :: fptr
fptr => get_version()

if(allocated(version_c))then
deallocate(version_c)
endif
allocate(character(len=len(fptr)+1) :: version_c)

version_c = fptr // c_null_char
cptr = c_loc(fptr)
end function

end module codata__version
33 changes: 0 additions & 33 deletions src/codata_version_capi.f90

This file was deleted.

0 comments on commit cd211a4

Please sign in to comment.