Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PATCH] INTERN/EXTERN C++ cleanup #14469

Closed
p5pRT opened this issue Feb 4, 2015 · 11 comments
Closed

[PATCH] INTERN/EXTERN C++ cleanup #14469

p5pRT opened this issue Feb 4, 2015 · 11 comments

Comments

@p5pRT
Copy link
Collaborator

@p5pRT p5pRT commented Feb 4, 2015

Migrated from rt.perl.org#123727 (status was 'open')

Searchable as RT123727$

@p5pRT

This comment has been minimized.

Copy link
Collaborator Author

@p5pRT p5pRT commented Feb 4, 2015

From @bulk88

Created by @bulk88

This patch never got any comments in its its original thread at
http​://www.nntp.perl.org/group/perl.perl5.porters/2015/01/msg225087.html
, so I am filing it as a ticket. It is not intended to be committed as
is (no commit body for example).

Perl Info

Flags:
               category=core
               severity=low

Site configuration information for perl 5.21.4:

Configured by Owner at Thu Sep 18 12:08:58 2014.

Summary of my perl5 (revision 5 version 21 subversion 4) configuration:
             Derived from: 7d2b2edb94ab56333b9049a3e26d15ea18445512
             Ancestor: 19be3be6968e2337bcdfe480693fff795ecd1304
             Platform:
               osname=MSWin32, osvers=5.1, archname=MSWin32-x86-multi-thread
               uname=''
               config_args='undef'
               hint=recommended, useposix=true, d_sigaction=undef
               useithreads=define, usemultiplicity=define
               use64bitint=undef, use64bitall=undef, uselongdouble=undef
               usemymalloc=n, bincompat5005=undef
             Compiler:
               cc='cl', ccflags ='-nologo -GF -W3 -O1 -MD -Zi -DNDEBUG
-DWIN32
-D_CONSOLE -DNO_STRICT  -DPERL_TEXTMODE_SCRIPTS
-DPERL_HASH_FUNC_ONE_AT_A_TIME -DPERL_IMPLICIT_CONTEXT
-DPERL_IMPLICIT_SYS -DUSE_PERLIO -D_USE_32BIT_TIME_T',
               optimize='-O1 -MD -Zi -DNDEBUG',
               cppflags='-DWIN32'
               ccversion='12.00.8168', gccversion='', gccosandvers=''
               intsize=4, longsize=4, ptrsize=4, doublesize=8,
byteorder=1234
               d_longlong=undef, longlongsize=8, d_longdbl=define,
longdblsize=8,
longdblkind=0
               ivtype='long', ivsize=4, nvtype='double', nvsize=8,
Off_t='__int64',
lseeksize=8
               alignbytes=8, prototype=define
             Linker and Libraries:
               ld='link', ldflags ='-nologo -nodefaultlib -debug
-opt:ref,icf
-libpath:"c:\perl521\lib\CORE"  -machine:x86'
               libpth=C:\PROGRA~1\MIAF9D~1\VC98\lib
               libs=oldnames.lib kernel32.lib user32.lib gdi32.lib
winspool.lib
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib
netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib  version.lib
odbc32.lib odbccp32.lib comctl32.lib msvcrt.lib
               perllibs=oldnames.lib kernel32.lib user32.lib gdi32.lib
winspool.lib  comdlg32.lib advapi32.lib shell32.lib ole32.lib
oleaut32.lib  netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib
version.lib odbc32.lib odbccp32.lib comctl32.lib msvcrt.lib
               libc=msvcrt.lib, so=dll, useshrplib=true, libperl=perl521.lib
               gnulibc_version=''
             Dynamic Linking:
               dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
               cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -debug
-opt:ref,icf  -libpath:"c:\perl521\lib\CORE"  -machine:x86'

Locally applied patches:
               uncommitted-changes
               a0fe7a7e75de29e59f1da0d6822dc06e5be658fe
               a261faffee83d0145642ab5d1d046c9f813bc497
               6506ab86ad1602a9ca720fcd30446dce1461d23d
               7d2b2edb94ab56333b9049a3e26d15ea18445512


@INC for perl 5.21.4:
               lib
               C:/perl521/srcnew/lib
               .


Environment for perl 5.21.4:
               HOME (unset)
               LANG (unset)
               LANGUAGE (unset)
               LD_LIBRARY_PATH (unset)
               LOGDIR (unset)
               PATH=
               PERL_BADLANG (unset)
               PERL_JSON_BACKEND=Cpanel::JSON::XS
               PERL_YAML_BACKEND=YAML
               SHELL (unset)





















@p5pRT

This comment has been minimized.

Copy link
Collaborator Author

@p5pRT p5pRT commented Feb 4, 2015

From @bulk88

0001-INTERN-EXTERN-C-cleanup.patch
From 8a12f1e05d9aac2ed5ca1d716ad142f79e4e0f1c Mon Sep 17 00:00:00 2001
From: Daniel Dragan <bulk88@hotmail.com>
Date: Sat, 24 Jan 2015 04:09:17 -0500
Subject: [PATCH] INTERN/EXTERN C++ cleanup

---
 EXTERN.h        |   20 ++++++++++----------
 INTERN.h        |   11 +++++++----
 opcode.h        |   10 ----------
 perl.h          |   19 +++++--------------
 perlapi.c       |    3 ---
 perlapi.h       |    8 --------
 regcomp.h       |    5 -----
 regen/opcode.pl |   10 ----------
 utf8.h          |    3 ---
 utfebcdic.h     |    4 ----
 10 files changed, 22 insertions(+), 71 deletions(-)

diff --git a/EXTERN.h b/EXTERN.h
index 4e4f1ad..345eccd 100644
--- a/EXTERN.h
+++ b/EXTERN.h
@@ -22,33 +22,33 @@
 #  if (defined(WIN32) || defined(__SYMBIAN32__)) && !defined(PERL_STATIC_SYMS)
     /* miniperl should not export anything */
 #    if defined(PERL_IS_MINIPERL) && !defined(UNDER_CE) && defined(_MSC_VER)
-#      define EXT extern
+#      define EXT EXTERN_C
 #      define dEXT 
-#      define EXTCONST extern const
+#      define EXTCONST EXTERN_C const
 #      define dEXTCONST const
 #    else
 #      if defined(PERLDLL) || defined(__SYMBIAN32__)
-#        define EXT extern __declspec(dllexport)
+#        define EXT EXTERN_C __declspec(dllexport)
 #        define dEXT 
-#        define EXTCONST extern __declspec(dllexport) const
+#        define EXTCONST EXTERN_C __declspec(dllexport) const
 #        define dEXTCONST const
 #      else
-#        define EXT extern __declspec(dllimport)
+#        define EXT EXTERN_C __declspec(dllimport)
 #        define dEXT 
-#        define EXTCONST extern __declspec(dllimport) const
+#        define EXTCONST EXTERN_C __declspec(dllimport) const
 #        define dEXTCONST const
 #      endif
 #    endif
 #  else
 #    if defined(__CYGWIN__) && defined(USEIMPORTLIB)
-#      define EXT extern __declspec(dllimport)
+#      define EXT EXTERN_C __declspec(dllimport)
 #      define dEXT 
-#      define EXTCONST extern __declspec(dllimport) const
+#      define EXTCONST EXTERN_C __declspec(dllimport) const
 #      define dEXTCONST const
 #    else
-#      define EXT extern
+#      define EXT EXTERN_C
 #      define dEXT
-#      define EXTCONST extern const
+#      define EXTCONST EXTERN_C const
 #      define dEXTCONST const
 #    endif
 #  endif
