diff --git a/src/core.c b/src/core.c index a59214d7c..8a09a26a2 100644 --- a/src/core.c +++ b/src/core.c @@ -503,10 +503,10 @@ void nano_encode(nano_buf *enc, const SEXP object) { R_xlen_t i; size_t slen, outlen = 0; for (i = 0; i < xlen; i++) - outlen += strlen(CHAR(STRING_ELT(object, i))) + 1; + outlen += strlen(NANO_STR_N(object, i)) + 1; NANO_ALLOC(enc, outlen); for (i = 0; i < xlen; i++) { - s = CHAR(STRING_ELT(object, i)); + s = NANO_STR_N(object, i); slen = strlen(s) + 1; memcpy(enc->buf + enc->cur, s, slen); enc->cur += slen; @@ -595,7 +595,7 @@ int nano_matcharg(const SEXP mode) { int nano_matchargs(const SEXP mode) { if (TYPEOF(mode) != INTSXP) { - const char *mod = CHAR(STRING_ELT(mode, XLENGTH(mode) == 9)); + const char *mod = NANO_STR_N(mode, XLENGTH(mode) == 9); size_t slen = strlen(mod); switch (slen) { case 1: diff --git a/src/nanonext.h b/src/nanonext.h index d147f6fce..4f1bd1e08 100644 --- a/src/nanonext.h +++ b/src/nanonext.h @@ -96,6 +96,7 @@ typedef struct nano_handle_s { #define NANO_DATAPTR(x) (void *) DATAPTR_RO(x) #define NANO_VECTOR(x) ((const SEXP *) DATAPTR_RO(x)) #define NANO_STRING(x) CHAR(*((const SEXP *) DATAPTR_RO(x))) +#define NANO_STR_N(x, n) CHAR(((const SEXP *) DATAPTR_RO(x))[n]) #define NANO_INTEGER(x) *(int *) DATAPTR_RO(x) #define NANO_ERROR(x) { Rf_error(x); return R_NilValue; } diff --git a/src/ncurl.c b/src/ncurl.c index 1e68d5172..6d978fa20 100644 --- a/src/ncurl.c +++ b/src/ncurl.c @@ -168,8 +168,8 @@ SEXP rnng_ncurl(SEXP http, SEXP convert, SEXP follow, SEXP method, SEXP headers, if (TYPEOF(hnames) == STRSXP && XLENGTH(hnames) == hlen) { for (R_xlen_t i = 0; i < hlen; i++) { if ((xc = nng_http_req_set_header(req, - CHAR(STRING_ELT(hnames, i)), - CHAR(STRING_ELT(headers, i))))) + NANO_STR_N(hnames, i), + NANO_STR_N(headers, i)))) goto exitlevel4; } } @@ -262,7 +262,7 @@ SEXP rnng_ncurl(SEXP http, SEXP convert, SEXP follow, SEXP method, SEXP headers, SET_VECTOR_ELT(out, 1, rvec); Rf_namesgets(rvec, response); for (R_xlen_t i = 0; i < rlen; i++) { - const char *r = nng_http_res_get_header(res, CHAR(STRING_ELT(response, i))); + const char *r = nng_http_res_get_header(res, NANO_STR_N(response, i)); SET_VECTOR_ELT(rvec, i, r == NULL ? R_NilValue : Rf_mkString(r)); } } else { @@ -343,8 +343,8 @@ SEXP rnng_ncurl_aio(SEXP http, SEXP convert, SEXP method, SEXP headers, SEXP dat if (TYPEOF(hnames) == STRSXP && XLENGTH(hnames) == hlen) { for (R_xlen_t i = 0; i < hlen; i++) { if ((xc = nng_http_req_set_header(handle->req, - CHAR(STRING_ELT(hnames, i)), - CHAR(STRING_ELT(headers, i))))) + NANO_STR_N(hnames, i), + NANO_STR_N(headers, i)))) goto exitlevel4; } } @@ -476,7 +476,7 @@ static SEXP rnng_aio_http_impl(SEXP env, const int typ) { PROTECT(rvec = Rf_allocVector(VECSXP, rlen)); Rf_namesgets(rvec, response); for (R_xlen_t i = 0; i < rlen; i++) { - const char *r = nng_http_res_get_header(handle->res, CHAR(STRING_ELT(response, i))); + const char *r = nng_http_res_get_header(handle->res, NANO_STR_N(response, i)); SET_VECTOR_ELT(rvec, i, r == NULL ? R_NilValue : Rf_mkString(r)); } UNPROTECT(1); @@ -557,8 +557,8 @@ SEXP rnng_ncurl_session(SEXP http, SEXP convert, SEXP method, SEXP headers, SEXP if (TYPEOF(hnames) == STRSXP && XLENGTH(hnames) == hlen) { for (R_xlen_t i = 0; i < hlen; i++) { if ((xc = nng_http_req_set_header(handle->req, - CHAR(STRING_ELT(hnames, i)), - CHAR(STRING_ELT(headers, i))))) + NANO_STR_N(hnames, i), + NANO_STR_N(headers, i)))) goto exitlevel4; } } @@ -670,7 +670,7 @@ SEXP rnng_ncurl_transact(SEXP session) { SET_VECTOR_ELT(out, 1, rvec); Rf_namesgets(rvec, response); for (R_xlen_t i = 0; i < rlen; i++) { - const char *r = nng_http_res_get_header(handle->res, CHAR(STRING_ELT(response, i))); + const char *r = nng_http_res_get_header(handle->res, NANO_STR_N(response, i)); SET_VECTOR_ELT(rvec, i, r == NULL ? R_NilValue : Rf_mkString(r)); } } else { diff --git a/src/tls.c b/src/tls.c index 3daf68831..0b2850ef8 100644 --- a/src/tls.c +++ b/src/tls.c @@ -296,7 +296,7 @@ SEXP rnng_tls_config(SEXP client, SEXP server, SEXP pass, SEXP auth) { if ((usefile = Rf_xlength(client)) > 0) { file = NANO_STRING(client); if (usefile > 1) - crl = CHAR(STRING_ELT(client, 1)); + crl = NANO_STR_N(client, 1); if ((xc = nng_tls_config_alloc(&cfg, NNG_TLS_MODE_CLIENT))) goto exitlevel1; if ((xc = nng_tls_config_auth_mode(cfg, mod))) @@ -315,7 +315,7 @@ SEXP rnng_tls_config(SEXP client, SEXP server, SEXP pass, SEXP auth) { file = NANO_STRING(server); pss = pass != R_NilValue ? NANO_STRING(pass) : NULL; if (usefile > 1) - key = CHAR(STRING_ELT(server, 1)); + key = NANO_STR_N(server, 1); if ((xc = nng_tls_config_alloc(&cfg, NNG_TLS_MODE_SERVER))) goto exitlevel1; if ((xc = nng_tls_config_auth_mode(cfg, mod))) diff --git a/src/utils.c b/src/utils.c index 3c601c5bd..06ce11cff 100644 --- a/src/utils.c +++ b/src/utils.c @@ -501,7 +501,7 @@ SEXP rnng_next_config(SEXP refhook, SEXP klass, SEXP list, SEXP mark) { SETCAR(nano_refHook, plist ? CAR(refhook) : NANO_VECTOR(refhook)[0]); SETCADR(nano_refHook, plist ? CADR(refhook) : NANO_VECTOR(refhook)[1]); - SETCAR(nano_klassString, STRING_ELT(klass, 0)); + SETCAR(nano_klassString, *NANO_VECTOR(klass)); registered = NANO_INTEGER(list) ? 1 : 2;