Skip to content

Commit 678aa24

Browse files
committed
Use C99 named initialisers in core structs that define MGVTBLs
Since most Magic vtables do not provide every function, using C99 named initialisers allows us to more easily specify which ones are present, so readers don't have to count commas. Additionally provides a layer of robustness in case more functions are added in future.
1 parent 6a2327b commit 678aa24

File tree

8 files changed

+13
-29
lines changed

8 files changed

+13
-29
lines changed

doio.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,17 +1348,10 @@ If we have unlinkat(), renameat(), fchmodat(), dirfd() we also keep:
13481348
6: the DIR * for the current directory when we open the file, stored as an IV
13491349
*/
13501350

1351-
static const MGVTBL argvout_vtbl =
1352-
{
1353-
NULL, /* svt_get */
1354-
NULL, /* svt_set */
1355-
NULL, /* svt_len */
1356-
NULL, /* svt_clear */
1357-
S_argvout_free, /* svt_free */
1358-
NULL, /* svt_copy */
1359-
S_argvout_dup, /* svt_dup */
1360-
NULL /* svt_local */
1361-
};
1351+
static const MGVTBL argvout_vtbl = {
1352+
.svt_free = S_argvout_free,
1353+
.svt_dup = S_argvout_dup,
1354+
};
13621355

13631356
static bool
13641357
S_is_fork_open(const char *name) {

ext/PerlIO-encoding/encoding.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package PerlIO::encoding;
22

33
use strict;
4-
our $VERSION = '0.31';
4+
our $VERSION = '0.32';
55
our $DEBUG = 0;
66
$DEBUG and warn __PACKAGE__, " called by ", join(", ", caller), "\n";
77

ext/PerlIO-encoding/encoding.xs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ typedef struct {
5555

5656
#define NEEDS_LINES 1
5757

58-
static const MGVTBL PerlIOEncode_tag = { 0, 0, 0, 0, 0, 0, 0, 0 };
58+
static const MGVTBL PerlIOEncode_tag = {};
5959

6060
static SV *
6161
PerlIOEncode_getarg(pTHX_ PerlIO * f, CLONE_PARAMS * param, int flags)

ext/PerlIO-via/via.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package PerlIO::via;
2-
our $VERSION = '0.19';
2+
our $VERSION = '0.20';
33
require XSLoader;
44
XSLoader::load();
55
1;

ext/PerlIO-via/via.xs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ typedef struct
3838
CV *UTF8;
3939
} PerlIOVia;
4040

41-
static const MGVTBL PerlIOVia_tag = { 0, 0, 0, 0, 0, 0, 0, 0 };
41+
static const MGVTBL PerlIOVia_tag = {};
4242

4343
#define MYMethod(x) #x,&s->x
4444

ext/XS-APItest/APItest.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use strict;
44
use warnings;
55
use Carp;
66

7-
our $VERSION = '1.35';
7+
our $VERSION = '1.36';
88

99
require XSLoader;
1010

ext/XS-APItest/APItest.xs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ S_myset_set_dies(pTHX_ SV* sv, MAGIC* mg)
174174

175175

176176
static MGVTBL vtbl_foo, vtbl_bar;
177-
static MGVTBL vtbl_myset = { 0, S_myset_set, 0, 0, 0, 0, 0, 0 };
178-
static MGVTBL vtbl_myset_dies = { 0, S_myset_set_dies, 0, 0, 0, 0, 0, 0 };
177+
static MGVTBL vtbl_myset = { .svt_set = S_myset_set };
178+
static MGVTBL vtbl_myset_dies = { .svt_set = S_myset_set_dies };
179179

180180
static int
181181
S_mycopy_copy(pTHX_ SV *sv, MAGIC* mg, SV *nsv, const char *name, I32 namlen) {
@@ -192,7 +192,7 @@ S_mycopy_copy(pTHX_ SV *sv, MAGIC* mg, SV *nsv, const char *name, I32 namlen) {
192192
return 0;
193193
}
194194

195-
STATIC MGVTBL vtbl_mycopy = { 0, 0, 0, 0, 0, S_mycopy_copy, 0, 0 };
195+
STATIC MGVTBL vtbl_mycopy = { .svt_copy = S_mycopy_copy };
196196

197197
/* indirect functions to test the [pa]MY_CXT macros */
198198

op.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15328,16 +15328,7 @@ custom_op_register_free(pTHX_ SV *sv, MAGIC *mg)
1532815328

1532915329

1533015330
static const MGVTBL custom_op_register_vtbl = {
15331-
0, /* get */
15332-
0, /* set */
15333-
0, /* len */
15334-
0, /* clear */
15335-
custom_op_register_free, /* free */
15336-
0, /* copy */
15337-
0, /* dup */
15338-
#ifdef MGf_LOCAL
15339-
0, /* local */
15340-
#endif
15331+
.svt_free = custom_op_register_free,
1534115332
};
1534215333

1534315334

0 commit comments

Comments
 (0)