@@ -9,8 +9,8 @@
Loading
9 9
*/
10 10
11 11
/* .Call calls */
12 -
extern SEXP _fst_fstcomp(SEXP, SEXP, SEXP, SEXP, SEXP);
13 -
extern SEXP _fst_fstdecomp(SEXP, SEXP);
12 +
extern SEXP _fst_fstcomp(SEXP, SEXP, SEXP, SEXP);
13 +
extern SEXP _fst_fstdecomp(SEXP);
14 14
extern SEXP _fst_fsthasher(SEXP, SEXP, SEXP);
15 15
extern SEXP _fst_fstmetadata(SEXP);
16 16
extern SEXP _fst_fstretrieve(SEXP, SEXP, SEXP, SEXP);
@@ -24,8 +24,8 @@
Loading
24 24
25 25
26 26
static const R_CallMethodDef CallEntries[] = {
27 -
  {"_fst_fstcomp",            (DL_FUNC) &_fst_fstcomp,            5},
28 -
  {"_fst_fstdecomp",          (DL_FUNC) &_fst_fstdecomp,          2},
27 +
  {"_fst_fstcomp",            (DL_FUNC) &_fst_fstcomp,            4},
28 +
  {"_fst_fstdecomp",          (DL_FUNC) &_fst_fstdecomp,          1},
29 29
  {"_fst_fsthasher",          (DL_FUNC) &_fst_fsthasher,          3},
30 30
  {"_fst_fstmetadata",        (DL_FUNC) &_fst_fstmetadata,        1},
31 31
  {"_fst_fstretrieve",        (DL_FUNC) &_fst_fstretrieve,        4},

@@ -44,8 +44,7 @@
Loading
44 44
    stop("Parameter x is not set to a raw vector.")
45 45
  }
46 46
47 -
  container <- as.list(1)
48 -
  compressed_vec <- fstcomp(x, compressor, as.integer(compression), hash, container)
47 +
  compressed_vec <- fstcomp(x, compressor, as.integer(compression), hash)
49 48
50 49
  if (inherits(compressed_vec, "fst_error")) {
51 50
    stop(compressed_vec)
@@ -67,8 +66,7 @@
Loading
67 66
    stop("Parameter x should be a raw vector with compressed data.")
68 67
  }
69 68
70 -
  container <- as.list(1)
71 -
  decompressed_vec <- fstdecomp(x, container)
69 +
  decompressed_vec <- fstdecomp(x)
72 70
73 71
  if (inherits(decompressed_vec, "fst_error")) {
74 72
    stop(decompressed_vec)

@@ -33,8 +33,9 @@
Loading
33 33
#include <fst_type_factory.h>
34 34
#include <fst_error.h>
35 35
36 -
// Calculate the 64-bit xxHash of a raw vector using a default or
37 -
// custom hash seed
36 +
37 +
// Calculate the 64-bit xxHash of a raw vector using a default or custom hash seed
38 +
// Calculate the 64-bit xxHash of a raw vector using a default or custom hash seed
38 39
SEXP fsthasher(SEXP rawVec, SEXP seed, SEXP blockHash)
39 40
{
40 41
  FstHasher hasher;
@@ -72,7 +73,7 @@
Loading
72 73
73 74
  // use custom seed
74 75
  hashResult = hasher.HashBlobSeed((unsigned char*) RAW(rawVec), Rf_xlength(rawVec),
75 -
    *((unsigned int*) INTEGER(seed)), bHash);
76 +
                                   *((unsigned int*) INTEGER(seed)), bHash);
76 77
  std::memcpy(uintP, &hashResult, 8);
77 78
78 79
  UNPROTECT(1);
@@ -80,14 +81,19 @@
Loading
80 81
}
81 82
82 83
83 -
SEXP fstcomp(SEXP rawVec, SEXP compressor, SEXP compression, SEXP hash, SEXP r_container)
84 +
SEXP fstcomp(SEXP rawVec, SEXP compressor, SEXP compression, SEXP hash)
84 85
{
86 +
  // avoid using PROTECT statements in C++ classes (which generate rchk errors)
87 +
  // this PROTECTED container can be used to hold any R object safely
88 +
  SEXP r_container = PROTECT(Rf_allocVector(VECSXP, 1));
89 +
85 90
  std::unique_ptr<TypeFactory> typeFactoryP(new TypeFactory(r_container));
86 91
  COMPRESSION_ALGORITHM algo;
87 92
88 93
  if (!Rf_isLogical(hash))
89 94
  {
90 -
    Rf_error("Please specify true of false for parameter hash.");
95 +
    UNPROTECT(1);  // r_container
96 +
    Rcpp::stop("Please specify true of false for parameter hash.");
91 97
  }
92 98
93 99
  SEXP lz4_str  = PROTECT(Rf_mkChar("LZ4"));
@@ -101,8 +107,8 @@
Loading
101 107
    algo = COMPRESSION_ALGORITHM::ALGORITHM_ZSTD;
102 108
  } else
