Skip to content

Commit 72d2f37

Browse files
authored
Merge pull request #1 from pachadotdev/issue460
use a lamba to unwind protect around the loop
2 parents 05c888b + 9851423 commit 72d2f37

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

inst/include/cpp11/as.hpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -287,18 +287,14 @@ template <typename Container, typename AsCstring>
287287
SEXP as_sexp_strings(const Container& from, AsCstring&& c_str) {
288288
R_xlen_t size = from.size();
289289

290-
SEXP data;
291-
try {
292-
data = PROTECT(safe[Rf_allocVector](STRSXP, size));
290+
SEXP data = PROTECT(safe[Rf_allocVector](STRSXP, size));
293291

292+
unwind_protect([&] {
294293
auto it = from.begin();
295294
for (R_xlen_t i = 0; i < size; ++i, ++it) {
296-
SET_STRING_ELT(data, i, safe[Rf_mkCharCE](c_str(*it), CE_UTF8));
295+
SET_STRING_ELT(data, i, Rf_mkCharCE(c_str(*it), CE_UTF8));
297296
}
298-
} catch (const unwind_exception& e) {
299-
UNPROTECT(1);
300-
throw e;
301-
}
297+
});
302298

303299
UNPROTECT(1);
304300
return data;

0 commit comments

Comments
 (0)