From 3677d5e89092315cde08056bfdf4e006224ea0aa Mon Sep 17 00:00:00 2001 From: Lukas Mai Date: Sat, 16 Aug 2025 14:52:37 +0200 Subject: [PATCH] fix type of Perl_magic_getarylen This function is used as part of PL_magic_vtables, so its type must be 'int (pTHX_ SV *, MAGIC *)' exactly (no const). With the right type, we no longer need an ad-hoc cast in mg_vtables.h, which means we no longer need the 'const' code in regen/mg_vtable.pl, which was a special case used by this one function only. Should fix ASan complaints about functions being called with incorrect types. --- embed.fnc | 2 +- mg.c | 2 +- mg_vtable.h | 2 +- proto.h | 2 +- regen/mg_vtable.pl | 8 +------- 5 files changed, 5 insertions(+), 11 deletions(-) diff --git a/embed.fnc b/embed.fnc index c58deae6a8..6f5ea96931 100644 --- a/embed.fnc +++ b/embed.fnc @@ -1909,7 +1909,7 @@ p |int |magic_freeutf8 |NN SV *sv \ p |int |magic_get |NN SV *sv \ |NN MAGIC *mg p |int |magic_getarylen|NN SV *sv \ - |NN const MAGIC *mg + |NN MAGIC *mg p |int |magic_getdebugvar \ |NN SV *sv \ |NN MAGIC *mg diff --git a/mg.c b/mg.c index c876c17269..7a30f63c30 100644 --- a/mg.c +++ b/mg.c @@ -2364,7 +2364,7 @@ Perl_magic_setdbline(pTHX_ SV *sv, MAGIC *mg) } int -Perl_magic_getarylen(pTHX_ SV *sv, const MAGIC *mg) +Perl_magic_getarylen(pTHX_ SV *sv, MAGIC *mg) { AV * const obj = MUTABLE_AV(mg->mg_obj); diff --git a/mg_vtable.h b/mg_vtable.h index 7d46f671e7..46a56f50f4 100644 --- a/mg_vtable.h +++ b/mg_vtable.h @@ -165,7 +165,7 @@ EXTCONST char * const PL_magic_vtable_names[magic_vtable_max]; #ifdef DOINIT EXT_MGVTBL PL_magic_vtables[magic_vtable_max] = { - { (int (*)(pTHX_ SV *, MAGIC *))Perl_magic_getarylen, Perl_magic_setarylen, 0, 0, 0, 0, 0, 0 }, + { Perl_magic_getarylen, Perl_magic_setarylen, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, Perl_magic_cleararylen_p, Perl_magic_freearylen_p, 0, 0, 0 }, { 0, 0, 0, 0, Perl_magic_killbackrefs, 0, 0, 0 }, { 0, 0, 0, 0, 0, Perl_magic_copycallchecker, 0, 0 }, diff --git a/proto.h b/proto.h index 34d897217a..a8a106ddbb 100644 --- a/proto.h +++ b/proto.h @@ -2207,7 +2207,7 @@ Perl_magic_get(pTHX_ SV *sv, MAGIC *mg) assert(sv); assert(mg) PERL_CALLCONV int -Perl_magic_getarylen(pTHX_ SV *sv, const MAGIC *mg) +Perl_magic_getarylen(pTHX_ SV *sv, MAGIC *mg) __attribute__visibility__("hidden"); #define PERL_ARGS_ASSERT_MAGIC_GETARYLEN \ assert(sv); assert(mg) diff --git a/regen/mg_vtable.pl b/regen/mg_vtable.pl index a80075cd8c..e113464eac 100644 --- a/regen/mg_vtable.pl +++ b/regen/mg_vtable.pl @@ -245,11 +245,6 @@ my %mg = # prefix the vtable with the specified entry (e.g. '#ifdef FOO') # and suffix it with '#else { 0, 0, 0, 0, 0, 0, 0, 0 } #endif' # -# const -# special-case cast a 'get' function whose signature expects -# a pointer to constant magic, so that it can be added to a vtable -# which expects pointers to functions without the 'const'. -# # get # set # len @@ -277,7 +272,7 @@ my %vtable_conf = 'dbline' => {set => 'setdbline'}, 'isa' => {set => 'setisa', clear => 'clearisa'}, 'isaelem' => {set => 'setisa'}, - 'arylen' => {get => 'getarylen', set => 'setarylen', const => 1}, + 'arylen' => {get => 'getarylen', set => 'setarylen'}, 'arylen_p' => {clear => 'cleararylen_p', free => 'freearylen_p'}, 'mglob' => {set => 'setmglob', free => 'freemglob' }, @@ -528,7 +523,6 @@ while (my $name = shift @names) { $data->{$_} ? "Perl_magic_$data->{$_}" : 0; } qw(get set len clear free copy dup local); - $funcs[0] = "(int (*)(pTHX_ SV *, MAGIC *))" . $funcs[0] if $data->{const}; my $funcs = join ", ", @funcs; # Because we can't have a , after the last {...}