ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl5-porters
perl5-porters
Re: is $1 really readonly?
by Torsten Foertsch other posts by this author
Jul 17 2008 3:54AM messages near this date
Re: is $1 really readonly? | Re: is $1 really readonly?
On Thu 17 Jul 2008, �var Arnfjörð Bjarmason wrote:
>  > although both are documented as read-only.
> 
>  If capture variables are documented as READONLY somewhere that's a
>  bug, what documentation are you referring to?

Ok, that's my fault. They were documented as readonly in previous versions. I 
took that for granted, sorry.

So, it's ok to do the following in a function similar to read() (w/o UTF8 
handling)?

    SSize_t total;
    STRLEN blen;

    if (!SvOK(buffer)) {
        sv_setpvn(buffer, "", 0);
    }

    (void)SvPV_force(buffer, blen); /* make it a valid PV */

    if (len <= 0) {
        /* use the same error message as perl core's read() */
        Perl_croak(aTHX_ "Negative length");
    }

    /* handle negative offset */
    if (offset < 0) {
	if (-offset >  (int)blen) Perl_croak(aTHX_ "Offset outside string");
        offset += blen;
    }

    # this is: (void)SvUPGRADE(sv, SVt_PV); SvGROW(sv, len+1)
    mpxs_sv_grow(buffer, len+offset);

    /* need to pad with \0 if offset >  size of the buffer */
    if (offset >  SvCUR(buffer)) {
        Zero(SvEND(buffer), offset - SvCUR(buffer), char);
    }

    total = modperl_request_read(aTHX_ r, SvPVX(buffer)+offset, len);

    /* modperl_request_read can return only > =0. So it's save to do this. */
    /* if total==0 we need to set the buffer length in case it is larger */
    mpxs_sv_cur_set(buffer, offset+total);

    /* must run any set magic */
    SvSETMAGIC(buffer);

    SvTAINTED_on(buffer);

    return newSViv(total);

Torsten

--
Need professional mod_perl support?
Just hire me: torsten.foertsch@gmx.net
Thread:
Torsten Foertsch
avarab
Torsten Foertsch
avarab

Privacy Policy | Email Opt-out | Feedback | Syndication
© 2004 ActiveState, a division of Sophos All rights reserved