Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.9k stars 540 forks source link

Check SvTYPES in assert args macros #22421

Closed leonerd closed 1 month ago

leonerd commented 1 month ago

By default, any argument to a function whose type is AV , CV or HV * will have an SvTYPE() check added to its PERL_ARGSASSERT... macro. This helps catch errors of mismatched structure types being passed to API functions.

AV and HV checks are simple. CV checks must check for both SVt_PVCV and SVt_PVFM, because of forms.

Currently we do not implement checks on GVs because so many of the GV-related functions are sometimes used when the "gv" pointer does not in fact point at a valid GV instance.

Arguments to a number of the functions have been marked with a "NOCHECK" tag, which disables the type checking on that argument. These are for similar reasons to GVs; functions which permit pointers to be passed that don't in fact point at the type of structure the pointer argument would suggest.

It may be an ongoing task to tidy up some of these usecases (if internal), or to either change the external-facing APIs, or define new "union types" of pointer to better indicate the nature of allowed values for the remaining functions.