diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3e5cefa..f368455 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,5 +1,6 @@ set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/src/mod_files) -add_library(yajl_fort yajl_fort.F90 f90_assert.F90) +include_directories(${YAJL_INCLUDE_DIR}) +add_library(yajl_fort yajl_fort.F90 yajl_ext.c f90_assert.F90) install(TARGETS yajl_fort DESTINATION lib) target_link_libraries(yajl_fort ${LIBS}) diff --git a/src/yajl_ext.c b/src/yajl_ext.c new file mode 100644 index 0000000..122431e --- /dev/null +++ b/src/yajl_ext.c @@ -0,0 +1,13 @@ +/* Fortran interoperable interfaces to the varargs function yajl_config */ + +#include "yajl/yajl_parse.h" + +int yajl_set_option(yajl_handle h, yajl_option opt) +{ + return yajl_config(h, opt, 1); +} + +int yajl_unset_option(yajl_handle h, yajl_option opt) +{ + return yajl_config(h, opt, 0); +} diff --git a/src/yajl_fort.F90 b/src/yajl_fort.F90 index 471a331..e17e23f 100644 --- a/src/yajl_fort.F90 +++ b/src/yajl_fort.F90 @@ -223,12 +223,15 @@ subroutine yajl_free(handle) bind(c) use,intrinsic :: iso_c_binding type(c_ptr), value :: handle end subroutine - function yajl_config (handle, option, enable) result(stat) bind(c) - use,intrinsic :: iso_c_binding - type(c_ptr), value :: handle - integer(c_int), value :: option, enable - integer(c_int) :: stat - end function + !yajl_config is a varargs function, and this 'single argument' declaration + !has been found to be non-portable. See the 'extra' interfaces below for + !the replacement. + !function yajl_config (handle, option, enable) result(stat) bind(c) + ! use,intrinsic :: iso_c_binding + ! type(c_ptr), value :: handle + ! integer(c_int), value :: option, enable + ! integer(c_int) :: stat + ! end function function yajl_parse (handle, buffer, length) result(stat) bind(c) use,intrinsic :: iso_c_binding type(c_ptr), value :: handle @@ -266,6 +269,22 @@ subroutine yajl_free_error(handle, str) bind(c) end subroutine end interface + !! INTEROPERABLE INTERFACES TO EXTRA YAJL C FUNCTIONS (yajl_ext.c) + interface + function yajl_set_option (handle, option) result(stat) bind(c) + use,intrinsic :: iso_c_binding + type(c_ptr), value :: handle + integer(c_int), value :: option + integer(c_int) :: stat + end function + function yajl_unset_option (handle, option) result(stat) bind(c) + use,intrinsic :: iso_c_binding + type(c_ptr), value :: handle + integer(c_int), value :: option + integer(c_int) :: stat + end function + end interface + !! The Fortran yajl emitter. This holds the handle to the C yajl generator !! and provides bindings to the C parser functions as type-bound procedures. !! Note that the callback structure and callback context that are passed @@ -438,14 +457,14 @@ subroutine set_option (this, option) class(fyajl_parser), intent(in) :: this integer(c_int), intent(in) :: option integer :: stat - stat = yajl_config(this%handle, option, 1) ! ignore return code + stat = yajl_set_option(this%handle, option) ! ignore return code end subroutine subroutine unset_option (this, option) class(fyajl_parser), intent(in) :: this integer(c_int), intent(in) :: option integer :: stat - stat = yajl_config(this%handle, option, 0) ! ignore return code + stat = yajl_unset_option(this%handle, option) ! ignore return code end subroutine subroutine parse (this, buffer, stat)