From e7499964d9a3b156882b31fd5e4254c95c1f84c8 Mon Sep 17 00:00:00 2001 From: djvanderlaan Date: Wed, 23 May 2018 18:03:04 +0200 Subject: [PATCH] Fix UBSAN warning in ldat --- DESCRIPTION | 4 ++-- inst/include/tempfile.h | 2 +- src/as_lvec.cpp | 1 - src/as_rvec.cpp | 2 -- src/assign.cpp | 1 - src/assign_range.cpp | 1 - src/clone.cpp | 1 - src/construct.cpp | 1 - src/get_type.cpp | 1 - src/indexing.cpp | 1 - src/indexing_range.cpp | 3 +-- src/lvec-init.cpp | 6 ++---- src/order.cpp | 1 - src/r_export.h | 3 +-- src/size.cpp | 1 - src/sort.cpp | 1 - src/strlen.cpp | 1 - src/tempfile.h | 8 -------- src/{tempfile.cpp => tempfile_impl.cpp} | 5 ++--- src/tempfile_impl.h | 8 ++++++++ 20 files changed, 17 insertions(+), 35 deletions(-) delete mode 100644 src/tempfile.h rename src/{tempfile.cpp => tempfile_impl.cpp} (77%) create mode 100644 src/tempfile_impl.h diff --git a/DESCRIPTION b/DESCRIPTION index 7baa4a4..dd215ee 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: lvec Type: Package Title: Out of Memory Vectors -Version: 0.2.1 -Date: 2018-05-15 +Version: 0.2.2 +Date: 2018-05-23 Author: Jan van der Laan Maintainer: Jan van der Laan Description: Core functionality for working with vectors (numeric, integer, diff --git a/inst/include/tempfile.h b/inst/include/tempfile.h index 5160791..afe3866 100644 --- a/inst/include/tempfile.h +++ b/inst/include/tempfile.h @@ -9,7 +9,7 @@ inline std::string tempfile() { static std::string(*fun)() = NULL; if (fun == NULL) - fun = (std::string(*)()) R_GetCCallable("lvec", "tempfile"); + fun = (std::string(*)()) R_GetCCallable("lvec", "tempfile_impl"); return fun(); } diff --git a/src/as_lvec.cpp b/src/as_lvec.cpp index 053baa8..c135b77 100644 --- a/src/as_lvec.cpp +++ b/src/as_lvec.cpp @@ -1,4 +1,3 @@ -#include "../inst/include/lvec.h" #include "r_export.h" #include diff --git a/src/as_rvec.cpp b/src/as_rvec.cpp index 1fb0ad4..19cbb2c 100644 --- a/src/as_rvec.cpp +++ b/src/as_rvec.cpp @@ -1,5 +1,3 @@ -#include "../inst/include/lvec.h" - #include "r_export.h" #include diff --git a/src/assign.cpp b/src/assign.cpp index 38774be..2f5e8de 100644 --- a/src/assign.cpp +++ b/src/assign.cpp @@ -1,4 +1,3 @@ -#include "../inst/include/lvec.h" #include "r_export.h" class assign_visitor : public ldat::lvec_visitor { diff --git a/src/assign_range.cpp b/src/assign_range.cpp index 4bbe5ef..2e5209d 100644 --- a/src/assign_range.cpp +++ b/src/assign_range.cpp @@ -1,4 +1,3 @@ -#include "../inst/include/lvec.h" #include "r_export.h" class assign_range_visitor : public ldat::lvec_visitor { diff --git a/src/clone.cpp b/src/clone.cpp index 3025248..ac5f398 100644 --- a/src/clone.cpp +++ b/src/clone.cpp @@ -1,4 +1,3 @@ -#include "../inst/include/lvec.h" #include "r_export.h" RcppExport SEXP lclone(SEXP rv) { diff --git a/src/construct.cpp b/src/construct.cpp index dbba49d..a19a9ff 100644 --- a/src/construct.cpp +++ b/src/construct.cpp @@ -1,4 +1,3 @@ -#include "../inst/include/lvec.h" #include "r_export.h" RcppExport SEXP new_lvec(SEXP rsize, SEXP rtype, SEXP rstrlen) { diff --git a/src/get_type.cpp b/src/get_type.cpp index 44a2139..b49d424 100644 --- a/src/get_type.cpp +++ b/src/get_type.cpp @@ -1,4 +1,3 @@ -#include "../inst/include/lvec.h" #include "r_export.h" class type_visitor : public ldat::lvec_visitor { diff --git a/src/indexing.cpp b/src/indexing.cpp index 48e48e0..f51d082 100644 --- a/src/indexing.cpp +++ b/src/indexing.cpp @@ -1,4 +1,3 @@ -#include "../inst/include/lvec.h" #include "r_export.h" #include diff --git a/src/indexing_range.cpp b/src/indexing_range.cpp index 4c9f5c7..693acd0 100644 --- a/src/indexing_range.cpp +++ b/src/indexing_range.cpp @@ -1,6 +1,5 @@ -#include "../inst/include/lvec.h" -#include #include "r_export.h" +#include class range_indexing_visitor : public ldat::lvec_visitor { public: diff --git a/src/lvec-init.cpp b/src/lvec-init.cpp index da06996..f715cc7 100644 --- a/src/lvec-init.cpp +++ b/src/lvec-init.cpp @@ -1,10 +1,8 @@ -#include "tempfile.h" -#include "../inst/include/lvec.h" #include "r_export.h" +#include "tempfile_impl.h" #include - #define CALLDEF(name, n) {#name, (DL_FUNC) &name, n} extern "C" { @@ -29,7 +27,7 @@ extern "C" { }; void R_init_lvec(DllInfo *info) { - R_RegisterCCallable("lvec", "tempfile", (DL_FUNC) &tempfile); + R_RegisterCCallable("lvec", "tempfile_impl", (DL_FUNC) &tempfile_impl); R_registerRoutines(info, NULL, r_calldef, NULL, NULL); R_useDynamicSymbols(info, static_cast(FALSE)); } diff --git a/src/order.cpp b/src/order.cpp index 53fb133..fc32984 100644 --- a/src/order.cpp +++ b/src/order.cpp @@ -1,4 +1,3 @@ -#include "../inst/include/lvec.h" #include "r_export.h" #include diff --git a/src/r_export.h b/src/r_export.h index e1bf484..c75faec 100644 --- a/src/r_export.h +++ b/src/r_export.h @@ -1,5 +1,4 @@ -#include "../inst/include/cppr.h" -#include "../inst/include/lvec.h" +#include "../inst/include/lvec_interface.h" extern "C" { SEXP as_lvec(SEXP rv); diff --git a/src/size.cpp b/src/size.cpp index 91ce2d8..54034e3 100644 --- a/src/size.cpp +++ b/src/size.cpp @@ -1,4 +1,3 @@ -#include "../inst/include/lvec.h" #include "r_export.h" RcppExport SEXP get_size(SEXP rv) { diff --git a/src/sort.cpp b/src/sort.cpp index 18d3677..81c5bd1 100644 --- a/src/sort.cpp +++ b/src/sort.cpp @@ -1,4 +1,3 @@ -#include "../inst/include/lvec.h" #include "r_export.h" #include diff --git a/src/strlen.cpp b/src/strlen.cpp index 21dac64..875be93 100644 --- a/src/strlen.cpp +++ b/src/strlen.cpp @@ -1,4 +1,3 @@ -#include "../inst/include/lvec.h" #include "r_export.h" class strlen_visitor : public ldat::lvec_visitor { diff --git a/src/tempfile.h b/src/tempfile.h deleted file mode 100644 index 03b7426..0000000 --- a/src/tempfile.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef tempfile_h -#define tempfile_h - -#include - -std::string tempfile(); - -#endif diff --git a/src/tempfile.cpp b/src/tempfile_impl.cpp similarity index 77% rename from src/tempfile.cpp rename to src/tempfile_impl.cpp index 37b5dae..27d566e 100644 --- a/src/tempfile.cpp +++ b/src/tempfile_impl.cpp @@ -1,10 +1,9 @@ -#include "tempfile.h" -#include "../inst/include/cppr.h" #include "r_export.h" +#include "tempfile_impl.h" std::string tempdir = "."; -std::string tempfile() { +std::string tempfile_impl() { char* p = R_tmpnam("lvec", tempdir.c_str()); std::string res{p}; free(p); diff --git a/src/tempfile_impl.h b/src/tempfile_impl.h new file mode 100644 index 0000000..f400dcf --- /dev/null +++ b/src/tempfile_impl.h @@ -0,0 +1,8 @@ +#ifndef tempfile_impl_h +#define tempfile_impl_h + +#include + +std::string tempfile_impl(); + +#endif