Skip to content

Commit 83d611c

Browse files
author
ripley
committed
start replacing Rboolean by bool in R sources
git-svn-id: https://svn.r-project.org/R/trunk@87848 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent af40a57 commit 83d611c

File tree

6 files changed

+151
-138
lines changed

6 files changed

+151
-138
lines changed

doc/NEWS.Rd

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -347,13 +347,14 @@
347347
different size this would be an ABI-breaking change (but we are
348348
unaware of any such platform).
349349
350-
\item There is a new function \code{asRboolean}, a variannt of
351-
\code{asLogical} more suited to converting logical arguments to
352-
\code{Rboolean}.
353-
354350
\item Header \file{R_ext/Boolean.h} now ensures a \code{bool} type
355351
is available either as a keyword (C23 and C++) or by including the
356-
C99 header \file{stdbool.h}.
352+
C99 header \file{stdbool.h}. This is used in places in \R itself
353+
to replace \code{Rboolean} by \code{bool}.
354+
355+
\item There are a new functions \code{asRboolean} and
356+
\code{asBool}, variannts of \code{asLogical} more suited to
357+
converting logical arguments to \code{Rboolean} or to \code{bool}.
357358
}
358359
}
359360

doc/manual/R-exts.texi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13180,7 +13180,8 @@ first.
1318013180
@code{Rf_aaRboolean} is a stricter version of @code{Rf_asLogical}
1318113181
introduced in @R{}@tie{}4.5.0. It returns type @code{Rboolean} and
1318213182
gives an error for an input of length other than one, and for
13183-
coercion failure.
13183+
coercion failure. @code{Rf_asBool} is a variant returning the
13184+
C99/C23/C++ type @code{bool}.
1318413185

1318513186
but gives an weeo
1318613187
@apifun Rf_asInteger
@@ -13189,6 +13190,7 @@ but gives an weeo
1318913190
@apifun Rf_asComplex
1319013191
@apifun Rf_asChar
1319113192
@apifun Rf_asRboolean
13193+
@apifun Rf_asBbool
1319213194
The function @code{Rf_asCharacterFactor} converts a factor to a character
1319313195
vector.
1319413196
@apifun Rf_asCharacterFactor

src/include/Rinternals.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ int Rf_asInteger(SEXP x);
488488
double Rf_asReal(SEXP x);
489489
Rcomplex Rf_asComplex(SEXP x);
490490
Rboolean Rf_asRboolean(SEXP x);
491+
bool Rf_asBool(SEXP x);
491492

492493