diff --git a/INTERN.h b/INTERN.h
index e6e0602..8b8df49 100644
--- a/INTERN.h
+++ b/INTERN.h
@@ -21,9 +21,12 @@
 
 #  if (defined(WIN32) && defined(__MINGW32__)) || defined(__SYMBIAN32__)
 #    ifdef __cplusplus
-#      define EXT	__declspec(dllexport)
+#      define EXT	EXTERN_C __declspec(dllexport)
 #      define dEXT
-#      define EXTCONST	__declspec(dllexport) extern const
+/* Win32 GCC errors out with
+  "..\perl.h:4614:35: error: expected unqualified-id before string constant"
+  if dllexport is first, then EXTERN_C */
+#      define EXTCONST	EXTERN_C __declspec(dllexport) const
 #      define dEXTCONST	const
 #    else
 #      define EXT	__declspec(dllexport)
@@ -33,9 +36,9 @@
 #    endif
 #  else
 #    ifdef __cplusplus
-#      define EXT
+#      define EXT      EXTERN_C
 #      define dEXT
-#      define EXTCONST extern const
+#      define EXTCONST EXTERN_C const
 #      define dEXTCONST const
 #    else
 #      define EXT
diff --git a/opcode.h b/opcode.h
index 5d910fd..d16da3f 100644
--- a/opcode.h
+++ b/opcode.h
@@ -142,7 +142,6 @@
 #define Perl_pp_custom Perl_unimplemented_op
 #define Perl_pp_reach Perl_pp_rkeys
 #define Perl_pp_rvalues Perl_pp_rkeys
-START_EXTERN_C
 
 #ifndef DOINIT
 EXTCONST char* const PL_op_name[];
@@ -936,12 +935,8 @@ EXTCONST char* const PL_op_desc[] = {
 };
 #endif
 
-END_EXTERN_C
-
 #endif /* !PERL_GLOBAL_STRUCT_INIT */
 
-START_EXTERN_C
-
 #ifdef PERL_GLOBAL_STRUCT_INIT
 #  define PERL_PPADDR_INITED
 static const Perl_ppaddr_t Gppaddr[]
