<commit_before>------------------------------------------------------------------------------
-- HDF5 for Lua.
-- Copyright © 2013 <NAME>.
-- For conditions of distribution and use, see copyright notice in LICENSE.
------------------------------------------------------------------------------

local C   = require("hdf5.C")
local ffi = require("ffi")

-- Cache library functions.
local min = math.min

local _M = {}

-- C types.
local H5D_fill_value_t_1 = ffi.typeof("H5D_fill_value_t[1]")
local H5E_walk_t         = ffi.typeof("H5E_walk_t")
local H5F_libver_t_1     = ffi.typeof("H5F_libver_t[1]")
local H5O_info_t         = ffi.typeof("H5O_info_t")
local H5O_info_t_1       = ffi.typeof("H5O_info_t[1]")
local H5O_type_t_1       = ffi.typeof("H5O_type_t[1]")
local char_n             = ffi.typeof("char[?]")
local hsize_t_n          = ffi.typeof("hsize_t[?]")
local hssize_t_n         = ffi.typeof("hssize_t[?]")
local unsigned_1         = ffi.typeof("unsigned[1]")

-- Object identifiers.
local attribute_id = ffi.typeof("struct { hid_t id; }")
local dataset_id   = ffi.typeof("struct { hid_t id; }")
local dataspace_id = ffi.typeof("struct { hid_t id; }")
local datatype_id  = ffi.typeof("struct { hid_t id; }")
local file_id      = ffi.typeof("struct { hid_t id; }")
local group_id     = ffi.typeof("struct { hid_t id; }")
local plist_id     = ffi.typeof("struct { hid_t id; }")

-- Object methods.
local attribute = {}
local dataset   = {}
local dataspace = {}
local datatype  = {}
local file      = {}
local group     = {}
local location  = {}
local object    = {}
local plist     = {}

-- Compare header and library version.
assert(C.H5check_version(C.H5_VERS_MAJOR, C.H5_VERS_MINOR, C.H5_VERS_RELEASE) == 0)
-- Initialise HDF5 constants.
assert(C.H5open() == 0)

-- Returns error message on top of error stack.
local function get_error()
  local desc
  local cb = H5E_walk_t(function(n, err_desc)
    if n == 0 then desc = ffi.string(err_desc[0].desc) end
    return 0
  end)
  assert(C.H5Ewalk(C.H5E_DEFAULT, C.H5E_WALK_DOWNWARD, cb, nil) == 0)
  cb:free()
  return desc
end<commit_msg>Allow version mismatch for backward compatibility<commit_after>------------------------------------------------------------------------------
-- HDF5 for Lua.
-- Copyright © 2013 <NAME>.
-- For conditions of distribution and use, see copyright notice in LICENSE.
------------------------------------------------------------------------------

local C   = require("hdf5.C")
local ffi = require("ffi")

-- Cache library functions.
local min = math.min

local _M = {}

-- C types.
local H5D_fill_value_t_1 = ffi.typeof("H5D_fill_value_t[1]")
local H5E_walk_t         = ffi.typeof("H5E_walk_t")
local H5F_libver_t_1     = ffi.typeof("H5F_libver_t[1]")
local H5O_info_t         = ffi.typeof("H5O_info_t")
local H5O_info_t_1       = ffi.typeof("H5O_info_t[1]")
local H5O_type_t_1       = ffi.typeof("H5O_type_t[1]")
local char_n             = ffi.typeof("char[?]")
local hsize_t_n          = ffi.typeof("hsize_t[?]")
local hssize_t_n         = ffi.typeof("hssize_t[?]")
local unsigned_1         = ffi.typeof("unsigned[1]")

-- Object identifiers.
local attribute_id = ffi.typeof("struct { hid_t id; }")
local dataset_id   = ffi.typeof("struct { hid_t id; }")
local dataspace_id = ffi.typeof("struct { hid_t id; }")
local datatype_id  = ffi.typeof("struct { hid_t id; }")
local file_id      = ffi.typeof("struct { hid_t id; }")
local group_id     = ffi.typeof("struct { hid_t id; }")
local plist_id     = ffi.typeof("struct { hid_t id; }")

-- Object methods.
local attribute = {}
local dataset   = {}
local dataspace = {}
local datatype  = {}
local file      = {}
local group     = {}
local location  = {}
local object    = {}
local plist     = {}

-- Initialise HDF5 constants.
assert(C.H5open() == 0)

-- Returns error message on top of error stack.
local function get_error()
  local desc
  local cb = H5E_walk_t(function(n, err_desc)
    if n == 0 then desc = ffi.string(err_desc[0].desc) end
    return 0
  end)
  assert(C.H5Ewalk(C.H5E_DEFAULT, C.H5E_WALK_DOWNWARD, cb, nil) == 0)
  cb:free()
  return desc
end
{'fraction_non_alphanumeric': 0.20525931336742148, 'fraction_numerical': 0.020209398587776966, 'mean_word_length': 2.5051194539249146, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6762049', 'n_tokens_mistral': 1505, 'n_tokens_neox': 1469, 'n_words': 339}