From: Jarkko Hietaniemi Date: Mon, 17 Jul 2006 09:09:24 +0000 (+0300) Subject: make magic vtables const if PERL_GLOBAL_STRUCT_PRIVATE X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=bc028b6b7f0f25fba45e10fa46e3fe91dbe9a76d;p=p5sagit%2Fp5-mst-13.2.git make magic vtables const if PERL_GLOBAL_STRUCT_PRIVATE Message-ID: <44BB2994.5090609@iki.fi> p4raw-id: //depot/perl@28599 --- diff --git a/perl.h b/perl.h index 949fb51..ef558a4 100644 --- a/perl.h +++ b/perl.h @@ -4460,14 +4460,23 @@ END_EXTERN_C 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( diff --git a/pod/perlguts.pod b/pod/perlguts.pod index a39c8f9..bbf8742 100644 --- a/pod/perlguts.pod +++ b/pod/perlguts.pod @@ -1914,6 +1914,12 @@ please see F for usage details. You may also need to use C 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 libperl.a | grep -v ' [TURtr] ' + +If this displays any C or C 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 diff --git a/pod/perlhack.pod b/pod/perlhack.pod index f2109bb..efa3344 100644 --- a/pod/perlhack.pod +++ b/pod/perlhack.pod @@ -2404,9 +2404,9 @@ therefore more ways for things to go wrong. You should try it. 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 (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 (at the very end for binary compatibility). Introducing read-only (const) globals is okay, as long as you verify with e.g. C (if your C has @@ -2417,12 +2417,17 @@ If you want to have static strings, make them constant: 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 Cs: 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. + =item * Not exporting your new function