From 0ffb5b03d3cde2b28eda4897b664c02ce9f0e9dd Mon Sep 17 00:00:00 2001 From: Nicholas Clark Date: Fri, 13 May 2011 16:50:51 +0100 Subject: [PATCH] Move the work of MGVTBL_SET() from the C pre-processor to mg_vtable.pl Generating mg_vtable.h with MGVTBL_SET() effectively pre-expanded makes things clearer. This eliminates use of the macro MGVTBL_SET(), which can be deleted as nothing outside the core is relying on it. --- mg_vtable.h | 609 ++++++++++++++++++++--------------------------------- perl.h | 6 - regen/mg_vtable.pl | 15 +- 3 files changed, 232 insertions(+), 398 deletions(-) diff --git a/mg_vtable.h b/mg_vtable.h index 4353088..6353353 100644 --- a/mg_vtable.h +++ b/mg_vtable.h @@ -12,8 +12,7 @@ * (although most, but not all, compilers are prepared to do it) */ -/* args are: - vtable +/* order is: get set len @@ -24,393 +23,233 @@ local */ -MGVTBL_SET( - PL_vtbl_sv, - Perl_magic_get, - Perl_magic_set, - Perl_magic_len, - 0, - 0, - 0, - 0, - 0 -); - -MGVTBL_SET( - PL_vtbl_env, - 0, - Perl_magic_set_all_env, - 0, - Perl_magic_clear_all_env, - 0, - 0, - 0, - 0 -); - -MGVTBL_SET( - PL_vtbl_envelem, - 0, - Perl_magic_setenv, - 0, - Perl_magic_clearenv, - 0, - 0, - 0, - 0 -); +#ifdef DOINIT +EXT_MGVTBL PL_vtbl_sv + = { Perl_magic_get, Perl_magic_set, Perl_magic_len, 0, 0, 0, 0, 0 }; +#else +EXT_MGVTBL PL_vtbl_sv; +#endif + +#ifdef DOINIT +EXT_MGVTBL PL_vtbl_env + = { 0, Perl_magic_set_all_env, 0, Perl_magic_clear_all_env, 0, 0, 0, 0 }; +#else +EXT_MGVTBL PL_vtbl_env; +#endif + +#ifdef DOINIT +EXT_MGVTBL PL_vtbl_envelem + = { 0, Perl_magic_setenv, 0, Perl_magic_clearenv, 0, 0, 0, 0 }; +#else +EXT_MGVTBL PL_vtbl_envelem; +#endif #ifndef PERL_MICRO -MGVTBL_SET( - PL_vtbl_sigelem, - Perl_magic_getsig, - Perl_magic_setsig, - 0, - Perl_magic_clearsig, - 0, - 0, - 0, - 0 -); -#endif - -MGVTBL_SET( - PL_vtbl_pack, - 0, - 0, - Perl_magic_sizepack, - Perl_magic_wipepack, - 0, - 0, - 0, - 0 -); - -MGVTBL_SET( - PL_vtbl_packelem, - Perl_magic_getpack, - Perl_magic_setpack, - 0, - Perl_magic_clearpack, - 0, - 0, - 0, - 0 -); - -MGVTBL_SET( - PL_vtbl_dbline, - 0, - Perl_magic_setdbline, - 0, - 0, - 0, - 0, - 0, - 0 -); - -MGVTBL_SET( - PL_vtbl_isa, - 0, - Perl_magic_setisa, - 0, - Perl_magic_clearisa, - 0, - 0, - 0, - 0 -); - -MGVTBL_SET( - PL_vtbl_isaelem, - 0, - Perl_magic_setisa, - 0, - 0, - 0, - 0, - 0, - 0 -); - -MGVTBL_SET( - PL_vtbl_arylen, - (int (*)(pTHX_ SV *, MAGIC *))Perl_magic_getarylen, - Perl_magic_setarylen, - 0, - 0, - 0, - 0, - 0, - 0 -); - -MGVTBL_SET( - PL_vtbl_arylen_p, - 0, - 0, - 0, - 0, - Perl_magic_freearylen_p, - 0, - 0, - 0 -); - -MGVTBL_SET( - PL_vtbl_mglob, - 0, - Perl_magic_setmglob, - 0, - 0, - 0, - 0, - 0, - 0 -); - -MGVTBL_SET( - PL_vtbl_nkeys, - Perl_magic_getnkeys, - Perl_magic_setnkeys, - 0, - 0, - 0, - 0, - 0, - 0 -); - -MGVTBL_SET( - PL_vtbl_taint, - Perl_magic_gettaint, - Perl_magic_settaint, - 0, - 0, - 0, - 0, - 0, - 0 -); - -MGVTBL_SET( - PL_vtbl_substr, - Perl_magic_getsubstr, - Perl_magic_setsubstr, - 0, - 0, - 0, - 0, - 0, - 0 -); - -MGVTBL_SET( - PL_vtbl_vec, - Perl_magic_getvec, - Perl_magic_setvec, - 0, - 0, - 0, - 0, - 0, - 0 -); - -MGVTBL_SET( - PL_vtbl_pos, - Perl_magic_getpos, - Perl_magic_setpos, - 0, - 0, - 0, - 0, - 0, - 0 -); - -MGVTBL_SET( - PL_vtbl_bm, - 0, - Perl_magic_setregexp, - 0, - 0, - 0, - 0, - 0, - 0 -); - -MGVTBL_SET( - PL_vtbl_fm, - 0, - Perl_magic_setregexp, - 0, - 0, - 0, - 0, - 0, - 0 -); - -MGVTBL_SET( - PL_vtbl_uvar, - Perl_magic_getuvar, - Perl_magic_setuvar, - 0, - 0, - 0, - 0, - 0, - 0 -); - -MGVTBL_SET( - PL_vtbl_defelem, - Perl_magic_getdefelem, - Perl_magic_setdefelem, - 0, - 0, - 0, - 0, - 0, - 0 -); - -MGVTBL_SET( - PL_vtbl_regexp, - 0, - Perl_magic_setregexp, - 0, - 0, - 0, - 0, - 0, - 0 -); - -MGVTBL_SET( - PL_vtbl_regdata, - 0, - 0, - Perl_magic_regdata_cnt, - 0, - 0, - 0, - 0, - 0 -); - -MGVTBL_SET( - PL_vtbl_regdatum, - Perl_magic_regdatum_get, - Perl_magic_regdatum_set, - 0, - 0, - 0, - 0, - 0, - 0 -); - -MGVTBL_SET( - PL_vtbl_amagic, - 0, - Perl_magic_setamagic, - 0, - 0, - Perl_magic_setamagic, - 0, - 0, - 0 -); - -MGVTBL_SET( - PL_vtbl_amagicelem, - 0, - Perl_magic_setamagic, - 0, - 0, - Perl_magic_setamagic, - 0, - 0, - 0 -); - -MGVTBL_SET( - PL_vtbl_backref, - 0, - 0, - 0, - 0, - Perl_magic_killbackrefs, - 0, - 0, - 0 -); - -MGVTBL_SET( - PL_vtbl_ovrld, - 0, - 0, - 0, - 0, - Perl_magic_freeovrld, - 0, - 0, - 0 -); - -MGVTBL_SET( - PL_vtbl_utf8, - 0, - Perl_magic_setutf8, - 0, - 0, - 0, - 0, - 0, - 0 -); +#ifdef DOINIT +EXT_MGVTBL PL_vtbl_sigelem + = { Perl_magic_getsig, Perl_magic_setsig, 0, Perl_magic_clearsig, 0, 0, 0, 0 }; +#else +EXT_MGVTBL PL_vtbl_sigelem; +#endif +#endif + +#ifdef DOINIT +EXT_MGVTBL PL_vtbl_pack + = { 0, 0, Perl_magic_sizepack, Perl_magic_wipepack, 0, 0, 0, 0 }; +#else +EXT_MGVTBL PL_vtbl_pack; +#endif + +#ifdef DOINIT +EXT_MGVTBL PL_vtbl_packelem + = { Perl_magic_getpack, Perl_magic_setpack, 0, Perl_magic_clearpack, 0, 0, 0, 0 }; +#else +EXT_MGVTBL PL_vtbl_packelem; +#endif + +#ifdef DOINIT +EXT_MGVTBL PL_vtbl_dbline + = { 0, Perl_magic_setdbline, 0, 0, 0, 0, 0, 0 }; +#else +EXT_MGVTBL PL_vtbl_dbline; +#endif + +#ifdef DOINIT +EXT_MGVTBL PL_vtbl_isa + = { 0, Perl_magic_setisa, 0, Perl_magic_clearisa, 0, 0, 0, 0 }; +#else +EXT_MGVTBL PL_vtbl_isa; +#endif + +#ifdef DOINIT +EXT_MGVTBL PL_vtbl_isaelem + = { 0, Perl_magic_setisa, 0, 0, 0, 0, 0, 0 }; +#else +EXT_MGVTBL PL_vtbl_isaelem; +#endif + +#ifdef DOINIT +EXT_MGVTBL PL_vtbl_arylen + = { (int (*)(pTHX_ SV *, MAGIC *))Perl_magic_getarylen, Perl_magic_setarylen, 0, 0, 0, 0, 0, 0 }; +#else +EXT_MGVTBL PL_vtbl_arylen; +#endif + +#ifdef DOINIT +EXT_MGVTBL PL_vtbl_arylen_p + = { 0, 0, 0, 0, Perl_magic_freearylen_p, 0, 0, 0 }; +#else +EXT_MGVTBL PL_vtbl_arylen_p; +#endif + +#ifdef DOINIT +EXT_MGVTBL PL_vtbl_mglob + = { 0, Perl_magic_setmglob, 0, 0, 0, 0, 0, 0 }; +#else +EXT_MGVTBL PL_vtbl_mglob; +#endif + +#ifdef DOINIT +EXT_MGVTBL PL_vtbl_nkeys + = { Perl_magic_getnkeys, Perl_magic_setnkeys, 0, 0, 0, 0, 0, 0 }; +#else +EXT_MGVTBL PL_vtbl_nkeys; +#endif + +#ifdef DOINIT +EXT_MGVTBL PL_vtbl_taint + = { Perl_magic_gettaint, Perl_magic_settaint, 0, 0, 0, 0, 0, 0 }; +#else +EXT_MGVTBL PL_vtbl_taint; +#endif + +#ifdef DOINIT +EXT_MGVTBL PL_vtbl_substr + = { Perl_magic_getsubstr, Perl_magic_setsubstr, 0, 0, 0, 0, 0, 0 }; +#else +EXT_MGVTBL PL_vtbl_substr; +#endif + +#ifdef DOINIT +EXT_MGVTBL PL_vtbl_vec + = { Perl_magic_getvec, Perl_magic_setvec, 0, 0, 0, 0, 0, 0 }; +#else +EXT_MGVTBL PL_vtbl_vec; +#endif + +#ifdef DOINIT +EXT_MGVTBL PL_vtbl_pos + = { Perl_magic_getpos, Perl_magic_setpos, 0, 0, 0, 0, 0, 0 }; +#else +EXT_MGVTBL PL_vtbl_pos; +#endif + +#ifdef DOINIT +EXT_MGVTBL PL_vtbl_bm + = { 0, Perl_magic_setregexp, 0, 0, 0, 0, 0, 0 }; +#else +EXT_MGVTBL PL_vtbl_bm; +#endif + +#ifdef DOINIT +EXT_MGVTBL PL_vtbl_fm + = { 0, Perl_magic_setregexp, 0, 0, 0, 0, 0, 0 }; +#else +EXT_MGVTBL PL_vtbl_fm; +#endif + +#ifdef DOINIT +EXT_MGVTBL PL_vtbl_uvar + = { Perl_magic_getuvar, Perl_magic_setuvar, 0, 0, 0, 0, 0, 0 }; +#else +EXT_MGVTBL PL_vtbl_uvar; +#endif + +#ifdef DOINIT +EXT_MGVTBL PL_vtbl_defelem + = { Perl_magic_getdefelem, Perl_magic_setdefelem, 0, 0, 0, 0, 0, 0 }; +#else +EXT_MGVTBL PL_vtbl_defelem; +#endif + +#ifdef DOINIT +EXT_MGVTBL PL_vtbl_regexp + = { 0, Perl_magic_setregexp, 0, 0, 0, 0, 0, 0 }; +#else +EXT_MGVTBL PL_vtbl_regexp; +#endif + +#ifdef DOINIT +EXT_MGVTBL PL_vtbl_regdata + = { 0, 0, Perl_magic_regdata_cnt, 0, 0, 0, 0, 0 }; +#else +EXT_MGVTBL PL_vtbl_regdata; +#endif + +#ifdef DOINIT +EXT_MGVTBL PL_vtbl_regdatum + = { Perl_magic_regdatum_get, Perl_magic_regdatum_set, 0, 0, 0, 0, 0, 0 }; +#else +EXT_MGVTBL PL_vtbl_regdatum; +#endif + +#ifdef DOINIT +EXT_MGVTBL PL_vtbl_amagic + = { 0, Perl_magic_setamagic, 0, 0, Perl_magic_setamagic, 0, 0, 0 }; +#else +EXT_MGVTBL PL_vtbl_amagic; +#endif + +#ifdef DOINIT +EXT_MGVTBL PL_vtbl_amagicelem + = { 0, Perl_magic_setamagic, 0, 0, Perl_magic_setamagic, 0, 0, 0 }; +#else +EXT_MGVTBL PL_vtbl_amagicelem; +#endif + +#ifdef DOINIT +EXT_MGVTBL PL_vtbl_backref + = { 0, 0, 0, 0, Perl_magic_killbackrefs, 0, 0, 0 }; +#else +EXT_MGVTBL PL_vtbl_backref; +#endif + +#ifdef DOINIT +EXT_MGVTBL PL_vtbl_ovrld + = { 0, 0, 0, 0, Perl_magic_freeovrld, 0, 0, 0 }; +#else +EXT_MGVTBL PL_vtbl_ovrld; +#endif + +#ifdef DOINIT +EXT_MGVTBL PL_vtbl_utf8 + = { 0, Perl_magic_setutf8, 0, 0, 0, 0, 0, 0 }; +#else +EXT_MGVTBL PL_vtbl_utf8; +#endif #ifdef USE_LOCALE_COLLATE -MGVTBL_SET( - PL_vtbl_collxfrm, - 0, - Perl_magic_setcollxfrm, - 0, - 0, - 0, - 0, - 0, - 0 -); -#endif - -MGVTBL_SET( - PL_vtbl_hintselem, - 0, - Perl_magic_sethint, - 0, - Perl_magic_clearhint, - 0, - 0, - 0, - 0 -); - -MGVTBL_SET( - PL_vtbl_hints, - 0, - 0, - 0, - Perl_magic_clearhints, - 0, - 0, - 0, - 0 -); +#ifdef DOINIT +EXT_MGVTBL PL_vtbl_collxfrm + = { 0, Perl_magic_setcollxfrm, 0, 0, 0, 0, 0, 0 }; +#else +EXT_MGVTBL PL_vtbl_collxfrm; +#endif +#endif + +#ifdef DOINIT +EXT_MGVTBL PL_vtbl_hintselem + = { 0, Perl_magic_sethint, 0, Perl_magic_clearhint, 0, 0, 0, 0 }; +#else +EXT_MGVTBL PL_vtbl_hintselem; +#endif + +#ifdef DOINIT +EXT_MGVTBL PL_vtbl_hints + = { 0, 0, 0, Perl_magic_clearhints, 0, 0, 0, 0 }; +#else +EXT_MGVTBL PL_vtbl_hints; +#endif /* ex: set ro: */ diff --git a/perl.h b/perl.h index c4e3d6d..d00255b 100644 --- a/perl.h +++ b/perl.h @@ -5108,12 +5108,6 @@ START_EXTERN_C # 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} -#else -# define MGVTBL_SET(var,a,b,c,d,e,f,g,h) EXT_MGVTBL var -#endif - #include "mg_vtable.h" #include "overload.h" diff --git a/regen/mg_vtable.pl b/regen/mg_vtable.pl index 6322b8b..bd48545 100644 --- a/regen/mg_vtable.pl +++ b/regen/mg_vtable.pl @@ -68,8 +68,7 @@ print $h <<'EOH'; * (although most, but not all, compilers are prepared to do it) */ -/* args are: - vtable +/* order is: get set len @@ -88,14 +87,16 @@ while (my ($name, $data) = splice @sig, 0, 2) { } qw(get set len clear free copy dup local); $funcs[0] = "(int (*)(pTHX_ SV *, MAGIC *))" . $funcs[0] if $data->{const}; - my $funcs = join ",\n ", @funcs; + my $funcs = join ", ", @funcs; print $h "$data->{cond}\n" if $data->{cond}; print $h <<"EOT"; -MGVTBL_SET( - PL_vtbl_$name, - $funcs -); +#ifdef DOINIT +EXT_MGVTBL PL_vtbl_$name + = { $funcs }; +#else +EXT_MGVTBL PL_vtbl_$name; +#endif EOT print $h "#endif\n" if $data->{cond}; print $h "\n"; -- 2.7.4