Greetings,
I’ve tripped over a strange issue while testing my SQLite 3 bindings with Intel oneAPI 2024. It boils down to not being able to nullify C pointers. For instance, an SQLite database handle is freed by calling sqlite3_close(ptr)
. The C pointer ptr
is passed by value, as SQLite expects sqlite3 *db
. The pointer itself is therefore never set to NULL
by SQLite 3:
! int sqlite3_close(sqlite3 *db)
function sqlite3_close_(db) bind(c, name='sqlite3_close')
import :: c_int, c_ptr
implicit none
type(c_ptr), intent(in), value :: db
integer(kind=c_int) :: sqlite3_close_
end function sqlite3_close_
The interface library provides a wrapper which nullifies the pointer after calling the SQLite function:
function sqlite3_close(db)
type(c_ptr), intent(inout) :: db
integer :: sqlite3_close
sqlite3_close = sqlite3_close_(db)
if (sqlite3_close == SQLITE_OK) db = c_null_ptr
end function sqlite3_close
This works as expected with GNU Fortran 13. But compiling the test program using Intel oneAPI Fortran, ptr
is never nullified:
! The wrapper function sets `ptr` to `c_null_ptr` after
! calling interface `sqlite3_close_(ptr)`:
rc = sqlite3_close(ptr)
! Output:
! "F" - GNU Fortran
! "T" - Intel oneAPI Fortran
print *, c_associated(ptr)
The same behaviour can be observed when calling the interface directly:
! Pass `ptr` by value to SQLite, then nullify:
rc = sqlite3_close_(ptr)
ptr = c_null_ptr
! Output:
! "F" - GNU Fortran
! "T" - Intel oneAPI Fortran
print *, c_associated(ptr)
Does anybody know the reason for this?