From 40e5571f6f67e161e8f3cb8071267ff6374a3170 Mon Sep 17 00:00:00 2001 From: ripley Date: Sun, 2 Mar 2025 05:07:35 +0000 Subject: [PATCH] reduce use of Rboolean in front-ends interface git-svn-id: https://svn.r-project.org/R/trunk@87861 00db46b3-68df-0310-9c12-caf00c1e9a41 --- src/include/Defn.h | 12 +++++++----- src/include/R_ext/RStartup.h | 33 ++++++++++++++++++++++----------- src/main/startup.c | 32 +++++++++++++++++++++----------- 3 files changed, 50 insertions(+), 27 deletions(-) diff --git a/src/include/Defn.h b/src/include/Defn.h index ed1bafd89ff..85a9c518ec5 100644 --- a/src/include/Defn.h +++ b/src/include/Defn.h @@ -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 @@ -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_ @@ -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 */ @@ -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); diff --git a/src/include/R_ext/RStartup.h b/src/include/R_ext/RStartup.h index fb7a8aa264c..3ce56d716ae 100644 --- a/src/include/R_ext/RStartup.h +++ b/src/include/R_ext/RStartup.h @@ -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 @@ -34,7 +34,7 @@ # define R_SIZE_T size_t #endif -#include /* TRUE/FALSE */ +//#include /* TRUE/FALSE and formerly for Rboolean */ #ifdef __cplusplus extern "C" { @@ -57,15 +57,23 @@ 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; @@ -73,7 +81,10 @@ typedef struct 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 @@ -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 diff --git a/src/main/startup.c b/src/main/startup.c index 59c87af32ab..4616cd212aa 100644 --- a/src/main/startup.c +++ b/src/main/startup.c @@ -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 @@ -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 @@ -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);