From 2d4bbb5f7e986f9dc4038c1455ed659558a03865 Mon Sep 17 00:00:00 2001 From: Mauricio 'Pacha' Vargas Sepulveda Date: Wed, 1 Jan 2025 06:34:46 -0500 Subject: [PATCH] implement #432 --- cpp11test/DESCRIPTION | 2 +- inst/include/cpp11/as.hpp | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/cpp11test/DESCRIPTION b/cpp11test/DESCRIPTION index d1d05665..70c5649f 100644 --- a/cpp11test/DESCRIPTION +++ b/cpp11test/DESCRIPTION @@ -20,4 +20,4 @@ Suggests: xml2 LazyData: true Roxygen: list(markdown = TRUE) -RoxygenNote: 7.1.1 +RoxygenNote: 7.3.2 diff --git a/inst/include/cpp11/as.hpp b/inst/include/cpp11/as.hpp index 682f12b5..e0dd05fa 100644 --- a/inst/include/cpp11/as.hpp +++ b/inst/include/cpp11/as.hpp @@ -184,8 +184,14 @@ template enable_if_c_string as_cpp(SEXP from) { if (Rf_isString(from)) { if (Rf_xlength(from) == 1) { - // TODO: use vmaxget / vmaxset here? - return {unwind_protect([&] { return Rf_translateCharUTF8(STRING_ELT(from, 0)); })}; + void* vmax = vmaxget(); + + const char* result = + unwind_protect([&] { return Rf_translateCharUTF8(STRING_ELT(from, 0)); }); + + vmaxset(vmax); + + return {result}; } }