@@ -1072,17 +1072,14 @@ SEXP rnng_ncurl_session(SEXP http, SEXP convert, SEXP method, SEXP headers, SEXP
1072
1072
nng_http_conn * conn ;
1073
1073
conn = nng_aio_get_output (haio -> aio , 0 );
1074
1074
1075
- PROTECT (sess = R_MakeExternalPtr (conn , nano_StatusSymbol , R_NilValue ));
1075
+ PROTECT (sess = R_MakeExternalPtr (conn , nano_StatusSymbol , ( response != R_NilValue && TYPEOF ( response ) == STRSXP ) ? response : R_NilValue ));
1076
1076
R_RegisterCFinalizerEx (sess , session_finalizer , TRUE);
1077
1077
Rf_classgets (sess , Rf_mkString ("ncurlSession" ));
1078
1078
1079
1079
PROTECT (aio = R_MakeExternalPtr (haio , nano_AioSymbol , R_NilValue ));
1080
1080
R_RegisterCFinalizerEx (aio , haio_finalizer , TRUE);
1081
1081
Rf_setAttrib (sess , nano_AioSymbol , aio );
1082
1082
1083
- if (response != R_NilValue && TYPEOF (response ) == STRSXP )
1084
- Rf_setAttrib (sess , nano_ResponseSymbol , response );
1085
-
1086
1083
UNPROTECT (2 );
1087
1084
return sess ;
1088
1085
@@ -1131,7 +1128,7 @@ SEXP rnng_ncurl_transact(SEXP session) {
1131
1128
const uint16_t code = nng_http_res_get_status (handle -> res );
1132
1129
SET_VECTOR_ELT (out , 0 , Rf_ScalarInteger (code ));
1133
1130
1134
- response = Rf_getAttrib (session , nano_ResponseSymbol );
1131
+ response = R_ExternalPtrProtected (session );
1135
1132
if (response != R_NilValue ) {
1136
1133
const R_xlen_t rlen = XLENGTH (response );
1137
1134
rvec = Rf_allocVector (VECSXP , rlen );
@@ -1170,9 +1167,9 @@ SEXP rnng_ncurl_session_close(SEXP session) {
1170
1167
nng_http_conn * sp = (nng_http_conn * ) R_ExternalPtrAddr (session );
1171
1168
nng_http_conn_close (sp );
1172
1169
R_SetExternalPtrTag (session , R_NilValue );
1170
+ R_SetExternalPtrProtected (session , R_NilValue );
1173
1171
R_ClearExternalPtr (session );
1174
1172
Rf_setAttrib (session , nano_AioSymbol , R_NilValue );
1175
- Rf_setAttrib (session , nano_ResponseSymbol , R_NilValue );
1176
1173
1177
1174
return nano_success ;
1178
1175
@@ -1287,15 +1284,16 @@ SEXP rnng_set_promise_context(SEXP x, SEXP ctx) {
1287
1284
if (R_ExternalPtrTag (aio ) != nano_AioSymbol )
1288
1285
return x ;
1289
1286
1287
+ nano_aio * raio = (nano_aio * ) R_ExternalPtrAddr (aio );
1288
+ if (raio -> type != REQAIO )
1289
+ return x ;
1290
+
1290
1291
if (eln2 == eln2dummy ) {
1291
1292
Rf_eval (nano_onLoad , R_GlobalEnv );
1292
1293
eln2 = (void (* )(void (* )(void * ), void * , double , int )) R_GetCCallable ("later" , "execLaterNative2" );
1293
1294
}
1294
- nano_aio * raio = (nano_aio * ) R_ExternalPtrAddr (aio );
1295
- if (raio -> type == REQAIO ) {
1296
- nano_aio * saio = (nano_aio * ) raio -> next ;
1297
- saio -> data = nano_PreserveObject (ctx );
1298
- }
1295
+ nano_aio * saio = (nano_aio * ) raio -> next ;
1296
+ saio -> data = nano_PreserveObject (ctx );
1299
1297
1300
1298
return x ;
1301
1299
0 commit comments