Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add fix for issue with empty attributes #211

Closed

Conversation

rcannood
Copy link

@rcannood rcannood commented Dec 17, 2023

This PR adds a fix for the issue described in #208 and tested in #209.

I made changes to several instances XLENGTH(R_buf) == 0 was being used to check R_buf should be cast to a void pointer.

  if(XLENGTH(R_buf) == 0) {
    buf = NULL;
  }
  else {
    buf = (void *) VOIDPTR(R_buf);
  }

However, since the implementation of VOIDPTR is:

void* VOIDPTR(SEXP x) {

  switch(TYPEOF(x)) {
  case REALSXP:
    return((void *) REAL(x));
  case INTSXP:
    return((void *) INTEGER(x));
  case LGLSXP:
    return((void *) LOGICAL(x));
  case CPLXSXP:
    return((void *) COMPLEX(x));
  case RAWSXP:
    return((void *) RAW(x));
  case STRSXP:
    return((void *) STRING_PTR(x));
  case VECSXP:
    return((void *) VECTOR_PTR(x));
  default:
    error("Type cannot be converted to voidptr\n");
  }
}

I figured it may perhaps make more sense to check whether TYPEOF(R_buf) == NILSXP instead. I replaced XLENGTH(.) == 0 with TYPEOF(R_buf) == NILSXP in the places where the unit tests in #209 caused errors. Specifically:


If I undo my changes in R_H5Awrite(), I get:

Error (test-h5a.R:226:5): Creating attributes of different types of length 0
Error in `h5attr$write(robj)`: HDF5-API Errors:
    error #000: ../../src/H5A.c in H5Awrite(): line 657: buf parameter can't be NULL
        class: HDF5
        major: Invalid arguments to routine
        minor: Bad value

This may be related to mojaveazure/seurat-disk#15 (comment)


If I undo my changes in R_H5Aread(), I get:

Error (test-h5a.R:226:5): Creating attributes of different types of length 0
Error in `h5attr$read()`: HDF5-API Errors:
    error #000: ../../src/H5A.c in H5Aread(): line 702: buf parameter can't be NULL
        class: HDF5
        major: Invalid arguments to routine
        minor: Bad value

And if I undo my changes in R_H5Dvlen_reclaim(), I get:

Error (test-h5a.R:247:5): Creating attributes of different types of length 0
Error in `h5attr$read()`: HDF5-API Errors:
    error #000: ../../src/H5Ddeprec.c in H5Dvlen_reclaim(): line 323: invalid argument
        class: HDF5
        major: Invalid arguments to routine
        minor: Bad value

This may be related to #118, PMBio/MuDataSeurat#14 and JiekaiLab/scDIOR#7


@hhoeflin I'd appreciate your feedback on this ☺️

@hhoeflin
Copy link
Owner

hhoeflin commented Jan 7, 2024

Closing as I implemented the fix in #214. Thanks for providing the code.

@hhoeflin hhoeflin closed this Jan 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants