List Info

Thread: PERL_DONT_CREATE_GVSV and typeglob slot SCALAR - what goes on?




PERL_DONT_CREATE_GVSV and typeglob slot SCALAR - what goes on?
user name
2007-02-22 03:28:14
perl593delta.pod says: "PERL_DONT_CREATE_GVSV,
introduced as an option
in perl 5.8.8, is turned on by default in perl 5.9.3. It
prevents perl
from creating an empty scalar with every new
typeglob."

But if this snippet is run with a fairly recent revision 5
version 9 
subversion 5 patch 30104:

  our $aScalar = 'aScalar';
  our anArray = ( 'el0', 'el1' );
  no strict 'refs';
  print *{${'::'}}, "n";
  print *{${'::'}}, '==', $aScalar,
"n";
  print 'ARRAY ',
    defined (*{${'::'}} ) ? 'defined' :
'undef', "n";

  print *{${'::'}}, "n";
  print *{${'::'}}, '==', anArray,
"n";
  print 'SCALAR ',
    defined (*{${'::'}} ) ? 'defined' :
'undef', "n";

it produces:

  aScalar
  SCALAR(0x95cf780)==SCALAR(0x95cf780)
  ARRAY undef
  anArray
  ARRAY(0x95cf7d0)==ARRAY(0x95cf7d0)
  SCALAR defined

PERL_DONT_CREATE_GVSV is in effect, and the SCALAR slot is
not 
initialized in gv.c. Hence, the last line in the output is
quite 
unexpected. Or has the SCALAR slot *access* been modified so
that the 
old behaviour is still simulated?

Cheers
Wolfgang



Re: PERL_DONT_CREATE_GVSV and typeglob slot SCALAR - what goes on?
user name
2007-02-26 14:09:47
On 2/22/07, Wolfgang Laun <Wolfgang.Launthalesgroup.com> wrote:
>   print 'SCALAR ',
>     defined (*{${'::'}} ) ? 'defined'
: 'undef', "n";
>
> produces:
>
>   SCALAR defined

it looks like the reference will get created when looked
for, I don't
know if this misses the point or not

# perl -le '$x=4; print "{[*{main:}{SCA
LAR}]} points to ${*{main:}{SCA
LAR
SCALAR(0x804faa4) points to 4
R}]} points to ${*{main:}{SCA
LAR}}"'                                        <
SCALAR(0x804faa4) points to 4
# perl -le '$x=4; print "{[*{main::y}]}
points to
${*{main::y}}"'
SCALAR(0x804fad4) points to

Re: PERL_DONT_CREATE_GVSV and typeglob slot SCALAR - what goes on?
user name
2007-02-26 14:28:54
On Mon, Feb 26, 2007 at 02:09:47PM -0600, David Nicol
wrote:
> On 2/22/07, Wolfgang Laun <Wolfgang.Launthalesgroup.com> wrote:
> >  print 'SCALAR ',
> >    defined (*{${'::'}} ) ?
'defined' : 'undef', "n";
> >
> >produces:
> >
> >  SCALAR defined
> 
> it looks like the reference will get created when
looked for, I don't
> know if this misses the point or not

Yes, the intent is that the Perl space behaviour doesn't
change for SCALAR -
the implementation (attempts to) ensure that you can't tell
that it's
creating the variable for the GvSV slot lazily. In contrast,
XS code will
be able to see that the implementation has changed.

If pure Perl code changes behaviour (in particular,
generates errors) then
it's a core bug.

Nicholas Clark

[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )