summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2011-05-14 12:26:37 +0100
committerNicholas Clark <nick@ccl4.org>2011-06-11 10:39:58 +0200
commit2d1f1fe5758d1f7ec388be4bc09f029dd0df5b7c (patch)
tree5a687231add1e5afc45981f9d7347df80776e0ad
parentb76b0bf9b926e6a5504a59a935a232eb91d44437 (diff)
downloadperl-2d1f1fe5758d1f7ec388be4bc09f029dd0df5b7c.tar.gz
Provide the names of the magic vtables in PL_magic_vtable_names[].
As it's a 1 to 1 mapping with the vtables in PL_magic_vtables[], refactor Perl_do_magic_dump() to index into it directly to find the name for an arbitrary mg_virtual, avoiding a long switch statement.
-rw-r--r--dump.c38
-rw-r--r--globvar.sym1
-rw-r--r--mg_vtable.h37
-rw-r--r--regen/mg_vtable.pl17
4 files changed, 56 insertions, 37 deletions
diff --git a/dump.c b/dump.c
index 97505fb7c4..8165a7abf4 100644
--- a/dump.c
+++ b/dump.c
@@ -1290,39 +1290,11 @@ Perl_do_magic_dump(pTHX_ I32 level, PerlIO *file, const MAGIC *mg, I32 nest, I32
" MAGIC = 0x%"UVxf"\n", PTR2UV(mg));
if (mg->mg_virtual) {
const MGVTBL * const v = mg->mg_virtual;
- const char *s;
- if (v == &PL_vtbl_sv) s = "sv";
- else if (v == &PL_vtbl_env) s = "env";
- else if (v == &PL_vtbl_envelem) s = "envelem";
-#ifndef PERL_MICRO
- else if (v == &PL_vtbl_sigelem) s = "sigelem";
-#endif
- else if (v == &PL_vtbl_pack) s = "pack";
- else if (v == &PL_vtbl_packelem) s = "packelem";
- else if (v == &PL_vtbl_dbline) s = "dbline";
- else if (v == &PL_vtbl_isa) s = "isa";
- else if (v == &PL_vtbl_arylen) s = "arylen";
- else if (v == &PL_vtbl_mglob) s = "mglob";
- else if (v == &PL_vtbl_nkeys) s = "nkeys";
- else if (v == &PL_vtbl_taint) s = "taint";
- else if (v == &PL_vtbl_substr) s = "substr";
- else if (v == &PL_vtbl_vec) s = "vec";
- else if (v == &PL_vtbl_pos) s = "pos";
- else if (v == &PL_vtbl_uvar) s = "uvar";
- else if (v == &PL_vtbl_defelem) s = "defelem";
-#ifdef USE_LOCALE_COLLATE
- else if (v == &PL_vtbl_collxfrm) s = "collxfrm";
-#endif
- else if (v == &PL_vtbl_amagic) s = "amagic";
- else if (v == &PL_vtbl_amagicelem) s = "amagicelem";
- else if (v == &PL_vtbl_backref) s = "backref";
- else if (v == &PL_vtbl_utf8) s = "utf8";
- else if (v == &PL_vtbl_arylen_p) s = "arylen_p";
- else if (v == &PL_vtbl_hintselem) s = "hintselem";
- else if (v == &PL_vtbl_hints) s = "hints";
- else s = NULL;
- if (s)
- Perl_dump_indent(aTHX_ level, file, " MG_VIRTUAL = &PL_vtbl_%s\n", s);
+ if (v >= PL_magic_vtables
+ && v < PL_magic_vtables + magic_vtable_max) {
+ const U32 i = v - PL_magic_vtables;
+ Perl_dump_indent(aTHX_ level, file, " MG_VIRTUAL = &PL_vtbl_%s\n", PL_magic_vtable_names[i]);
+ }
else
Perl_dump_indent(aTHX_ level, file, " MG_VIRTUAL = 0x%"UVxf"\n", PTR2UV(v));
}
diff --git a/globvar.sym b/globvar.sym
index bb349731f1..49c2abf9a7 100644
--- a/globvar.sym
+++ b/globvar.sym
@@ -14,6 +14,7 @@ fold_locale
freq
keyword_plugin
magic_vtables
+magic_vtable_names
memory_wrap
no_aelem
no_dir_func
diff --git a/mg_vtable.h b/mg_vtable.h
index 52937d7460..516d2c949e 100644
--- a/mg_vtable.h
+++ b/mg_vtable.h
@@ -40,6 +40,43 @@ enum { /* pass one of these to get_vtbl */
magic_vtable_max
};
+#ifdef DOINIT
+EXTCONST char *PL_magic_vtable_names[magic_vtable_max] = {
+ "sv",
+ "env",
+ "envelem",
+ "sigelem",
+ "pack",
+ "packelem",
+ "dbline",
+ "isa",
+ "isaelem",
+ "arylen",
+ "arylen_p",
+ "mglob",
+ "nkeys",
+ "taint",
+ "substr",
+ "vec",
+ "pos",
+ "uvar",
+ "defelem",
+ "regexp",
+ "regdata",
+ "regdatum",
+ "amagic",
+ "amagicelem",
+ "backref",
+ "ovrld",
+ "utf8",
+ "collxfrm",
+ "hintselem",
+ "hints"
+};
+#else
+EXTCONST char *PL_magic_vtable_names[magic_vtable_max];
+#endif
+
/* These all need to be 0, not NULL, as NULL can be (void*)0, which is a
* pointer to data, whereas we're assigning pointers to functions, which are
* not the same beast. ANSI doesn't allow the assignment from one to the other.
diff --git a/regen/mg_vtable.pl b/regen/mg_vtable.pl
index 0e78029571..f527a3ed76 100644
--- a/regen/mg_vtable.pl
+++ b/regen/mg_vtable.pl
@@ -60,13 +60,22 @@ my $h = open_new('mg_vtable.h', '>',
style => '*' });
{
- my @names = map {"want_vtbl_$_"} grep {!ref $_} @sig;
- push @names, 'magic_vtable_max';
- local $" = ",\n ";
+ my @names = grep {!ref $_} @sig;
+ my $want = join ",\n ", (map {"want_vtbl_$_"} @names), 'magic_vtable_max';
+ my $names = join qq{",\n "}, @names;
+
print $h <<"EOH";
enum { /* pass one of these to get_vtbl */
- @names
+ $want
+};
+
+#ifdef DOINIT
+EXTCONST char *PL_magic_vtable_names[magic_vtable_max] = {
+ "$names"
};
+#else
+EXTCONST char *PL_magic_vtable_names[magic_vtable_max];
+#endif
EOH
}