@@ -2153,8 +2148,6 @@ EXTCONST U32 PL_opargs[] = {
 
 #endif /* !PERL_GLOBAL_STRUCT_INIT */
 
-END_EXTERN_C
-
 
 #define OPpLVREF_SV             0x00
 #define OPpARG1_MASK            0x01
@@ -2250,7 +2243,6 @@ END_EXTERN_C
 #define OPpPV_IS_UTF8           0x80
 #define OPpSPLIT_IMPLIM         0x80
 #define OPpTRANS_DELETE         0x80
-START_EXTERN_C
 
 #ifndef PERL_GLOBAL_STRUCT_INIT
 
@@ -3263,8 +3255,6 @@ EXTCONST U8 PL_op_private_valid[] = {
 #  endif /* !DOINIT */
 #endif /* !PERL_GLOBAL_STRUCT_INIT */
 
-END_EXTERN_C
-
 
 
 /* ex: set ro: */
diff --git a/perl.h b/perl.h
index d9cfdb3..270bffd 100644
--- a/perl.h
+++ b/perl.h
@@ -4608,8 +4608,6 @@ extern char **	environ;	/* environment variables supplied via exec */
 				STRINGIFY(PERL_API_VERSION) "." \
 				STRINGIFY(PERL_API_SUBVERSION)
 
-START_EXTERN_C
-
 /* handy constants */
 EXTCONST char PL_warn_uninit[]
   INIT("Use of uninitialized value%s%s%s");
@@ -5191,8 +5189,6 @@ EXTCONST char *const PL_phase_names[];
 
 #define PL_hints PL_compiling.cop_hints
 
-END_EXTERN_C
-
 /*****************************************************************************/
 /* This lexer/parser stuff is currently global since yacc is hard to reenter */
 /*****************************************************************************/
@@ -5512,15 +5508,18 @@ struct tempsym; /* defined in pp_pack.c */
  * these include variables that would have been their struct-s
  */
 
+#ifdef DOINIT
+#define PERLVAR(prefix,var,type) EXT type PL_##var; type PL_##var;
+#define PERLVARA(prefix,var,n,type) EXT type PL_##var[n]; type PL_##var[n];
+#else
 #define PERLVAR(prefix,var,type) EXT type PL_##var;
 #define PERLVARA(prefix,var,n,type) EXT type PL_##var[n];
+#endif
 #define PERLVARI(prefix,var,type,init) EXT type  PL_##var INIT(init);
 #define PERLVARIC(prefix,var,type,init) EXTCONST type PL_##var INIT(init);
 
 #if !defined(MULTIPLICITY)
-START_EXTERN_C
 #  include "intrpvar.h"
-END_EXTERN_C
 #endif
 
 #ifdef PERL_CORE
@@ -5534,11 +5533,7 @@ END_EXTERN_C
 #include "embed.h"
 
 #ifndef PERL_GLOBAL_STRUCT
-START_EXTERN_C
-
 #  include "perlvars.h"
-
-END_EXTERN_C
 #endif
 
 #undef PERLVAR
@@ -5566,8 +5561,6 @@ struct PerlHandShakeInterpreter {
 #  undef PERLVARIC
 #endif
 
-START_EXTERN_C
-
 /* dummy variables that hold pointers to both runops functions, thus forcing
  * them *both* to get linked in (useful for Peek.xs, debugging etc) */
 
@@ -5663,8 +5656,6 @@ EXTCONST bool PL_valid_types_NV_set[];
 
 #include "overload.h"
 
-END_EXTERN_C
-
 struct am_table {
   U8 flags;
   U8 fallback;
diff --git a/perlapi.c b/perlapi.c
index 7858337..90111d8 100644
--- a/perlapi.c
+++ b/perlapi.c
@@ -31,7 +31,6 @@
 #if defined (MULTIPLICITY) && defined (PERL_GLOBAL_STRUCT)
 
 /* accessor functions for Perl "global" variables */
-START_EXTERN_C
 
 #undef PERLVARI
 #define PERLVARI(p,v,t,i) PERLVAR(p,v,t)
@@ -53,8 +52,6 @@ START_EXTERN_C
 #undef PERLVARI
 #undef PERLVARIC
 
-END_EXTERN_C
-
 #endif /* MULTIPLICITY && PERL_GLOBAL_STRUCT */
 
 /* ex: set ro: */
diff --git a/perlapi.h b/perlapi.h
index 5268c2c..4d512a2 100644
--- a/perlapi.h
+++ b/perlapi.h
@@ -22,8 +22,6 @@
 
 #if defined (MULTIPLICITY) && defined (PERL_GLOBAL_STRUCT)
 
-START_EXTERN_C
-
 #undef PERLVAR
 #undef PERLVARA
 #undef PERLVARI
@@ -41,8 +39,6 @@ START_EXTERN_C
 #undef PERLVARI
 #undef PERLVARIC
 
-END_EXTERN_C
-
 #if defined(PERL_CORE)
 
 /* accessor functions for Perl "global" variables */
@@ -52,8 +48,6 @@ END_EXTERN_C
 
 #ifndef PERL_NO_FORCE_LINK
 
-START_EXTERN_C
-
 #ifndef DOINIT
 EXTCONST void * const PL_force_link_funcs[];
 #else
@@ -93,8 +87,6 @@ EXTCONST void * const PL_force_link_funcs[] = {
 };
 #endif	/* DOINIT */
 
-END_EXTERN_C
-
 #endif	/* PERL_NO_FORCE_LINK */
 
 #else	/* !PERL_CORE */
diff --git a/regcomp.h b/regcomp.h
index de31d65..edafd59 100644
--- a/regcomp.h
+++ b/regcomp.h
@@ -610,8 +610,6 @@ struct regnode_ssc {
 #define REG_UNBOUNDED_QUANTIFIER_SEEN       0x00001000
 
 
-START_EXTERN_C
-
 #ifdef PLUGGABLE_RE_EXTENSION
 #include "re_nodes.h"
 #else
@@ -643,9 +641,6 @@ EXTCONST regexp_engine PL_core_reg_engine = {
 #endif /* PLUGGABLE_RE_EXTENSION */
 
 
-END_EXTERN_C
-
-
 /* .what is a character array with one character for each member of .data
  * The character describes the function of the corresponding .data item:
  *   a - AV for paren_name_list under DEBUGGING
diff --git a/regen/opcode.pl b/regen/opcode.pl
index 327e45e..8cc9e5c 100755
--- a/regen/opcode.pl
+++ b/regen/opcode.pl
@@ -814,7 +814,6 @@ sub print_PL_op_private_tables {
     }
 
     print $fh <<EOF;
-START_EXTERN_C
 
 #ifndef PERL_GLOBAL_STRUCT_INIT
 
@@ -893,8 +892,6 @@ $PL_op_private_valid
 #  endif /* !DOINIT */
 #endif /* !PERL_GLOBAL_STRUCT_INIT */
 
-END_EXTERN_C
-
 
 EOF
 
@@ -971,7 +968,6 @@ print $on "#define OP_FREED MAXO\n";
 # Emit op names and descriptions.
 
 print $oc <<'END';
-START_EXTERN_C
 
 #ifndef DOINIT
 EXTCONST char* const PL_op_name[];
@@ -1008,8 +1004,6 @@ print $oc <<'END';
 };
 #endif
 
-END_EXTERN_C
-
 #endif /* !PERL_GLOBAL_STRUCT_INIT */
 END
 
@@ -1017,8 +1011,6 @@ END
 
 print $oc <<'END';
 
-START_EXTERN_C
-
 #ifdef PERL_GLOBAL_STRUCT_INIT
 #  define PERL_PPADDR_INITED
 static const Perl_ppaddr_t Gppaddr[]
@@ -1185,8 +1177,6 @@ print $oc <<'END';
 #endif
 
 #endif /* !PERL_GLOBAL_STRUCT_INIT */
-
-END_EXTERN_C
 END
 
 # Emit OP_IS_* macros
diff --git a/utf8.h b/utf8.h
index aaf878c..8313298 100644
--- a/utf8.h
+++ b/utf8.h
@@ -89,7 +89,6 @@ than just the ASCII characters, so C<is_invariant_string> is preferred.
 #include "utfebcdic.h"
 
 #else	/* ! EBCDIC */
-START_EXTERN_C
 
 #ifdef DOINIT
 EXTCONST unsigned char PL_utf8skip[] = {
@@ -117,8 +116,6 @@ EXTCONST unsigned char PL_utf8skip[] = {
 EXTCONST unsigned char PL_utf8skip[];
 #endif
 
-END_EXTERN_C
-
 /* Native character to/from iso-8859-1.  Are the identity functions on ASCII
  * platforms */
 #define NATIVE_TO_LATIN1(ch)     (ch)
diff --git a/utfebcdic.h b/utfebcdic.h
index 23b4ae2..04e7276 100644
--- a/utfebcdic.h
+++ b/utfebcdic.h
@@ -97,8 +97,6 @@
  * UTF-EBCDIC is 0x3FFF, instead of 0x7FFF in UTF-8.
  */
 
-START_EXTERN_C
-
 #ifdef DOINIT
 
 #include "ebcdic_tables.h"
@@ -115,8 +113,6 @@ EXTCONST U8 PL_latin1_lc[];
 EXTCONST U8 PL_mod_latin1_uc[];
 #endif
 
-END_EXTERN_C
-
 /* EBCDIC-happy ways of converting native code to UTF-8 */
 
 #define NATIVE_TO_LATIN1(ch)            PL_e2a[(U8)(ch)]
-- 
1.7.9.msysgit.0

@p5pRT

This comment has been minimized.

Copy link
Collaborator Author

@p5pRT p5pRT commented Feb 9, 2015

From @steve-m-hay

On 4 February 2015 at 07​:18, bulk88 <perlbug-followup@​perl.org> wrote​:

# New Ticket Created by bulk88
# Please include the string​: [perl #123727]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl5/Ticket/Display.html?id=123727 >

This is a bug report for perl from bulk88@​hotmail.com,
generated with the help of perlbug 1.40 running under perl 5.21.4.

-----------------------------------------------------------------
[Please describe your issue here]

This patch never got any comments in its its original thread at
http​://www.nntp.perl.org/group/perl.perl5.porters/2015/01/msg225087.html
, so I am filing it as a ticket. It is not intended to be committed as
is (no commit body for example).

A couple of thoughts, without having tested it yet​:

I don't think the comment "Win32 GCC errors out with
"..\perl.h​:4614​:35​: error​: expected unqualified-id before string
constant" if dllexport is first, then EXTERN_C" in INTERN.h is
necessary. That's normal, isn't it? The extern "C" always has to be
first, e.g. VC++ also errors with​: "'__declspec(dllexport)' :
storage-class or type specifier(s) unexpected here; ignored. 'linkage
specification' requires use of keyword 'extern' and must precede all
other specifiers".

I've stared at the line

# if (defined(WIN32) && defined(__MINGW32__)) || defined(__SYMBIAN32__)

in INTERN.h before and wondered why something different is done for
MinGW compared to VC++ on Windows. Why do we have all the dllexport
stuff for MinGW but not for VC++? Couldn't the line change either to
"#if defined(WIN32) || defined(__SYMBIAN32__)" or to "#ifdef
__SYMBIAN32__"?

Otherwise it looks good to me, except for the "#ifdef DOINIT" part in
perl.h, which I didn't understand. I see that it's defining variables
after their declarations, but it's not obvious to me why this is
necessary now.

@p5pRT

This comment has been minimized.

Copy link
Collaborator Author

@p5pRT p5pRT commented Feb 9, 2015

The RT System itself - Status changed from 'new' to 'open'

@p5pRT

This comment has been minimized.

Copy link
Collaborator Author

@p5pRT p5pRT commented Mar 26, 2015

From @bulk88

On Tue Feb 03 23​:18​:42 2015, bulk88 wrote​:

This is a bug report for perl from bulk88@​hotmail.com,
generated with the help of perlbug 1.40 running under perl 5.21.4.

-----------------------------------------------------------------
[Please describe your issue here]

This patch never got any comments in its its original thread at
http​://www.nntp.perl.org/group/perl.perl5.porters/2015/01/msg225087.html
, so I am filing it as a ticket. It is not intended to be committed as
is (no commit body for example).

Updated patch attached. It fixes a regen.t failure. This doesn't address any of Steve Hay's concerns which I will get to later.

--
bulk88 ~ bulk88 at hotmail.com

@p5pRT

This comment has been minimized.

Copy link
Collaborator Author

@p5pRT p5pRT commented Mar 26, 2015

From @bulk88

0001-INTERN-EXTERN-C-cleanup.patch
From 0396b6e086746f16c9d4f0e0b36bf18c0d9f29ca Mon Sep 17 00:00:00 2001
From: Daniel Dragan <bulk88@hotmail.com>
Date: Thu, 26 Mar 2015 19:14:29 -0400
Subject: [PATCH] INTERN/EXTERN C++ cleanup

---
 EXTERN.h        |   20 ++++++++++----------
 INTERN.h        |   11 +++++++----
 opcode.h        |   10 ----------
 perl.h          |   19 +++++--------------
 perlapi.c       |    3 ---
 perlapi.h       |    8 --------
 regcomp.h       |    5 -----
 regen/embed.pl  |   11 -----------
 regen/opcode.pl |   10 ----------
 utf8.h          |    3 ---
 utfebcdic.h     |    4 ----
 11 files changed, 22 insertions(+), 82 deletions(-)

diff --git a/EXTERN.h b/EXTERN.h
index 4e4f1ad..345eccd 100644
--- a/EXTERN.h
+++ b/EXTERN.h
@@ -22,33 +22,33 @@
 #  if (defined(WIN32) || defined(__SYMBIAN32__)) && !defined(PERL_STATIC_SYMS)
     /* miniperl should not export anything */
 #    if defined(PERL_IS_MINIPERL) && !defined(UNDER_CE) && defined(_MSC_VER)
-#      define EXT extern
+#      define EXT EXTERN_C
 #      define dEXT 
-#      define EXTCONST extern const
+#      define EXTCONST EXTERN_C const
 #      define dEXTCONST const
 #    else
 #      if defined(PERLDLL) || defined(__SYMBIAN32__)
-#        define EXT extern __declspec(dllexport)
+#        define EXT EXTERN_C __declspec(dllexport)
 #        define dEXT 
-#        define EXTCONST extern __declspec(dllexport) const
+#        define EXTCONST EXTERN_C __declspec(dllexport) const
 #        define dEXTCONST const
 #      else
-#        define EXT extern __declspec(dllimport)
+#        define EXT EXTERN_C __declspec(dllimport)
 #        define dEXT 
-#        define EXTCONST extern __declspec(dllimport) const
+#        define EXTCONST EXTERN_C __declspec(dllimport) const
 #        define dEXTCONST const
 #      endif
 #    endif
 #  else
 #    if defined(__CYGWIN__) && defined(USEIMPORTLIB)
-#      define EXT extern __declspec(dllimport)
+#      define EXT EXTERN_C __declspec(dllimport)
 #      define dEXT 
-#      define EXTCONST extern __declspec(dllimport) const
+#      define EXTCONST EXTERN_C __declspec(dllimport) const
 #      define dEXTCONST const
 #    else
-#      define EXT extern
+#      define EXT EXTERN_C
 #      define dEXT
-#      define EXTCONST extern const
+#      define EXTCONST EXTERN_C const
 #      define dEXTCONST const
 #    endif
 #  endif
diff --git a/INTERN.h b/INTERN.h
index e6e0602..8b8df49 100644
--- a/INTERN.h
+++ b/INTERN.h
@@ -21,9 +21,12 @@
 
 #  if (defined(WIN32) && defined(__MINGW32__)) || defined(__SYMBIAN32__)
 #    ifdef __cplusplus
-#      define EXT	__declspec(dllexport)
+#      define EXT	EXTERN_C __declspec(dllexport)
 #      define dEXT
-#      define EXTCONST	__declspec(dllexport) extern const
+/* Win32 GCC errors out with
+  "..\perl.h:4614:35: error: expected unqualified-id before string constant"
+  if dllexport is first, then EXTERN_C */
+#      define EXTCONST	EXTERN_C __declspec(dllexport) const
 #      define dEXTCONST	const
 #    else
 #      define EXT	__declspec(dllexport)
@@ -33,9 +36,9 @@
 #    endif
 #  else
 #    ifdef __cplusplus
-#      define EXT
+#      define EXT      EXTERN_C
 #      define dEXT
-#      define EXTCONST extern const
+#      define EXTCONST EXTERN_C const
 #      define dEXTCONST const
 #    else
 #      define EXT
diff --git a/opcode.h b/opcode.h
index cf39a4b..a11e372 100644
--- a/opcode.h
+++ b/opcode.h
@@ -144,7 +144,6 @@
 #define Perl_pp_custom Perl_unimplemented_op
 #define Perl_pp_reach Perl_pp_rkeys
 #define Perl_pp_rvalues Perl_pp_rkeys
-START_EXTERN_C
 
 #ifndef DOINIT
 EXTCONST char* const PL_op_name[];
@@ -954,12 +953,8 @@ EXTCONST char* const PL_op_desc[] = {
 };
 #endif
 
-END_EXTERN_C
-
 #endif /* !PERL_GLOBAL_STRUCT_INIT */
 
-START_EXTERN_C
-
 #ifdef PERL_GLOBAL_STRUCT_INIT
 #  define PERL_PPADDR_INITED
 static const Perl_ppaddr_t Gppaddr[]
@@ -2195,8 +2190,6 @@ EXTCONST U32 PL_opargs[] = {
 
 #endif /* !PERL_GLOBAL_STRUCT_INIT */
 
-END_EXTERN_C
-
 
 #define OPpLVREF_SV             0x00
 #define OPpARG1_MASK            0x01
@@ -2292,7 +2285,6 @@ END_EXTERN_C
 #define OPpPV_IS_UTF8           0x80
 #define OPpSPLIT_IMPLIM         0x80
 #define OPpTRANS_DELETE         0x80
-START_EXTERN_C
 
 #ifndef PERL_GLOBAL_STRUCT_INIT
 
@@ -3321,8 +3313,6 @@ EXTCONST U8 PL_op_private_valid[] = {
 #  endif /* !DOINIT */
 #endif /* !PERL_GLOBAL_STRUCT_INIT */
 
-END_EXTERN_C
-
 
 
 /* ex: set ro: */
diff --git a/perl.h b/perl.h
index cc4111a..55383ad 100644
--- a/perl.h
+++ b/perl.h
@@ -4620,8 +4620,6 @@ extern char **	environ;	/* environment variables supplied via exec */
 				STRINGIFY(PERL_API_VERSION) "." \
 				STRINGIFY(PERL_API_SUBVERSION)
 
-START_EXTERN_C
-
 /* handy constants */
 EXTCONST char PL_warn_uninit[]
   INIT("Use of uninitialized value%s%s%s");
@@ -5203,8 +5201,6 @@ EXTCONST char *const PL_phase_names[];
 
 #define PL_hints PL_compiling.cop_hints
 
-END_EXTERN_C
-
 /*****************************************************************************/
 /* This lexer/parser stuff is currently global since yacc is hard to reenter */
 /*****************************************************************************/
@@ -5524,15 +5520,18 @@ struct tempsym; /* defined in pp_pack.c */
  * these include variables that would have been their struct-s
  */
 
+#ifdef DOINIT
+#define PERLVAR(prefix,var,type) EXT type PL_##var; type PL_##var;
+#define PERLVARA(prefix,var,n,type) EXT type PL_##var[n]; type PL_##var[n];
+#else
 #define PERLVAR(prefix,var,type) EXT type PL_##var;
 #define PERLVARA(prefix,var,n,type) EXT type PL_##var[n];
+#endif
 #define PERLVARI(prefix,var,type,init) EXT type  PL_##var INIT(init);
 #define PERLVARIC(prefix,var,type,init) EXTCONST type PL_##var INIT(init);
 
 #if !defined(MULTIPLICITY)
-START_EXTERN_C
 #  include "intrpvar.h"
-END_EXTERN_C
 #endif
 
 #ifdef PERL_CORE
@@ -5546,11 +5545,7 @@ END_EXTERN_C
 #include "embed.h"
 
 #ifndef PERL_GLOBAL_STRUCT
-START_EXTERN_C
-
 #  include "perlvars.h"
-
-END_EXTERN_C
 #endif
 
 #undef PERLVAR
@@ -5578,8 +5573,6 @@ struct PerlHandShakeInterpreter {
 #  undef PERLVARIC
 #endif
 
-START_EXTERN_C
-
 /* dummy variables that hold pointers to both runops functions, thus forcing
  * them *both* to get linked in (useful for Peek.xs, debugging etc) */
 
@@ -5675,8 +5668,6 @@ EXTCONST bool PL_valid_types_NV_set[];
 
 #include "overload.h"
 
-END_EXTERN_C
-
 struct am_table {
   U8 flags;
   U8 fallback;
diff --git a/perlapi.c b/perlapi.c
index 7858337..90111d8 100644
--- a/perlapi.c
+++ b/perlapi.c
@@ -31,7 +31,6 @@
 #if defined (MULTIPLICITY) && defined (PERL_GLOBAL_STRUCT)
 
 /* accessor functions for Perl "global" variables */
-START_EXTERN_C
 
 #undef PERLVARI
 #define PERLVARI(p,v,t,i) PERLVAR(p,v,t)
@@ -53,8 +52,6 @@ START_EXTERN_C
 #undef PERLVARI
 #undef PERLVARIC
 
-END_EXTERN_C
-
 #endif /* MULTIPLICITY && PERL_GLOBAL_STRUCT */
 
 /* ex: set ro: */
diff --git a/perlapi.h b/perlapi.h
index 5268c2c..4d512a2 100644
--- a/perlapi.h
+++ b/perlapi.h
@@ -22,8 +22,6 @@
 
 #if defined (MULTIPLICITY) && defined (PERL_GLOBAL_STRUCT)
 
-START_EXTERN_C
-
 #undef PERLVAR
 #undef PERLVARA
 #undef PERLVARI
@@ -41,8 +39,6 @@ START_EXTERN_C
 #undef PERLVARI
 #undef PERLVARIC
 
-END_EXTERN_C
-
 #if defined(PERL_CORE)
 
 /* accessor functions for Perl "global" variables */
@@ -52,8 +48,6 @@ END_EXTERN_C
 
 #ifndef PERL_NO_FORCE_LINK
 
-START_EXTERN_C
-
 #ifndef DOINIT
 EXTCONST void * const PL_force_link_funcs[];
 #else
@@ -93,8 +87,6 @@ EXTCONST void * const PL_force_link_funcs[] = {
 };
 #endif	/* DOINIT */
 
-END_EXTERN_C
-
 #endif	/* PERL_NO_FORCE_LINK */
 
 #else	/* !PERL_CORE */
diff --git a/regcomp.h b/regcomp.h
index c17bf62..a6c63e8 100644
--- a/regcomp.h
+++ b/regcomp.h
@@ -610,8 +610,6 @@ struct regnode_ssc {
 #define REG_UNBOUNDED_QUANTIFIER_SEEN       0x00001000
 
 
-START_EXTERN_C
-
 #ifdef PLUGGABLE_RE_EXTENSION
 #include "re_nodes.h"
 #else
@@ -643,9 +641,6 @@ EXTCONST regexp_engine PL_core_reg_engine = {
 #endif /* PLUGGABLE_RE_EXTENSION */
 
 
-END_EXTERN_C
-
-
 /* .what is a character array with one character for each member of .data
  * The character describes the function of the corresponding .data item:
  *   a - AV for paren_name_list under DEBUGGING
diff --git a/regen/embed.pl b/regen/embed.pl
index 07438de..5e28743 100755
--- a/regen/embed.pl
+++ b/regen/embed.pl
@@ -501,8 +501,6 @@ print $capih <<'EOT';
 
 #if defined (MULTIPLICITY) && defined (PERL_GLOBAL_STRUCT)
 
-START_EXTERN_C
-
 #undef PERLVAR
 #undef PERLVARA
 #undef PERLVARI
@@ -520,8 +518,6 @@ START_EXTERN_C
 #undef PERLVARI
 #undef PERLVARIC
 
-END_EXTERN_C
-
 #if defined(PERL_CORE)
 
 /* accessor functions for Perl "global" variables */
@@ -531,8 +527,6 @@ END_EXTERN_C
 
 #ifndef PERL_NO_FORCE_LINK
 
-START_EXTERN_C
-
 #ifndef DOINIT
 EXTCONST void * const PL_force_link_funcs[];
 #else
@@ -572,8 +566,6 @@ EXTCONST void * const PL_force_link_funcs[] = {
 };
 #endif	/* DOINIT */
 
-END_EXTERN_C
-
 #endif	/* PERL_NO_FORCE_LINK */
 
 #else	/* !PERL_CORE */
@@ -615,7 +607,6 @@ print $capi <<'EOT';
 #if defined (MULTIPLICITY) && defined (PERL_GLOBAL_STRUCT)
 
 /* accessor functions for Perl "global" variables */
-START_EXTERN_C
 
 #undef PERLVARI
 #define PERLVARI(p,v,t,i) PERLVAR(p,v,t)
@@ -637,8 +628,6 @@ START_EXTERN_C
 #undef PERLVARI
 #undef PERLVARIC
 
-END_EXTERN_C
-
 #endif /* MULTIPLICITY && PERL_GLOBAL_STRUCT */
 EOT
 
diff --git a/regen/opcode.pl b/regen/opcode.pl
index fe10584..6a80e1b 100755
--- a/regen/opcode.pl
+++ b/regen/opcode.pl
@@ -816,7 +816,6 @@ sub print_PL_op_private_tables {
     }
 
     print $fh <<EOF;
-START_EXTERN_C
 
 #ifndef PERL_GLOBAL_STRUCT_INIT
 
@@ -895,8 +894,6 @@ $PL_op_private_valid
 #  endif /* !DOINIT */
 #endif /* !PERL_GLOBAL_STRUCT_INIT */
 
-END_EXTERN_C
-
 
 EOF
 
@@ -973,7 +970,6 @@ print $on "#define OP_FREED MAXO\n";
 # Emit op names and descriptions.
 
 print $oc <<'END';
-START_EXTERN_C
 
 #ifndef DOINIT
 EXTCONST char* const PL_op_name[];
@@ -1010,8 +1006,6 @@ print $oc <<'END';
 };
 #endif
 
-END_EXTERN_C
-
 #endif /* !PERL_GLOBAL_STRUCT_INIT */
 END
 
@@ -1019,8 +1013,6 @@ END
 
 print $oc <<'END';
 
-START_EXTERN_C
-
 #ifdef PERL_GLOBAL_STRUCT_INIT
 #  define PERL_PPADDR_INITED
 static const Perl_ppaddr_t Gppaddr[]
@@ -1189,8 +1181,6 @@ print $oc <<'END';
 #endif
 
 #endif /* !PERL_GLOBAL_STRUCT_INIT */
-
-END_EXTERN_C
 END
 
 # Emit OP_IS_* macros
diff --git a/utf8.h b/utf8.h
index aaf878c..8313298 100644
--- a/utf8.h
+++ b/utf8.h
@@ -89,7 +89,6 @@ than just the ASCII characters, so C<is_invariant_string> is preferred.
 #include "utfebcdic.h"
 
 #else	/* ! EBCDIC */
-START_EXTERN_C
 
 #ifdef DOINIT
 EXTCONST unsigned char PL_utf8skip[] = {
@@ -117,8 +116,6 @@ EXTCONST unsigned char PL_utf8skip[] = {
 EXTCONST unsigned char PL_utf8skip[];
 #endif
 
-END_EXTERN_C
-
 /* Native character to/from iso-8859-1.  Are the identity functions on ASCII
  * platforms */
 #define NATIVE_TO_LATIN1(ch)     (ch)
diff --git a/utfebcdic.h b/utfebcdic.h
index 23b4ae2..04e7276 100644
--- a/utfebcdic.h
+++ b/utfebcdic.h
@@ -97,8 +97,6 @@
  * UTF-EBCDIC is 0x3FFF, instead of 0x7FFF in UTF-8.
  */
 
-START_EXTERN_C
-
 #ifdef DOINIT
 
 #include "ebcdic_tables.h"
@@ -115,8 +113,6 @@ EXTCONST U8 PL_latin1_lc[];
 EXTCONST U8 PL_mod_latin1_uc[];
 #endif
 
-END_EXTERN_C
-
 /* EBCDIC-happy ways of converting native code to UTF-8 */
 
 #define NATIVE_TO_LATIN1(ch)            PL_e2a[(U8)(ch)]
-- 
1.7.9.msysgit.0

@p5pRT

This comment has been minimized.

Copy link
Collaborator Author

@p5pRT p5pRT commented May 19, 2015

From @bulk88

Another patch update. VC6 but not any newer VCs doesn't like a "static __inline" declaration inside an "extern "C" {" block. So proto.h was fixed. Also PERL_CALLCONV_NO_RET was missing "extern "C"" in win32.h.

--
bulk88 ~ bulk88 at hotmail.com

@p5pRT

This comment has been minimized.

Copy link
Collaborator Author

@p5pRT p5pRT commented May 19, 2015

From @bulk88

0001-INTERN-EXTERN-C-cleanup.patch
From 9ab5732b45d6aadfc130d15845c3dbdf09318d11 Mon Sep 17 00:00:00 2001
From: Daniel Dragan <bulk88@hotmail.com>
Date: Tue, 19 May 2015 11:58:34 -0400
Subject: [PATCH] INTERN/EXTERN C++ cleanup

---
 EXTERN.h        |   20 ++++++++++----------
 INTERN.h        |   11 +++++++----
 opcode.h        |   10 ----------
 perl.h          |   19 +++++--------------
 perlapi.c       |    3 ---
 perlapi.h       |    8 --------
 proto.h         |    2 --
 regcomp.h       |    5 -----
 regen/embed.pl  |   13 -------------
 regen/opcode.pl |   10 ----------
 utf8.h          |    3 ---
 utfebcdic.h     |    4 ----
 win32/win32.h   |    6 +++++-
 13 files changed, 27 insertions(+), 87 deletions(-)

diff --git a/EXTERN.h b/EXTERN.h
index 4e4f1ad..345eccd 100644
--- a/EXTERN.h
+++ b/EXTERN.h
@@ -22,33 +22,33 @@
 #  if (defined(WIN32) || defined(__SYMBIAN32__)) && !defined(PERL_STATIC_SYMS)
     /* miniperl should not export anything */
 #    if defined(PERL_IS_MINIPERL) && !defined(UNDER_CE) && defined(_MSC_VER)
-#      define EXT extern
+#      define EXT EXTERN_C
 #      define dEXT 
-#      define EXTCONST extern const
+#      define EXTCONST EXTERN_C const
 #      define dEXTCONST const
 #    else
 #      if defined(PERLDLL) || defined(__SYMBIAN32__)
-#        define EXT extern __declspec(dllexport)
+#        define EXT EXTERN_C __declspec(dllexport)
 #        define dEXT 
-#        define EXTCONST extern __declspec(dllexport) const
+#        define EXTCONST EXTERN_C __declspec(dllexport) const
 #        define dEXTCONST const
 #      else
-#        define EXT extern __declspec(dllimport)
+#        define EXT EXTERN_C __declspec(dllimport)
 #        define dEXT 
-#        define EXTCONST extern __declspec(dllimport) const
+#        define EXTCONST EXTERN_C __declspec(dllimport) const
 #        define dEXTCONST const
 #      endif
 #    endif
 #  else
 #    if defined(__CYGWIN__) && defined(USEIMPORTLIB)
-#      define EXT extern __declspec(dllimport)
+#      define EXT EXTERN_C __declspec(dllimport)
 #      define dEXT 
-#      define EXTCONST extern __declspec(dllimport) const
+#      define EXTCONST EXTERN_C __declspec(dllimport) const
 #      define dEXTCONST const
 #    else
-#      define EXT extern
+#      define EXT EXTERN_C
 #      define dEXT
-#      define EXTCONST extern const
+#      define EXTCONST EXTERN_C const
 #      define dEXTCONST const
 #    endif
 #  endif
diff --git a/INTERN.h b/INTERN.h
index e6e0602..8b8df49 100644
--- a/INTERN.h
+++ b/INTERN.h
@@ -21,9 +21,12 @@
 
 #  if (defined(WIN32) && defined(__MINGW32__)) || defined(__SYMBIAN32__)
 #    ifdef __cplusplus
-#      define EXT	__declspec(dllexport)
+#      define EXT	EXTERN_C __declspec(dllexport)
 #      define dEXT
-#      define EXTCONST	__declspec(dllexport) extern const
+/* Win32 GCC errors out with
+  "..\perl.h:4614:35: error: expected unqualified-id before string constant"
+  if dllexport is first, then EXTERN_C */
+#      define EXTCONST	EXTERN_C __declspec(dllexport) const
 #      define dEXTCONST	const
 #    else
 #      define EXT	__declspec(dllexport)
@@ -33,9 +36,9 @@
 #    endif
 #  else
 #    ifdef __cplusplus
-#      define EXT
+#      define EXT      EXTERN_C
 #      define dEXT
-#      define EXTCONST extern const
+#      define EXTCONST EXTERN_C const
 #      define dEXTCONST const
 #    else
 #      define EXT
diff --git a/opcode.h b/opcode.h
index 5c4254b..b81bd4f 100644
--- a/opcode.h
+++ b/opcode.h
@@ -144,7 +144,6 @@
 #define Perl_pp_custom Perl_unimplemented_op
 #define Perl_pp_reach Perl_pp_rkeys
 #define Perl_pp_rvalues Perl_pp_rkeys
-START_EXTERN_C
 
 #ifndef DOINIT
 EXTCONST char* const PL_op_name[];
@@ -954,12 +953,8 @@ EXTCONST char* const PL_op_desc[] = {
 };
 #endif
 
-END_EXTERN_C
-
 #endif /* !PERL_GLOBAL_STRUCT_INIT */
 
-START_EXTERN_C
-
 #ifdef PERL_GLOBAL_STRUCT_INIT
 #  define PERL_PPADDR_INITED
 static const Perl_ppaddr_t Gppaddr[]
@@ -2195,8 +2190,6 @@ EXTCONST U32 PL_opargs[] = {
 
 #endif /* !PERL_GLOBAL_STRUCT_INIT */
 
-END_EXTERN_C
-
 
 #define OPpLVREF_SV             0x00
 #define OPpARG1_MASK            0x01
@@ -2292,7 +2285,6 @@ END_EXTERN_C
 #define OPpPV_IS_UTF8           0x80
 #define OPpSPLIT_IMPLIM         0x80
 #define OPpTRANS_DELETE         0x80
-START_EXTERN_C
 
 #ifndef PERL_GLOBAL_STRUCT_INIT
 
@@ -3319,8 +3311,6 @@ EXTCONST U8 PL_op_private_valid[] = {
 #  endif /* !DOINIT */
 #endif /* !PERL_GLOBAL_STRUCT_INIT */
 
-END_EXTERN_C
-
 
 
 /* ex: set ro: */
diff --git a/perl.h b/perl.h
index b9de947..9c9b8c0 100644
--- a/perl.h
+++ b/perl.h
@@ -4638,8 +4638,6 @@ extern char **	environ;	/* environment variables supplied via exec */
 				STRINGIFY(PERL_API_VERSION) "." \
 				STRINGIFY(PERL_API_SUBVERSION)
 
-START_EXTERN_C
-
 /* handy constants */
 EXTCONST char PL_warn_uninit[]
   INIT("Use of uninitialized value%s%s%s");
@@ -5221,8 +5219,6 @@ EXTCONST char *const PL_phase_names[];
 
 #define PL_hints PL_compiling.cop_hints
 
-END_EXTERN_C
-
 /*****************************************************************************/
 /* This lexer/parser stuff is currently global since yacc is hard to reenter */
 /*****************************************************************************/
@@ -5542,15 +5538,18 @@ struct tempsym; /* defined in pp_pack.c */
  * these include variables that would have been their struct-s
  */
 
+#ifdef DOINIT
+#define PERLVAR(prefix,var,type) EXT type PL_##var; type PL_##var;
+#define PERLVARA(prefix,var,n,type) EXT type PL_##var[n]; type PL_##var[n];
+#else
 #define PERLVAR(prefix,var,type) EXT type PL_##var;
 #define PERLVARA(prefix,var,n,type) EXT type PL_##var[n];
+#endif
 #define PERLVARI(prefix,var,type,init) EXT type  PL_##var INIT(init);
 #define PERLVARIC(prefix,var,type,init) EXTCONST type PL_##var INIT(init);
 
 #if !defined(MULTIPLICITY)
-START_EXTERN_C
 #  include "intrpvar.h"
-END_EXTERN_C
 #endif
 
 #ifdef PERL_CORE
@@ -5564,11 +5563,7 @@ END_EXTERN_C
 #include "embed.h"
 
 #ifndef PERL_GLOBAL_STRUCT
-START_EXTERN_C
-
 #  include "perlvars.h"
-
-END_EXTERN_C
 #endif
 
 #undef PERLVAR
@@ -5596,8 +5591,6 @@ struct PerlHandShakeInterpreter {
 #  undef PERLVARIC
 #endif
 
-START_EXTERN_C
-
 /* dummy variables that hold pointers to both runops functions, thus forcing
  * them *both* to get linked in (useful for Peek.xs, debugging etc) */
 
@@ -5693,8 +5686,6 @@ EXTCONST bool PL_valid_types_NV_set[];
 
 #include "overload.h"
 
-END_EXTERN_C
-
 struct am_table {
   U8 flags;
   U8 fallback;
diff --git a/perlapi.c b/perlapi.c
index 7858337..90111d8 100644
--- a/perlapi.c
+++ b/perlapi.c
@@ -31,7 +31,6 @@
 #if defined (MULTIPLICITY) && defined (PERL_GLOBAL_STRUCT)
 
 /* accessor functions for Perl "global" variables */
-START_EXTERN_C
 
 #undef PERLVARI
 #define PERLVARI(p,v,t,i) PERLVAR(p,v,t)
@@ -53,8 +52,6 @@ START_EXTERN_C
 #undef PERLVARI
 #undef PERLVARIC
 
-END_EXTERN_C
-
 #endif /* MULTIPLICITY && PERL_GLOBAL_STRUCT */
 
 /* ex: set ro: */
diff --git a/perlapi.h b/perlapi.h
index 5268c2c..4d512a2 100644
--- a/perlapi.h
+++ b/perlapi.h
@@ -22,8 +22,6 @@
 
 #if defined (MULTIPLICITY) && defined (PERL_GLOBAL_STRUCT)
 
-START_EXTERN_C
-
 #undef PERLVAR
 #undef PERLVARA
 #undef PERLVARI
@@ -41,8 +39,6 @@ START_EXTERN_C
 #undef PERLVARI
 #undef PERLVARIC
 
-END_EXTERN_C
-
 #if defined(PERL_CORE)
 
 /* accessor functions for Perl "global" variables */
@@ -52,8 +48,6 @@ END_EXTERN_C
 
 #ifndef PERL_NO_FORCE_LINK
 
-START_EXTERN_C
-
 #ifndef DOINIT
 EXTCONST void * const PL_force_link_funcs[];
 #else
@@ -93,8 +87,6 @@ EXTCONST void * const PL_force_link_funcs[] = {
 };
 #endif	/* DOINIT */
 
-END_EXTERN_C
-
 #endif	/* PERL_NO_FORCE_LINK */
 
 #else	/* !PERL_CORE */
diff --git a/proto.h b/proto.h
index 8ad321f..9fa5b7f 100644
--- a/proto.h
+++ b/proto.h
@@ -16,7 +16,6 @@
  * Edit those files and run 'make regen_headers' to effect changes.
  */
 
-START_EXTERN_C
 PERL_CALLCONV UV	ASCII_TO_NEED(const UV enc, const UV ch)
 			__attribute__deprecated__
 			__attribute__warn_unused_result__
@@ -8353,6 +8352,5 @@ PERL_CALLCONV int	Perl_magic_regdatum_set(pTHX_ SV* sv, MAGIC* mg)
 #ifdef PERL_CORE
 #  include "pp_proto.h"
 #endif
-END_EXTERN_C
 
 /* ex: set ro: */
diff --git a/regcomp.h b/regcomp.h
index f418086..eda2b46 100644
--- a/regcomp.h
+++ b/regcomp.h
@@ -608,8 +608,6 @@ struct regnode_ssc {
 #define REG_UNBOUNDED_QUANTIFIER_SEEN       0x00001000
 
 
-START_EXTERN_C
-
 #ifdef PLUGGABLE_RE_EXTENSION
 #include "re_nodes.h"
 #else
@@ -641,9 +639,6 @@ EXTCONST regexp_engine PL_core_reg_engine = {
 #endif /* PLUGGABLE_RE_EXTENSION */
 
 
-END_EXTERN_C
-
-
 /* .what is a character array with one character for each member of .data
  * The character describes the function of the corresponding .data item:
  *   a - AV for paren_name_list under DEBUGGING
diff --git a/regen/embed.pl b/regen/embed.pl
index 07438de..cb8068c 100755
--- a/regen/embed.pl
+++ b/regen/embed.pl
@@ -65,7 +65,6 @@ my ($embed, $core, $ext, $api) = setup_embed();
 # generate proto.h
 {
     my $pr = open_print_header("proto.h");
-    print $pr "START_EXTERN_C\n";
     my $ret;
 
     foreach (@$embed) {
@@ -229,7 +228,6 @@ my ($embed, $core, $ext, $api) = setup_embed();
 #ifdef PERL_CORE
 #  include "pp_proto.h"
 #endif
-END_EXTERN_C
 EOF
 
     read_only_bottom_close_and_rename($pr);
@@ -501,8 +499,6 @@ print $capih <<'EOT';
 
 #if defined (MULTIPLICITY) && defined (PERL_GLOBAL_STRUCT)
 
-START_EXTERN_C
-
 #undef PERLVAR
 #undef PERLVARA
 #undef PERLVARI
@@ -520,8 +516,6 @@ START_EXTERN_C
 #undef PERLVARI
 #undef PERLVARIC
 
-END_EXTERN_C
-
 #if defined(PERL_CORE)
 
 /* accessor functions for Perl "global" variables */
@@ -531,8 +525,6 @@ END_EXTERN_C
 
 #ifndef PERL_NO_FORCE_LINK
 
-START_EXTERN_C
-
 #ifndef DOINIT
 EXTCONST void * const PL_force_link_funcs[];
 #else
@@ -572,8 +564,6 @@ EXTCONST void * const PL_force_link_funcs[] = {
 };
 #endif	/* DOINIT */
 
-END_EXTERN_C
-
 #endif	/* PERL_NO_FORCE_LINK */
 
 #else	/* !PERL_CORE */
@@ -615,7 +605,6 @@ print $capi <<'EOT';
 #if defined (MULTIPLICITY) && defined (PERL_GLOBAL_STRUCT)
 
 /* accessor functions for Perl "global" variables */
-START_EXTERN_C
 
 #undef PERLVARI
 #define PERLVARI(p,v,t,i) PERLVAR(p,v,t)
@@ -637,8 +626,6 @@ START_EXTERN_C
 #undef PERLVARI
 #undef PERLVARIC
 
-END_EXTERN_C
-
 #endif /* MULTIPLICITY && PERL_GLOBAL_STRUCT */
 EOT
 
diff --git a/regen/opcode.pl b/regen/opcode.pl
index fe10584..6a80e1b 100755
--- a/regen/opcode.pl
+++ b/regen/opcode.pl
@@ -816,7 +816,6 @@ sub print_PL_op_private_tables {
     }
 
     print $fh <<EOF;
-START_EXTERN_C
 
 #ifndef PERL_GLOBAL_STRUCT_INIT
 
@@ -895,8 +894,6 @@ $PL_op_private_valid
 #  endif /* !DOINIT */
 #endif /* !PERL_GLOBAL_STRUCT_INIT */
 
-END_EXTERN_C
-
 
 EOF
 
@@ -973,7 +970,6 @@ print $on "#define OP_FREED MAXO\n";
 # Emit op names and descriptions.
 
 print $oc <<'END';
-START_EXTERN_C
 
 #ifndef DOINIT
 EXTCONST char* const PL_op_name[];
@@ -1010,8 +1006,6 @@ print $oc <<'END';
 };
 #endif
 
-END_EXTERN_C
-
 #endif /* !PERL_GLOBAL_STRUCT_INIT */
 END
 
@@ -1019,8 +1013,6 @@ END
 
 print $oc <<'END';
 
-START_EXTERN_C
-
 #ifdef PERL_GLOBAL_STRUCT_INIT
 #  define PERL_PPADDR_INITED
 static const Perl_ppaddr_t Gppaddr[]
@@ -1189,8 +1181,6 @@ print $oc <<'END';
 #endif
 
 #endif /* !PERL_GLOBAL_STRUCT_INIT */
-
-END_EXTERN_C
 END
 
 # Emit OP_IS_* macros
diff --git a/utf8.h b/utf8.h
index 3e15707..6a6315f 100644
--- a/utf8.h
+++ b/utf8.h
@@ -95,7 +95,6 @@ than just the ASCII characters, so C<is_invariant_string> is preferred.
 #include "utfebcdic.h"
 
 #else	/* ! EBCDIC */
-START_EXTERN_C
 
 #ifdef DOINIT
 EXTCONST unsigned char PL_utf8skip[] = {
@@ -123,8 +122,6 @@ EXTCONST unsigned char PL_utf8skip[] = {
 EXTCONST unsigned char PL_utf8skip[];
 #endif
 
-END_EXTERN_C
-
 /* Native character to/from iso-8859-1.  Are the identity functions on ASCII
  * platforms */
 #define NATIVE_TO_LATIN1(ch)     (ch)
diff --git a/utfebcdic.h b/utfebcdic.h
index 24101ed..df3404a 100644
--- a/utfebcdic.h
+++ b/utfebcdic.h
@@ -108,8 +108,6 @@
  * UTF-EBCDIC is 0x3FFF, instead of 0x7FFF in UTF-8.
  */
 
-START_EXTERN_C
-
 #ifdef DOINIT
 
 #include "ebcdic_tables.h"
@@ -126,8 +124,6 @@ EXTCONST U8 PL_latin1_lc[];
 EXTCONST U8 PL_mod_latin1_uc[];
 #endif
 
-END_EXTERN_C
-
 /* EBCDIC-happy ways of converting native code to UTF-8 */
 
 #define NATIVE_TO_LATIN1(ch)            PL_e2a[(U8)(ch)]
diff --git a/win32/win32.h b/win32/win32.h
index 107062a..c0e9073 100644
--- a/win32/win32.h
+++ b/win32/win32.h
@@ -120,7 +120,11 @@
 #  endif
 #else /* MSVC noreturn support inside the interp */
 #  ifdef _MSC_VER
-#    define PERL_CALLCONV_NO_RET __declspec(noreturn)
+#    ifdef __cplusplus
+#      define PERL_CALLCONV_NO_RET extern "C" __declspec(noreturn)
+#    else
+#      define PERL_CALLCONV_NO_RET __declspec(noreturn)
+#    endif
 #  endif
 #endif
 
-- 
1.7.9.msysgit.0

@p5pRT

This comment has been minimized.

Copy link
Collaborator Author

@p5pRT p5pRT commented Jul 29, 2015

From @tonycoz

On Tue May 19 09​:02​:06 2015, bulk88 wrote​:

Another patch update. VC6 but not any newer VCs doesn't like a "static
__inline" declaration inside an "extern "C" {" block. So proto.h was
fixed. Also PERL_CALLCONV_NO_RET was missing "extern "C"" in win32.h.

Is this still "not intended to be committed as is"? The description still doesn't say what it's trying to fix.

Tony

@p5pRT

This comment has been minimized.

Copy link
Collaborator Author

@p5pRT p5pRT commented Aug 3, 2015

From @bulk88

On Tue Jul 28 19​:11​:50 2015, tonyc wrote​:

On Tue May 19 09​:02​:06 2015, bulk88 wrote​:

Another patch update. VC6 but not any newer VCs doesn't like a
"static
__inline" declaration inside an "extern "C" {" block. So proto.h was
fixed. Also PERL_CALLCONV_NO_RET was missing "extern "C"" in win32.h.

Is this still "not intended to be committed as is"? The description
still doesn't say what it's trying to fix.

Tony

This patch was a proof of concept based on discussions in this thread http://www.nntp.perl.org/group/perl.perl5.porters/2015/01/msg225087.html

It removed the requirement to keep declarations and definitions inside multi-line blocks, and instead each declaration or definition statement, on its own, does the extern "C" for itself alone. In a C++ perl build there were problems where some symbols were just "extern" not "extern "C"" and that was causing linking problems with plain C XS or plain C parts of perl core in some corner cases. The patch also removes usage of "extern" (implied C++) from perl core. Everything should be more uniformly C names in C++ mode with this patch, rather than a pool of C++ perl symbols existing that plain C XS code happens to never try to link with since those C++ perl symbols aren't public api (not like p5p can technically enforce public API), but once in a while for whatever (perl macro got changed by P5P, XS author decides to use non-public macro or func/global data var) reason plain C code tries linking with that C++ symbol and C++ builds break.

For example this commit came as a result of that ML thread 7aa20b4..6635f04:/handy.h which shows perl is inconsistent in using extern "C" inside itself.

@toddr

This comment has been minimized.

Copy link
Contributor

@toddr toddr commented Feb 13, 2020

@bulk88 This patch no longer applies and appears to be only a proof of concept. I suggest a rebase and submitting the patch as a PR if we want to pursue it further.

@toddr toddr closed this Feb 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.