From 43d5769bece45767ad8d8706a636ab6b5816e141 Mon Sep 17 00:00:00 2001 From: kalibera Date: Thu, 29 Aug 2024 08:08:35 +0000 Subject: [PATCH] Avoid including headers from extern C blocks to reduce the risk of breakage with C++ compilers. git-svn-id: https://svn.r-project.org/R/trunk@87075 00db46b3-68df-0310-9c12-caf00c1e9a41 --- src/extra/graphapp/graphapp.h | 8 +++--- src/extra/graphapp/internal.h | 8 +++--- src/include/R_ext/Altrep.h | 5 ++-- src/include/R_ext/GraphicsDevice.h | 4 +-- src/include/R_ext/GraphicsEngine.h | 9 ++++++- src/include/R_ext/MathThreads.h | 5 ++-- src/include/R_ext/QuartzDevice.h | 10 +++++--- src/include/R_ext/RS.h | 2 +- src/include/Rinterface.h | 40 +++++++++++++++++++----------- src/include/Rinternals.h | 17 +++++++------ 10 files changed, 68 insertions(+), 40 deletions(-) diff --git a/src/extra/graphapp/graphapp.h b/src/extra/graphapp/graphapp.h index 692c50ac9c8..d1919530f4e 100644 --- a/src/extra/graphapp/graphapp.h +++ b/src/extra/graphapp/graphapp.h @@ -21,6 +21,11 @@ * Assume C declarations for C++ */ +#include +#include + +#include + #ifdef __cplusplus extern "C" { #endif /* begin normal C declarations */ @@ -29,8 +34,6 @@ extern "C" { * Definition of some constants. */ -#include -#include #ifndef Pi #define Pi 3.14159265359 @@ -1251,7 +1254,6 @@ void showcaret(control c, int showing); * Library supplied variables. */ -#include #undef LibExtern #ifdef GA_DLL_BUILD # define LibExtern extern diff --git a/src/extra/graphapp/internal.h b/src/extra/graphapp/internal.h index 0d522a93d4b..b813ca4854a 100644 --- a/src/extra/graphapp/internal.h +++ b/src/extra/graphapp/internal.h @@ -74,10 +74,6 @@ PROTECTED void updatestatus(const char *text); PROTECTED font new_font_object(HFONT hf); UINT default_font_charset(void); -#ifdef __cplusplus -extern "C" { -#endif - #include #include #include @@ -87,6 +83,10 @@ extern "C" { #include +#ifdef __cplusplus +extern "C" { +#endif + #ifdef __MWERKS__ /* Metrowerks Codewarrior Cross-Platform C/C++ Compiler */ #define COMPILER 32 diff --git a/src/include/R_ext/Altrep.h b/src/include/R_ext/Altrep.h index 85cddb7e82f..b5e0df7345f 100644 --- a/src/include/R_ext/Altrep.h +++ b/src/include/R_ext/Altrep.h @@ -1,6 +1,6 @@ /* * R : A Computer Language for Statistical Data Analysis - * Copyright (C) 2016-2023 The R Core Team. + * Copyright (C) 2016-2024 The R Core Team. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by @@ -26,6 +26,8 @@ #ifndef R_EXT_ALTREP_H_ #define R_EXT_ALTREP_H_ +#include + #ifdef __cplusplus extern "C" { #endif @@ -104,7 +106,6 @@ typedef Rbyte (*R_altraw_Elt_method_t)(SEXP, R_xlen_t); typedef R_xlen_t (*R_altraw_Get_region_method_t)(SEXP, R_xlen_t, R_xlen_t, Rbyte *); -#include typedef Rcomplex (*R_altcomplex_Elt_method_t)(SEXP, R_xlen_t); typedef R_xlen_t (*R_altcomplex_Get_region_method_t)(SEXP, R_xlen_t, R_xlen_t, Rcomplex *); diff --git a/src/include/R_ext/GraphicsDevice.h b/src/include/R_ext/GraphicsDevice.h index 2b102483a6b..bd225c0ba6b 100644 --- a/src/include/R_ext/GraphicsDevice.h +++ b/src/include/R_ext/GraphicsDevice.h @@ -1,6 +1,6 @@ /* * R : A Computer Language for Statistical Data Analysis - * Copyright (C) 2001-11 The R Core Team. + * Copyright (C) 2001-24 The R Core Team. * * This header file is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by @@ -44,6 +44,7 @@ # endif #endif +#include #include #ifdef __cplusplus @@ -973,7 +974,6 @@ Rboolean doesIdle(pDevDesc dd); Rf_onintr(); \ } while(0) -#include LibExtern Rboolean R_interrupts_suspended; LibExtern int R_interrupts_pending; extern void Rf_onintr(void); diff --git a/src/include/R_ext/GraphicsEngine.h b/src/include/R_ext/GraphicsEngine.h index 1934c1819d8..ad26afe619b 100644 --- a/src/include/R_ext/GraphicsEngine.h +++ b/src/include/R_ext/GraphicsEngine.h @@ -1,6 +1,6 @@ /* * R : A Computer Language for Statistical Data Analysis - * Copyright (C) 2001-21 The R Core Team. + * Copyright (C) 2001-24 The R Core Team. * * This header file is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by @@ -229,9 +229,16 @@ typedef struct { typedef R_GE_gcontext* pGEcontext; +#ifdef __cplusplus +} +#endif #include /* needed for DevDesc */ +#ifdef __cplusplus +extern "C" { +#endif + typedef struct _GEDevDesc GEDevDesc; typedef SEXP (* GEcallback)(GEevent, GEDevDesc *, SEXP); diff --git a/src/include/R_ext/MathThreads.h b/src/include/R_ext/MathThreads.h index 7445a3c54dd..995b789941c 100644 --- a/src/include/R_ext/MathThreads.h +++ b/src/include/R_ext/MathThreads.h @@ -1,6 +1,6 @@ /* * R : A Computer Language for Statistical Data Analysis - * Copyright (C) 2000-2014 The R Core Team. + * Copyright (C) 2000-2024 The R Core Team. * * This header file is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by @@ -36,11 +36,12 @@ #ifndef R_EXT_MATHTHREADS_H_ #define R_EXT_MATHTHREADS_H_ +#include + #ifdef __cplusplus extern "C" { #endif -#include LibExtern int R_num_math_threads; LibExtern int R_max_num_math_threads; diff --git a/src/include/R_ext/QuartzDevice.h b/src/include/R_ext/QuartzDevice.h index 4ca21c849b3..396b832ded7 100644 --- a/src/include/R_ext/QuartzDevice.h +++ b/src/include/R_ext/QuartzDevice.h @@ -1,6 +1,6 @@ /* * R : A Computer Language for Statistical Data Analysis - * Copyright (C) 2007-2016 The R Core Team + * Copyright (C) 2007-2024 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 @@ -95,13 +95,15 @@ #include #endif +#if HAVE_AQUA +#include +#endif + #ifdef __cplusplus extern "C" { #endif -#if HAVE_AQUA -#include -#else +#ifndef HAVE_AQUA typedef void* CGContextRef; #endif diff --git a/src/include/R_ext/RS.h b/src/include/R_ext/RS.h index d6c4717ca20..16a98184be4 100644 --- a/src/include/R_ext/RS.h +++ b/src/include/R_ext/RS.h @@ -36,7 +36,7 @@ # define R_SIZE_T size_t #endif -#include /* for F77_APPEND_UNDERSCORE */ +#include /* for HAVE_F77_UNDERSCORE */ #ifdef __cplusplus extern "C" { diff --git a/src/include/Rinterface.h b/src/include/Rinterface.h index 7eec60b554d..de6a8988d04 100644 --- a/src/include/Rinterface.h +++ b/src/include/Rinterface.h @@ -1,7 +1,7 @@ /* * R : A Computer Language for Statistical Data Analysis * Copyright (C) 1995, 1996 Robert Gentleman and Ross Ihaka - * Copyright (C) 1998--2022 The R Core Team. + * Copyright (C) 1998--2024 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 @@ -33,16 +33,39 @@ #ifndef RINTERFACE_H_ #define RINTERFACE_H_ -#include +#ifdef CSTACK_DEFNS +/* duplicating older Defn.h. + Note: this is never used when including Rinterface.h from R itself +*/ +# if !defined(HAVE_UINTPTR_T) && !defined(uintptr_t) + typedef unsigned long uintptr_t; +# else +# ifndef __cplusplus +# include +# elif __cplusplus >= 201103L +# include +# endif +# endif +#endif #ifdef __cplusplus /* we do not support DO_NOT_USE_CXX_HEADERS in this file */ # include -extern "C" { #else # include #endif +#include + +#ifdef R_INTERFACE_PTRS +# include // for SEXP +# include // for SA_TYPE +#endif + +#ifdef __cplusplus +extern "C" { +#endif + // See R_ext/Error.h #if defined NORET #elif (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202301L) @@ -112,15 +135,6 @@ extern int R_running_as_main_program; /* duplicating older Defn.h. Note: this is never used when including Rinterface.h from R itself */ -#if !defined(HAVE_UINTPTR_T) && !defined(uintptr_t) - typedef unsigned long uintptr_t; -#else -# ifndef __cplusplus -# include -# elif __cplusplus >= 201103L -# include -# endif -#endif extern uintptr_t R_CStackLimit; /* C stack limit */ extern uintptr_t R_CStackStart; /* Initial stack address */ @@ -129,8 +143,6 @@ extern uintptr_t R_CStackStart; /* Initial stack address */ /* formerly in src/unix/devUI.h */ #ifdef R_INTERFACE_PTRS -#include // for SEXP -#include // for SA_TYPE #ifdef __SYSTEM__ # define extern diff --git a/src/include/Rinternals.h b/src/include/Rinternals.h index 517376b19aa..3fb375b9160 100644 --- a/src/include/Rinternals.h +++ b/src/include/Rinternals.h @@ -34,7 +34,6 @@ # include # include # include -extern "C" { #else # include # include /* for INT_MAX */ @@ -52,18 +51,22 @@ extern "C" { #include -typedef unsigned char Rbyte; - -/* type for length of (standard, not long) vectors etc */ -typedef int R_len_t; -#define R_LEN_T_MAX INT_MAX - /* both config.h and Rconfig.h set SIZEOF_SIZE_T, but Rconfig.h is skipped if config.h has already been included. */ #ifndef R_CONFIG_H # include #endif +#ifdef __cplusplus +extern "C" { +#endif + +typedef unsigned char Rbyte; + +/* type for length of (standard, not long) vectors etc */ +typedef int R_len_t; +#define R_LEN_T_MAX INT_MAX + #if ( SIZEOF_SIZE_T > 4 ) # define LONG_VECTOR_SUPPORT #endif