perl5 icon indicating copy to clipboard operation
perl5 copied to clipboard

Use C99 named initialisers in core structs that define MGVTBLs

Open leonerd opened this issue 1 year ago • 7 comments

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.

(No rush before 5.39.9 but I would like to test this out at least, sometime before too long)

leonerd avatar Mar 18 '24 21:03 leonerd

I thought we couldn't use this in public headers because C++?

Leont avatar Mar 18 '24 21:03 Leont

I thought we could use this in public headers because C++?

Ugh; it's mg_vtable.h, indeed. Does that still count? Even if we can't use it there, I'd still like to do the .c files.

leonerd avatar Mar 18 '24 22:03 leonerd

I thought we could use this in public headers because C++?

Ugh; it's mg_vtable.h, indeed. Does that still count? Even if we can't use it there, I'd still like to do the .c files.

It gets included in perl.h, so yes. But having it for the hand-written ones in .c files is still a big win.

ilmari avatar Mar 18 '24 22:03 ilmari

I thought we could use this in public headers because C++?

Ugh; it's mg_vtable.h, indeed. Does that still count? Even if we can't use it there, I'd still like to do the .c files.

Another option would be to generate a separate mg_vtable.c with the initializations.

The DOINIT code doesn't appear usable outside of the executable/libperl.so since the magic functions are marked hidden.

tonycoz avatar Mar 18 '24 22:03 tonycoz

@leonerd, Given where we are in our annual production cycle, are you thinking of this for 5.40 or 5.42?

jkeenan avatar Mar 18 '24 22:03 jkeenan

@leonerd, Given where we are in our annual production cycle, are you thinking of this for 5.40 or 5.42?

Oh it doesn't need to be in 5.40 at all; it isn't doing any kind of user-benefit change. It's purely tidying up the code internally for our benefit. It can wait for 5.42, I just happen to have started writing it now.

leonerd avatar Mar 19 '24 08:03 leonerd

The DOINIT code doesn't appear usable outside of the executable/libperl.so since the magic functions are marked hidden.

Looking more closely at things, DOINIT is only defined in INTERN.h, which is only included in globals.c, so even though mg_vtable.h is included in perl.h, that only causes the extern declarations to be visible outside globals.c, so we could change the generated code after all.

ilmari avatar Mar 19 '24 11:03 ilmari