From eb637d5a950e15e83ca07aab2884a3a4c3e7758d Mon Sep 17 00:00:00 2001 From: Jeroen Ooms Date: Tue, 29 Jan 2019 17:27:30 -0800 Subject: [PATCH 01/38] Port to new v8 api --- DESCRIPTION | 2 +- R/RcppExports.R | 16 +- configure | 26 +- src/Makevars.in | 3 +- src/RcppExports.cpp | 53 +-- src/V8.cpp | 254 ------------- src/V8_types.h | 1 + src/bindings.cpp | 216 ++++++++++++ src/v8_json.h | 51 --- src/v8_typed_array.cpp | 785 ----------------------------------------- src/v8_typed_array.h | 35 -- 11 files changed, 240 insertions(+), 1202 deletions(-) delete mode 100644 src/V8.cpp create mode 100644 src/bindings.cpp delete mode 100644 src/v8_json.h delete mode 100644 src/v8_typed_array.cpp delete mode 100644 src/v8_typed_array.h diff --git a/DESCRIPTION b/DESCRIPTION index 41a8e8f..e05ac23 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -27,4 +27,4 @@ Suggests: testthat, knitr, rmarkdown -RoxygenNote: 6.0.1.9000 +RoxygenNote: 6.1.1 diff --git a/R/RcppExports.R b/R/RcppExports.R index 1815e06..08cc30f 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -1,12 +1,8 @@ # Generated by using Rcpp::compileAttributes() -> do not edit by hand # Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 -make_context <- function(set_console) { - .Call('_V8_make_context', PACKAGE = 'V8', set_console) -} - -context_enable_typed_arrays <- function(ctx) { - .Call('_V8_context_enable_typed_arrays', PACKAGE = 'V8', ctx) +R_init_all <- function() { + invisible(.Call('_V8_R_init_all', PACKAGE = 'V8')) } version <- function() { @@ -25,11 +21,7 @@ context_null <- function(ctx) { .Call('_V8_context_null', PACKAGE = 'V8', ctx) } -context_assign_bin <- function(name, data, ctx) { - .Call('_V8_context_assign_bin', PACKAGE = 'V8', name, data, ctx) -} - -context_get_bin <- function(name, ctx) { - .Call('_V8_context_get_bin', PACKAGE = 'V8', name, ctx) +make_context <- function(set_console) { + .Call('_V8_make_context', PACKAGE = 'V8', set_console) } diff --git a/configure b/configure index 64897bc..274d5c2 100755 --- a/configure +++ b/configure @@ -1,7 +1,6 @@ #!/bin/bash # Anticonf (tm) script by Jeroen Ooms (2017) -# V8 requires libv8 version 3.14 or 3.15. Newer versions are not supported. -# A suitable version is available here: https://github.com/v8-314/v8 +# V8 requires either libv8 6.8 LTS OR legacy libv8 (3.14 / 3.15). # This script will check for the required cflags and ldflags. # If your libv8 is installed in a custom location you need to set # INCLUDE_DIR and LIB_DIR manually via e.g: @@ -10,11 +9,11 @@ PKG_DEB_NAME="libv8-3.14-dev (formerly: libv8-dev)" PKG_RPM_NAME="v8-314-devel (formerly: v8-devel)" PKG_CSW_NAME="libv8_dev" -PKG_BREW_NAME="v8@3.15" +PKG_BREW_NAME="v8" PKG_TEST_HEADER="" -PKG_LIBS="-lv8" +PKG_LIBS="-lv8 -lv8_libplatform" PKG_LIBS_STATIC="-lv8_{base,snapshot} -lpreparser_lib" -PKG_CFLAGS="-I/usr/include/v8-3.14" +PKG_CFLAGS="-I/usr/include/nodejs/deps" # Check for custom locations if [ "$INCLUDE_DIR" ] || [ "$LIB_DIR" ]; then @@ -56,23 +55,6 @@ if [ $? -ne 0 ]; then exit 1; fi -# Test for libv8 version -${CXXCPP} ${CPPFLAGS} ${PKG_CFLAGS} ${CXXFLAGS} tools/version.cpp >/dev/null 2>&1 -if [ $? -ne 0 ]; then - echo "------------------------- ANTICONF ERROR ---------------------------" - echo "Oh dear. The wrong version of libv8 is installed on the system." - echo "This package needs the 3.14 / 3.15 branch of libv8." - echo "On Fedora try this:" - echo " sudo yum remove v8-devel" - echo " sudo yum install v8-314-devel" - echo "On MacOS Homebrew you need:" - echo " brew remove v8" - echo " brew install v8@3.15" - echo "To use a custom libv8 build set INCLUDE_DIR and LIB_DIR manually via:" - echo "R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'" - echo "--------------------------------------------------------------------" - exit 1; -fi # Write to Makevars sed -e "s|@cflags@|$PKG_CFLAGS|" -e "s|@libs@|$PKG_LIBS|" src/Makevars.in > src/Makevars diff --git a/src/Makevars.in b/src/Makevars.in index 00ca9d7..4c1ee12 100644 --- a/src/Makevars.in +++ b/src/Makevars.in @@ -1,6 +1,7 @@ -PKG_CXXFLAGS=-DV8_DISABLE_DEPRECATIONS $(C_VISIBILITY) +#PKG_CXXFLAGS=-DV8_DISABLE_DEPRECATIONS $(C_VISIBILITY) PKG_CPPFLAGS=@cflags@ PKG_LIBS=@libs@ +CXX_STD=CXX11 all: clean diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index 6113e18..1ba7665 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -6,26 +6,13 @@ using namespace Rcpp; -// make_context -ctxptr make_context(bool set_console); -RcppExport SEXP _V8_make_context(SEXP set_consoleSEXP) { +// R_init_all +void R_init_all(); +RcppExport SEXP _V8_R_init_all() { BEGIN_RCPP - Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< bool >::type set_console(set_consoleSEXP); - rcpp_result_gen = Rcpp::wrap(make_context(set_console)); - return rcpp_result_gen; -END_RCPP -} -// context_enable_typed_arrays -bool context_enable_typed_arrays(Rcpp::XPtr< v8::Persistent > ctx); -RcppExport SEXP _V8_context_enable_typed_arrays(SEXP ctxSEXP) { -BEGIN_RCPP - Rcpp::RObject rcpp_result_gen; - Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< Rcpp::XPtr< v8::Persistent > >::type ctx(ctxSEXP); - rcpp_result_gen = Rcpp::wrap(context_enable_typed_arrays(ctx)); - return rcpp_result_gen; + R_init_all(); + return R_NilValue; END_RCPP } // version @@ -73,41 +60,25 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } -// context_assign_bin -bool context_assign_bin(std::string name, Rcpp::RawVector data, Rcpp::XPtr< v8::Persistent > ctx); -RcppExport SEXP _V8_context_assign_bin(SEXP nameSEXP, SEXP dataSEXP, SEXP ctxSEXP) { -BEGIN_RCPP - Rcpp::RObject rcpp_result_gen; - Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< std::string >::type name(nameSEXP); - Rcpp::traits::input_parameter< Rcpp::RawVector >::type data(dataSEXP); - Rcpp::traits::input_parameter< Rcpp::XPtr< v8::Persistent > >::type ctx(ctxSEXP); - rcpp_result_gen = Rcpp::wrap(context_assign_bin(name, data, ctx)); - return rcpp_result_gen; -END_RCPP -} -// context_get_bin -Rcpp::RawVector context_get_bin(std::string name, Rcpp::XPtr< v8::Persistent > ctx); -RcppExport SEXP _V8_context_get_bin(SEXP nameSEXP, SEXP ctxSEXP) { +// make_context +ctxptr make_context(bool set_console); +RcppExport SEXP _V8_make_context(SEXP set_consoleSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< std::string >::type name(nameSEXP); - Rcpp::traits::input_parameter< Rcpp::XPtr< v8::Persistent > >::type ctx(ctxSEXP); - rcpp_result_gen = Rcpp::wrap(context_get_bin(name, ctx)); + Rcpp::traits::input_parameter< bool >::type set_console(set_consoleSEXP); + rcpp_result_gen = Rcpp::wrap(make_context(set_console)); return rcpp_result_gen; END_RCPP } static const R_CallMethodDef CallEntries[] = { - {"_V8_make_context", (DL_FUNC) &_V8_make_context, 1}, - {"_V8_context_enable_typed_arrays", (DL_FUNC) &_V8_context_enable_typed_arrays, 1}, + {"_V8_R_init_all", (DL_FUNC) &_V8_R_init_all, 0}, {"_V8_version", (DL_FUNC) &_V8_version, 0}, {"_V8_context_eval", (DL_FUNC) &_V8_context_eval, 2}, {"_V8_context_validate", (DL_FUNC) &_V8_context_validate, 2}, {"_V8_context_null", (DL_FUNC) &_V8_context_null, 1}, - {"_V8_context_assign_bin", (DL_FUNC) &_V8_context_assign_bin, 3}, - {"_V8_context_get_bin", (DL_FUNC) &_V8_context_get_bin, 2}, + {"_V8_make_context", (DL_FUNC) &_V8_make_context, 1}, {NULL, NULL, 0} }; diff --git a/src/V8.cpp b/src/V8.cpp deleted file mode 100644 index 5f04fab..0000000 --- a/src/V8.cpp +++ /dev/null @@ -1,254 +0,0 @@ -/* - R bindings to V8. Copyright 2014, Jeroen Ooms. - - Notes: - - Implementation of Typed Arrays taken from node v0.6.21 - - V8 source parsing: - - http://stackoverflow.com/questions/16613828/how-to-convert-stdstring-to-v8s-localstring - - Xptr examples: - - https://github.com/RcppCore/Rcpp/blob/master/inst/unitTests/cpp/XPtr.cpp - - http://romainfrancois.blog.free.fr/index.php?post/2010/01/08/External-pointers-with-Rcpp -*/ - -#include -#include -#include "v8_typed_array.h" -#include "v8_json.h" -using namespace v8; - -void ctx_finalizer( Persistent* context ){ - if(context) - context->Dispose(); - delete context; -} - -typedef Rcpp::XPtr, Rcpp::PreserveStorage, ctx_finalizer> ctxptr; - -/* Helper fun that compiles JavaScript source code */ -Handle