develooper Front page | perl.perl5.porters | Postings from February 2008

PERL_RUNTIME

Thread Next
From:
Nicholas Clark
Date:
February 20, 2008 01:13
Subject:
PERL_RUNTIME
Message ID:
20080220091255.GH38653@plum.flirble.org
So, buoyed with my success at using the f flag on the op for length, I tried it
on some other ops. In theory, it ought to work for sprintf:

==== //depot/perl/opcode.h#148 - /afs/wu-wien.ac.at/home/ma/nclark/pecuchet/perl/opcode.h ====
--- /tmp/tmp.9925.0     2008-02-20 10:05:27.000000000 +0100
+++ /afs/wu-wien.ac.at/home/ma/nclark/pecuchet/perl/opcode.h    2008-02-20 10:03:23.000000000 +0100
@@ -1663,7 +1663,7 @@ EXTCONST U32 PL_opargs[] = {
        0x0022281c,     /* vec */
        0x0122291c,     /* index */
        0x0122291c,     /* rindex */
-       0x0004280d,     /* sprintf */
+       0x0004280f,     /* sprintf */
        0x00042805,     /* formline */
        0x0001379e,     /* ord */
        0x0001378e,     /* chr */
==== //depot/perl/opcode.pl#171 - /afs/wu-wien.ac.at/home/ma/nclark/pecuchet/perl/opcode.pl ====
--- /tmp/tmp.9925.1     2008-02-20 10:05:27.000000000 +0100
+++ /afs/wu-wien.ac.at/home/ma/nclark/pecuchet/perl/opcode.pl   2008-02-20 10:03:18.000000000 +0100
@@ -767,7 +767,7 @@ vec         vec                     ck_fun          ist@   S S S
 index          index                   ck_index        isT@    S S S?
 rindex         rindex                  ck_index        isT@    S S S?

-sprintf                sprintf                 ck_fun          mst@    S L
+sprintf                sprintf                 ck_fun          fmst@   S L
 formline       formline                ck_fun          ms@     S L
 ord            ord                     ck_fun          ifsTu%  S?
 chr            chr                     ck_fun          fsTu%   S?


And, looks good:

$ ./perl -Ilib -MO=Concise -e '$a = sprintf "%f", 4'
6  <@> leave[1 ref] vKP/REFC ->(end)
1     <0> enter ->2
2     <;> nextstate(main 1 -e:1) v:{ ->3
5     <2> sassign vKS/2 ->6
3        <$> const[PV "4.000000"] s ->4
-        <1> ex-rv2sv sKRM*/1 ->5
4           <#> gvsv[*a] s ->5
-e syntax OK

But the test that checks part of %n fails:

$ ./perl -lwe '$a = sprintf "xxx%n"; print $a'
xxx
$

Should be:

$ perl -lwe '$a = sprintf "xxx%n"; print $a'
Modification of a read-only value attempted at -e line 1.

A bit of investigation reveals that there are "interesting" side effects:

$ ./perl -lwe '$a = sprintf "xxx%n"; print $a; print undef'
xxx
3

Yes, undef is now 3. How useful. The culprit is this

	else if (IN_PERL_RUNTIME)
	    Perl_croak(aTHX_ PL_no_modify);

because:

#define IN_PERL_COMPILETIME	(PL_curcop == &PL_compiling)
#define IN_PERL_RUNTIME		(PL_curcop != &PL_compiling)


So, it seems that constant folding runs in "compile time", which scares me
somewhat. Surely it should be running in run time?

I tried setting PL_curcop to NULL, but that causes things to SEGV. What's
the correct fix? (because I think that this should be fixed, independent of
folding sprintf)

Nicholas Clark

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