@@ -44,14 +44,14 @@ SEXP rnng_serial(SEXP mode) {
4444SEXP nano_encode (SEXP object ) {
4545
4646 R_xlen_t xlen = Rf_xlength (object );
47- void * buf ;
4847 size_t sz ;
4948 SEXP out ;
5049
5150 if (!Rf_isVectorAtomic (object ))
5251 error_return ("'data' is not an atomic vector type" );
5352 if (TYPEOF (object ) == STRSXP ) {
5453 const char * s ;
54+ unsigned char * buf ;
5555 size_t np , outlen = 0 ;
5656 R_xlen_t i ;
5757 for (i = 0 ; i < xlen ; i ++ )
@@ -67,28 +67,24 @@ SEXP nano_encode(SEXP object) {
6767 } else {
6868 switch (TYPEOF (object )) {
6969 case REALSXP :
70- buf = REAL (object );
7170 sz = xlen * sizeof (double );
7271 out = Rf_allocVector (RAWSXP , sz );
73- memcpy (RAW (out ), buf , sz );
72+ memcpy (RAW (out ), REAL ( object ) , sz );
7473 break ;
7574 case INTSXP :
76- buf = INTEGER (object );
7775 sz = xlen * sizeof (int );
7876 out = Rf_allocVector (RAWSXP , sz );
79- memcpy (RAW (out ), buf , sz );
77+ memcpy (RAW (out ), INTEGER ( object ) , sz );
8078 break ;
8179 case LGLSXP :
82- buf = LOGICAL (object );
8380 sz = xlen * sizeof (int );
8481 out = Rf_allocVector (RAWSXP , sz );
85- memcpy (RAW (out ), buf , sz );
82+ memcpy (RAW (out ), LOGICAL ( object ) , sz );
8683 break ;
8784 case CPLXSXP :
88- buf = COMPLEX (object );
8985 sz = xlen * (sizeof (double ) + sizeof (double ));
9086 out = Rf_allocVector (RAWSXP , sz );
91- memcpy (RAW (out ), buf , sz );
87+ memcpy (RAW (out ), COMPLEX ( object ) , sz );
9288 break ;
9389 case RAWSXP :
9490 out = object ;
@@ -199,7 +195,7 @@ SEXP rnng_matchargs(SEXP mode) {
199195
200196}
201197
202- SEXP nano_decode (void * buf , size_t sz , const int mod , const int kpr ) {
198+ SEXP nano_decode (unsigned char * buf , size_t sz , const int mod , const int kpr ) {
203199
204200 int tryErr = 0 ;
205201 SEXP raw , data ;
@@ -751,7 +747,7 @@ SEXP rnng_recv(SEXP socket, SEXP mode, SEXP block, SEXP keep) {
751747 mode = rnng_matcharg (mode );
752748 const int mod = INTEGER (mode )[0 ], kpr = LOGICAL (keep )[0 ];
753749 int xc ;
754- void * buf ;
750+ unsigned char * buf ;
755751 size_t sz ;
756752 nng_aio * aiop ;
757753 SEXP res ;
@@ -847,7 +843,7 @@ SEXP rnng_ctx_recv(SEXP context, SEXP mode, SEXP timeout, SEXP keep) {
847843 mode = rnng_matcharg (mode );
848844 const int mod = INTEGER (mode )[0 ], kpr = LOGICAL (keep )[0 ];
849845 int xc ;
850- void * buf ;
846+ unsigned char * buf ;
851847 size_t sz ;
852848 SEXP res ;
853849
@@ -946,6 +942,7 @@ SEXP rnng_stream_recv(SEXP stream, SEXP mode, SEXP timeout, SEXP keep, SEXP byte
946942 const size_t xlen = (size_t ) Rf_asInteger (bytes );
947943 nng_duration dur ;
948944 int xc ;
945+ unsigned char * buf ;
949946 size_t sz ;
950947 nng_iov iov ;
951948 nng_aio * aiop ;
@@ -985,8 +982,9 @@ SEXP rnng_stream_recv(SEXP stream, SEXP mode, SEXP timeout, SEXP keep, SEXP byte
985982 return mk_error (xc );
986983 }
987984
985+ buf = iov .iov_buf ;
988986 sz = nng_aio_count (aiop );
989- res = nano_decode (iov . iov_buf , sz , mod , kpr );
987+ res = nano_decode (buf , sz , mod , kpr );
990988 nng_aio_free (aiop );
991989 R_Free (iov .iov_buf );
992990
0 commit comments