Skip to content

Commit d5caf74

Browse files
author
ripley
committed
more uses of asRbool catching incorrect calls
git-svn-id: https://svn.r-project.org/R/trunk@87808 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent 2e7ed46 commit d5caf74

File tree

8 files changed

+29
-23
lines changed

8 files changed

+29
-23
lines changed

doc/NEWS.Rd

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
respective metadata.
4949
(Thanks to \I{Edzer Pebesma}.)
5050

51-
\item \code{grDevices::glyphInfo()} gains \code{rot} argument
51+
\item \code{grDevices::glyphInfo()} gains a \code{rot} argument
5252
to allow per-glyph rotation.
5353
(Thanks to \I{Daniel Sabanes Bove}.)
5454

@@ -633,6 +633,11 @@
633633
more thoroughly. The most commonly seen errors are in
634634
\code{unlink(, recursive)}, \code{tempdir()} and the \code{na.rm}
635635
argument of \code{max()}, \code{min()}, \code{sum()}, \dots.
636+
637+
\code{grep()} and similar took non-\code{TRUE} values of their logical
638+
arguments as \code{FALSE}, but these were almost always coding
639+
mistakes and are now reported as \code{NA}. [In progress, in place
640+
for \code{regexpr()].]
636641
}
637642
}
638643
}

src/main/Rdynload.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1470,7 +1470,7 @@ R_getSymbolInfo(SEXP sname, SEXP spackage, SEXP withRegistrationInfo)
14701470

14711471
if(f)
14721472
sym = createRSymbolObject(sname, f, &symbol,
1473-
LOGICAL(withRegistrationInfo)[0]);
1473+
asRbool(withRegistrationInfo, R_NilValue));
14741474

14751475
vmaxset(vmax);
14761476
return sym;

src/main/agrep.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ attribute_hidden SEXP do_adist(SEXP call, SEXP op, SEXP args, SEXP env)
490490
SEXP x, y;
491491
SEXP ans, counts, offsets, dimnames, names, elt;
492492
SEXP opt_costs;
493-
int opt_fixed, opt_partial, opt_counts, opt_icase, useBytes;
493+
Rboolean opt_fixed, opt_partial, opt_counts, opt_icase, useBytes;
494494
int i = 0, j = 0, m, nx, ny, nxy;
495495
const char *s, *t;
496496
const void *vmax = NULL;
@@ -509,11 +509,11 @@ attribute_hidden SEXP do_adist(SEXP call, SEXP op, SEXP args, SEXP env)
509509
x = CAR(args); args = CDR(args);
510510
y = CAR(args); args = CDR(args);
511511
opt_costs = CAR(args); args = CDR(args);
512-
opt_counts = asLogical(CAR(args)); args = CDR(args);
513-
opt_fixed = asInteger(CAR(args)); args = CDR(args);
514-
opt_partial = asInteger(CAR(args)); args = CDR(args);
515-
opt_icase = asLogical(CAR(args)); args = CDR(args);
516-
useBytes = asLogical(CAR(args));
512+
opt_counts = asRbool(CAR(args), call); args = CDR(args);
513+
opt_fixed = asRbool(CAR(args), call); args = CDR(args);
514+
opt_partial = asRbool(CAR(args), call); args = CDR(args);
515+
opt_icase = asRbool(CAR(args), call); args = CDR(args);
516+
useBytes = asRbool(CAR(args), call);
517517

518518
if(opt_counts == NA_INTEGER) opt_counts = 0;
519519
if(opt_fixed == NA_INTEGER) opt_fixed = 1;

