Skip to content

Commit

Permalink
Various clang fixes for spooky_serialize
Browse files Browse the repository at this point in the history
  • Loading branch information
eddelbuettel committed May 16, 2024
1 parent 20cf1ba commit 52667c1
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/spooky_serialize.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright (C) 2024 Dirk Eddelbuettel
// Copyright (C) 2019 Kendon Bell
// Copyright (C) 2014 Gabe Becker
//
Expand Down Expand Up @@ -53,18 +54,18 @@ static void OutBytesSpooky(R_outpstream_t stream, void *buf, int length) {


static void InitSpookyPStream(R_outpstream_t stream, SpookyHash *spooky,
R_pstream_format_t type, int version,
SEXP (*phook)(SEXP, SEXP), SEXP pdata) {
R_pstream_format_t type, int version,
SEXP (*phook)(SEXP, SEXP), SEXP pdata) {
R_InitOutPStream(stream, (R_pstream_data_t) spooky, type, version,
OutCharSpooky, OutBytesSpooky, phook, pdata);
OutCharSpooky, OutBytesSpooky, phook, pdata);
}


//From serialize.c in R sources
/* ought to quote the argument, but it should only be an ENVSXP or STRSXP */
static SEXP CallHook(SEXP x, SEXP fun) { // #nocov start
SEXP val, call;
PROTECT(call = LCONS(fun, LCONS(x, R_NilValue)));
PROTECT(call = Rf_lcons(fun, Rf_lcons(x, R_NilValue)));
val = Rf_eval(call, R_GlobalEnv);
UNPROTECT(1);
return val;
Expand All @@ -73,17 +74,17 @@ static SEXP CallHook(SEXP x, SEXP fun) { // #nocov start

extern "C" SEXP spookydigest_impl(SEXP s, SEXP to_skip_r, SEXP seed1_r, SEXP seed2_r, SEXP version_r, SEXP fun) {
SpookyHash spooky;
double seed1_d = NUMERIC_VALUE(seed1_r);
double seed2_d = NUMERIC_VALUE(seed2_r);
uint64 seed1 = seed1_d;
uint64 seed2 = seed2_d;
double seed1_d = Rf_asReal(seed1_r);
double seed2_d = Rf_asReal(seed2_r);
uint64_t seed1 = static_cast<uint64_t>(seed1_d);
uint64_t seed2 = static_cast<uint64_t>(seed2_d);

uint8 to_skip = INTEGER_VALUE(to_skip_r);
uint8_t to_skip = static_cast<uint8_t>(Rf_asInteger(to_skip_r));
spooky.Init(seed1, seed2, to_skip);
R_outpstream_st spooky_stream;
R_pstream_format_t type = R_pstream_binary_format;
SEXP (*hook)(SEXP, SEXP);
int version = INTEGER_VALUE(version_r);
int version = Rf_asInteger(version_r);
hook = fun != R_NilValue ? CallHook : NULL;
InitSpookyPStream(&spooky_stream, &spooky, type, version, hook, fun);
R_Serialize(s, &spooky_stream);
Expand Down

0 comments on commit 52667c1

Please sign in to comment.