Skip to content

Commit

Permalink
Allow switching between hdf5 versions
Browse files Browse the repository at this point in the history
  • Loading branch information
kojix2 committed Sep 11, 2024
1 parent 93e17d6 commit 8f9746d
Show file tree
Hide file tree
Showing 7 changed files with 10,253 additions and 45 deletions.
4 changes: 2 additions & 2 deletions lib/hdf5.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ def search_hdf5lib
end
return lib_path if File.exist?(lib_path)

warn "htslib shared library '#{name}' not found."
warn "hdf5 shared library '#{name}' not found."
end
end

self.lib_path = search_hdf5lib
end

require_relative 'hdf5/ffi3'
require_relative 'hdf5/ffi'

require_relative 'hdf5/file'
require_relative 'hdf5/group'
Expand Down
47 changes: 47 additions & 0 deletions lib/hdf5/ffi.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
module HDF5
module FFI
extend ::FFI::Library

begin
ffi_lib HDF5.lib_path
rescue LoadError => e
raise LoadError, "#{e}\nCould not find #{HDF5.lib_path}"
end

# @!macro attach_function
# @!scope class
# @!method $1(${2--2})
# @return [${-1}] the return value of $0
def self.attach_function(*)
super
rescue ::FFI::NotFoundError => e
warn e.message # if $VERBOSE
end

def self.attach_variable(*)
super
rescue ::FFI::NotFoundError => e
warn e.message # if $VERBOSE
end

attach_function 'H5get_libversion', %i[
pointer
pointer
pointer
], :int

major_ptr = ::FFI::MemoryPointer.new(:int)
minor_ptr = ::FFI::MemoryPointer.new(:int)
release_ptr = ::FFI::MemoryPointer.new(:int)
HDF5::FFI.H5get_libversion(major_ptr, minor_ptr, release_ptr)

raise 'HDF5 major version mismatch' if major_ptr.read_int != 1

case minor_ptr.read_int
when 10
require_relative 'ffi_10'
when 14..Float::INFINITY
require_relative 'ffi_14'
end
end
end
36 changes: 8 additions & 28 deletions lib/hdf5/ffi3.rb → lib/hdf5/ffi_10.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1,8 @@
# require_relative 'ffi'

module HDF5
module FFI
extend ::FFI::Library

begin
ffi_lib HDF5.lib_path
rescue LoadError => e
raise LoadError, "#{e}\nCould not find #{HDF5.lib_path}"
end

# @!macro attach_function
# @!scope class
# @!method $1(${2--2})
# @return [${-1}] the return value of $0
def self.attach_function(*)
super
rescue ::FFI::NotFoundError => e
warn e.message # if $VERBOSE
end

def self.attach_variable(*)
super
rescue ::FFI::NotFoundError => e
warn e.message # if $VERBOSE
end
MiV = 10

typedef :uchar, :__u_char

Expand Down Expand Up @@ -663,11 +643,11 @@ class H5AllocStatsT < ::FFI::Struct
H5AllocStatsT.ptr
], :herr_t

attach_function 'H5get_libversion', %i[
pointer
pointer
pointer
], :herr_t
# attach_function 'H5get_libversion', %i[
# pointer
# pointer
# pointer
# ], :herr_t

attach_function 'H5check_version', %i[
uint
Expand Down
Loading

0 comments on commit 8f9746d

Please sign in to comment.