Why does sv_setref_pv () save its void * argument in slot IV?

When looking at the Perl API, I was wondering why

  • sv_setref_iv()stores the argument IVin the slot IV,
  • sv_setref_nv()stores the argument NVin the slot NV,
  • but sv_setref_pv()stores its argument void *in a slot IVinstead of a slot PV?

I have a hunch (the CUR and LEN fields do not make sense for such a variable), but I would like to get an opinion on what someone knows in XS :-)

+3
source share
1 answer

There are many different types of scalars.

  • SvNULL cannot contain any value except undef.
  • SvIV is capable of retaining IV, UV, or RV.
  • SvNV is capable of supporting NV.
  • SvPV is able to retain PV.
  • SvPVIV is capable of retaining PV as well as IV, UV or RV.
  • ...

AV, HV, CV, GV are really just types of scalars.

. , "" . , - . .

.

SvIV ( , IV) , SvPV ( , PV).

$ perl -le'
   use Devel::Size qw( total_size );

   use Inline C => <<'\''__EOI__'\'';

      void upgrade_to_iv(SV* sv) {
         SvUPGRADE(sv, SVt_IV);
      }

      void upgrade_to_pv(SV* sv) {
         SvUPGRADE(sv, SVt_PV);
      }

__EOI__

   { my $x; upgrade_to_iv($x); print total_size($x); }
   { my $x; upgrade_to_pv($x); print total_size($x); }
'
24
40

SvIV SvPV - 16 .

+6

All Articles