Skip to content

Commit 7b38f46

Browse files
committed
Also use C99 named initialisers in mg_vtable.h - unsuitable for C++ compilers
1 parent cf6347e commit 7b38f46

File tree

2 files changed

+43
-72
lines changed

2 files changed

+43
-72
lines changed

mg_vtable.h

Lines changed: 37 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -146,65 +146,49 @@ EXTCONST char * const PL_magic_vtable_names[magic_vtable_max] = {
146146
EXTCONST char * const PL_magic_vtable_names[magic_vtable_max];
147147
#endif
148148

149-
/* These all need to be 0, not NULL, as NULL can be (void*)0, which is a
150-
* pointer to data, whereas we're assigning pointers to functions, which are
151-
* not the same beast. ANSI doesn't allow the assignment from one to the other.
152-
* (although most, but not all, compilers are prepared to do it)
153-
*/
154-
155-
/* order is:
156-
get
157-
set
158-
len
159-
clear
160-
free
161-
copy
162-
dup
163-
local
164-
*/
165149

166150
#ifdef DOINIT
167151
EXT_MGVTBL PL_magic_vtables[magic_vtable_max] = {
168-
{ (int (*)(pTHX_ SV *, MAGIC *))Perl_magic_getarylen, Perl_magic_setarylen, 0, 0, 0, 0, 0, 0 },
169-
{ 0, 0, 0, Perl_magic_cleararylen_p, Perl_magic_freearylen_p, 0, 0, 0 },
170-
{ 0, 0, 0, 0, Perl_magic_killbackrefs, 0, 0, 0 },
171-
{ 0, 0, 0, 0, 0, Perl_magic_copycallchecker, 0, 0 },
152+
{ .svt_get = (int (*)(pTHX_ SV *, MAGIC *))Perl_magic_getarylen, .svt_set = Perl_magic_setarylen },
153+
{ .svt_clear = Perl_magic_cleararylen_p, .svt_free = Perl_magic_freearylen_p },
154+
{ .svt_free = Perl_magic_killbackrefs },
155+
{ .svt_copy = Perl_magic_copycallchecker },
172156
#ifdef USE_LOCALE_COLLATE
173-
{ 0, Perl_magic_setcollxfrm, 0, 0, Perl_magic_freecollxfrm, 0, 0, 0 },
157+
{ .svt_set = Perl_magic_setcollxfrm, .svt_free = Perl_magic_freecollxfrm },
174158
#else
175-
{ 0, 0, 0, 0, 0, 0, 0, 0 },
159+
{ .svt_get = 0 },
176160
#endif
177-
{ 0, Perl_magic_setdbline, 0, 0, 0, 0, 0, 0 },
178-
{ Perl_magic_getdebugvar, Perl_magic_setdebugvar, 0, 0, 0, 0, 0, 0 },
179-
{ Perl_magic_getdefelem, Perl_magic_setdefelem, 0, 0, 0, 0, 0, 0 },
180-
{ 0, 0, 0, 0, Perl_magic_freedestruct, 0, 0, 0 },
181-
{ 0, Perl_magic_set_all_env, 0, Perl_magic_clear_all_env, 0, 0, 0, 0 },
182-
{ 0, Perl_magic_setenv, 0, Perl_magic_clearenv, 0, 0, 0, 0 },
183-
{ 0, 0, 0, Perl_magic_clearhints, 0, 0, 0, 0 },
184-
{ 0, Perl_magic_sethint, 0, Perl_magic_clearhint, 0, 0, 0, 0 },
185-
{ 0, Perl_magic_sethookall, 0, Perl_magic_clearhookall, 0, 0, 0, 0 },
186-
{ 0, Perl_magic_sethook, 0, Perl_magic_clearhook, 0, 0, 0, 0 },
187-
{ 0, Perl_magic_setisa, 0, Perl_magic_clearisa, 0, 0, 0, 0 },
188-
{ 0, Perl_magic_setisa, 0, 0, 0, 0, 0, 0 },
189-
{ 0, Perl_magic_setlvref, 0, 0, 0, 0, 0, 0 },
190-
{ 0, Perl_magic_setmglob, 0, 0, Perl_magic_freemglob, 0, 0, 0 },
191-
{ Perl_magic_getnkeys, Perl_magic_setnkeys, 0, 0, 0, 0, 0, 0 },
192-
{ 0, Perl_magic_setnonelem, 0, 0, 0, 0, 0, 0 },
193-
{ 0, 0, 0, 0, Perl_magic_freeovrld, 0, 0, 0 },
194-
{ 0, 0, Perl_magic_sizepack, Perl_magic_wipepack, 0, 0, 0, 0 },
195-
{ Perl_magic_getpack, Perl_magic_setpack, 0, Perl_magic_clearpack, 0, 0, 0, 0 },
196-
{ Perl_magic_getpos, Perl_magic_setpos, 0, 0, 0, 0, 0, 0 },
197-
{ 0, 0, Perl_magic_regdata_cnt, 0, 0, 0, 0, 0 },
198-
{ Perl_magic_regdatum_get, Perl_magic_regdatum_set, 0, 0, 0, 0, 0, 0 },
199-
{ 0, Perl_magic_setregexp, 0, 0, 0, 0, 0, 0 },
200-
{ 0, Perl_magic_setsigall, 0, 0, 0, 0, 0, 0 },
201-
{ Perl_magic_getsig, Perl_magic_setsig, 0, Perl_magic_clearsig, 0, 0, 0, 0 },
202-
{ Perl_magic_getsubstr, Perl_magic_setsubstr, 0, 0, 0, 0, 0, 0 },
203-
{ Perl_magic_get, Perl_magic_set, 0, 0, 0, 0, 0, 0 },
204-
{ Perl_magic_gettaint, Perl_magic_settaint, 0, 0, 0, 0, 0, 0 },
205-
{ 0, Perl_magic_setutf8, 0, 0, Perl_magic_freeutf8, 0, 0, 0 },
206-
{ Perl_magic_getuvar, Perl_magic_setuvar, 0, 0, 0, 0, 0, 0 },
207-
{ Perl_magic_getvec, Perl_magic_setvec, 0, 0, 0, 0, 0, 0 }
161+
{ .svt_set = Perl_magic_setdbline },
162+
{ .svt_get = Perl_magic_getdebugvar, .svt_set = Perl_magic_setdebugvar },
163+
{ .svt_get = Perl_magic_getdefelem, .svt_set = Perl_magic_setdefelem },
164+
{ .svt_free = Perl_magic_freedestruct },
165+
{ .svt_set = Perl_magic_set_all_env, .svt_clear = Perl_magic_clear_all_env },
166+
{ .svt_set = Perl_magic_setenv, .svt_clear = Perl_magic_clearenv },
167+
{ .svt_clear = Perl_magic_clearhints },
168+
{ .svt_set = Perl_magic_sethint, .svt_clear = Perl_magic_clearhint },
169+
{ .svt_set = Perl_magic_sethookall, .svt_clear = Perl_magic_clearhookall },
170+
{ .svt_set = Perl_magic_sethook, .svt_clear = Perl_magic_clearhook },
171+
{ .svt_set = Perl_magic_setisa, .svt_clear = Perl_magic_clearisa },
172+
{ .svt_set = Perl_magic_setisa },
173+
{ .svt_set = Perl_magic_setlvref },
174+
{ .svt_set = Perl_magic_setmglob, .svt_free = Perl_magic_freemglob },
175+
{ .svt_get = Perl_magic_getnkeys, .svt_set = Perl_magic_setnkeys },
176+
{ .svt_set = Perl_magic_setnonelem },
177+
{ .svt_free = Perl_magic_freeovrld },
178+
{ .svt_len = Perl_magic_sizepack, .svt_clear = Perl_magic_wipepack },
179+
{ .svt_get = Perl_magic_getpack, .svt_set = Perl_magic_setpack, .svt_clear = Perl_magic_clearpack },
180+
{ .svt_get = Perl_magic_getpos, .svt_set = Perl_magic_setpos },
181+
{ .svt_len = Perl_magic_regdata_cnt },
182+
{ .svt_get = Perl_magic_regdatum_get, .svt_set = Perl_magic_regdatum_set },
183+
{ .svt_set = Perl_magic_setregexp },
184+
{ .svt_set = Perl_magic_setsigall },
185+
{ .svt_get = Perl_magic_getsig, .svt_set = Perl_magic_setsig, .svt_clear = Perl_magic_clearsig },
186+
{ .svt_get = Perl_magic_getsubstr, .svt_set = Perl_magic_setsubstr },
187+
{ .svt_get = Perl_magic_get, .svt_set = Perl_magic_set },
188+
{ .svt_get = Perl_magic_gettaint, .svt_set = Perl_magic_settaint },
189+
{ .svt_set = Perl_magic_setutf8, .svt_free = Perl_magic_freeutf8 },
190+
{ .svt_get = Perl_magic_getuvar, .svt_set = Perl_magic_setuvar },
191+
{ .svt_get = Perl_magic_getvec, .svt_set = Perl_magic_setvec }
208192
};
209193
#else
210194
EXT_MGVTBL PL_magic_vtables[magic_vtable_max];

regen/mg_vtable.pl

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -497,22 +497,6 @@ BEGIN
497497
}
498498

