Skip to content

Commit

Permalink
reduce use of Rboolean in front-ends interface
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.r-project.org/R/trunk@87861 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information
ripley committed Mar 2, 2025
1 parent 874d3d8 commit 40e5571
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 27 deletions.
12 changes: 7 additions & 5 deletions src/include/Defn.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* R : A Computer Language for Statistical Data Analysis
* Copyright (C) 1998--2024 The R Core Team.
* Copyright (C) 1998--2025 The R Core Team.
* Copyright (C) 1995, 1996 Robert Gentleman and Ross Ihaka
*
* This program is free software; you can redistribute it and/or modify
Expand All @@ -18,7 +18,7 @@
* https://www.R-project.org/Licenses/
*/

/* Internal header, not installed */
/* Internal header, not installed, usied in some standard packages */

#ifndef DEFN_H_
#define DEFN_H_
Expand Down Expand Up @@ -1521,10 +1521,12 @@ extern0 struct RPRSTACK *R_PendingPromises INI_as(NULL); /* Pending promise stac
#endif

/* File Input/Output */
extern0 bool R_Quiet INI_as(false); /* Be as quiet as possible */
extern0 bool R_Verbose INI_as(false); /* Be verbose */
// Next two are duplicated in Rinterface.h
// R_Interactive is accessed in parallel's fork.c and on Windows in util's stubs.c
LibExtern Rboolean R_Interactive INI_as(TRUE); /* TRUE during interactive use*/
extern0 Rboolean R_Quiet INI_as(FALSE); /* Be as quiet as possible */
extern Rboolean R_NoEcho INI_as(FALSE); /* do not echo R code */
extern0 Rboolean R_Verbose INI_as(FALSE); /* Be verbose */
/* extern int R_Console; */ /* Console active flag */
/* IoBuffer R_ConsoleIob; : --> ./IOStuff.h */
/* R_Consolefile is used in the internet module */
Expand Down Expand Up @@ -2330,7 +2332,7 @@ void get_current_mem(size_t *,size_t *,size_t *); /* from memory.c */
unsigned long get_duplicate_counter(void); /* from duplicate.c */
void reset_duplicate_counter(void); /* from duplicate.c */
void BindDomain(char *); /* from main.c */
extern Rboolean LoadInitFile; /* from startup.c */
extern bool LoadInitFile; /* from startup.c, uses in sys-*.c */

// Unix and Windows versions
double R_getClockIncrement(void);
Expand Down
33 changes: 22 additions & 11 deletions src/include/R_ext/RStartup.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* R : A Computer Language for Statistical Data Analysis
* Copyright (C) 1999-2022 The R Core Team
* Copyright (C) 1999-2025 The R Core Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -34,7 +34,7 @@
# define R_SIZE_T size_t
#endif

#include <R_ext/Boolean.h> /* TRUE/FALSE */
//#include <R_ext/Boolean.h> /* TRUE/FALSE and formerly for Rboolean */

#ifdef __cplusplus
extern "C" {
Expand All @@ -57,23 +57,34 @@ typedef enum {
SA_SUICIDE
} SA_TYPE;

/* This is a public struct which is used by alternative front-ends
* which wish to to bw able to link to different versions of R. So
* only change the layout if essential.
*/
typedef struct
{
Rboolean R_Quiet;
Rboolean R_NoEcho;
Rboolean R_Interactive;
Rboolean R_Verbose;
Rboolean LoadSiteFile;
Rboolean LoadInitFile;
Rboolean DebugInitFile;
/* Some of thse were Rboolean, but if we change the size of
* that it would affect alignment and padding here.
* So changed to int in R 4.5.0.
*/
int R_Quiet;
int R_NoEcho;
int R_Interactive;
int R_Verbose;
int LoadSiteFile;
int LoadInitFile;
int DebugInitFile; // unused
SA_TYPE RestoreAction;
SA_TYPE SaveAction;
R_SIZE_T vsize;
R_SIZE_T nsize;
R_SIZE_T max_vsize;
R_SIZE_T max_nsize;
R_SIZE_T ppsize;
Rboolean NoRenviron : 16;
int NoRenviron : 16; /* was Rboolean, so assumed that had an
underlying type of at leat 16 bits.
Only used for TRUE/FALSE so only one bit used.
*/
/* RstartVersion has been added in R 4.2.0. Earlier, NoRenviron was an
int (normally 32-bit like Rboolean), so on most machines the
version would become 0 when setting NoRenviron to FALSE in
Expand Down Expand Up @@ -104,7 +115,7 @@ typedef struct
/* used only if WriteConsole is NULL */

/* The following field has been added in R 4.0.0. */
Rboolean EmitEmbeddedUTF8;
int EmitEmbeddedUTF8;
/* R may embed UTF-8 sections into strings otherwise in current native
encoding, escaped by UTF8in and UTF8out (rgui_UTF8.h). The setting
has no effect in Rgui (escaping happens iff the system codepage is
Expand Down
32 changes: 21 additions & 11 deletions src/main/startup.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
R : A Computer Language for Statistical Data Analysis
Copyright (C) 1995-1996 Robert Gentleman and Ross Ihaka
Copyright (C) 1997-2023 The R Core Team
Copyright (C) 1997-2025 The R Core Team
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -42,9 +42,10 @@
/* These are used in ../gnuwin32/system.c, ../unix/sys-std.c */
SA_TYPE SaveAction = SA_SAVEASK;
SA_TYPE RestoreAction = SA_RESTORE;
static Rboolean LoadSiteFile = TRUE;
attribute_hidden Rboolean LoadInitFile = TRUE; /* Used in R_OpenInitFile */
static Rboolean DebugInitFile = FALSE;
attribute_hidden bool LoadInitFile = true; /* Used in R_OpenInitFile */

static bool LoadSiteFile = true;
// static bool DebugInitFile = false; // unused

/*
* INITIALIZATION AND TERMINATION ACTIONS
Expand Down Expand Up @@ -348,17 +349,26 @@ static void SetMaxSize(R_size_t vsize, R_size_t nsize)
}
}

static bool checkBool(int in, const char *name)
{
if(in != 0 && in != 1) {
warning("At startup: value %d of Rp->%s taken as true", in, name);
in = 1;
}
return (bool)(in != 0);
}

void R_SetParams(Rstart Rp)
{
R_Quiet = Rp->R_Quiet;
R_NoEcho = Rp->R_NoEcho;
R_Interactive = Rp->R_Interactive;
R_Verbose = Rp->R_Verbose;
R_Quiet = checkBool(Rp->R_Quiet, "R_Quiet");
R_NoEcho = (Rboolean) checkBool(Rp->R_NoEcho, "R_NoEcho");
R_Interactive = (Rboolean) checkBool(Rp->R_Interactive, "R_Interactive");
R_Verbose = checkBool(Rp->R_Verbose, "R_Verbose");
LoadSiteFile = checkBool(Rp->LoadSiteFile, "R_LoadSitefile");
LoadInitFile = checkBool(Rp->LoadInitFile, "R_LoadInitFile");
// DebugInitFile = checkBool(Rp->DebugInitFile, "R_DebugInitFile"); // unused
RestoreAction = Rp->RestoreAction;
SaveAction = Rp->SaveAction;
LoadSiteFile = Rp->LoadSiteFile;
LoadInitFile = Rp->LoadInitFile;
DebugInitFile = Rp->DebugInitFile;
SetSize(Rp->vsize, Rp->nsize);
SetMaxSize(Rp->max_vsize, Rp->max_nsize);
R_SetPPSize(Rp->ppsize);
Expand Down

0 comments on commit 40e5571

Please sign in to comment.