Skip to content

Commit 8f9746d

Browse files
committed
Allow switching between hdf5 versions
1 parent 93e17d6 commit 8f9746d

File tree

7 files changed

+10253
-45
lines changed

7 files changed

+10253
-45
lines changed

lib/hdf5.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ def search_hdf5lib
2424
end
2525
return lib_path if File.exist?(lib_path)
2626

27-
warn "htslib shared library '#{name}' not found."
27+
warn "hdf5 shared library '#{name}' not found."
2828
end
2929
end
3030

3131
self.lib_path = search_hdf5lib
3232
end
3333

34-
require_relative 'hdf5/ffi3'
34+
require_relative 'hdf5/ffi'
3535

3636
require_relative 'hdf5/file'
3737
require_relative 'hdf5/group'

lib/hdf5/ffi.rb

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
module HDF5
2+
module FFI
3+
extend ::FFI::Library
4+
5+
begin
6+
ffi_lib HDF5.lib_path
7+
rescue LoadError => e
8+
raise LoadError, "#{e}\nCould not find #{HDF5.lib_path}"
9+
end
10+
11+
# @!macro attach_function
12+
# @!scope class
13+
# @!method $1(${2--2})
14+
# @return [${-1}] the return value of $0
15+
def self.attach_function(*)
16+
super
17+
rescue ::FFI::NotFoundError => e
18+
warn e.message # if $VERBOSE
19+
end
20+
21+
def self.attach_variable(*)
22+
super
23+
rescue ::FFI::NotFoundError => e
24+
warn e.message # if $VERBOSE
25+
end
26+
27+
attach_function 'H5get_libversion', %i[
28+
pointer
29+
pointer
30+
pointer
31+
], :int
32+
33+
major_ptr = ::FFI::MemoryPointer.new(:int)
34+
minor_ptr = ::FFI::MemoryPointer.new(:int)
35+
release_ptr = ::FFI::MemoryPointer.new(:int)
36+
HDF5::FFI.H5get_libversion(major_ptr, minor_ptr, release_ptr)
37+
38+
raise 'HDF5 major version mismatch' if major_ptr.read_int != 1
39+
40+
case minor_ptr.read_int
41+
when 10
42+
require_relative 'ffi_10'
43+
when 14..Float::INFINITY
44+
require_relative 'ffi_14'
45+
end
46+
end
47+
end

lib/hdf5/ffi3.rb renamed to lib/hdf5/ffi_10.rb

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,8 @@
1+
# require_relative 'ffi'
2+
13
module HDF5
24
module FFI
3-
extend ::FFI::Library
4-
5-
begin
6-
ffi_lib HDF5.lib_path
7-
rescue LoadError => e
8-
raise LoadError, "#{e}\nCould not find #{HDF5.lib_path}"
9-
end
10-
11-
# @!macro attach_function
12-
# @!scope class
13-
# @!method $1(${2--2})
14-
# @return [${-1}] the return value of $0
15-
def self.attach_function(*)
16-
super
17-
rescue ::FFI::NotFoundError => e
18-
warn e.message # if $VERBOSE
19-
end
20-
21-
def self.attach_variable(*)
22-
super
23-
rescue ::FFI::NotFoundError => e
24-
warn e.message # if $VERBOSE
25-
end
5+
MiV = 10
266

277
typedef :uchar, :__u_char
288

@@ -663,11 +643,11 @@ class H5AllocStatsT < ::FFI::Struct
663643
H5AllocStatsT.ptr
664644
], :herr_t
665645

666-
attach_function 'H5get_libversion', %i[
667-
pointer
668-
pointer
669-
pointer
670-
], :herr_t
646+
# attach_function 'H5get_libversion', %i[
647+
# pointer
648+
# pointer
649+
# pointer
650+
# ], :herr_t
671651

672652
attach_function 'H5check_version', %i[
673653
uint

0 commit comments

Comments
 (0)