Skip to content

Commit 3bee0a1

Browse files
author
ripley
committed
more taking care over Rboolean
git-svn-id: https://svn.r-project.org/R/trunk@87813 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent eb1cf88 commit 3bee0a1

File tree

17 files changed

+73
-68
lines changed

17 files changed

+73
-68
lines changed

src/include/Rinlinedfuns.h

Lines changed: 5 additions & 3 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) 1999-2024 The R Core Team.
3+
* Copyright (C) 1999-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
@@ -334,11 +334,13 @@ INLINE_FUN R_xlen_t XTRUELENGTH(SEXP x)
334334
CHECK_STDVEC_LGL(x);
335335
return (int *) STDVEC_DATAPTR(x);
336336
}
337-
HIDDEN INLINE_FUN Rboolean SCALAR_LVAL(SEXP x) {
337+
/* This should not be Rboolean as could be NA_LOGICAL */
338+
HIDDEN INLINE_FUN int SCALAR_LVAL(SEXP x) {
338339
CHECK_SCALAR_LGL(x);
339340
return LOGICAL(x)[0];
340341
}
341-
HIDDEN INLINE_FUN void SET_SCALAR_LVAL(SEXP x, Rboolean v) {
342+
/* ditto */
343+
HIDDEN INLINE_FUN void SET_SCALAR_LVAL(SEXP x, int v) {
342344
CHECK_SCALAR_LGL(x);
343345
LOGICAL(x)[0] = v;
344346
}

src/main/array.c

Lines changed: 7 additions & 7 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) 1998-2023 The R Core Team
3+
* Copyright (C) 1998-2025 The R Core Team
44
* Copyright (C) 2002-2015 The R Foundation
55
* Copyright (C) 1995, 1996 Robert Gentleman and Ross Ihaka
66
*
@@ -82,7 +82,7 @@ SEXP GetColNames(SEXP dimnames)
8282
attribute_hidden SEXP do_matrix(SEXP call, SEXP op, SEXP args, SEXP rho)
8383
{
8484
SEXP vals, ans, snr, snc, dimnames;
85-
int nr = 1, nc = 1, byrow, miss_nr, miss_nc;
85+
int nr = 1, nc = 1, byrow0, miss_nr, miss_nc;
8686
R_xlen_t lendat;
8787

8888
checkArity(op, args);
@@ -104,9 +104,10 @@ attribute_hidden SEXP do_matrix(SEXP call, SEXP op, SEXP args, SEXP rho)
104104
lendat = XLENGTH(vals);
105105
snr = CAR(args); args = CDR(args);
106106
snc = CAR(args); args = CDR(args);
107-
byrow = asLogical(CAR(args)); args = CDR(args);
108-
if (byrow == NA_INTEGER)
107+
byrow0 = asLogical(CAR(args)); args = CDR(args);
108+
if (byrow0 == NA_INTEGER)
109109
error(_("invalid '%s' argument"), "byrow");
110+
Rboolean byrow = (Rboolean) byrow0;
110111
dimnames = CAR(args);
111112
args = CDR(args);
112113
miss_nr = asLogical(CAR(args)); args = CDR(args);
@@ -1898,19 +1899,18 @@ attribute_hidden SEXP do_colsum(SEXP call, SEXP op, SEXP args, SEXP rho)
18981899
{
18991900
SEXP x, ans = R_NilValue;
19001901
int type;
1901-
Rboolean NaRm, keepNA;
19021902

19031903
checkArity(op, args);
19041904
x = CAR(args); args = CDR(args);
19051905
R_xlen_t n = asVecSize(CAR(args)); args = CDR(args);
19061906
R_xlen_t p = asVecSize(CAR(args)); args = CDR(args);
1907-
NaRm = asLogical(CAR(args));
1907+
int NaRm = asLogical(CAR(args));
19081908
if (n == NA_INTEGER || n < 0)
19091909
error(_("invalid '%s' argument"), "n");
19101910
if (p == NA_INTEGER || p < 0)
19111911
error(_("invalid '%s' argument"), "p");
19121912
if (NaRm == NA_LOGICAL) error(_("invalid '%s' argument"), "na.rm");
1913-
keepNA = !NaRm;
1913+
Rboolean keepNA = !NaRm;
19141914

19151915
switch (type = TYPEOF(x)) {
19161916
case LGLSXP:

src/main/attrib.c

Lines changed: 2 additions & 2 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
@@ -746,7 +746,7 @@ static SEXP S4_extends(SEXP klass, Rboolean use_tab) {
746746

747747
attribute_hidden SEXP R_S4_extends(SEXP klass, SEXP useTable)
748748
{
749-
return S4_extends(klass, asLogical(useTable));
749+
return S4_extends(klass, asRbool(useTable, R_NilValue));
750750
}
751751

752752

src/main/bind.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ static SEXP c_Extract_opt(SEXP ans, Rboolean *recurse, Rboolean *usenames,
738738
if (n_recurse++ == 1)
739739
errorcall(call, _("repeated formal argument 'recursive'"));
740740
if ((v = asLogical(CAR(a))) != NA_INTEGER) {
741-
*recurse = v;
741+
*recurse = (Rboolean) v;
742742
}
743743
if (last == NULL)
744744
ans = next;
@@ -749,7 +749,7 @@ static SEXP c_Extract_opt(SEXP ans, Rboolean *recurse, Rboolean *usenames,
749749
if (n_usenames++ == 1)
750750
errorcall(call, _("repeated formal argument 'use.names'"));
751751
if ((v = asLogical(CAR(a))) != NA_INTEGER) {
752-
*usenames = v;
752+
*usenames = (Rboolean) v;
753753
}
754754
if (last == NULL)
755755
ans = next;

src/main/coerce.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,7 +1829,7 @@ Rboolean asRbool(SEXP x, SEXP call)
18291829
int ans = asLogical2(x, 1, call);
18301830
if (ans == NA_LOGICAL)
18311831
errorcall(call, _("NA in coercion to Rboolean"));
1832-
return ans;
1832+
return (Rboolean) ans;
18331833
}
18341834

18351835

@@ -2362,9 +2362,10 @@ static Rboolean anyNA(SEXP call, SEXP op, SEXP args, SEXP env)
23622362
{
23632363
SEXP x = CAR(args);
23642364
SEXPTYPE xT = TYPEOF(x);
2365-
Rboolean isList = (xT == VECSXP || xT == LISTSXP), recursive = FALSE;
2365+
Rboolean isList = (Rboolean) (xT == VECSXP || xT == LISTSXP),
2366+
recursive = FALSE;
23662367

2367-
if (isList && length(args) > 1) recursive = asLogical(CADR(args));
2368+
if (isList && length(args) > 1) recursive = asRbool(CADR(args), call);
23682369
if (OBJECT(x) || (isList && !recursive)) {
23692370
SEXP e0 = PROTECT(lang2(install("is.na"), x));
23702371
SEXP e = PROTECT(lang2(install("any"), e0));

src/main/datetime.c

Lines changed: 2 additions & 2 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) 2000-2024 The R Core Team.
3+
* Copyright (C) 2000-2025 The R Core Team.
44
*
55
* This program is free software; you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -1652,7 +1652,7 @@ attribute_hidden SEXP do_D2POSIXlt(SEXP call, SEXP op, SEXP args, SEXP env)
16521652
for(R_xlen_t i = 0; i < n; i++) {
16531653
stm tm;
16541654
double x_i = REAL(x)[i];
1655-
Rboolean valid = R_FINITE(x_i);
1655+
Rboolean valid = R_FINITE(x_i) != 0;
16561656
if(valid) {
16571657
/* every 400 years is exactly 146097 days long and the
16581658
pattern is repeated */

src/main/debug.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ attribute_hidden SEXP do_traceOnOff(SEXP call, SEXP op, SEXP args, SEXP rho)
105105
if(length(onOff) > 0) {
106106
int _new = asLogical(onOff);
107107
if(_new == TRUE || _new == FALSE)
108-
if(trace) SET_TRACE_STATE(_new);
109-
else SET_DEBUG_STATE(_new);
108+
if(trace) SET_TRACE_STATE((Rboolean) _new);
109+
else SET_DEBUG_STATE((Rboolean) _new);
110110
else
111111
error(_("Value for '%s' must be TRUE or FALSE"),
112112
trace ? "tracingState" : "debuggingState");

src/main/deparse.c

Lines changed: 4 additions & 4 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--2023 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
@@ -178,7 +178,7 @@ attribute_hidden SEXP do_deparse(SEXP call, SEXP op, SEXP args, SEXP rho)
178178
}
179179
}
180180
args = CDR(args);
181-
int backtick = isNull(CAR(args)) ? 0 : asLogical(CAR(args));
181+
Rboolean backtick = isNull(CAR(args)) ? 0 : asRbool(CAR(args), call);
182182
args = CDR(args);
183183
int opts = isNull(CAR(args)) ? SHOWATTRIBUTES : asInteger(CAR(args));
184184
args = CDR(args);
@@ -734,7 +734,7 @@ static attr_type attr1(SEXP s, LocalParseData *d)
734734
SEXP a = ATTRIB(s), nm = getAttrib(s, R_NamesSymbol);
735735
attr_type attr = UNKNOWN;
736736
Rboolean
737-
nice_names = d->opts & NICE_NAMES,
737+
nice_names = (Rboolean) (d->opts & NICE_NAMES),
738738
show_attr = d->opts & SHOWATTRIBUTES,
739739
has_names = !isNull(nm), ok_names;
740740
#ifdef DEBUG_DEPARSE
@@ -1633,7 +1633,7 @@ static void vector2buff(SEXP vector, LocalParseData *d)
16331633
}
16341634

16351635
SEXP nv = R_NilValue;
1636-
Rboolean do_names = d_opts_in & SHOW_ATTR_OR_NMS;// iff TRUE use '<tag_i> = <comp_i>'
1636+
Rboolean do_names = (Rboolean)(d_opts_in & SHOW_ATTR_OR_NMS);// iff TRUE use '<tag_i> = <comp_i>'
16371637
if(do_names) {
16381638
nv = getAttrib(vector, R_NamesSymbol); // only "do names" if have names:
16391639
if(isNull(nv))

src/main/eval.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2639,13 +2639,13 @@ static SEXP replaceCall(SEXP fun, SEXP val, SEXP args, SEXP rhs)
26392639

26402640
static R_INLINE Rboolean asLogicalNoNA(SEXP s, SEXP call)
26412641
{
2642-
Rboolean cond = NA_LOGICAL;
2642+
int cond = NA_LOGICAL; // cannot be Rboolean
26432643

26442644
/* handle most common special case directly */
26452645
if (IS_SCALAR(s, LGLSXP)) {
26462646
cond = SCALAR_LVAL(s);
26472647
if (cond != NA_LOGICAL)
2648-
return cond;
2648+
return (Rboolean) cond;
26492649
}
26502650
else if (IS_SCALAR(s, INTSXP)) {
26512651
int val = SCALAR_IVAL(s);
@@ -6908,9 +6908,9 @@ static R_INLINE Rboolean GETSTACK_LOGICAL_NO_NA_PTR(R_bcstack_t *s, int callidx,
69086908

69096909
SEXP value = GETSTACK_PTR(s);
69106910
if (IS_SCALAR(value, LGLSXP)) {
6911-
Rboolean lval = SCALAR_LVAL(value);
6911+
int lval = SCALAR_LVAL(value);
69126912
if (lval != NA_LOGICAL)
6913-
return lval;
6913+
return (Rboolean) lval;
69146914
}
69156915
SEXP call = GETCONST(constants, callidx);
69166916
PROTECT(value);
@@ -6924,7 +6924,7 @@ static R_INLINE Rboolean GETSTACK_LOGICAL_PTR(R_bcstack_t *s)
69246924
{
69256925
if (s->tag == LGLSXP) return s->u.ival;
69266926
SEXP value = GETSTACK_PTR(s);
6927-
return SCALAR_LVAL(value);
6927+
return SCALAR_LVAL(value); //what about NA_LOGICAL?
69286928
}
69296929

69306930
/* Find locations table in the constant pool */

src/main/grep.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2119,7 +2119,7 @@ attribute_hidden SEXP do_gsub(SEXP call, SEXP op, SEXP args, SEXP env)
21192119

21202120
checkArity(op, args);
21212121

2122-
global = PRIMVAL(op);
2122+
global = (Rboolean) PRIMVAL(op);
21232123

21242124
pat = CAR(args); args = CDR(args);
21252125
rep = CAR(args); args = CDR(args);

0 commit comments

Comments
 (0)