Skip to content

Commit e8226fb

Browse files
committed
safer and more efficient to release cb object in request finalizer
1 parent b8ed236 commit e8226fb

File tree

4 files changed

+19
-16
lines changed

4 files changed

+19
-16
lines changed

NEWS.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
# nanonext 0.13.6.9002 (development)
22

3+
#### New Features
4+
35
* Integrates with the `later` package to provide the foundation for truly event-driven (non-polling) promises (thanks @jcheng5 for the initial prototype in #28), where side-effects are enacted asynchronously upon aio completion.
46
* Adds `request2()` for creating a request that may be turned into an event-driven promise.
7+
8+
#### Updates
9+
510
* Updates minimum 'libnng' version requirement to v1.6.0 (if a suitable system-installed version is not found, the bundled version is compiled from source).
611

712
# nanonext 0.13.6

src/aio.c

+11-13
Original file line numberDiff line numberDiff line change
@@ -232,17 +232,11 @@ static void request_complete_signal(void *arg) {
232232

233233
}
234234

235-
static void release_object(void *data, Rboolean jump) {
236-
if (jump)
237-
R_ReleaseObject((SEXP) data);
238-
}
239-
240235
static void raio_invoke_cb(void *arg) {
241-
SEXP call, env = (SEXP) arg;
242-
PROTECT(call = Rf_lcons(CADR(ATTRIB(env)), R_NilValue));
243-
(void) R_UnwindProtect(eval_safe, call, release_object, env, NULL);
236+
SEXP call, cb = (SEXP) arg;
237+
PROTECT(call = Rf_lcons(cb, R_NilValue));
238+
(void) Rf_eval(call, R_GlobalEnv);
244239
UNPROTECT(1);
245-
R_ReleaseObject(env);
246240
}
247241

248242
static void raio_complete_cb(void *arg) {
@@ -254,8 +248,9 @@ static void raio_complete_cb(void *arg) {
254248
raio->result = res - !res;
255249

256250
nano_aio *saio = (nano_aio *) raio->next;
257-
if (CADR(ATTRIB((SEXP) saio->data)) != R_NilValue)
258-
later2(raio_invoke_cb, saio->data, 0);
251+
SEXP ax = CADR(ATTRIB((SEXP) saio->data));
252+
if (ax != R_NilValue)
253+
later2(raio_invoke_cb, ax, 0);
259254

260255
}
261256

@@ -277,8 +272,9 @@ static void request_complete_cb(void *arg) {
277272
nng_cv_wake(cv);
278273
nng_mtx_unlock(mtx);
279274

280-
if (CADR(ATTRIB((SEXP) saio->data)) != R_NilValue)
281-
later2(raio_invoke_cb, saio->data, 0);
275+
SEXP ax = CADR(ATTRIB((SEXP) saio->data));
276+
if (ax != R_NilValue)
277+
later2(raio_invoke_cb, ax, 0);
282278

283279
}
284280

@@ -338,6 +334,8 @@ static void request_finalizer(SEXP xptr) {
338334
nng_aio_free(xp->aio);
339335
if (xp->data != NULL)
340336
nng_msg_free((nng_msg *) xp->data);
337+
if (saio->data != NULL)
338+
R_ReleaseObject((SEXP) saio->data);
341339
R_Free(saio);
342340
R_Free(xp);
343341

src/core.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,13 @@ SEXP mk_error(const int xc) {
4242

4343
}
4444

45-
SEXP eval_safe (void *call) {
45+
static SEXP eval_safe (void *call) {
4646
return Rf_eval((SEXP) call, R_GlobalEnv);
4747
}
4848

4949
static void rl_reset(void *data, Rboolean jump) {
50-
if (jump && data == NULL)
50+
(void) data;
51+
if (jump)
5152
SET_TAG(nano_refHook, R_NilValue);
5253
}
5354

src/nanonext.h

-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ typedef struct nano_buf_s {
184184

185185
SEXP mk_error(const int);
186186
SEXP mk_error_ncurl(const int);
187-
SEXP eval_safe(void *);
188187
nano_buf nano_char_buf(const SEXP);
189188
SEXP nano_decode(unsigned char *, const size_t, const int);
190189
void nano_encode(nano_buf *, const SEXP);

0 commit comments

Comments
 (0)