Skip to content

Commit

Permalink
Avoid including headers from extern C blocks to reduce the risk of br…
Browse files Browse the repository at this point in the history
…eakage

with C++ compilers.


git-svn-id: https://svn.r-project.org/R/trunk@87075 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information
kalibera committed Aug 29, 2024
1 parent f0219d6 commit 43d5769
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 40 deletions.
8 changes: 5 additions & 3 deletions src/extra/graphapp/graphapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
* Assume C declarations for C++
*/

#include <stdio.h>
#include <stdlib.h>

#include <R_ext/libextern.h>

#ifdef __cplusplus
extern "C" {
#endif /* begin normal C declarations */
Expand All @@ -29,8 +34,6 @@ extern "C" {
* Definition of some constants.
*/

#include <stdio.h>
#include <stdlib.h>

#ifndef Pi
#define Pi 3.14159265359
Expand Down Expand Up @@ -1251,7 +1254,6 @@ void showcaret(control c, int showing);
* Library supplied variables.
*/

#include <R_ext/libextern.h>
#undef LibExtern
#ifdef GA_DLL_BUILD
# define LibExtern extern
Expand Down
8 changes: 4 additions & 4 deletions src/extra/graphapp/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand All @@ -87,6 +83,10 @@ extern "C" {

#include <commdlg.h>

#ifdef __cplusplus
extern "C" {
#endif

#ifdef __MWERKS__
/* Metrowerks Codewarrior Cross-Platform C/C++ Compiler */
#define COMPILER 32
Expand Down
5 changes: 3 additions & 2 deletions src/include/R_ext/Altrep.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) 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
Expand All @@ -26,6 +26,8 @@
#ifndef R_EXT_ALTREP_H_
#define R_EXT_ALTREP_H_

#include <R_ext/Complex.h>

#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -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 <R_ext/Complex.h>
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 *);
Expand Down
4 changes: 2 additions & 2 deletions src/include/R_ext/GraphicsDevice.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) 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
Expand Down Expand Up @@ -44,6 +44,7 @@
# endif
#endif

#include <R_ext/libextern.h>
#include <R_ext/Boolean.h>

#ifdef __cplusplus
Expand Down Expand Up @@ -973,7 +974,6 @@ Rboolean doesIdle(pDevDesc dd);
Rf_onintr(); \
} while(0)

#include <R_ext/libextern.h>
LibExtern Rboolean R_interrupts_suspended;
LibExtern int R_interrupts_pending;
extern void Rf_onintr(void);
Expand Down
9 changes: 8 additions & 1 deletion src/include/R_ext/GraphicsEngine.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) 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
Expand Down Expand Up @@ -229,9 +229,16 @@ typedef struct {

typedef R_GE_gcontext* pGEcontext;

#ifdef __cplusplus
}
#endif

#include <R_ext/GraphicsDevice.h> /* needed for DevDesc */

#ifdef __cplusplus
extern "C" {
#endif

typedef struct _GEDevDesc GEDevDesc;

typedef SEXP (* GEcallback)(GEevent, GEDevDesc *, SEXP);
Expand Down
5 changes: 3 additions & 2 deletions src/include/R_ext/MathThreads.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) 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
Expand Down Expand Up @@ -36,11 +36,12 @@
#ifndef R_EXT_MATHTHREADS_H_
#define R_EXT_MATHTHREADS_H_

#include <R_ext/libextern.h>

#ifdef __cplusplus
extern "C" {
#endif

#include <R_ext/libextern.h>
LibExtern int R_num_math_threads;
LibExtern int R_max_num_math_threads;

Expand Down
10 changes: 6 additions & 4 deletions src/include/R_ext/QuartzDevice.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) 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
Expand Down Expand Up @@ -95,13 +95,15 @@
#include <config.h>
#endif

#if HAVE_AQUA
#include <ApplicationServices/ApplicationServices.h>
#endif

#ifdef __cplusplus
extern "C" {
#endif

#if HAVE_AQUA
#include <ApplicationServices/ApplicationServices.h>
#else
#ifndef HAVE_AQUA
typedef void* CGContextRef;
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/include/R_ext/RS.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
# define R_SIZE_T size_t
#endif

#include <Rconfig.h> /* for F77_APPEND_UNDERSCORE */
#include <Rconfig.h> /* for HAVE_F77_UNDERSCORE */

#ifdef __cplusplus
extern "C" {
Expand Down
40 changes: 26 additions & 14 deletions src/include/Rinterface.h
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) 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
Expand Down Expand Up @@ -33,16 +33,39 @@
#ifndef RINTERFACE_H_
#define RINTERFACE_H_

#include <R_ext/Boolean.h>
#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 <stdint.h>
# elif __cplusplus >= 201103L
# include <cstdint>
# endif
# endif
#endif

#ifdef __cplusplus
/* we do not support DO_NOT_USE_CXX_HEADERS in this file */
# include <cstdio>
extern "C" {
#else
# include <stdio.h>
#endif

#include <R_ext/Boolean.h>

#ifdef R_INTERFACE_PTRS
# include <Rinternals.h> // for SEXP
# include <R_ext/RStartup.h> // for SA_TYPE
#endif

#ifdef __cplusplus
extern "C" {
#endif

// See R_ext/Error.h
#if defined NORET
#elif (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202301L)
Expand Down Expand Up @@ -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 <stdint.h>
# elif __cplusplus >= 201103L
# include <cstdint>
# endif
#endif

extern uintptr_t R_CStackLimit; /* C stack limit */
extern uintptr_t R_CStackStart; /* Initial stack address */
Expand All @@ -129,8 +143,6 @@ extern uintptr_t R_CStackStart; /* Initial stack address */
/* formerly in src/unix/devUI.h */

#ifdef R_INTERFACE_PTRS
#include <Rinternals.h> // for SEXP
#include <R_ext/RStartup.h> // for SA_TYPE

#ifdef __SYSTEM__
# define extern
Expand Down
17 changes: 10 additions & 7 deletions src/include/Rinternals.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
# include <cstdio>
# include <climits>
# include <cstddef>
extern "C" {
#else
# include <stdio.h>
# include <limits.h> /* for INT_MAX */
Expand All @@ -52,18 +51,22 @@ extern "C" {

#include <R_ext/libextern.h>

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 <Rconfig.h>
#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
Expand Down

0 comments on commit 43d5769

Please sign in to comment.