Skip to content

Commit

Permalink
suppressable conversion warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
shikokuchuo committed Sep 30, 2024
1 parent c4974c3 commit ce1dccc
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 29 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: nanonext
Type: Package
Title: NNG (Nanomsg Next Gen) Lightweight Messaging Library
Version: 1.2.1.9020
Version: 1.2.1.9021
Description: R binding for NNG (Nanomsg Next Gen), a successor to ZeroMQ. NNG is
a socket library implementing 'Scalability Protocols', a reliable,
high-performance standard for common communications patterns including
Expand Down
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# nanonext 1.2.1.9020 (development)
# nanonext 1.2.1.9021 (development)

#### New Features

Expand All @@ -7,6 +7,7 @@

#### Updates

* Warning messages for failure of unserialization or conversion of received message data are now suppressable.
* 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.
* Removes deprecated and defunct `next_config()`.
* Performance enhancements for `promises::as.promise()` methods.
Expand Down
14 changes: 7 additions & 7 deletions src/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ SEXP rawToChar(const unsigned char *buf, const size_t sz) {
int i, j;
for (i = 0, j = -1; i < sz; i++) if (buf[i]) j = i; else break;
if (sz - i > 1) {
nano_REprintf("data could not be converted to a character string\n");
Rf_warningcall_immediate(R_NilValue, "data could not be converted to a character string");
out = Rf_allocVector(RAWSXP, sz);
memcpy(NANO_DATAPTR(out), buf, sz);
return out;
Expand Down Expand Up @@ -445,7 +445,7 @@ SEXP nano_unserialize(unsigned char *buf, const size_t sz, SEXP hook) {
}
}

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

resume: ;
Expand Down Expand Up @@ -500,7 +500,7 @@ SEXP nano_decode(unsigned char *buf, const size_t sz, const uint8_t mod, SEXP ho
case 3:
size = 2 * sizeof(double);
if (sz % size) {
nano_REprintf("received data could not be converted to complex\n");
Rf_warningcall_immediate(R_NilValue, "received data could not be converted to complex");
data = Rf_allocVector(RAWSXP, sz);
} else {
data = Rf_allocVector(CPLXSXP, sz / size);
Expand All @@ -509,7 +509,7 @@ SEXP nano_decode(unsigned char *buf, const size_t sz, const uint8_t mod, SEXP ho
case 4:
size = sizeof(double);
if (sz % size) {
nano_REprintf("received data could not be converted to double\n");
Rf_warningcall_immediate(R_NilValue, "received data could not be converted to double");
data = Rf_allocVector(RAWSXP, sz);
} else {
data = Rf_allocVector(REALSXP, sz / size);
Expand All @@ -518,7 +518,7 @@ SEXP nano_decode(unsigned char *buf, const size_t sz, const uint8_t mod, SEXP ho
case 5:
size = sizeof(int);
if (sz % size) {
nano_REprintf("received data could not be converted to integer\n");
Rf_warningcall_immediate(R_NilValue, "received data could not be converted to integer");
data = Rf_allocVector(RAWSXP, sz);
} else {
data = Rf_allocVector(INTSXP, sz / size);
Expand All @@ -527,7 +527,7 @@ SEXP nano_decode(unsigned char *buf, const size_t sz, const uint8_t mod, SEXP ho
case 6:
size = sizeof(int);
if (sz % size) {
nano_REprintf("received data could not be converted to logical\n");
Rf_warningcall_immediate(R_NilValue, "received data could not be converted to logical");
data = Rf_allocVector(RAWSXP, sz);
} else {
data = Rf_allocVector(LGLSXP, sz / size);
Expand All @@ -536,7 +536,7 @@ SEXP nano_decode(unsigned char *buf, const size_t sz, const uint8_t mod, SEXP ho
case 7:
size = sizeof(double);
if (sz % size) {
nano_REprintf("received data could not be converted to numeric\n");
Rf_warningcall_immediate(R_NilValue, "received data could not be converted to numeric");
data = Rf_allocVector(RAWSXP, sz);
} else {
data = Rf_allocVector(REALSXP, sz / size);
Expand Down
1 change: 0 additions & 1 deletion src/nanonext.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,6 @@ int nano_encodes(const SEXP);
int nano_matcharg(const SEXP);
int nano_matchargs(const SEXP);

void nano_REprintf(const char *);
void pipe_cb_signal(nng_pipe, nng_pipe_ev, void *);

SEXP rnng_advance_rng_state(void);
Expand Down
6 changes: 0 additions & 6 deletions src/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@
#define NANONEXT_IO
#include "nanonext.h"

void nano_REprintf(const char *fmt) {

if (write(STDERR_FILENO, fmt, strlen(fmt))) {} ;

}

// messenger -------------------------------------------------------------------

// # nocov start
Expand Down
10 changes: 5 additions & 5 deletions src/tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ SEXP rnng_write_cert(SEXP cn, SEXP valid, SEXP inter) {
snprintf(issuer_name, clen, "CN=%s,O=Nanonext,C=JP", common);

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

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

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

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

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

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

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

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

exitlevel1:
Expand Down
16 changes: 8 additions & 8 deletions tests/tests.R
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ test_class("errorValue", msg$data)
test_identical(call_aio(n), n)
test_class("sendAio", sraio <- n$send_aio(as.raw(0L), mode = "r", timeout = 500))
test_class("recvAio", rraio <- n1$recv_aio(mode = 1L, timeout = 500))
test_true(is_nul_byte(call_aio_(rraio)$data))
test_true(is_nul_byte(suppressWarnings(call_aio_(rraio)$data)))
test_class("sendAio", sraio <- n$send_aio(as.raw(1L), mode = "ra", timeout = 500))
test_class("recvAio", rraio <- n1$recv_aio(mode = "raw", timeout = 500))
test_type("raw", call_aio(rraio)$data)
Expand All @@ -128,16 +128,16 @@ test_class("recvAio", rraio <- n1$recv_aio(mode = "i", timeout = 500))
test_type("integer", call_aio(rraio)$data)
test_class("sendAio", sraio <- n$send_aio(as.raw(0L), mode = "raw", timeout = 500))
test_class("recvAio", rraio <- n1$recv_aio(mode = "double", timeout = 500))
test_type("raw", call_aio(rraio)$data)
test_type("raw", suppressWarnings(call_aio(rraio)$data))
test_class("sendAio", sraio <- n$send_aio(as.raw(0L), mode = "raw", timeout = 500))
test_class("recvAio", rraio <- n1$recv_aio(mode = "int", timeout = 500))
test_type("raw", call_aio(rraio)$data)
test_type("raw", suppressWarnings(call_aio(rraio)$data))
test_class("sendAio", sraio <- n$send_aio(as.raw(0L), mode = "raw", timeout = 500))
test_class("recvAio", rraio <- n1$recv_aio(mode = "logical", timeout = 500))
test_type("raw", collect_aio(rraio))
test_type("raw", suppressWarnings(collect_aio(rraio)))
test_class("sendAio", sraio <- n$send_aio(as.raw(0L), mode = "raw", timeout = 500))
test_class("recvAio", rraio <- n1$recv_aio(mode = "numeric", timeout = 500))
test_type("raw", rraio[])
test_type("raw", suppressWarnings(rraio[]))
test_class("sendAio", sraio <- n$send_aio(as.raw(0L), mode = "raw", timeout = 500))
test_class("recvAio", rraio <- n1$recv_aio(mode = "complex", timeout = 500))
test_type("raw", suppressWarnings(collect_aio_(rraio)))
Expand Down Expand Up @@ -405,7 +405,7 @@ haio <- ncurl_aio("https://i.i")
test_class("errorValue", call_aio(haio)$data)
test_print(haio$data)
ncaio <- ncurl_aio("https://shikokuchuo.net/nanonext/reference/figures/logo.png")
if (call_aio(ncaio)$status == 200L) test_true(is.raw(ncaio$data))
if (suppressWarnings(call_aio(ncaio)$status == 200L)) test_type("raw", ncaio$data)
test_class("errorValue", ncurl_aio("http")$data)
sess <- ncurl_session("https://postman-echo.com/post", method = "POST", headers = c(`Content-Type` = "text/plain"), data = "test", response = c("date", "Server"), timeout = 3000L)
test_true(is_ncurl_session(sess) || is_error_value(sess))
Expand Down Expand Up @@ -468,14 +468,14 @@ is_nano(s) && {
test_notnull(recv(s, mode = 9L, block = 100))
test_type("integer", send(s, 2L, block = 500))
test_class("recvAio", sr <- recv_aio(s, mode = "i", timeout = 500L, n = 8192L))
test_notnull(call_aio(sr)[["data"]])
test_notnull(suppressWarnings(call_aio(sr)[["data"]]))
test_null(stop_aio(sr))
test_class("sendAio", ss <- send_aio(s, "async", timeout = 500L))
test_type("integer", ss[])
test_null(stop_aio(ss))
test_type("integer", send(s, 12.56, mode = "raw", block = 500L))
test_class("recvAio", sr <- recv_aio(s, mode = "double", timeout = 500L, cv = cv))
test_notnull(call_aio_(sr)[["data"]])
test_notnull(suppressWarnings(call_aio_(sr)[["data"]]))
test_true(cv_value(cv) > 0L)
test_type("character", opt(s, "ws:request-headers"))
test_notnull(opt(s, "tcp-nodelay") <- FALSE)
Expand Down

0 comments on commit ce1dccc

Please sign in to comment.