Change 28599 by [EMAIL PROTECTED] on 2006/07/18 21:43:52

        Subject: [PATCH] make magic vtables const if PERL_GLOBAL_STRUCT_PRIVATE
        From: Jarkko Hietaniemi <[EMAIL PROTECTED]>
        Date: Mon, 17 Jul 2006 09:09:24 +0300
        Message-ID: <[EMAIL PROTECTED]>

Affected files ...

... //depot/perl/perl.h#710 edit
... //depot/perl/pod/perlguts.pod#139 edit
... //depot/perl/pod/perlhack.pod#116 edit

Differences ...

==== //depot/perl/perl.h#710 (text) ====
Index: perl/perl.h
--- perl/perl.h#709~28582~      2006-07-15 14:59:43.000000000 -0700
+++ perl/perl.h 2006-07-18 14:43:52.000000000 -0700
@@ -4460,14 +4460,23 @@
 
 START_EXTERN_C
 
+/* PERL_GLOBAL_STRUCT_PRIVATE wants to keep global data like the
+ * magic vtables const, but this is incompatible with SWIG which
+ * does want to modify the vtables. */
+#ifdef PERL_GLOBAL_STRUCT_PRIVATE
+#  define EXT_MGVTBL EXTCONST MGVTBL
+#else
+#  define EXT_MGVTBL EXT MGVTBL
+#endif
+
 #ifdef DOINIT
-#  define MGVTBL_SET(var,a,b,c,d,e,f,g,h) EXT MGVTBL var = {a,b,c,d,e,f,g,h}
+#  define MGVTBL_SET(var,a,b,c,d,e,f,g,h) EXT_MGVTBL var = {a,b,c,d,e,f,g,h}
 /* Like MGVTBL_SET but with the get magic having a const MG* */
-#  define MGVTBL_SET_CONST_MAGIC_GET(var,a,b,c,d,e,f,g,h) EXT MGVTBL var \
+#  define MGVTBL_SET_CONST_MAGIC_GET(var,a,b,c,d,e,f,g,h) EXT_MGVTBL var \
     = {(int (*)(pTHX_ SV *, MAGIC *))a,b,c,d,e,f,g,h}
 #else
-#  define MGVTBL_SET(var,a,b,c,d,e,f,g,h) EXT MGVTBL var
-#  define MGVTBL_SET_CONST_MAGIC_GET(var,a,b,c,d,e,f,g,h) EXT MGVTBL var
+#  define MGVTBL_SET(var,a,b,c,d,e,f,g,h) EXT_MGVTBL var
+#  define MGVTBL_SET_CONST_MAGIC_GET(var,a,b,c,d,e,f,g,h) EXT_MGVTBL var
 #endif
 
 MGVTBL_SET(

==== //depot/perl/pod/perlguts.pod#139 (text) ====
Index: perl/pod/perlguts.pod
--- perl/pod/perlguts.pod#138~28430~    2006-06-26 09:29:06.000000000 -0700
+++ perl/pod/perlguts.pod       2006-07-18 14:43:52.000000000 -0700
@@ -1914,6 +1914,12 @@
 to use C<dVAR> in your coding to "declare the global variables"
 when you are using them.  dTHX does this for you automatically.
 
+To see whether you have non-const data you can use a BSD-compatible C<nm>:
+
+  nm libperl.a | grep -v ' [TURtr] '
+
+If this displays any C<D> or C<d> symbols, you have non-const data.
+
 For backward compatibility reasons defining just PERL_GLOBAL_STRUCT
 doesn't actually hide all symbols inside a big global struct: some
 PerlIO_xxx vtables are left visible.  The PERL_GLOBAL_STRUCT_PRIVATE

==== //depot/perl/pod/perlhack.pod#116 (text) ====
Index: perl/pod/perlhack.pod
--- perl/pod/perlhack.pod#115~28595~    2006-07-17 14:11:52.000000000 -0700
+++ perl/pod/perlhack.pod       2006-07-18 14:43:52.000000000 -0700
@@ -2404,9 +2404,9 @@
 Introducing (non-read-only) globals
 
 Do not introduce any modifiable globals, truly global or file static.
-They are bad form and break multithreading.  The right way is to
-introduce them as new interpreter variables, see F<intrpvar.h> (at the
-very end for binary compatibility).
+They are bad form and complicate multithreading and other forms of
+concurrency.  The right way is to introduce them as new interpreter
+variables, see F<intrpvar.h> (at the very end for binary compatibility).
 
 Introducing read-only (const) globals is okay, as long as you verify
 with e.g. C<nm libperl.a|egrep -v ' [TURtr] '> (if your C<nm> has
@@ -2417,12 +2417,17 @@
 
   static const char etc[] = "...";
 
-If you want to have arrays of static strings, note carefully
+If you want to have arrays of constant strings, note carefully
 the right combination of C<const>s:
 
     static const char * const yippee[] =
        {"hi", "ho", "silver"};
 
+There is a way to completely hide any modifiable globals (they are all
+moved to heap), the compilation setting C<-DPERL_GLOBAL_STRUCT_PRIVATE>.
+It is not normally used, but can be used for testing, read more
+about it in L<perlhack>.
+
 =item *
 
 Not exporting your new function
End of Patch.

Reply via email to