From 5ea59af0df405dbfe0b2bad8b0f3303168e3bc1a Mon Sep 17 00:00:00 2001 From: Davis Vaughan Date: Fri, 12 Jul 2024 12:08:00 +0200 Subject: [PATCH] Use read only pointer for atomic vectors in `R_compute_identical()` --- src/main/identical.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/identical.c b/src/main/identical.c index ad99f83d9e5..a126fcaec32 100644 --- a/src/main/identical.c +++ b/src/main/identical.c @@ -230,19 +230,19 @@ R_compute_identical(SEXP x, SEXP y, int flags) case LGLSXP: if (XLENGTH(x) != XLENGTH(y)) return FALSE; /* Use memcmp (which is ISO C90) to speed up the comparison */ - return memcmp((void *)LOGICAL(x), (void *)LOGICAL(y), + return memcmp((const void *)LOGICAL_RO(x), (const void *)LOGICAL_RO(y), xlength(x) * sizeof(int)) == 0 ? TRUE : FALSE; case INTSXP: if (XLENGTH(x) != XLENGTH(y)) return FALSE; /* Use memcmp (which is ISO C90) to speed up the comparison */ - return memcmp((void *)INTEGER(x), (void *)INTEGER(y), + return memcmp((const void *)INTEGER_RO(x), (const void *)INTEGER_RO(y), xlength(x) * sizeof(int)) == 0 ? TRUE : FALSE; case REALSXP: { R_xlen_t n = XLENGTH(x); if(n != XLENGTH(y)) return FALSE; else { - double *xp = REAL(x), *yp = REAL(y); + const double *xp = REAL_RO(x), *yp = REAL_RO(y); int ne_strict = NUM_EQ | (SINGLE_NA << 1); for(R_xlen_t i = 0; i < n; i++) if(neWithNaN(xp[i], yp[i], ne_strict)) return FALSE; @@ -254,7 +254,7 @@ R_compute_identical(SEXP x, SEXP y, int flags) R_xlen_t n = XLENGTH(x); if(n != XLENGTH(y)) return FALSE; else { - Rcomplex *xp = COMPLEX(x), *yp = COMPLEX(y); + const Rcomplex *xp = COMPLEX_RO(x), *yp = COMPLEX_RO(y); int ne_strict = NUM_EQ | (SINGLE_NA << 1); for(R_xlen_t i = 0; i < n; i++) if(neWithNaN(xp[i].r, yp[i].r, ne_strict) || @@ -345,7 +345,7 @@ R_compute_identical(SEXP x, SEXP y, int flags) case RAWSXP: if (XLENGTH(x) != XLENGTH(y)) return FALSE; /* Use memcmp (which is ISO C90) to speed up the comparison */ - return memcmp((void *)RAW(x), (void *)RAW(y), + return memcmp((const void *)RAW_RO(x), (const void *)RAW_RO(y), XLENGTH(x) * sizeof(Rbyte)) == 0 ? TRUE : FALSE; case PROMSXP: {