Perl

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • Change 28158: Integrate:

    0 answers - 9023 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    Change 28158 by nicholas@nicholas-saigo on 2006/05/11 10:36:47
    Integrate:
    [ 25832]
    Add my_sprintf, which is usually just a macro for sprintf, for those
    places where we want to use the return value of sprintf. This allows
    a wrapper to be used for platforms where the C library isn't ANSI-
    conformant.
    [ 25841]
    Replace all the strlen()s related to PL_pidstatus with the return
    value of my_sprintf
    [ 25862]
    Use the return value from sprintf and avoid a call to strlen
    [ 26001]
    Use the return value from sprintf().
    [ 26006]
    s/printf/my_printf/ because we're using the return value.
    My mistake spotted by Gisle.
    Affected files
    //depot/maint-5.8/perl/embed.fnc#149 integrate
    //depot/maint-5.8/perl/embed.h#113 integrate
    //#47 integrate
    //#34 integrate
    //depot/maint-5.8/perl/perl.h#119 integrate
    //depot/maint-5.8/perl/proto.h#138 integrate
    //depot/maint-5.8/perl/regcomp.c#69 integrate
    //depot/maint-5.8/perl/sv.c#253 integrate
    //depot/maint-5.8/perl/taint.c#15 integrate
    //#47 integrate
    //depot/maint-5.8/perl/util.c#101 integrate
    Differences
    //depot/maint-5.8/perl/embed.fnc#149 (text)
    Index: perl/embed.fnc
    perl/embed.fnc#148~28157~2006-05-11 03:03:53.000000000 -0700
    perl/embed.fnc2006-05-11 03:36:47.000000000 -0700
    @@ -1605,6 +1605,10 @@
    Ap|GV*|gv_fetchsv|SV *name|I32 flags|I32 sv_type
    dp|bool|is_gv_magical_sv|SV *name|U32 flags
    +#ifndef SPRINTF_RETURNS_STRLEN
    +Apnod|int|my_sprintf|NN char *buffer|NN const char *pat|
    +#endif
    +
    END_EXTERN_C
    /*
    * ex: set ts=8 sts=4 sw=4 noet:
    //depot/maint-5.8/perl/embed.h#113 (text+w)
    Index: perl/embed.h
    perl/embed.h#112~28157~2006-05-11 03:03:53.000000000 -0700
    perl/embed.h2006-05-11 03:36:47.000000000 -0700
    @@ -1704,6 +1704,8 @@
    #ifdef PERL_CRE
    #define my_clearenvPerl_my_clearenv
    #endif
    +#ifndef SPRINTF_RETURNS_STRLEN
    +#endif
    #define ck_anoncodePerl_ck_anoncode
    #define ck_bitopPerl_ck_bitop
    #define ck_concatPerl_ck_concat
    @@ -3743,6 +3745,8 @@
    #ifdef PERL_CRE
    #define my_clearenv()Perl_my_clearenv(aTHX)
    #endif
    +#ifndef SPRINTF_RETURNS_STRLEN
    +#endif
    #define ck_anoncode(a)Perl_ck_anoncode(aTHX_ a)
    #define ck_bitop(a)Perl_ck_bitop(aTHX_ a)
    #define ck_concat(a)Perl_ck_concat(aTHX_ a)
    //#47 (text+w)
    Index: perl/global.sym
    perl/global.sym#46~28157~2006-05-11 03:03:53.000000000 -0700
    perl/global.sym2006-05-11 03:36:47.000000000 -0700
    @@ -728,4 +728,5 @@
    Perl_gv_SVadd
    Perl_ckwarn
    Perl_ckwarn_d
    +Perl_my_sprintf
    # ex: set ro:
    //#34 (text)
    Index: perl/makedef.pl
    perl/makedef.pl#33~28120~2006-05-08 08:31:45.000000000 -0700
    perl/makedef.pl2006-05-11 03:36:47.000000000 -0700
    @@ -796,6 +796,11 @@
    Perl_gv_SVadd
    )];
    }
    +if ($define{'SPRINTF_RETURNS_STRLEN'}) {
    + skip_symbols [qw(
    + Perl_my_sprintf
    + )];
    +}
    # Ideally this would also check SA_SIGINF, but there doesn't seem to be an
    # easy way to find that out from here. Fix it if it breaks because there is
    //depot/maint-5.8/perl/perl.h#119 (text)
    Index: perl/perl.h
    perl/perl.h#118~28157~2006-05-11 03:03:53.000000000 -0700
    perl/perl.h2006-05-11 03:36:47.000000000 -0700
    @@ -1355,6 +1355,16 @@
    # define sprintf UTS_sprintf_wrap
    #endif
    +/* For the times when you want the return value of sprintf, and you want it
    + to be the length. Can't have a thread variable passed in, because C89 has
    + no varargs macros.
    +*/
    +#ifdef SPRINTF_RETURNS_STRLEN
    +# define my_sprintf sprintf
    +#else
    +# define my_sprintf Perl_my_sprintf
    +#endif
    +
    /* Configure gets this right but the UTS compiler gets it wrong.
    -- Hal Morris <hom00 (AT) utsglobal (DOT) com*/
    #ifdef UTS
    //depot/maint-5.8/perl/proto.h#138 (text+w)
    Index: perl/proto.h
    perl/proto.h#137~28157~2006-05-11 03:03:53.000000000 -0700
    perl/proto.h2006-05-11 03:36:47.000000000 -0700
    @@ -2329,6 +2329,13 @@
    PERL_CALLCNV voidPerl_my_clearenv(pTHX);
    +#ifndef SPRINTF_RETURNS_STRLEN
    +PERL_CALLCNV intPerl_my_sprintf(char *buffer, const char *pat, )
    +__attribute__nonnull__(1)
    +__attribute__nonnull__(2);
    +
    +#endif
    +
    END_EXTERN_C
    /*
    * ex: set ts=8 sts=4 sw=4 noet:
    //depot/maint-5.8/perl/regcomp.c#69 (text)
    Index: perl/regcomp.c
    perl/regcomp.c#68~28157~2006-05-11 03:03:53.000000000 -0700
    perl/regcomp.c2006-05-11 03:36:47.000000000 -0700
    @@ -5108,8 +5108,8 @@
    for (i = 1; i <= rx->nparens; i++) {
    GV *mgv;
    char digits[TYPE_CHARS(long)];
    -sprintf(digits, "%lu", (long)i);
    -if ((mgv = gv_fetchpv(digits, 0, SVt_PV)))
    +const STRLEN len = my_sprintf(digits, "%lu", (long)i);
    +if ((mgv = gv_fetchpvn_flags(digits, len, 0, SVt_PV)))
    save_scalar(mgv);
    }
    }
    //depot/maint-5.8/perl/sv.c#253 (text)
    Index: perl/sv.c
    perl/sv.c#252~28157~2006-05-11 03:03:53.000000000 -0700
    perl/sv.c2006-05-11 03:36:47.000000000 -0700
    @@ -8481,8 +8481,11 @@
    aka precis is 0 */
    if ( c == 'g' && precis) {
    Gconvert((NV)nv, (int)precis, 0, PL_efloatbuf);
    - if (*PL_efloatbuf)/* May return an empty string for digits==0 */
    + /* May return an empty string for digits==0 */
    + if (*PL_efloatbuf) {
    +elen = strlen(PL_efloatbuf);
    goto float_converted;
    + }
    } else if ( c == 'f' && !precis) {
    if ((eptr = F0convert(nv, ebuf + sizeof ebuf, &elen)))
    break;
    @@ -8526,17 +8529,15 @@
    * where printf() taints but print($float) doesn't.
    * */
    #if defined(HAS_LNG_DUBLE)
    -if (intsize == 'q')
    - (void)sprintf(PL_efloatbuf, ptr, nv);
    -else
    - (void)sprintf(PL_efloatbuf, ptr, (double)nv);
    +elen = ((intsize == 'q')
    +? my_sprintf(PL_efloatbuf, ptr, nv)
    +: my_sprintf(PL_efloatbuf, ptr, (double)nv));
    #else
    -(void)sprintf(PL_efloatbuf, ptr, nv);
    +elen = my_sprintf(PL_efloatbuf, ptr, nv);
    #endif
    }
    float_converted:
    eptr = PL_efloatbuf;
    - elen = strlen(PL_efloatbuf);
    break;
    /* SPECIAL */
    //depot/maint-5.8/perl/taint.c#15 (text)
    Index: perl/taint.c
    perl/taint.c#14~25673~2005-09-30 10:13:04.000000000 -0700
    perl/taint.c2006-05-11 03:36:47.000000000 -0700
    @@ -107,11 +107,12 @@
    {
    int i = 0;
    char name[10 + TYPE_DIGITS(int)] = "DCL$PATH";
    + STRLEN len = 8; /* strlen(name) */
    while (1) {
    if (i)
    - (void)sprintf(name,"DCL$PATH;%d", i);
    -svp = hv_fetch(GvHVn(PL_envgv), name, strlen(name), FALSE);
    + len = my_sprintf(name,"DCL$PATH;%d", i);
    +svp = hv_fetch(GvHVn(PL_envgv), name, len, FALSE);
    if (!svp || *svp == &PL_sv_undef)
    break;
    if (SvTAINTED(*svp)) {
    //depot/maint-5.8/perl/util.c#101 (text)
    Index: perl/util.c
    perl/util.c#100~28128~2006-05-08 12:22:03.000000000 -0700
    perl/util.c2006-05-11 03:36:47.000000000 -0700
    @@ -2641,8 +2641,9 @@
    if (pid 0) {
    SV** svp;
    - sprintf(spid, "%"IVdf, (IV)pid);
    - svp = hv_fetch(PL_pidstatus,spid,strlen(spid),FALSE);
    + const I32 len = my_sprintf(spid, "%"IVdf, (IV)pid);
    +
    + svp = hv_fetch(PL_pidstatus,spid,len,FALSE);
    if (svp && *svp != &PL_sv_undef) {
    *statusp = SvIVX(*svp);
    (void)hv_delete(PL_pidstatus,spid,strlen(spid),G_D ISCARD);
    @@ -2655,11 +2656,12 @@
    hv_iterinit(PL_pidstatus);
    if ((entry = hv_iternext(PL_pidstatus))) {
    SV *sv = hv_iterval(PL_pidstatus,entry);
    +I32 len;
    pid = atoi(hv_iterkey(entry,(I32*)statusp));
    *statusp = SvIVX(sv);
    -sprintf(spid, "%"IVdf, (IV)pid);
    -(void)hv_delete(PL_pidstatus,spid,strlen(spid),G_D ISCARD);
    +len = my_sprintf(spid, "%"IVdf, (IV)pid);
    +(void)hv_delete(PL_pidstatus,spid,len,G_DISCARD);
    return pid;
    }
    }
    @@ -2707,9 +2709,9 @@
    {
    register SV *sv;
    char spid[TYPE_CHARS(IV)];
    + const size_t len = my_sprintf(spid, "%"IVdf, (IV)pid);
    - sprintf(spid, "%"IVdf, (IV)pid);
    - sv = *hv_fetch(PL_pidstatus,spid,strlen(spid),TRUE);
    + sv = *hv_fetch(PL_pidstatus,spid,len,TRUE);
    (void)SvUPGRADE(sv,SVt_IV);
    SvIV_set(sv, status);
    return;
    @@ -4682,6 +4684,27 @@
    }
    /*
    +=for apidoc my_sprintf
    +
    +The C library C<sprintf>, wrapped if necessary, to ensure that it will return
    +the length of the string written to the buffer. rare pre-ANSI systems
    +need the wrapper function - usually this is a direct call to C<sprintf>.
    +
    +=cut
    +*/
    +#ifndef SPRINTF_RETURNS_STRLEN
    +int
    +Perl_my_sprintf(char *buffer, const char* pat, )
    +{
    + va_list args;
    + va_start(args, pat);
    + vsprintf(buffer, pat, args);
    + va_end(args);
    + return strlen(buffer);
    +}
    +#endif
    +
    +/*
    * Local variables:
    * c-indentation-style: bsd
    * c-basic-offset: 4
    End of Patch.

Re: Change 28158: Integrate:


max 4000 letters.
Your nickname that display:
In order to stop the spam: 0 + 9 =
QUESTION ON "Perl"

EMSDN.COM