You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by "T.J. Mather" <tj...@thoughtstore.com> on 2000/08/09 17:00:08 UTC

[BUG FIX] Apache.xs write_client

There are differences in the variable after a non-global substitution vs.
a global substitution.  After a non-global substitution, a reference to
the scalar value is of type SVt_PVIV, as opposed to SVt_PV for global
substituion.

So I changed write_client() Apache.xs to also check if the reference is of
type SVt_PVIV, and it now works.

Doug, could you apply this patch to Apache.xs?  Thanks.
Also, thanks to Ken Williams for the useful pointers.

PATCH:
--- Apache.xs.old       Wed Aug  9 10:23:31 2000
+++ Apache.xs   Wed Aug  9 10:23:13 2000
@@ -1076,7 +1076,7 @@

     for(i = 1; i <= items - 1; i++) {
        int sent = 0;
-        SV *sv = SvROK(ST(i)) && (SvTYPE(SvRV(ST(i))) == SVt_PV) ?
+        SV *sv = SvROK(ST(i)) && (SvTYPE(SvRV(ST(i))) == SVt_PV || SvTYPE(SvRV(ST(i))) == SVt_PVIV) ?
                  (SV*)SvRV(ST(i)) : ST(i);
        buffer = SvPV(sv, len);
 #ifdef APACHE_SSL

TEST CODE:
#!/usr/bin/perl
        use Devel::Peek;
        $text1 = "hello";
        $text2 = "hello";
        $text3 = "hello";
        $text2 =~ s/hello/hi/;
        $text3 =~ s/hello/hi/g;
        print "reference to variable without any substitution\n";
        Dump \$text1;
        print "\nreference to variable after non-global substitution\n";
        Dump \$text2;
        print "\nreference to variable after global substitution\n";
        Dump \$text3;

TEST OUTPUT:
reference to variable without any substitution
SV = RV(0x8100370) at 0x80ea8f8
  REFCNT = 1
  FLAGS = (TEMP,ROK)
  RV = 0x80f8ca8
  SV = PV(0x80eabc4) at 0x80f8ca8
    REFCNT = 2
    FLAGS = (POK,pPOK)
    PV = 0x80f7868 "hello"\0
    CUR = 5
    LEN = 6

reference to variable after non-global substitution
SV = RV(0x8100370) at 0x80ea8f8
  REFCNT = 1
  FLAGS = (TEMP,ROK)
  RV = 0x80f8c54
  SV = PVIV(0x80eb010) at 0x80f8c54
    REFCNT = 2
    FLAGS = (POK,OOK,pPOK)
    IV = 3  (OFFSET)
    PV = 0x80efa1b ( "hel" . ) "hi"\0
    CUR = 2
    LEN = 3

reference to variable after global substitution
SV = RV(0x8100370) at 0x80ea8f8
  REFCNT = 1
  FLAGS = (TEMP,ROK)
  RV = 0x80fd160
  SV = PV(0x80eabac) at 0x80fd160
    REFCNT = 2
    FLAGS = (POK,pPOK)
    PV = 0x80f75a0 "hi"\0
    CUR = 2
    LEN = 6

Ken Williams wrote:
> T.J., if you grok XS you might have a look at this part of
> write_client() in Apache.xs:
> 
>     for(i = 1; i <= items - 1; i++) {
>         int sent = 0;
>         SV *sv = SvROK(ST(i)) && (SvTYPE(SvRV(ST(i))) == SVt_PV) ?
>                  (SV*)SvRV(ST(i)) : ST(i);
>         buffer = SvPV(sv, len);
> 
> 
> Try looking at your $text with Devel::Peek to see whether there are any
> differences in what it contains in the two cases.