develooper Front page | perl.perl5.porters | Postings from April 2011

[perl #89218] SVpfm_COMPILED flag bit clashes with PVBM flag bits

Thread Next
From:
Nicholas Clark
Date:
April 25, 2011 13:39
Subject:
[perl #89218] SVpfm_COMPILED flag bit clashes with PVBM flag bits
Message ID:
rt-3.6.HEAD-32285-1303763975-1355.89218-75-0@perl.org
# New Ticket Created by  Nicholas Clark 
# Please include the string:  [perl #89218]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=89218 >


This is a bug report for perl from nick@eris.etla.org,
generated with the help of perlbug 1.26 running under perl 5.00503.


-----------------------------------------------------------------
[Please enter your report here]

sv.h has:

#define SVpfm_COMPILED	0x80000000  /* FORMLINE is compiled */

This isn't actually set on the PVFM. It's set on the scalar containing the
format string.

For the past 5 years sv.h also has:

#define SVpbm_VALID	0x40000000
#define SVpbm_TAIL	0x80000000

(previously those two had transposed numeric values)

Unfortunately, if you're feeling pathological, it's possible to engineer code
to get a Boyer-Moore compiled scalar to pp_formline, where SvCOMPILED() is
checked. Note the different behaviour of formline with/without the index:

$ ~/Sandpit/5.005_03/bin/perl -e 'use constant PVBM => "0.1"; formline PVBM; warn ">$^A<"; warn length $^A; my $dummy = index "0.1", PVBM'
>0.1 at -e line 1.
771 at -e line 1.
$ ~/Sandpit/5.005_03/bin/perl -e 'use constant PVBM => "0.1"; formline PVBM; warn ">$^A<"; warn length $^A;'
>0.1< at -e line 1.
3 at -e line 1.


After this commit:

commit 5fe1b2e43d7b85573608a94dd98d2a8b7f06d58c
Author: Nicholas Clark <nick@ccl4.org>
Date:   Sun Dec 10 01:13:09 2006 +0000

    Swap SVpbm_TAIL and SVpbm_VALID.
    
    p4raw-id: //depot/perl@29496

diff --git a/sv.h b/sv.h
index 054ec6b..2ddd438 100644
--- a/sv.h
+++ b/sv.h
@@ -350,7 +350,7 @@ perform the upgrade if necessary.  See C<svtype>.
 /* PVHV */
 #define SVphv_LAZYDEL  0x40000000      /* entry in xhv_eiter must be deleted */
 /* Not just PVBM - basically anything that can be a regular scalar */
-#define SVpbm_TAIL     0x40000000
+#define SVpbm_VALID    0x40000000
 /* ??? */
 #define SVrepl_EVAL    0x40000000      /* Replacement part of s///e */
 
@@ -364,7 +364,7 @@ perform the upgrade if necessary.  See C<svtype>.
 /* PVFM */
 #define SVpfm_COMPILED 0x80000000      /* FORMLINE is compiled */
 /* PVBM */
-#define SVpbm_VALID    0x80000000
+#define SVpbm_TAIL     0x80000000
 /* RV upwards. However, SVf_ROK and SVp_IOK are exclusive  */
 #define SVprv_WEAKREF   0x80000000      /* Weak reference */
 

The nature of the bug changes. Now the formline works, but after the call to
formline the index fails:

$ ./perl -Ilib -MDevel::Peek -e 'use constant PVBM => "0.1"; Dump(PVBM); warn index "0.1", PVBM; Dump(PVBM); formline PVBM; warn ">$^A<"; Dump PVBM; warn index "0.1", PVBM'
SV = PVBM(0x8d8dd0) at 0x911870
  REFCNT = 7
  FLAGS = (PADMY,SMG,POK,READONLY,pPOK,VALID)
  IV = 0
  NV = 0
  PV = 0x8fea70 "0.1"\0
  CUR = 3
  LEN = 264
  MAGIC = 0x8cac00
    MG_VIRTUAL = &PL_vtbl_bm
    MG_TYPE = PERL_MAGIC_bm(B)
0 at -e line 1.
SV = PVBM(0x8d8dd0) at 0x911870
  REFCNT = 7
  FLAGS = (PADMY,SMG,POK,READONLY,pPOK,VALID)
  IV = 0
  NV = 0
  PV = 0x8fea70 "0.1"\0
  CUR = 3
  LEN = 264
  MAGIC = 0x8cac00
    MG_VIRTUAL = &PL_vtbl_bm
    MG_TYPE = PERL_MAGIC_bm(B)
>0.1< at -e line 1.
SV = PVBM(0x8d8dd0) at 0x911870
  REFCNT = 7
  FLAGS = (PADMY,SMG,POK,READONLY,pPOK,TAIL,VALID)
  UV = 0
  NV = 0
  PV = 0x8fea70 "0.1"\0
  CUR = 3
  LEN = 264
  MAGIC = 0x9111b0
    MG_VIRTUAL = &PL_vtbl_fm
    MG_TYPE = PERL_MAGIC_fm(f)
  MAGIC = 0x8cac00
    MG_VIRTUAL = &PL_vtbl_bm
    MG_TYPE = PERL_MAGIC_bm(B)
-1 at -e line 1.


I have a plan on how to fix this. I believe that the original variant of the
bug may date all the way back to 5.000, but I'm not in a position to check.

Nicholas Clark

[Please do not change anything below this line]
-----------------------------------------------------------------

---
Site configuration information for perl 5.00503:

Configured by nick at Sat Sep  4 07:46:22 BST 2010.

Summary of my perl5 (5.0 patchlevel 5 subversion 3) configuration:
  Platform:
    osname=linux, osvers=2.6.18.8-xenu, archname=x86_64-linux
    uname='linux eris 2.6.18.8-xenu #1 smp sat oct 3 10:27:42 bst 2009 x86_64 gnulinux '
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef useperlio=undef d_sfio=undef
  Compiler:
    cc='ccache gcc', optimize='-g -O2', gccversion=4.3.2
    cppflags='-Dbool=char -DHAS_BOOL -I/usr/local/include'
    ccflags ='-Dbool=char -DHAS_BOOL -I/usr/local/include'
    stdchar='char', d_stdstdio=undef, usevfork=false
    intsize=4, longsize=8, ptrsize=8, doublesize=8
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    alignbytes=8, usemymalloc=n, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -ldb -ldl -lm -lc -lcrypt
    libc=, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:
    

---
@INC for perl 5.00503:
    /home/nick/Sandpit/5.005_03/lib/perl5/5.00503/x86_64-linux
    /home/nick/Sandpit/5.005_03/lib/perl5/5.00503
    /home/nick/Sandpit/5.005_03/lib/perl5/site_perl/5.005/x86_64-linux
    /home/nick/Sandpit/5.005_03/lib/perl5/site_perl/5.005
    .

---
Environment for perl 5.00503:
    HOME=/home/nick
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/nick/bin:/usr/local/bin:/usr/bin:/bin:/usr/games:/usr/local/sbin:/sbin:/usr/sbin
    PERL_BADLANG (unset)
    SHELL=/bin/bash


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