Skip to content

Commit

Permalink
use ANY_ATTRIB
Browse files Browse the repository at this point in the history
  • Loading branch information
shikokuchuo committed Sep 8, 2024
1 parent 3335770 commit 6e23b46
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,14 +337,14 @@ static nano_buf sb_any_buf(const SEXP x) {

switch (TYPEOF(x)) {
case STRSXP:
if (XLENGTH(x) == 1 && ATTRIB(x) == R_NilValue) {
if (XLENGTH(x) == 1 && !ANY_ATTRIB(x)) {
const char *s = SB_STRING(x);
NANO_INIT(&buf, (unsigned char *) s, strlen(s));
goto resume;
}
break;
case RAWSXP:
if (ATTRIB(x) == R_NilValue) {
if (!ANY_ATTRIB(x)) {
NANO_INIT(&buf, (unsigned char *) DATAPTR_RO(x), XLENGTH(x));
goto resume;
}
Expand Down
4 changes: 2 additions & 2 deletions src/secret.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,14 +276,14 @@ static void hash_object(mbedtls_sha3_context *ctx, const SEXP x) {

switch (TYPEOF(x)) {
case STRSXP:
if (XLENGTH(x) == 1 && ATTRIB(x) == R_NilValue) {
if (XLENGTH(x) == 1 && !ANY_ATTRIB(x)) {
const char *s = SB_STRING(x);
mbedtls_sha3_update(ctx, (uint8_t *) s, strlen(s));
return;
}
break;
case RAWSXP:
if (ATTRIB(x) == R_NilValue) {
if (!ANY_ATTRIB(x)) {
mbedtls_sha3_update(ctx, (uint8_t *) DATAPTR_RO(x), (size_t) XLENGTH(x));
return;
}
Expand Down
4 changes: 4 additions & 0 deletions src/secret.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
#include <Rinternals.h>
#include <R_ext/Visibility.h>

#ifndef ANY_ATTRIB
#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)
Expand Down
4 changes: 2 additions & 2 deletions src/secret2.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,14 +411,14 @@ static void hash_object(mbedtls_sha256_context *ctx, const SEXP x) {

switch (TYPEOF(x)) {
case STRSXP:
if (XLENGTH(x) == 1 && ATTRIB(x) == R_NilValue) {
if (XLENGTH(x) == 1 && !ANY_ATTRIB(x)) {
const char *s = SB_STRING(x);
mbedtls_sha256_update(ctx, (uint8_t *) s, strlen(s));
return;
}
break;
case RAWSXP:
if (ATTRIB(x) == R_NilValue) {
if (!ANY_ATTRIB(x)) {
mbedtls_sha256_update(ctx, (uint8_t *) DATAPTR_RO(x), (size_t) XLENGTH(x));
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/secret3.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,14 @@ static void hash_object(CSipHash *ctx, const SEXP x) {

switch (TYPEOF(x)) {
case STRSXP:
if (XLENGTH(x) == 1 && ATTRIB(x) == R_NilValue) {
if (XLENGTH(x) == 1 && !ANY_ATTRIB(x)) {
const char *s = SB_STRING(x);
c_siphash_append(ctx, (uint8_t *) s, strlen(s));
return;
}
break;
case RAWSXP:
if (ATTRIB(x) == R_NilValue) {
if (!ANY_ATTRIB(x)) {
c_siphash_append(ctx, (uint8_t *) DATAPTR_RO(x), (size_t) XLENGTH(x));
return;
}
Expand Down

0 comments on commit 6e23b46

Please sign in to comment.