Skip to content

Commit 61005d7

Browse files
committed
adds compat for existing mirai release
1 parent a9b6a8b commit 61005d7

File tree

7 files changed

+130
-7
lines changed

7 files changed

+130
-7
lines changed

Diff for: DESCRIPTION

+1-1
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: 1.1.1.9016
4+
Version: 1.1.1.9017
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

Diff for: NEWS.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# nanonext 1.1.1.9016 (development)
1+
# nanonext 1.1.1.9017 (development)
22

33
#### New Features
44

Diff for: src/aio.c

+16-2
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,14 @@ SEXP rnng_send_aio(SEXP con, SEXP data, SEXP mode, SEXP timeout, SEXP clo) {
444444
const SEXP ptrtag = NANO_TAG(con);
445445
if ((sock = ptrtag == nano_SocketSymbol) || ptrtag == nano_ContextSymbol) {
446446

447-
nano_encodes(mode) == 2 ? nano_encode(&buf, data) : nano_serialize(&buf, data, NANO_PROT(con));
447+
switch (nano_encodes(mode)) {
448+
case 1:
449+
nano_serialize(&buf, data, NANO_PROT(con)); break;
450+
case 2:
451+
nano_encode(&buf, data); break;
452+
default:
453+
nano_serialize_old(&buf, data, NANO_PROT(con)); break;
454+
}
448455
nng_msg *msg;
449456
saio = R_Calloc(1, nano_aio);
450457
saio->type = SENDAIO;
@@ -500,7 +507,14 @@ SEXP rnng_send_aio(SEXP con, SEXP data, SEXP mode, SEXP timeout, SEXP clo) {
500507
nng_pipe *p = (nng_pipe *) NANO_PTR(con);
501508
nng_socket sock = nng_pipe_socket(*p);
502509

503-
nano_encodes(mode) == 2 ? nano_encode(&buf, data) : nano_serialize(&buf, data, NANO_PROT(con));
510+
switch (nano_encodes(mode)) {
511+
case 1:
512+
nano_serialize(&buf, data, NANO_PROT(con)); break;
513+
case 2:
514+
nano_encode(&buf, data); break;
515+
default:
516+
nano_serialize_old(&buf, data, NANO_PROT(con)); break;
517+
}
504518
nng_msg *msg;
505519
saio = R_Calloc(1, nano_aio);
506520
saio->type = SENDAIO;

Diff for: src/comms.c

+16-2
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,14 @@ SEXP rnng_send(SEXP con, SEXP data, SEXP mode, SEXP block) {
312312
const SEXP ptrtag = NANO_TAG(con);
313313
if (ptrtag == nano_SocketSymbol) {
314314

315-
nano_encodes(mode) == 2 ? nano_encode(&buf, data) : nano_serialize(&buf, data, NANO_PROT(con));
315+
switch (nano_encodes(mode)) {
316+
case 1:
317+
nano_serialize(&buf, data, NANO_PROT(con)); break;
318+
case 2:
319+
nano_encode(&buf, data); break;
320+
default:
321+
nano_serialize_old(&buf, data, NANO_PROT(con)); break;
322+
}
316323
nng_socket *sock = (nng_socket *) NANO_PTR(con);
317324

318325
if (flags <= 0) {
@@ -347,7 +354,14 @@ SEXP rnng_send(SEXP con, SEXP data, SEXP mode, SEXP block) {
347354

348355
} else if (ptrtag == nano_ContextSymbol) {
349356

350-
nano_encodes(mode) == 2 ? nano_encode(&buf, data) : nano_serialize(&buf, data, NANO_PROT(con));
357+
switch (nano_encodes(mode)) {
358+
case 1:
359+
nano_serialize(&buf, data, NANO_PROT(con)); break;
360+
case 2:
361+
nano_encode(&buf, data); break;
362+
default:
363+
nano_serialize_old(&buf, data, NANO_PROT(con)); break;
364+
}
351365
nng_ctx *ctxp = (nng_ctx *) NANO_PTR(con);
352366
nng_msg *msgp;
353367

Diff for: src/core.c

+87
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,93 @@ SEXP rawToChar(const unsigned char *buf, const size_t sz) {
235235

236236
}
237237

238+
void nano_serialize_old(nano_buf *buf, const SEXP object, SEXP hook) {
239+
240+
NANO_ALLOC(buf, NANONEXT_INIT_BUFSIZE);
241+
const int reg = hook != R_NilValue;
242+
int vec;
243+
244+
vec = reg ? NANO_INTEGER(CADDDR(hook)) : 0;
245+
buf->buf[0] = 0x7;
246+
buf->buf[1] = (uint8_t) vec;
247+
buf->buf[2] = special_bit;
248+
buf->cur += 16;
249+
250+
struct R_outpstream_st output_stream;
251+
252+
R_InitOutPStream(
253+
&output_stream,
254+
(R_pstream_data_t) buf,
255+
#ifdef WORDS_BIGENDIAN
256+
R_pstream_xdr_format,
257+
#else
258+
R_pstream_binary_format,
259+
#endif
260+
NANONEXT_SERIAL_VER,
261+
NULL,
262+
nano_write_bytes,
263+
reg ? nano_inHook : NULL,
264+
reg ? hook : R_NilValue
265+
);
266+
267+
R_Serialize(object, &output_stream);
268+
269+
if (reg && TAG(hook) != R_NilValue) {
270+
((uint64_t *) (buf->buf))[1] = (uint64_t) buf->cur;
271+
SEXP call, out;
272+
273+
if (vec) {
274+
275+
PROTECT(call = Rf_lcons(CADR(hook), Rf_cons(TAG(hook), R_NilValue)));
276+
PROTECT(out = R_UnwindProtect(eval_safe, call, rl_reset, hook, NULL));
277+
if (TYPEOF(out) == RAWSXP) {
278+
R_xlen_t xlen = XLENGTH(out);
279+
if (buf->cur + xlen > buf->len) {
280+
buf->len = buf->cur + xlen;
281+
buf->buf = R_Realloc(buf->buf, buf->len, unsigned char);
282+
}
283+
memcpy(buf->buf + buf->cur, DATAPTR_RO(out), xlen);
284+
buf->cur += xlen;
285+
}
286+
UNPROTECT(2);
287+
288+
} else {
289+
290+
SEXP refList = TAG(hook);
291+
SEXP func = CADR(hook);
292+
R_xlen_t llen = Rf_xlength(refList);
293+
if (buf->cur + sizeof(R_xlen_t) > buf->len) {
294+
buf->len = buf->cur + NANONEXT_INIT_BUFSIZE;
295+
buf->buf = R_Realloc(buf->buf, buf->len, unsigned char);
296+
}
297+
memcpy(buf->buf + buf->cur, &llen, sizeof(R_xlen_t));
298+
buf->cur += sizeof(R_xlen_t);
299+
300+
for (R_xlen_t i = 0; i < llen; i++) {
301+
PROTECT(call = Rf_lcons(func, Rf_cons(NANO_VECTOR(refList)[i], R_NilValue)));
302+
PROTECT(out = R_UnwindProtect(eval_safe, call, rl_reset, hook, NULL));
303+
if (TYPEOF(out) == RAWSXP) {
304+
R_xlen_t xlen = XLENGTH(out);
305+
if (buf->cur + xlen + sizeof(R_xlen_t) > buf->len) {
306+
buf->len = buf->cur + xlen + sizeof(R_xlen_t);
307+
buf->buf = R_Realloc(buf->buf, buf->len, unsigned char);
308+
}
309+
memcpy(buf->buf + buf->cur, &xlen, sizeof(R_xlen_t));
310+
buf->cur += sizeof(R_xlen_t);
311+
memcpy(buf->buf + buf->cur, DATAPTR_RO(out), xlen);
312+
buf->cur += xlen;
313+
}
314+
UNPROTECT(2);
315+
}
316+
317+
}
318+
319+
SET_TAG(hook, R_NilValue);
320+
321+
}
322+
323+
}
324+
238325
void nano_serialize(nano_buf *buf, const SEXP object, SEXP hook) {
239326

240327
NANO_ALLOC(buf, NANONEXT_INIT_BUFSIZE);

Diff for: src/nanonext.h

+1
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ int nano_integer(SEXP);
217217
SEXP mk_error(const int);
218218
SEXP mk_error_data(const int);
219219
SEXP rawToChar(const unsigned char *, const size_t);
220+
void nano_serialize_old(nano_buf *, const SEXP, SEXP);
220221
void nano_serialize(nano_buf *, const SEXP, SEXP);
221222
SEXP nano_unserialize(unsigned char *, const size_t, SEXP);
222223
SEXP nano_decode(unsigned char *, const size_t, const int, SEXP);

Diff for: src/sync.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,14 @@ SEXP rnng_request(SEXP con, SEXP data, SEXP sendmode, SEXP recvmode, SEXP timeou
456456
nng_msg *msg;
457457
int xc;
458458

459-
nano_encodes(sendmode) == 2 ? nano_encode(&buf, data) : nano_serialize(&buf, data, NANO_PROT(con));
459+
switch (nano_encodes(sendmode)) {
460+
case 1:
461+
nano_serialize(&buf, data, NANO_PROT(con)); break;
462+
case 2:
463+
nano_encode(&buf, data); break;
464+
default:
465+
nano_serialize_old(&buf, data, NANO_PROT(con)); break;
466+
}
460467
saio = R_Calloc(1, nano_aio);
461468
saio->data = NULL;
462469
saio->next = ncv;

0 commit comments

Comments
 (0)