Skip to content

Commit

Permalink
R_UnwindProtect eval call
Browse files Browse the repository at this point in the history
  • Loading branch information
shikokuchuo committed Dec 27, 2023
1 parent a0273a5 commit 8eeaff5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

* Using mode 'next', serialization functions with incorrect signatures are now simply ignored rather than raising errors.
* Deprecated function `.until()` is removed.
* Eliminates potential memory leaks along certain error paths.

# nanonext 0.11.0

Expand Down
13 changes: 12 additions & 1 deletion src/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ SEXP mk_error(const int xc) {

}

SEXP eval_safe (void * call) {
return Rf_eval((SEXP) call, R_GlobalEnv);
}

void rl_reset(void * nothing, Rboolean jump) {
if (jump) {
R_ReleaseObject(nano_refList);
nano_refList = R_NilValue;
}
}

static void nano_write_char(R_outpstream_t stream, int c) {

nano_buf *buf = (nano_buf *) stream->data;
Expand Down Expand Up @@ -240,7 +251,7 @@ void nano_serialize_next(nano_buf *buf, SEXP object) {
memcpy(buf->buf + 4, &cursor, 8);
SEXP call, out;
PROTECT(call = Rf_lcons(nano_refHookIn, Rf_cons(nano_refList, R_NilValue)));
PROTECT(out = Rf_eval(call, R_GlobalEnv));
PROTECT(out = R_UnwindProtect(eval_safe, call, rl_reset, NULL, NULL));
if (TYPEOF(out) == RAWSXP) {
R_xlen_t xlen = XLENGTH(out);
if (buf->cur + xlen > buf->len) {
Expand Down

0 comments on commit 8eeaff5

Please sign in to comment.