Skip to content

Commit

Permalink
Fix for issue #2.
Browse files Browse the repository at this point in the history
  • Loading branch information
nncarlson committed Oct 25, 2014
1 parent 830e8b2 commit f2d4184
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})

Expand Down
13 changes: 13 additions & 0 deletions src/yajl_ext.c
Original file line number Diff line number Diff line change
@@ -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);
}
35 changes: 27 additions & 8 deletions src/yajl_fort.F90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit f2d4184

Please sign in to comment.