103 109
  {
104 -
    UNPROTECT(2);  // lz4_str and zstd_str
105 -
    return fst_error("Unknown compression algorithm selected");
110 +
    UNPROTECT(3);  // r_container, lz4_str and zstd_str
111 +
    Rcpp::stop("Unknown compression algorithm selected");
106 112
  }
107 113
108 114
  UNPROTECT(2);  // lz4_str and zstd_str
@@ -121,25 +127,32 @@
Loading
121 127
  }
122 128
  catch(const std::runtime_error& e)
123 129
  {
124 -
    return fst_error(e.what());
130 +
    UNPROTECT(1);  // r_container
131 +
    Rcpp::stop(e.what());
125 132
  }
126 133
  catch ( ... )
127 134
  {
128 -
    return fst_error("Unexpected error detected while compressing data.");
135 +
    UNPROTECT(1);  // r_container
136 +
    Rcpp::stop("Unexpected error detected while compressing data.");
129 137
  }
130 138
131 -
  SEXP resVec = ((BlobContainer*)(blobContainerP.get()))->RVector();
139 +
  UNPROTECT(1);  // r_container
132 140
133 -
  // IBlobContainer will be destructed upon exiting function
134 -
  return resVec;
141 +
  return VECTOR_ELT(r_container, 0);
135 142
}
136 143
137 144
138 -
SEXP fstdecomp(SEXP rawVec, SEXP r_container)
145 +
SEXP fstdecomp(SEXP rawVec)
139 146
{
140 -
  std::unique_ptr<ITypeFactory> typeFactoryP(new TypeFactory(r_container));
147 +
  // avoid using PROTECT statements in C++ classes (which generate rchk errors)
148 +
  // this PROTECTED container can be used to hold any R object safely
149 +
  SEXP r_container = PROTECT(Rf_allocVector(VECSXP, 1));
141 150
142 -
  FstCompressor fstcompressor((ITypeFactory*) typeFactoryP.get());
151 +
  // TODO: UBSAN warning generated here
152 +
  TypeFactory* type_factory = new TypeFactory(r_container);
153 +
  std::unique_ptr<TypeFactory> typeFactoryP(type_factory);
154 +
155 +
  FstCompressor fstcompressor((ITypeFactory*) type_factory);
143 156
144 157
  unsigned long long vecLength = Rf_xlength(rawVec);
145 158
  unsigned char* data = (unsigned char*) (RAW(rawVec));
@@ -152,15 +165,15 @@
Loading
152 165
  }
153 166
  catch(const std::runtime_error& e)
154 167
  {
155 -
    return fst_error(e.what());
168 +
    Rcpp::stop(e.what());
156 169
  }
157 170
  catch ( ... )
158 171
  {
159 -
    return fst_error("Error detected while decompressing data.");
172 +
    UNPROTECT(1);  // r_container
173 +
    Rcpp::stop("Error detected while decompressing data.");
160 174
  }
161 175
162 -
  SEXP resVec = resultContainerP->RVector();
176 +
  UNPROTECT(1);  // r_container
163 177
164 -
  return resVec;
178 +
  return VECTOR_ELT(r_container, 0);
165 179
}
166 -
Files Coverage
R 71.56%
src 57.59%
Project Totals (72 files) 57.98%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading