Skip to content

Commit

Permalink
Add H5PLget and use it to set the plugin path on load
Browse files Browse the repository at this point in the history
  • Loading branch information
grimbough committed Apr 12, 2024
1 parent f0410d3 commit 730d84f
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 2 deletions.
14 changes: 14 additions & 0 deletions R/H5PL.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,18 @@ H5PLprepend <- function(path) {
H5PLsize <- function() {
size <- .Call("_H5PLsize", PACKAGE = 'rhdf5')
return(size)
}

H5PLget <- function(index) {
path <- .Call("_H5PLget", as.integer(index-1), PACKAGE = "rhdf5")
return(path)
}

h5getPluginPaths <- function() {

n_paths <- H5PLsize()
paths <- vapply(seq_len(n_paths),
FUN = H5PLget,
FUN.VALUE = character(1))
return(paths)
}
6 changes: 6 additions & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@
.onLoad <- function(libname, pkgname) {
h5constants <<- H5loadConstants()
h5errorHandling()

if(requireNamespace('rhdf5filters')) {
plugin_path <- rhdf5filters::hdf5_plugin_path()
H5PLprepend(plugin_path)
}

}
21 changes: 19 additions & 2 deletions src/H5PL.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,38 @@ SEXP _H5PLprepend( SEXP _search_path ) {
res = H5PLprepend(search_path);

if(res < 0) {
error("Unable to prepend value to plugin search path");
error("Unable to prepend value to plugin search path\n");
}

SEXP Rval = ScalarLogical(1);
return Rval;
}

/* ssize_t H5PLget ( unsigned int index, char *path_buf, size_t buf_size ) */
SEXP _H5PLget( SEXP index ) {

int i = asInteger(index);
char buf[512];
SEXP Rval;

if(H5PLget(i, buf, 512) < 0) {
error("Unable to read plugin path position\n");
}

PROTECT(Rval = mkString(buf));
UNPROTECT(1);
return Rval;
}


/* herr_t H5PLsize ( unsigned int * num_paths ) */
SEXP _H5PLsize() {

SEXP Rval;
unsigned int nvals = 0;

if(H5PLsize( &nvals ) < 0 ) {
error("Unable to prepend value to plugin search path");
error("Unable to determine size of the plugin path\n");
}

if(nvals <= INT32_MAX) {
Expand Down
1 change: 1 addition & 0 deletions src/H5PL.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@

SEXP _H5PLprepend( SEXP _search_path );
SEXP _H5PLsize();
SEXP _H5PLget( SEXP index );

#endif
1 change: 1 addition & 0 deletions src/wrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ static R_CallMethodDef libraryRCalls[] = {
{"_h5getEnumValues", (DL_FUNC) &_h5getEnumValues, 1},
{"_H5PLprepend", (DL_FUNC) &_H5PLprepend, 1},
{"_H5PLsize", (DL_FUNC) &_H5PLsize, 0},
{"_H5PLget", (DL_FUNC) &_H5PLget, 1},
#ifdef _H5P_filters
{"_H5Pset_lzf", (DL_FUNC) &_H5Pset_lzf, 2},
{"_H5Pset_bzip2", (DL_FUNC) &_H5Pset_bzip2, 2},
Expand Down

0 comments on commit 730d84f

Please sign in to comment.