From e0614b5df16c4e8c83f21678a5f617c7adcf89c9 Mon Sep 17 00:00:00 2001 From: shikokuchuo <53399081+shikokuchuo@users.noreply.github.com> Date: Thu, 25 Jul 2024 16:55:49 +0100 Subject: [PATCH] optimize implementation --- src/aio.c | 4 ++-- src/sync.c | 2 +- src/thread.c | 4 ---- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/aio.c b/src/aio.c index b1bbcc3fd..700b11e90 100644 --- a/src/aio.c +++ b/src/aio.c @@ -228,7 +228,7 @@ SEXP rnng_aio_get_msg(SEXP env) { sz = nng_msg_len(msg); } - PROTECT(out = nano_decode(buf, sz, raio->mode, ATTRIB(aio))); + PROTECT(out = nano_decode(buf, sz, raio->mode, NANO_PROT(aio))); Rf_defineVar(nano_ValueSymbol, out, env); Rf_defineVar(nano_AioSymbol, R_NilValue, env); @@ -584,7 +584,7 @@ SEXP rnng_recv_aio(SEXP con, SEXP mode, SEXP timeout, SEXP cvar, SEXP bytes, SEX PROTECT(aio = R_MakeExternalPtr(raio, nano_AioSymbol, R_NilValue)); R_RegisterCFinalizerEx(aio, raio_finalizer, TRUE); - SET_ATTRIB(aio, NANO_PROT(con)); + NANO_SET_PROT(aio, NANO_PROT(con)); } else if (ptrtag == nano_StreamSymbol) { diff --git a/src/sync.c b/src/sync.c index 71d067b4a..56f89d9f2 100644 --- a/src/sync.c +++ b/src/sync.c @@ -495,7 +495,7 @@ SEXP rnng_request(SEXP con, SEXP data, SEXP sendmode, SEXP recvmode, SEXP timeou PROTECT(aio = R_MakeExternalPtr(raio, nano_AioSymbol, R_NilValue)); R_RegisterCFinalizerEx(aio, request_finalizer, TRUE); - SET_ATTRIB(aio, NANO_PROT(con)); + NANO_SET_PROT(aio, NANO_PROT(con)); PROTECT(env = Rf_allocSExp(ENVSXP)); Rf_classgets(env, nano_reqAio); diff --git a/src/thread.c b/src/thread.c index 80a7ecaab..d5eac4998 100644 --- a/src/thread.c +++ b/src/thread.c @@ -238,7 +238,6 @@ SEXP rnng_wait_thread_create(SEXP x) { if (NANO_TAG(coreaio) != nano_AioSymbol) return x; - PROTECT(coreaio); nano_aio *aiop = (nano_aio *) NANO_PTR(coreaio); nano_thread_aio *taio = R_Calloc(1, nano_thread_aio); @@ -263,9 +262,7 @@ SEXP rnng_wait_thread_create(SEXP x) { ncv->cv = cv; SEXP xptr = R_MakeExternalPtr(taio, R_NilValue, R_NilValue); - NANO_SET_PROT(coreaio, xptr); R_RegisterCFinalizerEx(xptr, thread_aio_finalizer, TRUE); - UNPROTECT(1); nng_time time = nng_clock(); @@ -311,7 +308,6 @@ SEXP rnng_wait_thread_create(SEXP x) { exitlevel1: R_Free(ncv); R_Free(taio); - UNPROTECT(1); ERROR_OUT(xc); } else if (typ == VECSXP) {