Skip to content

Commit

Permalink
Fixed memory bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
kondziu committed Jul 23, 2019
1 parent 70c6169 commit bd87b2a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
3 changes: 3 additions & 0 deletions ufoaltrep/src/altrep_ufo_files.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ int __load_from_file(int debug, uint64_t start, uint64_t end, char const *path,
}

size_t read_status = fread(target, element_size, end - start, file);
if (debug) {
Rprintf(" read status: %li\n", element_size);
}
if (read_status < end - start || read_status == 0) {
// Read failed.
fprintf(stderr, "Read failed. Read %li out of %li elements.\n", read_status, end - start);
Expand Down
16 changes: 8 additions & 8 deletions ufoaltrep/src/altrep_ufo_vectors.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,45 +234,45 @@ static void ufo_vector_element(SEXP x, R_xlen_t i, void *target) {

__load_from_file(altrep_ufo_debug_mode, i, i+1,
cfg->path, cfg->element_size, cfg->vector_size,
(char *) &target);
(char *) target);
}

static int ufo_integer_element(SEXP x, R_xlen_t i) {
if (R_altrep_data2(x) != R_NilValue)
return INTEGER_ELT(R_altrep_data2(x), i);
int val;
ufo_vector_element(x, i, &val);
return val;
int ans = 0x5c5c5c5c;
ufo_vector_element(x, i, &ans);
return ans;
}

static double ufo_numeric_element(SEXP x, R_xlen_t i) {
if (R_altrep_data2(x) != R_NilValue)
return REAL_ELT(R_altrep_data2(x), i);
double val;
double val = 0x5c5c5c5c;
ufo_vector_element(x, i, &val);
return val;
}

static Rbyte ufo_raw_element(SEXP x, R_xlen_t i) {
if (R_altrep_data2(x) != R_NilValue)
return RAW_ELT(R_altrep_data2(x), i);
Rbyte val;
Rbyte val = 0;
ufo_vector_element(x, i, &val);
return val;
}

static Rcomplex ufo_complex_element(SEXP x, R_xlen_t i) {
if (R_altrep_data2(x) != R_NilValue)
return COMPLEX_ELT(R_altrep_data2(x), i);
Rcomplex val;
Rcomplex val = {0x5c5c5c5c, 0x5c5c5c5c};
ufo_vector_element(x, i, &val);
return val;
}

static int ufo_logical_element(SEXP x, R_xlen_t i) {
if (R_altrep_data2(x) != R_NilValue)
return LOGICAL_ELT(R_altrep_data2(x), i);
Rboolean val;
Rboolean val = FALSE;
ufo_vector_element(x, i, &val);
return (int) val;
}
Expand Down

0 comments on commit bd87b2a

Please sign in to comment.