From b921b7ed820d36232eb3fffcced3da3d736a5b6e Mon Sep 17 00:00:00 2001 From: shikokuchuo <53399081+shikokuchuo@users.noreply.github.com> Date: Thu, 16 Jan 2025 12:25:31 +0000 Subject: [PATCH] remove use of SB_STRING macro --- src/base.c | 6 +++--- src/secret.c | 6 +++--- src/secret.h | 3 +-- src/secret2.c | 8 ++++---- src/secret3.c | 8 ++++---- 5 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/base.c b/src/base.c index 6a357a2..329f02f 100644 --- a/src/base.c +++ b/src/base.c @@ -1,4 +1,4 @@ -// Copyright (C) 2024 Hibiki AI Limited +// Copyright (C) 2024-2025 Hibiki AI Limited // // This file is part of secretbase. // @@ -338,7 +338,7 @@ static nano_buf sb_any_buf(const SEXP x) { switch (TYPEOF(x)) { case STRSXP: if (XLENGTH(x) == 1 && !ANY_ATTRIB(x)) { - const char *s = SB_STRING(x); + const char *s = CHAR(*STRING_PTR_RO(x)); NANO_INIT(&buf, (unsigned char *) s, strlen(s)); break; } @@ -398,7 +398,7 @@ SEXP secretbase_base64dec(SEXP x, SEXP convert) { switch (TYPEOF(x)) { case STRSXP: ; - const char *str = SB_STRING(x); + const char *str = CHAR(*STRING_PTR_RO(x)); inbuf = (unsigned char *) str; inlen = strlen(str); break; diff --git a/src/secret.c b/src/secret.c index ea36ef1..a423dc1 100644 --- a/src/secret.c +++ b/src/secret.c @@ -1,4 +1,4 @@ -// Copyright (C) 2024 Hibiki AI Limited +// Copyright (C) 2024-2025 Hibiki AI Limited // // This file is part of secretbase. // @@ -250,7 +250,7 @@ static inline void hash_bytes(R_outpstream_t stream, void *src, int len) { static void hash_file(mbedtls_sha3_context *ctx, const SEXP x) { SB_ASSERT_STR(x); - const char *file = R_ExpandFileName(SB_STRING(x)); + const char *file = R_ExpandFileName(CHAR(*STRING_PTR_RO(x))); unsigned char buf[SB_BUF_SIZE]; FILE *f; size_t cur; @@ -277,7 +277,7 @@ static void hash_object(mbedtls_sha3_context *ctx, const SEXP x) { switch (TYPEOF(x)) { case STRSXP: if (XLENGTH(x) == 1 && !ANY_ATTRIB(x)) { - const char *s = SB_STRING(x); + const char *s = CHAR(*STRING_PTR_RO(x)); mbedtls_sha3_update(ctx, (uint8_t *) s, strlen(s)); return; } diff --git a/src/secret.h b/src/secret.h index 8902f95..203c0b6 100644 --- a/src/secret.h +++ b/src/secret.h @@ -1,4 +1,4 @@ -// Copyright (C) 2024 Hibiki AI Limited +// Copyright (C) 2024-2025 Hibiki AI Limited // // This file is part of secretbase. // @@ -104,7 +104,6 @@ typedef struct nano_buf_s { #define ANY_ATTRIB(x) (ATTRIB(x) != R_NilValue) #endif #define SB_DATAPTR(x) (void *) DATAPTR_RO(x) -#define SB_STRING(x) CHAR(*((const SEXP *) DATAPTR_RO(x))) #define SB_LOGICAL(x) *(int *) DATAPTR_RO(x) #define SB_ASSERT_LOGICAL(x) if (TYPEOF(x) != LGLSXP) \ Rf_error("'convert' must be a logical value") diff --git a/src/secret2.c b/src/secret2.c index fef30ae..3b44cc3 100644 --- a/src/secret2.c +++ b/src/secret2.c @@ -1,4 +1,4 @@ -// Copyright (C) 2024 Hibiki AI Limited +// Copyright (C) 2024-2025 Hibiki AI Limited // // This file is part of secretbase. // @@ -385,7 +385,7 @@ static inline void hash_bytes(R_outpstream_t stream, void *src, int len) { static void hash_file(mbedtls_sha256_context *ctx, const SEXP x) { SB_ASSERT_STR(x); - const char *file = R_ExpandFileName(SB_STRING(x)); + const char *file = R_ExpandFileName(CHAR(*STRING_PTR_RO(x))); unsigned char buf[SB_BUF_SIZE]; FILE *f; size_t cur; @@ -412,7 +412,7 @@ static void hash_object(mbedtls_sha256_context *ctx, const SEXP x) { switch (TYPEOF(x)) { case STRSXP: if (XLENGTH(x) == 1 && !ANY_ATTRIB(x)) { - const char *s = SB_STRING(x); + const char *s = CHAR(*STRING_PTR_RO(x)); mbedtls_sha256_update(ctx, (uint8_t *) s, strlen(s)); return; } @@ -470,7 +470,7 @@ static SEXP secretbase_sha256_impl(const SEXP x, const SEXP key, const SEXP conv switch (TYPEOF(key)) { case STRSXP: - data = (unsigned char *) (XLENGTH(key) ? SB_STRING(key) : ""); + data = (unsigned char *) (XLENGTH(key) ? CHAR(*STRING_PTR_RO(key)) : ""); klen = strlen((char *) data); break; case RAWSXP: diff --git a/src/secret3.c b/src/secret3.c index b3ceec2..e36fd77 100644 --- a/src/secret3.c +++ b/src/secret3.c @@ -1,4 +1,4 @@ -// Copyright (C) 2024 Hibiki AI Limited +// Copyright (C) 2024-2025 Hibiki AI Limited // // This file is part of secretbase. // @@ -192,7 +192,7 @@ static inline void hash_bytes(R_outpstream_t stream, void *src, int len) { static void hash_file(CSipHash *ctx, const SEXP x) { SB_ASSERT_STR(x); - const char *file = R_ExpandFileName(SB_STRING(x)); + const char *file = R_ExpandFileName(CHAR(*STRING_PTR_RO(x))); unsigned char buf[SB_BUF_SIZE]; FILE *f; size_t cur; @@ -217,7 +217,7 @@ static void hash_object(CSipHash *ctx, const SEXP x) { switch (TYPEOF(x)) { case STRSXP: if (XLENGTH(x) == 1 && !ANY_ATTRIB(x)) { - const char *s = SB_STRING(x); + const char *s = CHAR(*STRING_PTR_RO(x)); c_siphash_append(ctx, (uint8_t *) s, strlen(s)); return; } @@ -266,7 +266,7 @@ static SEXP secretbase_siphash_impl(const SEXP x, const SEXP key, const SEXP con size_t klen; switch (TYPEOF(key)) { case STRSXP: - data = (unsigned char *) (XLENGTH(key) ? SB_STRING(key) : ""); + data = (unsigned char *) (XLENGTH(key) ? CHAR(*STRING_PTR_RO(key)) : ""); klen = strlen((char *) data); break; case RAWSXP: