develooper Front page | perl.perl5.porters | Postings from June 2016

[perl #128260] Assert fail in Perl_sv_2pv_flags: '(vec%0,0,0)=0'

Thread Previous | Thread Next
From:
Father Chrysostomos via RT
Date:
June 9, 2016 14:03
Subject:
[perl #128260] Assert fail in Perl_sv_2pv_flags: '(vec%0,0,0)=0'
Message ID:
rt-4.0.18-22690-1465480986-1938.128260-15-0@perl.org
On Fri May 27 17:55:20 2016, sprout wrote:
> It’s more complicated than that.  vec does accept $_+1 if vec itself
> is in rvalue context, so its actual behaviour cannot be represented
> perfectly with a prototype.
> 
> > Also, those ‘Can't modify’ messages cite the wrong op (list/scalar
> > assignment instead of vec).
> 
> That’s actually a clue to the problem.  Scalar assignment dies at
> compile time, but list assignment goes on to do the wrong thing (and
> fail an assertion) at run time, because vec’s own type of lvalue
> context is being propagated, whereas it probably should not be.
> 
> $ perl  -we 'vec(%a,0,1)=0'
> Can't modify hash dereference in scalar assignment at -e line 1, at
> EOF
> Execution of -e aborted due to compilation errors.
> $ perl  -we '(vec%a,0,1)=0'
> Name "main::a" used only once: possible typo at -e line 1.
> Use of uninitialized value within %a in vec at -e line 1.
> Can't coerce HASH to string in aassign at -e line 1.
> 
> vec is not the only problematic operator.
> 
> $ ./perl  -we '(substr %a,0,1)=0'
> Name "main::a" used only once: possible typo at -e line 1.
> Can't coerce HASH to string in list assignment at -e line 1.
> $ ./perl  -we 'substr(%a,0,1)=0'
> Can't modify hash dereference in scalar assignment at -e line 1, at
> EOF
> Execution of -e aborted due to compilation errors.
> 
> The second one dies at compile time; the first one does the wrong
> thing at run time.  Same problem.

Should assignment to substr(keys) be allowed?

$ ./perl -le 'substr(keys %h,1) = 3; print "ok"'
ok
$ ./perl -e '(substr keys %h,1) = 3;'
Can't modify keys in list assignment at -e line 1, near "3;"
Execution of -e aborted due to compilation errors.

(The logic in op.c:op_lvalue_flags is really broken.)

Currently assignment to substr(keys) actually does something:

$ ./perl -le 'substr(keys %h,1) = 3; use Devel::Peek; Dump %h'
ok
SV = PVHV(0x7fb14c00aea0) at 0x7fb14c02b7e0
  REFCNT = 1
  FLAGS = (OOK,SHAREKEYS)
  AUX_FLAGS = 0
  ARRAY = 0x7fb14bc09970
  KEYS = 0
  FILL = 0 (cached = 0)
  MAX = 7
  RITER = -1
  EITER = 0x0
  RAND = 0x34097f19
$ ./perl -le 'substr(keys %h,1) = 30; use Devel::Peek; Dump %h'
ok
SV = PVHV(0x7fa35880aea0) at 0x7fa35882b7e0
  REFCNT = 1
  FLAGS = (OOK,SHAREKEYS)
  AUX_FLAGS = 0
  ARRAY = 0x7fa358412350
  KEYS = 0
  FILL = 0 (cached = 0)
  MAX = 31
  RITER = -1
  EITER = 0x0
  RAND = 0x77bd0a5d

(See the MAX line, indicating the highest bucket index.)

I just want to know if I should go ahead and break that, which would be the easiest way to fix the other bugs in this ticket.

-- 

Father Chrysostomos


---
via perlbug:  queue: perl5 status: open
https://rt.perl.org/Ticket/Display.html?id=128260

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About