src/main/character.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,9 @@ attribute_hidden SEXP do_nchar(SEXP call, SEXP op, SEXP args, SEXP env)
339339
int *s_ = INTEGER(s);
340340
for (R_xlen_t i = 0; i < len; i++) {
341341
SEXP sxi = STRING_ELT(x, i);
342-
int res = R_nchar(sxi, type_, allowNA, keepNA, NULL);
342+
// NA_LOGICAL has now been excluded
343+
int res = R_nchar(sxi, type_,
344+
(Rboolean) allowNA, (Rboolean) keepNA, NULL);
343345
switch(res) {
344346
case -1:
345347
error(_("invalid multibyte string, element %ld"), (long)i+1);

src/main/grep.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* R : A Computer Language for Statistical Data Analysis
3-
* Copyright (C) 1997--2024 The R Core Team
3+
* Copyright (C) 1997--2025 The R Core Team
44
* Copyright (C) 1995, 1996 Robert Gentleman and Ross Ihaka
55
*
66
* This program is free software; you can redistribute it and/or modify
@@ -2967,7 +2967,7 @@ attribute_hidden SEXP do_regexpr(SEXP call, SEXP op, SEXP args, SEXP env)
29672967
regex_t reg;
29682968
regmatch_t regmatch[10];
29692969
R_xlen_t i, n;
2970-
int rc, igcase_opt, perl_opt, fixed_opt, useBytes;
2970+
Rboolean rc, igcase_opt, perl_opt, fixed_opt, useBytes;
29712971
const char *spat = NULL; /* -Wall */
29722972
const wchar_t *wpat = NULL;
29732973
const char *s = NULL;
@@ -2994,14 +2994,10 @@ attribute_hidden SEXP do_regexpr(SEXP call, SEXP op, SEXP args, SEXP env)
29942994
checkArity(op, args);
29952995
pat = CAR(args); args = CDR(args);
29962996
text = CAR(args); args = CDR(args);
2997-
igcase_opt = asLogical(CAR(args)); args = CDR(args);
2998-
perl_opt = asLogical(CAR(args)); args = CDR(args);
2999-
fixed_opt = asLogical(CAR(args)); args = CDR(args);
3000-
useBytes = asLogical(CAR(args)); args = CDR(args);
3001-
if (igcase_opt == NA_INTEGER) igcase_opt = 0;
3002-
if (perl_opt == NA_INTEGER) perl_opt = 0;
3003-
if (fixed_opt == NA_INTEGER) fixed_opt = 0;
3004-
if (useBytes == NA_INTEGER) useBytes = 0;
2997+
igcase_opt = asRbool(CAR(args), call); args = CDR(args);
2998+
perl_opt = asRbool(CAR(args), call); args = CDR(args);
2999+
fixed_opt = asRbool(CAR(args), call); args = CDR(args);
3000+
useBytes = asRbool(CAR(args), call); args = CDR(args);
30053001
if (fixed_opt && igcase_opt)
30063002
warning(_("argument '%s' will be ignored"), "ignore.case = TRUE");
30073003
if (fixed_opt && perl_opt) {

src/main/summary.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ static R_INLINE SEXP real_mean(SEXP x)
484484
for (R_xlen_t k = 0; k < nbatch; k++)
485485
s += dx[k];
486486
});
487-
Rboolean finite_s = R_FINITE((double) s);
487+
Rboolean finite_s = R_FINITE((double) s) != 0; //isfinite returns non-zero
488488
if (finite_s) {
489489
s /= n;
490490
DbgP3("real_mean(): n=%g, s=%g\n", (double)n, s);

src/main/unique.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2307,7 +2307,7 @@ attribute_hidden SEXP do_sample2(SEXP call, SEXP op, SEXP args, SEXP env)
23072307
* Low Level Functions
23082308
*/
23092309

2310-
static int hash_identical(SEXP x, int K, int useCloEnv)
2310+
static int hash_identical(SEXP x, int K, Rboolean useCloEnv)
23112311
{
23122312
/* using 31 seems to work reasonably */
23132313
if (K == 0 || K > 31) K = 31;
@@ -2649,7 +2649,8 @@ attribute_hidden SEXP do_vhash(SEXP call, SEXP op, SEXP args, SEXP env)
26492649
SEXP sUseCloEnv = CADDR(args);
26502650

26512651
int K = sK == R_NilValue ? 31 : asInteger(sK);
2652-
int useCloEnv = sUseCloEnv == R_NilValue ? TRUE : asLogical(sUseCloEnv);
2652+
Rboolean useCloEnv =
2653+
(sUseCloEnv == R_NilValue) ? TRUE : asRbool(sUseCloEnv,call);
26532654

26542655
int val = hash_identical(x, K, useCloEnv);
26552656
return ScalarInteger(val);

src/main/util.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2838,7 +2838,9 @@ attribute_hidden SEXP do_findinterval(SEXP call, SEXP op, SEXP args, SEXP rho)
28382838
int n = LENGTH(xt);
28392839
if (n == NA_INTEGER) error(_("invalid '%s' argument"), "vec");
28402840
R_xlen_t nx = XLENGTH(x);
2841-
int sr = asLogical(right), si = asLogical(inside), lO = asLogical(leftOp);
2841+
Rboolean sr = asRbool(right, call),
2842+
si = asRbool(inside, call),
2843+
lO = asRbool(leftOp, call);
28422844
if (sr == NA_INTEGER)
28432845
error(_("invalid '%s' argument"), "rightmost.closed");
28442846
if (si == NA_INTEGER)

0 commit comments

Comments
 (0)