<commit_before>module exports
  use ISO_C_BINDING
  implicit none

  integer, dimension(:), allocatable, target :: xs
  integer :: foo = 1

  type point
    sequence
    integer :: x, y
  end type point

  type, bind(c) :: cpoint
    integer(c_int) :: x, y
  end type cpoint

  contains

    ! this will not update, due to use of `value`
    subroutine wont_set_out (input, output) bind(c, name = 'wont_set_out')
      implicit none
      integer, intent(in), value :: input
      integer, value :: output
      output = 3
    end subroutine wont_set_out

    subroutine assign_arr (my_arr) bind(c, name = 'assign_arr')
      implicit none
      integer, target, allocatable, dimension(:) :: my_arr
      allocate(my_arr(0:4))
      my_arr = [1,2,3,4,5]
    end subroutine assign_arr

    ! works
    integer function ret_i() bind(c, name = 'ret_i')
      ret_i = 3
    end function ret_i

    ! this compiles, but doesn't interop with ruby
    integer function ret_loc_i(n) bind(c, name = 'ret_loc_i')
      ! fails unless we specify call by value
      ! integer, intent(in), value :: n
      integer, intent(in), value :: n
      integer i
      i = n + 4
      ! allocate(xs(n))
      ! xs = ([(i,i=1,n)])
      ! ret_loc_i = loc(xs)
      ret_loc_i = loc(foo)
    end function ret_loc_i

    ! compiles but doesn't work with ruby...
    ! type (point) function ret_p(a, b) bind(c, name = 'ret_p') 
      ! implicit none
      ! integer, intent(in) :: a, b
      ! type (point) :: p
      ! ret_p%x = a
      ! ret_p%y = b
      ! ret_p = p
    ! end function ret_p

    function ret_p(a, b) result(p)
      implicit none
      integer, intent(in) :: a, b
      type (point), target :: p
      p%x = a
      p%y = b
    end function ret_p

    ! compiles but causes segfault with ruby
    ! this suggests the problem is merely creating the point
    function ret_p_loc(a, b) result(p_loc) bind(c, name= 'ret_p_loc')
      implicit none
      integer, intent(in) :: a, b
      type (point), target :: p
      integer p_loc
      p%x = a
      p%y = b
      p_loc = 1
    end function ret_p_loc

    ! tried changing inout to value, doesn't work with ruby still
    ! tried using bind_c, doesn't work
    ! 
    subroutine sub_p(a, b)
      implicit none
      integer, intent(in) :: a, b
      type (point) :: p
      ! p%x = a
      ! p%y = b
    end subroutine sub_p

    ! tried changing inout to value, doesn't work with ruby still
    ! tried using bind_c, doesn't work
    subroutine sub_p_two(a, b) bind(c, name = 'sub_p_two')
      implicit none
      integer, intent(in) :: a, b
      type (cpoint) :: p
      p%x = a
      p%y = b
    end subroutine sub_p_two

    ! this won't work, return type of BIND(C) function can't be an array
    ! function fn_arr(n) bind(c, name = 'fn_arr')
      ! integer, intent(in) :: n
      ! integer, dimension(n) :: fn_arr
      ! integer i
      ! fn_arr = ([(i, i=1, n)])
    ! end function fn_arr

    ! this also won't work, can't have bind(c) and return pointer
    ! function point_to_xs(n) bind(c, name = 'point_to_xs')
      ! implicit none
      ! integer, intent(in) :: n<commit_msg>removing `sequence` doesn't help, still segfaults<commit_after>module exports
  use ISO_C_BINDING
  implicit none

  integer, dimension(:), allocatable, target :: xs
  integer :: foo = 1

  type point
    integer :: x, y
  end type point

  type, bind(c) :: cpoint
    integer(c_int) :: x, y
  end type cpoint

  contains

    ! this will not update, due to use of `value`
    subroutine wont_set_out (input, output) bind(c, name = 'wont_set_out')
      implicit none
      integer, intent(in), value :: input
      integer, value :: output
      output = 3
    end subroutine wont_set_out

    subroutine assign_arr (my_arr) bind(c, name = 'assign_arr')
      implicit none
      integer, target, allocatable, dimension(:) :: my_arr
      allocate(my_arr(0:4))
      my_arr = [1,2,3,4,5]
    end subroutine assign_arr

    ! works
    integer function ret_i() bind(c, name = 'ret_i')
      ret_i = 3
    end function ret_i

    ! this compiles, but doesn't interop with ruby
    integer function ret_loc_i(n) bind(c, name = 'ret_loc_i')
      ! fails unless we specify call by value
      ! integer, intent(in), value :: n
      integer, intent(in), value :: n
      integer i
      i = n + 4
      ! allocate(xs(n))
      ! xs = ([(i,i=1,n)])
      ! ret_loc_i = loc(xs)
      ret_loc_i = loc(foo)
    end function ret_loc_i

    ! compiles but doesn't work with ruby...
    ! type (point) function ret_p(a, b) bind(c, name = 'ret_p') 
      ! implicit none
      ! integer, intent(in) :: a, b
      ! type (point) :: p
      ! ret_p%x = a
      ! ret_p%y = b
      ! ret_p = p
    ! end function ret_p

    function ret_p(a, b) result(p)
      implicit none
      integer, intent(in) :: a, b
      type (point), target :: p
      p%x = a
      p%y = b
    end function ret_p

    ! compiles but causes segfault with ruby
    ! this suggests the problem is merely creating the point
    function ret_p_loc(a, b) result(p_loc) bind(c, name= 'ret_p_loc')
      implicit none
      integer, intent(in) :: a, b
      type (point), target :: p
      integer p_loc
      p%x = a
      p%y = b
      p_loc = 1
    end function ret_p_loc

    ! tried changing inout to value, doesn't work with ruby still
    ! tried using bind_c, doesn't work
    ! 
    subroutine sub_p(a, b)
      implicit none
      integer, intent(in) :: a, b
      type (point) :: p
      p%x = a
      p%y = b
    end subroutine sub_p

    ! tried changing inout to value, doesn't work with ruby still
    ! tried using bind_c, doesn't work
    subroutine sub_p_two(a, b) bind(c, name = 'sub_p_two')
      implicit none
      integer, intent(in) :: a, b
      type (cpoint) :: p
      p%x = a
      p%y = b
    end subroutine sub_p_two

    ! this won't work, return type of BIND(C) function can't be an array
    ! function fn_arr(n) bind(c, name = 'fn_arr')
      ! integer, intent(in) :: n
      ! integer, dimension(n) :: fn_arr
      ! integer i
      ! fn_arr = ([(i, i=1, n)])
    ! end function fn_arr

    ! this also won't work, can't have bind(c) and return pointer
    ! function point_to_xs(n) bind(c, name = 'point_to_xs')
      ! implicit none
      ! integer, intent(in) :: n
{'fraction_non_alphanumeric': 0.1092236862994126, 'fraction_numerical': 0.004445150023813304, 'mean_word_length': 2.3421750663129974, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1500017', 'n_tokens_mistral': 2242, 'n_tokens_neox': 2169, 'n_words': 715}