Skip to content

Commit

Permalink
remove use of SB_STRING macro
Browse files Browse the repository at this point in the history
  • Loading branch information
shikokuchuo committed Jan 16, 2025
1 parent 6a5a217 commit b921b7e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/base.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2024 Hibiki AI Limited <[email protected]>
// Copyright (C) 2024-2025 Hibiki AI Limited <[email protected]>
//
// This file is part of secretbase.
//
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/secret.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2024 Hibiki AI Limited <[email protected]>
// Copyright (C) 2024-2025 Hibiki AI Limited <[email protected]>
//
// This file is part of secretbase.
//
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
3 changes: 1 addition & 2 deletions src/secret.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2024 Hibiki AI Limited <[email protected]>
// Copyright (C) 2024-2025 Hibiki AI Limited <[email protected]>
//
// This file is part of secretbase.
//
Expand Down Expand Up @@ -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")
Expand Down
8 changes: 4 additions & 4 deletions src/secret2.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2024 Hibiki AI Limited <[email protected]>
// Copyright (C) 2024-2025 Hibiki AI Limited <[email protected]>
//
// This file is part of secretbase.
//
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions src/secret3.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2024 Hibiki AI Limited <[email protected]>
// Copyright (C) 2024-2025 Hibiki AI Limited <[email protected]>
//
// This file is part of secretbase.
//
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit b921b7e

Please sign in to comment.