Skip to content

Commit 70eb283

Browse files
committed
tidy up c code
1 parent d12832e commit 70eb283

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

src/aio.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,10 @@ SEXP rnng_aio_get_msg(SEXP aio, SEXP mode, SEXP keep) {
181181
return mk_error(res);
182182

183183
const int mod = *INTEGER(mode), kpr = *LOGICAL(keep);
184-
unsigned char *buf = (unsigned char *) nng_msg_body(raio->data);
184+
void *buf = nng_msg_body(raio->data);
185185
size_t sz = nng_msg_len(raio->data);
186186

187-
return nano_decode(buf, sz, mod, kpr);
187+
return nano_decode((unsigned char *) buf, sz, mod, kpr);
188188

189189
}
190190

@@ -210,10 +210,9 @@ SEXP rnng_aio_stream_in(SEXP aio, SEXP mode, SEXP keep) {
210210

211211
const int mod = *INTEGER(mode), kpr = *LOGICAL(keep);
212212
nng_iov *iov = (nng_iov *) iaio->data;
213-
unsigned char *buf = (unsigned char *) iov->iov_buf;
214213
size_t sz = nng_aio_count(iaio->aio);
215214

216-
return nano_decode(buf, sz, mod, kpr);
215+
return nano_decode((unsigned char *) iov->iov_buf, sz, mod, kpr);
217216

218217
}
219218

@@ -399,7 +398,7 @@ SEXP rnng_stream_recv_aio(SEXP stream, SEXP bytes, SEXP timeout) {
399398
iaio->type = IOV_RECVAIO;
400399
iaio->data = iov;
401400
iov->iov_len = xlen;
402-
iov->iov_buf = (unsigned char *) R_Calloc(xlen, unsigned char);
401+
iov->iov_buf = R_Calloc(xlen, unsigned char);
403402

404403
xc = nng_aio_alloc(&iaio->aio, iaio_complete, iaio);
405404
if (xc) {
@@ -804,7 +803,6 @@ SEXP rnng_aio_http(SEXP aio) {
804803
SEXP vec;
805804

806805
nng_http_res_get_data(handle->res, &dat, &sz);
807-
808806
vec = Rf_allocVector(RAWSXP, sz);
809807
memcpy(RAW(vec), (unsigned char *) dat, sz);
810808

src/core.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,8 +1022,9 @@ SEXP rnng_recv(SEXP socket, SEXP mode, SEXP block, SEXP keep) {
10221022
return mk_error(xc);
10231023
}
10241024
nng_msg *msgp = nng_aio_get_msg(aiop);
1025+
buf = nng_msg_body(msgp);
10251026
sz = nng_msg_len(msgp);
1026-
res = nano_decode((unsigned char *) nng_msg_body(msgp), sz, mod, kpr);
1027+
res = nano_decode((unsigned char *) buf, sz, mod, kpr);
10271028
nng_msg_free(msgp);
10281029
nng_aio_free(aiop);
10291030
}
@@ -1090,7 +1091,7 @@ SEXP rnng_ctx_recv(SEXP context, SEXP mode, SEXP timeout, SEXP keep) {
10901091
mode = rnng_matcharg(mode);
10911092
const int mod = *INTEGER(mode), kpr = *LOGICAL(keep);
10921093
int xc;
1093-
unsigned char *buf;
1094+
void *buf;
10941095
size_t sz;
10951096
SEXP res;
10961097

@@ -1115,9 +1116,9 @@ SEXP rnng_ctx_recv(SEXP context, SEXP mode, SEXP timeout, SEXP keep) {
11151116
}
11161117

11171118
nng_msg *msgp = nng_aio_get_msg(aiop);
1118-
buf = (unsigned char *) nng_msg_body(msgp);
1119+
buf = nng_msg_body(msgp);
11191120
sz = nng_msg_len(msgp);
1120-
res = nano_decode(buf, sz, mod, kpr);
1121+
res = nano_decode((unsigned char *) buf, sz, mod, kpr);
11211122
nng_msg_free(msgp);
11221123
nng_aio_free(aiop);
11231124

@@ -1189,6 +1190,7 @@ SEXP rnng_stream_recv(SEXP stream, SEXP mode, SEXP timeout, SEXP keep, SEXP byte
11891190
const size_t xlen = (size_t) Rf_asInteger(bytes);
11901191
nng_duration dur;
11911192
int xc;
1193+
size_t sz;
11921194
nng_iov iov;
11931195
nng_aio *aiop;
11941196
SEXP res;
@@ -1201,7 +1203,7 @@ SEXP rnng_stream_recv(SEXP stream, SEXP mode, SEXP timeout, SEXP keep, SEXP byte
12011203
}
12021204

12031205
iov.iov_len = xlen;
1204-
iov.iov_buf = (unsigned char *) R_Calloc(xlen, unsigned char);
1206+
iov.iov_buf = R_Calloc(xlen, unsigned char);
12051207

12061208
xc = nng_aio_alloc(&aiop, NULL, NULL);
12071209
if (xc) {
@@ -1227,7 +1229,8 @@ SEXP rnng_stream_recv(SEXP stream, SEXP mode, SEXP timeout, SEXP keep, SEXP byte
12271229
return mk_error(xc);
12281230
}
12291231

1230-
res = nano_decode(iov.iov_buf, nng_aio_count(aiop), mod, kpr);
1232+
sz = nng_aio_count(aiop);
1233+
res = nano_decode((unsigned char *) iov.iov_buf, sz, mod, kpr);
12311234
nng_aio_free(aiop);
12321235
R_Free(iov.iov_buf);
12331236

0 commit comments

Comments
 (0)