499499
print $vt <<'EOH';
500-
/* These all need to be 0, not NULL, as NULL can be (void*)0, which is a
501-
* pointer to data, whereas we're assigning pointers to functions, which are
502-
* not the same beast. ANSI doesn't allow the assignment from one to the other.
503-
* (although most, but not all, compilers are prepared to do it)
504-
*/
505-
506-
/* order is:
507-
get
508-
set
509-
len
510-
clear
511-
free
512-
copy
513-
dup
514-
local
515-
*/
516500
517501
#ifdef DOINIT
518502
EXT_MGVTBL PL_magic_vtables[magic_vtable_max] = {
@@ -525,10 +509,13 @@ BEGIN
525509
my $data = $vtable_conf{$name};
526510
push @vtable_names, $name;
527511
my @funcs = map {
528-
$data->{$_} ? "Perl_magic_$data->{$_}" : 0;
512+
my $cast = ( $_ eq "get" and $data->{const} ) ?
513+
"(int (*)(pTHX_ SV *, MAGIC *))" :
514+
"";
515+
516+
$data->{$_} ? ( ".svt_$_ = ${cast}Perl_magic_$data->{$_}" ) : ();
529517
} qw(get set len clear free copy dup local);
530518

531-
$funcs[0] = "(int (*)(pTHX_ SV *, MAGIC *))" . $funcs[0] if $data->{const};
532519
my $funcs = join ", ", @funcs;
533520

534521
# Because we can't have a , after the last {...}
@@ -538,7 +525,7 @@ BEGIN
538525
print $vt " { $funcs }$comma\n";
539526
print $vt <<"EOH" if $data->{cond};
540527
#else
541-
{ 0, 0, 0, 0, 0, 0, 0, 0 }$comma
528+
{ .svt_get = 0 }$comma
542529
#endif
543530
EOH
544531
foreach(@{$data->{alias}}) {

0 commit comments

Comments
 (0)