Skip to content

Commit 3fd86a7

Browse files
committed
RC15; efficiency encoding, make a proper pairlist
1 parent 535753c commit 3fd86a7

File tree

2 files changed

+9
-23
lines changed

2 files changed

+9
-23
lines changed

src/aio.c

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -174,22 +174,9 @@ static SEXP mk_error_haio(const int xc, SEXP env) {
174174

175175
static SEXP mk_error_data(const int xc) {
176176

177-
const char *names[] = {"data", ""};
177+
const char *names[] = {xc < 0 ? "result" : "data", ""};
178178
SEXP out = PROTECT(Rf_mkNamed(VECSXP, names));
179-
SEXP err = Rf_ScalarInteger(xc);
180-
SET_ATTRIB(err, nano_error);
181-
SET_OBJECT(err, 1);
182-
SET_VECTOR_ELT(out, 0, err);
183-
UNPROTECT(1);
184-
return out;
185-
186-
}
187-
188-
static SEXP mk_error_result(const int xc) {
189-
190-
const char *names[] = {"result", ""};
191-
SEXP out = PROTECT(Rf_mkNamed(VECSXP, names));
192-
SEXP err = Rf_ScalarInteger(xc);
179+
SEXP err = Rf_ScalarInteger(abs(xc));
193180
SET_ATTRIB(err, nano_error);
194181
SET_OBJECT(err, 1);
195182
SET_VECTOR_ELT(out, 0, err);
@@ -428,13 +415,13 @@ SEXP rnng_send_aio(SEXP con, SEXP data, SEXP mode, SEXP timeout, SEXP clo) {
428415

429416
if ((xc = nng_msg_alloc(&msg, 0))) {
430417
R_Free(saio);
431-
return mk_error_result(xc);
418+
return mk_error_data(-xc);
432419
}
433420
if ((xc = nng_msg_append(msg, dp, xlen)) ||
434421
(xc = nng_aio_alloc(&saio->aio, saio_complete, saio))) {
435422
nng_msg_free(msg);
436423
R_Free(saio);
437-
return mk_error_result(xc);
424+
return mk_error_data(-xc);
438425
}
439426

440427
nng_aio_set_msg(saio->aio, msg);
@@ -460,14 +447,14 @@ SEXP rnng_send_aio(SEXP con, SEXP data, SEXP mode, SEXP timeout, SEXP clo) {
460447

461448
if ((xc = nng_msg_alloc(&msg, 0))) {
462449
R_Free(saio);
463-
return mk_error_result(xc);
450+
return mk_error_data(-xc);
464451
}
465452

466453
if ((xc = nng_msg_append(msg, dp, xlen)) ||
467454
(xc = nng_aio_alloc(&saio->aio, saio_complete, saio))) {
468455
nng_msg_free(msg);
469456
R_Free(saio);
470-
return mk_error_result(xc);
457+
return mk_error_data(-xc);
471458
}
472459

473460
nng_aio_set_msg(saio->aio, msg);
@@ -497,14 +484,14 @@ SEXP rnng_send_aio(SEXP con, SEXP data, SEXP mode, SEXP timeout, SEXP clo) {
497484
if ((xc = nng_aio_alloc(&iaio->aio, iaio_complete, iaio))) {
498485
R_Free(iov);
499486
R_Free(iaio);
500-
return mk_error_result(xc);
487+
return mk_error_data(-xc);
501488
}
502489

503490
if ((xc = nng_aio_set_iov(iaio->aio, 1u, iov))) {
504491
nng_aio_free(iaio->aio);
505492
R_Free(iov);
506493
R_Free(iaio);
507-
return mk_error_result(xc);
494+
return mk_error_data(-xc);
508495
}
509496

510497
nng_aio_set_timeout(iaio->aio, dur);

src/init.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ static void PreserveObjects(void) {
8888
SETCADR(nano_aioNFuncs, Rf_lang5(nano_DotcallSymbol, nano_AioHttpSymbol, nano_DataSymbol, nano_ResponseSymbol, Rf_ScalarInteger(2)));
8989
SETCADDR(nano_aioNFuncs, Rf_lang5(nano_DotcallSymbol, nano_AioHttpSymbol, nano_DataSymbol, nano_ResponseSymbol, Rf_ScalarInteger(3)));
9090
SETCADDDR(nano_aioNFuncs, Rf_lang5(nano_DotcallSymbol, nano_AioHttpSymbol, nano_DataSymbol, nano_ResponseSymbol, Rf_ScalarInteger(4)));
91-
R_PreserveObject(nano_error = Rf_allocVector(LISTSXP, 1));
92-
SETCAR(nano_error, Rf_mkString("errorValue"));
91+
R_PreserveObject(nano_error = Rf_cons(Rf_mkString("errorValue"), R_NilValue));
9392
SET_TAG(nano_error, R_ClassSymbol);
9493
Rf_classgets(nano_error, Rf_mkString("errorValue"));
9594
R_PreserveObject(nano_ncurlAio = Rf_allocVector(STRSXP, 2));

0 commit comments

Comments
 (0)