Skip to content

Commit de7a45d

Browse files
committed
use own precious list
1 parent f379cb0 commit de7a45d

File tree

6 files changed

+38
-5
lines changed

6 files changed

+38
-5
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: nanonext
22
Type: Package
33
Title: NNG (Nanomsg Next Gen) Lightweight Messaging Library
4-
Version: 0.13.6.9000
4+
Version: 0.13.6.9001
55
Description: R binding for NNG (Nanomsg Next Gen), a successor to ZeroMQ. NNG is
66
a socket library implementing 'Scalability Protocols', a reliable,
77
high-performance standard for common communications patterns including

NEWS.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
# nanonext 0.13.6 (development)
1+
# nanonext 0.13.6.9001 (development)
2+
3+
* Integrates with the `later` package to provide the foundation for truly event-driven promises (thanks @jcheng5 for the initial prototype in #28), where side-effects are enacted upon aio request completions.
4+
* Adds `request_promise()` function for creating a request that may be turned into an event-driven promise.
25

36
# nanonext 0.13.6
47

src/aio.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,15 +254,15 @@ static void request_complete_signal(void *arg) {
254254

255255
static void release_object(void *data, Rboolean jump) {
256256
if (jump)
257-
R_ReleaseObject((SEXP) data);
257+
nano_ReleaseObject((SEXP) data);
258258
}
259259

260260
static void raio_invoke_cb(void *arg) {
261261
SEXP call, env = (SEXP) arg;
262262
PROTECT(call = Rf_lcons(CADR(ATTRIB(env)), R_NilValue));
263263
(void) R_UnwindProtect(eval_safe, call, release_object, env, NULL);
264264
UNPROTECT(1);
265-
R_ReleaseObject(env);
265+
nano_ReleaseObject(env);
266266
}
267267

268268
static void raio_complete_cb(void *arg) {
@@ -1315,7 +1315,7 @@ SEXP rnng_request_impl(const SEXP con, const SEXP data, const SEXP sendmode,
13151315
raio->mode = mod;
13161316
raio->next = saio;
13171317
if (promises) {
1318-
R_PreserveObject(env);
1318+
nano_PreserveObject(env);
13191319
raio->cb = env;
13201320
}
13211321

src/core.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,30 @@ SEXP mk_error(const int xc) {
4242

4343
}
4444

45+
static SEXP DeleteFromList(SEXP object, SEXP list) {
46+
if (CAR(list) == object) {
47+
return CDR(list);
48+
} else {
49+
SEXP last = list;
50+
for (SEXP head = CDR(list); head != R_NilValue; head = CDR(head)) {
51+
if (CAR(head) == object) {
52+
SETCDR(last, CDR(head));
53+
return list;
54+
}
55+
else last = head;
56+
}
57+
return list;
58+
}
59+
}
60+
61+
void nano_PreserveObject(SEXP object) {
62+
Rf_cons(object, nano_precious);
63+
}
64+
65+
void nano_ReleaseObject(SEXP object) {
66+
nano_precious = DeleteFromList(object, nano_precious);
67+
}
68+
4569
SEXP eval_safe (void *call) {
4670
return Rf_eval((SEXP) call, R_GlobalEnv);
4771
}

src/init.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ SEXP nano_aioFuncs;
4646
SEXP nano_aioNFuncs;
4747
SEXP nano_error;
4848
SEXP nano_klassString;
49+
SEXP nano_precious;
4950
SEXP nano_refHook;
5051
SEXP nano_success;
5152
SEXP nano_unresolved;
@@ -94,6 +95,7 @@ static void PreserveObjects(void) {
9495
SET_STRING_ELT(CAR(nano_error), 0, Rf_mkChar("errorValue"));
9596
SET_STRING_ELT(CAR(nano_error), 1, Rf_mkChar("try-error"));
9697
R_PreserveObject(nano_klassString = Rf_cons(R_NilValue, R_NilValue));
98+
R_PreserveObject(nano_precious = Rf_cons(R_NilValue, R_NilValue));
9799
R_PreserveObject(nano_refHook = Rf_list2(R_NilValue, R_NilValue));
98100
R_PreserveObject(nano_success = Rf_ScalarInteger(0));
99101
R_PreserveObject(nano_unresolved = Rf_shallow_duplicate(Rf_ScalarLogical(NA_LOGICAL)));
@@ -104,6 +106,7 @@ static void ReleaseObjects(void) {
104106
R_ReleaseObject(nano_unresolved);
105107
R_ReleaseObject(nano_success);
106108
R_ReleaseObject(nano_refHook);
109+
R_ReleaseObject(nano_precious);
107110
R_ReleaseObject(nano_klassString);
108111
R_ReleaseObject(nano_error);
109112
R_ReleaseObject(nano_aioNFuncs);

src/nanonext.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ typedef struct nano_buf_s {
192192

193193
SEXP mk_error(const int);
194194
SEXP mk_error_ncurl(const int);
195+
void nano_PreserveObject(SEXP);
196+
void nano_ReleaseObject(SEXP);
195197
SEXP eval_safe(void *);
196198
nano_buf nano_char_buf(const SEXP);
197199
SEXP nano_decode(unsigned char *, const size_t, const int);
@@ -307,6 +309,7 @@ extern SEXP nano_aioFuncs;
307309
extern SEXP nano_aioNFuncs;
308310
extern SEXP nano_error;
309311
extern SEXP nano_klassString;
312+
extern SEXP nano_precious;
310313
extern SEXP nano_refHook;
311314
extern SEXP nano_success;
312315
extern SEXP nano_unresolved;

0 commit comments

Comments
 (0)