493494
// also included in R_ext/Rallocators.h
@@ -895,6 +896,7 @@ void R_orderVector1(int *indx, int n, SEXP x, Rboolean nalast, Rboolean de
895896
#define any_duplicated3 Rf_any_duplicated3
896897
#define applyClosure Rf_applyClosure
897898
#define arraySubscript Rf_arraySubscript
899+
#define asBool Rf_asRool
898900
#define asChar Rf_asChar
899901
#define asCharacterFactor Rf_asCharacterFactor
900902
#define asComplex Rf_asComplex

src/main/agrep.c

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ attribute_hidden SEXP do_agrep(SEXP call, SEXP op, SEXP args, SEXP env)
102102
int opt_icase, opt_value, opt_fixed, useBytes;
103103
R_xlen_t i, j, n;
104104
int nmatches, patlen;
105-
Rboolean useWC = FALSE;
105+
bool useWC = false;
106106
const void *vmax = NULL;
107107

108108
regex_t reg;
@@ -139,22 +139,22 @@ attribute_hidden SEXP do_agrep(SEXP call, SEXP op, SEXP args, SEXP env)
139139

140140
n = XLENGTH(vec);
141141
if(!useBytes) {
142-
Rboolean haveBytes = IS_BYTES(STRING_ELT(pat, 0));
142+
bool haveBytes = IS_BYTES(STRING_ELT(pat, 0));
143143
if(!haveBytes)
144144
for (i = 0; i < n; i++)
145145
if(IS_BYTES(STRING_ELT(vec, i))) {
146-
haveBytes = TRUE;
146+
haveBytes = true;
147147
break;
148148
}
149-
if(haveBytes) useBytes = TRUE;
149+
if(haveBytes) useBytes = true;
150150
}
151151
if(!useBytes) {
152152
useWC = !IS_ASCII(STRING_ELT(pat, 0));
153153
if(!useWC) {
154154
for (i = 0 ; i < n ; i++) {
155155
if(STRING_ELT(vec, i) == NA_STRING) continue;
156156
if(!IS_ASCII(STRING_ELT(vec, i))) {
157-
useWC = TRUE;
157+
useWC = true;
158158
break;
159159
}
160160
}
@@ -295,7 +295,7 @@ attribute_hidden SEXP do_agrep(SEXP call, SEXP op, SEXP args, SEXP env)
295295
#define MAT(X, I, J) X[I + (J) * nr]
296296

297297
static SEXP
298-
adist_full(SEXP x, SEXP y, double *costs, Rboolean opt_counts)
298+
adist_full(SEXP x, SEXP y, double *costs, bool opt_counts)
299299
{
300300
SEXP ans, counts, trafos = R_NilValue /* -Wall */, dimnames, names;
301301
double cost_ins, cost_del, cost_sub;
@@ -490,12 +490,12 @@ 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-
Rboolean opt_fixed, opt_partial, opt_counts, opt_icase, useBytes;
493+
bool 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;
497497

498-
Rboolean haveBytes, useWC = FALSE;
498+
bool haveBytes, useWC = false;
499499

500500
regex_t reg;
501501
regaparams_t params;
@@ -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 = 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);
512+
opt_counts = asBool2(CAR(args), call); args = CDR(args);
513+
opt_fixed = asBool2(CAR(args), call); args = CDR(args);
514+
opt_partial = asBool2(CAR(args), call); args = CDR(args);
515+
opt_icase = asBool2(CAR(args), call); args = CDR(args);
516+
useBytes = asBool2(CAR(args), call);
517517

518518
if(opt_counts == NA_INTEGER) opt_counts = 0;
519519
if(opt_fixed == NA_INTEGER) opt_fixed = 1;
@@ -541,37 +541,37 @@ attribute_hidden SEXP do_adist(SEXP call, SEXP op, SEXP args, SEXP env)
541541
nxy = nx * ny;
542542

543543
if(!useBytes) {
544-
haveBytes = FALSE;
544+
haveBytes = false;
545545
for(i = 0; i < nx; i++) {
546546
if(IS_BYTES(STRING_ELT(x, i))) {
547-
haveBytes = TRUE;
547+
haveBytes = true;
548548
break;
549549
}
550550
}
551551
if(!haveBytes) {
552552
for(j = 0; j < ny; j++) {
553553
if(IS_BYTES(STRING_ELT(y, j))) {
554-
haveBytes = TRUE;
554+
haveBytes = true;
555555
break;
556556
}
557557
}
558558
}
559-
if(haveBytes) useBytes = TRUE;
559+
if(haveBytes) useBytes = true;
560560
}
561561

562562
if(!useBytes) {
563563
for(i = 0; i < nx; i++) {
564564
if(STRING_ELT(x, i) == NA_STRING) continue;
565565
if(!IS_ASCII(STRING_ELT(x, i))) {
566-
useWC = TRUE;
566+
useWC = true;
567567
break;
568568
}
569569
}
570570
if(!useWC) {
571571
for(j = 0; j < ny; j++) {
572572
if(STRING_ELT(y, j) == NA_STRING) continue;
573573
if(!IS_ASCII(STRING_ELT(y, j))) {
574-
useWC = TRUE;
574+
useWC = true;
575575
break;
576576
}
577577
}
@@ -739,7 +739,7 @@ attribute_hidden SEXP do_aregexec(SEXP call, SEXP op, SEXP args, SEXP env)
739739
SEXP opt_bounds, opt_costs;
740740
int opt_icase, opt_fixed, useBytes;
741741

742-
Rboolean haveBytes, useWC = FALSE;
742+
bool haveBytes, useWC = false;
743743
const char *s, *t;
744744
const void *vmax = NULL;
745745

@@ -789,11 +789,11 @@ attribute_hidden SEXP do_aregexec(SEXP call, SEXP op, SEXP args, SEXP env)
789789
if(!haveBytes)
790790
for(R_xlen_t i = 0; i < n; i++) {
791791
if(IS_BYTES(STRING_ELT(vec, i))) {
792-
haveBytes = TRUE;
792+
haveBytes = true;
793793
break;
794794
}
795795
}
796-
if(haveBytes) useBytes = TRUE;
796+
if(haveBytes) useBytes = true;
797797
}
798798

799799
if(!useBytes) {
@@ -802,7 +802,7 @@ attribute_hidden SEXP do_aregexec(SEXP call, SEXP op, SEXP args, SEXP env)
802802
for(R_xlen_t i = 0 ; i < n ; i++) {
803803
if(STRING_ELT(vec, i) == NA_STRING) continue;
804804
if(!IS_ASCII(STRING_ELT(vec, i))) {
805-
useWC = TRUE;
805+
useWC = true;
806806
break;
807807
}
808808
}
@@ -891,7 +891,7 @@ attribute_hidden SEXP do_aregexec(SEXP call, SEXP op, SEXP args, SEXP env)
891891
setAttrib(matchpos, install("match.length"), matchlen);
892892
if(useBytes)
893893
setAttrib(matchpos, install("useBytes"),
894-
ScalarLogical(TRUE));
894+
ScalarLogical(true));
895895
SET_VECTOR_ELT(ans, i, matchpos);
896896
UNPROTECT(2);
897897
} else {

src/main/coerce.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1837,11 +1837,11 @@ bool asBool2(SEXP x, SEXP call)
18371837
{
18381838
int ans = asLogical2(x, 1, call);
18391839
if (ans == NA_LOGICAL)
1840-
errorcall(call, _("NA in coercion to Rboolean"));
1840+
errorcall(call, _("NA in coercion to bool"));
18411841
return (bool) ans;
18421842
}
18431843

1844-
// public version
1844+
// public versions
18451845
Rboolean asRboolean(SEXP x)
18461846
{
18471847
int ans = asLogical2(x, 1, R_NilValue);
@@ -1850,6 +1850,14 @@ Rboolean asRboolean(SEXP x)
18501850
return (Rboolean) ans;
18511851
}
18521852

1853+
bool asBool(SEXP x)
1854+
{
1855+
int ans = asLogical2(x, 1, R_NilValue);
1856+
if (ans == NA_LOGICAL)
1857+
error(_("NA in coercion to bool"));
1858+
return (bool) ans;
1859+
}
1860+
18531861

18541862
int asInteger(SEXP x)
18551863
{

0 commit comments

Comments
 (0)