@@ -137,50 +137,48 @@ static void haio_finalizer(SEXP xptr) {
137137
138138static SEXP mk_error_saio (const int xc , SEXP env ) {
139139
140- SEXP err ;
141- PROTECT (err = Rf_ScalarInteger (xc ));
142- Rf_classgets (err , nano_error );
143- Rf_defineVar (nano_ResultSymbol , err , ENCLOS (env ));
144- UNPROTECT (1 );
145- return err ;
140+ SET_INTEGER_ELT (nano_error , 0 , xc );
141+ Rf_defineVar (nano_ResultSymbol , nano_error , ENCLOS (env ));
142+ return nano_error ;
146143
147144}
148145
149146static SEXP mk_error_raio (const int xc , SEXP env ) {
150147
151- SEXP err ;
152- PROTECT (err = Rf_ScalarInteger (xc ));
153- Rf_classgets (err , nano_error );
154- Rf_defineVar (nano_RawSymbol , err , ENCLOS (env ));
155- Rf_defineVar (nano_DataSymbol , err , ENCLOS (env ));
156- UNPROTECT (1 );
157- return err ;
148+ SET_INTEGER_ELT (nano_error , 0 , xc );
149+ Rf_defineVar (nano_RawSymbol , nano_error , ENCLOS (env ));
150+ Rf_defineVar (nano_DataSymbol , nano_error , ENCLOS (env ));
151+ return nano_error ;
158152
159153}
160154
161155static SEXP mk_error_haio (const int xc , SEXP env ) {
162156
163- SEXP err ;
164- PROTECT (err = Rf_ScalarInteger (xc ));
165- Rf_classgets (err , nano_error );
166- Rf_defineVar (nano_StatusSymbol , err , ENCLOS (env ));
167- Rf_defineVar (nano_IdSymbol , err , ENCLOS (env ));
168- Rf_defineVar (nano_RawSymbol , err , ENCLOS (env ));
169- Rf_defineVar (nano_ProtocolSymbol , err , ENCLOS (env ));
170- UNPROTECT (1 );
171- return err ;
157+ SET_INTEGER_ELT (nano_error , 0 , xc );
158+ Rf_defineVar (nano_StatusSymbol , nano_error , ENCLOS (env ));
159+ Rf_defineVar (nano_IdSymbol , nano_error , ENCLOS (env ));
160+ Rf_defineVar (nano_RawSymbol , nano_error , ENCLOS (env ));
161+ Rf_defineVar (nano_ProtocolSymbol , nano_error , ENCLOS (env ));
162+ return nano_error ;
172163
173164}
174165
175- static SEXP mk_error_list (const int xc , const int data ) {
166+ static SEXP mk_error_data (const int xc ) {
176167
177- SEXP out , err ;
178- const char * names [] = {data ? "data" : "result" , "" };
179- PROTECT (out = Rf_mkNamed (VECSXP , names ));
180- err = Rf_ScalarInteger (xc );
181- Rf_classgets (err , nano_error );
182- SET_VECTOR_ELT (out , 0 , err );
183- UNPROTECT (1 );
168+ const char * names [] = {"data" , "" };
169+ SET_INTEGER_ELT (nano_error , 0 , xc );
170+ SEXP out = Rf_mkNamed (VECSXP , names );
171+ SET_VECTOR_ELT (out , 0 , nano_error );
172+ return out ;
173+
174+ }
175+
176+ static SEXP mk_error_result (const int xc ) {
177+
178+ const char * names [] = {"result" , "" };
179+ SET_INTEGER_ELT (nano_error , 0 , xc );
180+ SEXP out = Rf_mkNamed (VECSXP , names );
181+ SET_VECTOR_ELT (out , 0 , nano_error );
184182 return out ;
185183
186184}
@@ -415,13 +413,13 @@ SEXP rnng_send_aio(SEXP con, SEXP data, SEXP mode, SEXP timeout, SEXP clo) {
415413
416414 if ((xc = nng_msg_alloc (& msg , 0 ))) {
417415 R_Free (saio );
418- return mk_error_list (xc , 0 );
416+ return mk_error_result (xc );
419417 }
420418 if ((xc = nng_msg_append (msg , dp , xlen )) ||
421419 (xc = nng_aio_alloc (& saio -> aio , saio_complete , saio ))) {
422420 nng_msg_free (msg );
423421 R_Free (saio );
424- return mk_error_list (xc , 0 );
422+ return mk_error_result (xc );
425423 }
426424
427425 nng_aio_set_msg (saio -> aio , msg );
@@ -447,14 +445,14 @@ SEXP rnng_send_aio(SEXP con, SEXP data, SEXP mode, SEXP timeout, SEXP clo) {
447445
448446 if ((xc = nng_msg_alloc (& msg , 0 ))) {
449447 R_Free (saio );
450- return mk_error_list (xc , 0 );
448+ return mk_error_result (xc );
451449 }
452450
453451 if ((xc = nng_msg_append (msg , dp , xlen )) ||
454452 (xc = nng_aio_alloc (& saio -> aio , saio_complete , saio ))) {
455453 nng_msg_free (msg );
456454 R_Free (saio );
457- return mk_error_list (xc , 0 );
455+ return mk_error_result (xc );
458456 }
459457
460458 nng_aio_set_msg (saio -> aio , msg );
@@ -484,14 +482,14 @@ SEXP rnng_send_aio(SEXP con, SEXP data, SEXP mode, SEXP timeout, SEXP clo) {
484482 if ((xc = nng_aio_alloc (& iaio -> aio , iaio_complete , iaio ))) {
485483 R_Free (iov );
486484 R_Free (iaio );
487- return mk_error_list (xc , 0 );
485+ return mk_error_result (xc );
488486 }
489487
490488 if ((xc = nng_aio_set_iov (iaio -> aio , 1u , iov ))) {
491489 nng_aio_free (iaio -> aio );
492490 R_Free (iov );
493491 R_Free (iaio );
494- return mk_error_list (xc , 0 );
492+ return mk_error_result (xc );
495493 }
496494
497495 nng_aio_set_timeout (iaio -> aio , dur );
@@ -546,7 +544,7 @@ SEXP rnng_recv_aio(SEXP con, SEXP mode, SEXP timeout, SEXP keep, SEXP bytes, SEX
546544
547545 if ((xc = nng_aio_alloc (& raio -> aio , raio_complete , raio ))) {
548546 R_Free (raio );
549- return kpr ? mk_error_recv (xc ) : mk_error_list (xc , 1 );
547+ return kpr ? mk_error_recv (xc ) : mk_error_data (xc );
550548 }
551549
552550 nng_aio_set_timeout (raio -> aio , dur );
@@ -567,7 +565,7 @@ SEXP rnng_recv_aio(SEXP con, SEXP mode, SEXP timeout, SEXP keep, SEXP bytes, SEX
567565
568566 if ((xc = nng_aio_alloc (& raio -> aio , raio_complete , raio ))) {
569567 R_Free (raio );
570- return kpr ? mk_error_recv (xc ) : mk_error_list (xc , 1 );
568+ return kpr ? mk_error_recv (xc ) : mk_error_data (xc );
571569 }
572570
573571 nng_aio_set_timeout (raio -> aio , dur );
@@ -594,15 +592,15 @@ SEXP rnng_recv_aio(SEXP con, SEXP mode, SEXP timeout, SEXP keep, SEXP bytes, SEX
594592 R_Free (iov -> iov_buf );
595593 R_Free (iov );
596594 R_Free (iaio );
597- return kpr ? mk_error_recv (xc ) : mk_error_list (xc , 1 );
595+ return kpr ? mk_error_recv (xc ) : mk_error_data (xc );
598596 }
599597
600598 if ((xc = nng_aio_set_iov (iaio -> aio , 1u , iov ))) {
601599 nng_aio_free (iaio -> aio );
602600 R_Free (iov -> iov_buf );
603601 R_Free (iov );
604602 R_Free (iaio );
605- return kpr ? mk_error_recv (xc ) : mk_error_list (xc , 1 );
603+ return kpr ? mk_error_recv (xc ) : mk_error_data (xc );
606604 }
607605
608606 nng_aio_set_timeout (iaio -> aio , dur );
@@ -898,14 +896,14 @@ SEXP rnng_request(SEXP con, SEXP data, SEXP sendmode, SEXP recvmode, SEXP timeou
898896
899897 if ((xc = nng_msg_alloc (& msg , 0 ))) {
900898 R_Free (saio );
901- return kpr ? mk_error_recv (xc ) : mk_error_list (xc , 1 );
899+ return kpr ? mk_error_recv (xc ) : mk_error_data (xc );
902900 }
903901
904902 if ((xc = nng_msg_append (msg , dp , xlen )) ||
905903 (xc = nng_aio_alloc (& saio -> aio , saio_complete , saio ))) {
906904 nng_msg_free (msg );
907905 R_Free (saio );
908- return kpr ? mk_error_recv (xc ) : mk_error_list (xc , 1 );
906+ return kpr ? mk_error_recv (xc ) : mk_error_data (xc );
909907 }
910908
911909 nng_aio_set_msg (saio -> aio , msg );
@@ -922,7 +920,7 @@ SEXP rnng_request(SEXP con, SEXP data, SEXP sendmode, SEXP recvmode, SEXP timeou
922920
923921 if ((xc = nng_aio_alloc (& raio -> aio , raio_complete , raio ))) {
924922 R_Free (raio );
925- return kpr ? mk_error_recv (xc ) : mk_error_list (xc , 1 );
923+ return kpr ? mk_error_recv (xc ) : mk_error_data (xc );
926924 }
927925
928926 nng_aio_set_timeout (raio -> aio , dur );
0 commit comments