Skip to content

Commit ce1dccc

Browse files
committed
suppressable conversion warnings
1 parent c4974c3 commit ce1dccc

File tree

7 files changed

+23
-29
lines changed

7 files changed

+23
-29
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: nanonext
22
Type: Package
33
Title: NNG (Nanomsg Next Gen) Lightweight Messaging Library
4-
Version: 1.2.1.9020
4+
Version: 1.2.1.9021
55
Description: R binding for NNG (Nanomsg Next Gen), a successor to ZeroMQ. NNG is
66
a socket library implementing 'Scalability Protocols', a reliable,
77
high-performance standard for common communications patterns including

NEWS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# nanonext 1.2.1.9020 (development)
1+
# nanonext 1.2.1.9021 (development)
22

33
#### New Features
44

@@ -7,6 +7,7 @@
77

88
#### Updates
99

10+
* Warning messages for failure of unserialization or conversion of received message data are now suppressable.
1011
* Upgrades `reply()` to always return even when there is an evaluation error. This allows it to be used safely in a loop without exiting early, for example.
1112
* Removes deprecated and defunct `next_config()`.
1213
* Performance enhancements for `promises::as.promise()` methods.

src/core.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ SEXP rawToChar(const unsigned char *buf, const size_t sz) {
290290
int i, j;
291291
for (i = 0, j = -1; i < sz; i++) if (buf[i]) j = i; else break;
292292
if (sz - i > 1) {
293-
nano_REprintf("data could not be converted to a character string\n");
293+
Rf_warningcall_immediate(R_NilValue, "data could not be converted to a character string");
294294
out = Rf_allocVector(RAWSXP, sz);
295295
memcpy(NANO_DATAPTR(out), buf, sz);
296296
return out;
@@ -445,7 +445,7 @@ SEXP nano_unserialize(unsigned char *buf, const size_t sz, SEXP hook) {
445445
}
446446
}
447447

448-
nano_REprintf("received data could not be unserialized\n");
448+
Rf_warningcall_immediate(R_NilValue, "received data could not be unserialized");
449449
return nano_decode(buf, sz, 8, R_NilValue);
450450

451451
resume: ;
@@ -500,7 +500,7 @@ SEXP nano_decode(unsigned char *buf, const size_t sz, const uint8_t mod, SEXP ho
500500
case 3:
501501
size = 2 * sizeof(double);
502502
if (sz % size) {
503-
nano_REprintf("received data could not be converted to complex\n");
503+
Rf_warningcall_immediate(R_NilValue, "received data could not be converted to complex");
504504
data = Rf_allocVector(RAWSXP, sz);
505505
} else {
506506
data = Rf_allocVector(CPLXSXP, sz / size);
@@ -509,7 +509,7 @@ SEXP nano_decode(unsigned char *buf, const size_t sz, const uint8_t mod, SEXP ho
509509
case 4:
510510
size = sizeof(double);
511511
if (sz % size) {
512-
nano_REprintf("received data could not be converted to double\n");
512+
Rf_warningcall_immediate(R_NilValue, "received data could not be converted to double");
513513
data = Rf_allocVector(RAWSXP, sz);
514514
} else {
515515
data = Rf_allocVector(REALSXP, sz / size);
@@ -518,7 +518,7 @@ SEXP nano_decode(unsigned char *buf, const size_t sz, const uint8_t mod, SEXP ho
518518
case 5:
519519
size = sizeof(int);
520520
if (sz % size) {
521-
nano_REprintf("received data could not be converted to integer\n");
521+
Rf_warningcall_immediate(R_NilValue, "received data could not be converted to integer");
522522
data = Rf_allocVector(RAWSXP, sz);
523523
} else {
524524
data = Rf_allocVector(INTSXP, sz / size);
@@ -527,7 +527,7 @@ SEXP nano_decode(unsigned char *buf, const size_t sz, const uint8_t mod, SEXP ho
527527
case 6:
528528
size = sizeof(int);
529529
if (sz % size) {
530-
nano_REprintf("received data could not be converted to logical\n");
530+
Rf_warningcall_immediate(R_NilValue, "received data could not be converted to logical");
531531
data = Rf_allocVector(RAWSXP, sz);
532532
} else {
533533
data = Rf_allocVector(LGLSXP, sz / size);
@@ -536,7 +536,7 @@ SEXP nano_decode(unsigned char *buf, const size_t sz, const uint8_t mod, SEXP ho
536536
case 7:
537537
size = sizeof(double);
538538
if (sz % size) {
539-
nano_REprintf("received data could not be converted to numeric\n");
539+
Rf_warningcall_immediate(R_NilValue, "received data could not be converted to numeric");
540540
data = Rf_allocVector(RAWSXP, sz);
541541
} else {
542542
data = Rf_allocVector(REALSXP, sz / size);

src/nanonext.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,6 @@ int nano_encodes(const SEXP);
302302
int nano_matcharg(const SEXP);
303303
int nano_matchargs(const SEXP);
304304

305-
void nano_REprintf(const char *);
306305
void pipe_cb_signal(nng_pipe, nng_pipe_ev, void *);
307306

308307
SEXP rnng_advance_rng_state(void);

src/thread.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@
2020
#define NANONEXT_IO
2121
#include "nanonext.h"
2222

23-
void nano_REprintf(const char *fmt) {
24-
25-
if (write(STDERR_FILENO, fmt, strlen(fmt))) {} ;
26-
27-
}
28-
2923
// messenger -------------------------------------------------------------------
3024

3125
// # nocov start

src/tls.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ SEXP rnng_write_cert(SEXP cn, SEXP valid, SEXP inter) {
165165
snprintf(issuer_name, clen, "CN=%s,O=Nanonext,C=JP", common);
166166

167167
int xc, exit = 1;
168-
if (interactive) nano_REprintf("Generating key + certificate [ ]");
168+
if (interactive) REprintf("Generating key + certificate [ ]");
169169
mbedtls_x509_crt issuer_crt;
170170
mbedtls_pk_context loaded_issuer_key;
171171
mbedtls_pk_context *issuer_key = &loaded_issuer_key;
@@ -191,18 +191,18 @@ SEXP rnng_write_cert(SEXP cn, SEXP valid, SEXP inter) {
191191
mbedtls_mpi_init(&serial);
192192
#endif
193193

194-
if (interactive) nano_REprintf("\rGenerating key + certificate [. ]");
194+
if (interactive) REprintf("\rGenerating key + certificate [. ]");
195195

196196
if ((xc = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy, (const unsigned char *) pers, strlen(pers))) ||
197197
(xc = mbedtls_pk_setup(&key, mbedtls_pk_info_from_type((mbedtls_pk_type_t) MBEDTLS_PK_RSA))))
198198
goto exitlevel1;
199199

200-
if (interactive) nano_REprintf("\rGenerating key + certificate [.. ]");
200+
if (interactive) REprintf("\rGenerating key + certificate [.. ]");
201201

202202
if ((xc = mbedtls_rsa_gen_key(mbedtls_pk_rsa(key), mbedtls_ctr_drbg_random, &ctr_drbg, 4096, 65537)))
203203
goto exitlevel1;
204204

205-
if (interactive) nano_REprintf("\rGenerating key + certificate [... ]");
205+
if (interactive) REprintf("\rGenerating key + certificate [... ]");
206206

207207
if ((xc = mbedtls_pk_write_key_pem(&key, key_buf, 16000)))
208208
goto exitlevel1;
@@ -256,7 +256,7 @@ SEXP rnng_write_cert(SEXP cn, SEXP valid, SEXP inter) {
256256
SET_STRING_ELT(cstr, 0, Rf_mkChar((char *) &output_buf));
257257
SET_STRING_ELT(cstr, 1, R_BlankString);
258258

259-
if (interactive) nano_REprintf("\rGenerating key + certificate [done]\n");
259+
if (interactive) REprintf("\rGenerating key + certificate [done]\n");
260260
exit = 0;
261261

262262
exitlevel1:

tests/tests.R

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ test_class("errorValue", msg$data)
110110
test_identical(call_aio(n), n)
111111
test_class("sendAio", sraio <- n$send_aio(as.raw(0L), mode = "r", timeout = 500))
112112
test_class("recvAio", rraio <- n1$recv_aio(mode = 1L, timeout = 500))
113-
test_true(is_nul_byte(call_aio_(rraio)$data))
113+
test_true(is_nul_byte(suppressWarnings(call_aio_(rraio)$data)))
114114
test_class("sendAio", sraio <- n$send_aio(as.raw(1L), mode = "ra", timeout = 500))
115115
test_class("recvAio", rraio <- n1$recv_aio(mode = "raw", timeout = 500))
116116
test_type("raw", call_aio(rraio)$data)
@@ -128,16 +128,16 @@ test_class("recvAio", rraio <- n1$recv_aio(mode = "i", timeout = 500))
128128
test_type("integer", call_aio(rraio)$data)
129129
test_class("sendAio", sraio <- n$send_aio(as.raw(0L), mode = "raw", timeout = 500))
130130
test_class("recvAio", rraio <- n1$recv_aio(mode = "double", timeout = 500))
131-
test_type("raw", call_aio(rraio)$data)
131+
test_type("raw", suppressWarnings(call_aio(rraio)$data))
132132
test_class("sendAio", sraio <- n$send_aio(as.raw(0L), mode = "raw", timeout = 500))
133133
test_class("recvAio", rraio <- n1$recv_aio(mode = "int", timeout = 500))
134-
test_type("raw", call_aio(rraio)$data)
134+
test_type("raw", suppressWarnings(call_aio(rraio)$data))
135135
test_class("sendAio", sraio <- n$send_aio(as.raw(0L), mode = "raw", timeout = 500))
136136
test_class("recvAio", rraio <- n1$recv_aio(mode = "logical", timeout = 500))
137-
test_type("raw", collect_aio(rraio))
137+
test_type("raw", suppressWarnings(collect_aio(rraio)))
138138
test_class("sendAio", sraio <- n$send_aio(as.raw(0L), mode = "raw", timeout = 500))
139139
test_class("recvAio", rraio <- n1$recv_aio(mode = "numeric", timeout = 500))
140-
test_type("raw", rraio[])
140+
test_type("raw", suppressWarnings(rraio[]))
141141
test_class("sendAio", sraio <- n$send_aio(as.raw(0L), mode = "raw", timeout = 500))
142142
test_class("recvAio", rraio <- n1$recv_aio(mode = "complex", timeout = 500))
143143
test_type("raw", suppressWarnings(collect_aio_(rraio)))
@@ -405,7 +405,7 @@ haio <- ncurl_aio("https://i.i")
405405
test_class("errorValue", call_aio(haio)$data)
406406
test_print(haio$data)
407407
ncaio <- ncurl_aio("https://shikokuchuo.net/nanonext/reference/figures/logo.png")
408-
if (call_aio(ncaio)$status == 200L) test_true(is.raw(ncaio$data))
408+
if (suppressWarnings(call_aio(ncaio)$status == 200L)) test_type("raw", ncaio$data)
409409
test_class("errorValue", ncurl_aio("http")$data)
410410
sess <- ncurl_session("https://postman-echo.com/post", method = "POST", headers = c(`Content-Type` = "text/plain"), data = "test", response = c("date", "Server"), timeout = 3000L)
411411
test_true(is_ncurl_session(sess) || is_error_value(sess))
@@ -468,14 +468,14 @@ is_nano(s) && {
468468
test_notnull(recv(s, mode = 9L, block = 100))
469469
test_type("integer", send(s, 2L, block = 500))
470470
test_class("recvAio", sr <- recv_aio(s, mode = "i", timeout = 500L, n = 8192L))
471-
test_notnull(call_aio(sr)[["data"]])
471+
test_notnull(suppressWarnings(call_aio(sr)[["data"]]))
472472
test_null(stop_aio(sr))
473473
test_class("sendAio", ss <- send_aio(s, "async", timeout = 500L))
474474
test_type("integer", ss[])
475475
test_null(stop_aio(ss))
476476
test_type("integer", send(s, 12.56, mode = "raw", block = 500L))
477477
test_class("recvAio", sr <- recv_aio(s, mode = "double", timeout = 500L, cv = cv))
478-
test_notnull(call_aio_(sr)[["data"]])
478+
test_notnull(suppressWarnings(call_aio_(sr)[["data"]]))
479479
test_true(cv_value(cv) > 0L)
480480
test_type("character", opt(s, "ws:request-headers"))
481481
test_notnull(opt(s, "tcp-nodelay") <- FALSE)

0 commit comments

Comments
 (0)