X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pp.c;h=998cf93da1ccc3a26667d97d6d65962503e81ba6;hb=1e2878e610af032604518a9feca8663968d7369a;hp=626c5b123085c39c48d790fb7eba8b150ca31692;hpb=599cee73f2261c5e09cde7ceba3f9a896989e117;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pp.c b/pp.c index 626c5b1..998cf93 100644 --- a/pp.c +++ b/pp.c @@ -669,7 +669,7 @@ PP(pp_trans) EXTEND(SP,1); } TARG = sv_newmortal(); - PUSHi(do_trans(sv, PL_op)); + PUSHi(do_trans(sv)); RETURN; } @@ -1560,11 +1560,13 @@ PP(pp_cos) compatibility by calling rand() but allow the user to override it. See INSTALL for details. --Andy Dougherty 15 July 1998 */ -#ifndef my_rand -# define my_rand rand -#endif -#ifndef my_srand -# define my_srand srand +/* Now it's after 5.005, and Configure supports drand48() and random(), + in addition to rand(). So the overrides should not be needed any more. + --Jarkko Hietaniemi 27 September 1998 + */ + +#ifndef HAS_DRAND48_PROTO +extern double drand48 _((void)); #endif PP(pp_rand) @@ -1578,22 +1580,10 @@ PP(pp_rand) if (value == 0.0) value = 1.0; if (!srand_called) { - (void)my_srand((unsigned)seed()); + (void)seedDrand01((Rand_seed_t)seed()); srand_called = TRUE; } -#if RANDBITS == 31 - value = my_rand() * value / 2147483648.0; -#else -#if RANDBITS == 16 - value = my_rand() * value / 65536.0; -#else -#if RANDBITS == 15 - value = my_rand() * value / 32768.0; -#else - value = my_rand() * value / (double)(((unsigned long)1) << RANDBITS); -#endif -#endif -#endif + value *= Drand01(); XPUSHn(value); RETURN; } @@ -1606,7 +1596,7 @@ PP(pp_srand) anum = seed(); else anum = POPu; - (void)my_srand((unsigned)anum); + (void)seedDrand01((Rand_seed_t)anum); srand_called = TRUE; EXTEND(SP, 1); RETPUSHYES; @@ -1619,9 +1609,9 @@ seed(void) * This is really just a quick hack which grabs various garbage * values. It really should be a real hash algorithm which * spreads the effect of every input bit onto every output bit, - * if someone who knows about such tings would bother to write it. + * if someone who knows about such things would bother to write it. * Might be a good idea to add that function to CORE as well. - * No numbers below come from careful analysis or anyting here, + * No numbers below come from careful analysis or anything here, * except they are primes and SEED_C1 > 1E6 to get a full-width * value from (tv_sec * SEED_C1 + tv_usec). The multipliers should * probably be bigger too. @@ -1638,21 +1628,50 @@ seed(void) #define SEED_C5 26107 dTHR; +#ifndef PERL_NO_DEV_RANDOM + int fd; +#endif U32 u; #ifdef VMS # include /* when[] = (low 32 bits, high 32 bits) of time since epoch * in 100-ns units, typically incremented ever 10 ms. */ unsigned int when[2]; +#else +# ifdef HAS_GETTIMEOFDAY + struct timeval when; +# else + Time_t when; +# endif +#endif + +/* This test is an escape hatch, this symbol isn't set by Configure. */ +#ifndef PERL_NO_DEV_RANDOM +#ifndef PERL_RANDOM_DEVICE + /* /dev/random isn't used by default because reads from it will block + * if there isn't enough entropy available. You can compile with + * PERL_RANDOM_DEVICE to it if you'd prefer Perl to block until there + * is enough real entropy to fill the seed. */ +# define PERL_RANDOM_DEVICE "/dev/urandom" +#endif + fd = PerlLIO_open(PERL_RANDOM_DEVICE, 0); + if (fd != -1) { + if (PerlLIO_read(fd, &u, sizeof u) != sizeof u) + u = 0; + PerlLIO_close(fd); + if (u) + return u; + } +#endif + +#ifdef VMS _ckvmssts(sys$gettim(when)); u = (U32)SEED_C1 * when[0] + (U32)SEED_C2 * when[1]; #else # ifdef HAS_GETTIMEOFDAY - struct timeval when; gettimeofday(&when,(struct timezone *) 0); u = (U32)SEED_C1 * when.tv_sec + (U32)SEED_C2 * when.tv_usec; # else - Time_t when; (void)time(&when); u = (U32)SEED_C1 * when; # endif @@ -2098,7 +2117,7 @@ PP(pp_ord) { djSP; dTARGET; I32 value; - char *tmps = POPp; + U8 *tmps = (U8*)POPp; I32 retlen; if (IN_UTF8 && (*tmps & 0x80)) @@ -2120,7 +2139,7 @@ PP(pp_chr) if (IN_UTF8 && value >= 128) { SvGROW(TARG,8); tmps = SvPVX(TARG); - tmps = uv_to_utf8(tmps, (UV)value); + tmps = (char*)uv_to_utf8((U8*)tmps, (UV)value); SvCUR_set(TARG, tmps - SvPVX(TARG)); *tmps = '\0'; (void)SvPOK_only(TARG); @@ -2163,7 +2182,7 @@ PP(pp_ucfirst) register U8 *s; STRLEN slen; - if (IN_UTF8 && (s = SvPV(sv, slen)) && slen && (*s & 0xc0) == 0xc0) { + if (IN_UTF8 && (s = (U8*)SvPV(sv, slen)) && slen && (*s & 0xc0) == 0xc0) { I32 ulen; U8 tmpbuf[10]; U8 *tend; @@ -2181,12 +2200,12 @@ PP(pp_ucfirst) if (!SvPADTMP(sv) || tend - tmpbuf != ulen) { dTARGET; - sv_setpvn(TARG, tmpbuf, tend - tmpbuf); - sv_catpvn(TARG, s + ulen, slen - ulen); + sv_setpvn(TARG, (char*)tmpbuf, tend - tmpbuf); + sv_catpvn(TARG, (char*)(s + ulen), slen - ulen); SETs(TARG); } else { - s = SvPV_force(sv, slen); + s = (U8*)SvPV_force(sv, slen); Copy(tmpbuf, s, ulen, U8); } RETURN; @@ -2198,7 +2217,7 @@ PP(pp_ucfirst) sv = TARG; SETs(sv); } - s = SvPV_force(sv, PL_na); + s = (U8*)SvPV_force(sv, PL_na); if (*s) { if (PL_op->op_private & OPpLOCALE) { TAINT; @@ -2219,7 +2238,7 @@ PP(pp_lcfirst) register U8 *s; STRLEN slen; - if (IN_UTF8 && (s = SvPV(sv, slen)) && slen && (*s & 0xc0) == 0xc0) { + if (IN_UTF8 && (s = (U8*)SvPV(sv, slen)) && slen && (*s & 0xc0) == 0xc0) { I32 ulen; U8 tmpbuf[10]; U8 *tend; @@ -2237,12 +2256,12 @@ PP(pp_lcfirst) if (!SvPADTMP(sv) || tend - tmpbuf != ulen) { dTARGET; - sv_setpvn(TARG, tmpbuf, tend - tmpbuf); - sv_catpvn(TARG, s + ulen, slen - ulen); + sv_setpvn(TARG, (char*)tmpbuf, tend - tmpbuf); + sv_catpvn(TARG, (char*)(s + ulen), slen - ulen); SETs(TARG); } else { - s = SvPV_force(sv, slen); + s = (U8*)SvPV_force(sv, slen); Copy(tmpbuf, s, ulen, U8); } RETURN; @@ -2254,7 +2273,7 @@ PP(pp_lcfirst) sv = TARG; SETs(sv); } - s = SvPV_force(sv, PL_na); + s = (U8*)SvPV_force(sv, PL_na); if (*s) { if (PL_op->op_private & OPpLOCALE) { TAINT; @@ -2282,7 +2301,7 @@ PP(pp_uc) register U8 *d; U8 *send; - s = SvPV(sv,len); + s = (U8*)SvPV(sv,len); if (!len) { sv_setpvn(TARG, "", 0); SETs(TARG); @@ -2292,7 +2311,7 @@ PP(pp_uc) (void)SvUPGRADE(TARG, SVt_PV); SvGROW(TARG, (len * 2) + 1); (void)SvPOK_only(TARG); - d = SvPVX(TARG); + d = (U8*)SvPVX(TARG); send = s + len; if (PL_op->op_private & OPpLOCALE) { TAINT; @@ -2321,7 +2340,7 @@ PP(pp_uc) SETs(sv); } - s = SvPV_force(sv, len); + s = (U8*)SvPV_force(sv, len); if (len) { register U8 *send = s + len; @@ -2352,7 +2371,7 @@ PP(pp_lc) register U8 *d; U8 *send; - s = SvPV(sv,len); + s = (U8*)SvPV(sv,len); if (!len) { sv_setpvn(TARG, "", 0); SETs(TARG); @@ -2362,7 +2381,7 @@ PP(pp_lc) (void)SvUPGRADE(TARG, SVt_PV); SvGROW(TARG, (len * 2) + 1); (void)SvPOK_only(TARG); - d = SvPVX(TARG); + d = (U8*)SvPVX(TARG); send = s + len; if (PL_op->op_private & OPpLOCALE) { TAINT; @@ -2391,7 +2410,7 @@ PP(pp_lc) SETs(sv); } - s = SvPV_force(sv, len); + s = (U8*)SvPV_force(sv, len); if (len) { register U8 *send = s + len; @@ -3043,17 +3062,17 @@ PP(pp_reverse) up = SvPV_force(TARG, len); if (len > 1) { if (IN_UTF8) { /* first reverse each character */ - unsigned char* s = SvPVX(TARG); - unsigned char* send = s + len; + U8* s = (U8*)SvPVX(TARG); + U8* send = (U8*)(s + len); while (s < send) { if (*s < 0x80) { s++; continue; } else { - up = s; + up = (char*)s; s += UTF8SKIP(s); - down = s - 1; + down = (char*)(s - 1); if (s > send || !((*down & 0xc0) == 0x80)) { warn("Malformed UTF-8 character"); break; @@ -3395,7 +3414,7 @@ PP(pp_unpack) len = strend - s; if (checksum) { while (len-- > 0 && s < strend) { - auint = utf8_to_uv(s, &along); + auint = utf8_to_uv((U8*)s, &along); s += along; culong += auint; } @@ -3404,7 +3423,7 @@ PP(pp_unpack) EXTEND(SP, len); EXTEND_MORTAL(len); while (len-- > 0 && s < strend) { - auint = utf8_to_uv(s, &along); + auint = utf8_to_uv((U8*)s, &along); s += along; sv = NEWSV(37, 0); sv_setiv(sv, (IV)auint); @@ -3798,7 +3817,7 @@ PP(pp_unpack) char hunk[4]; hunk[3] = '\0'; - len = (*s++ - ' ') & 077; + len = uudmap[*s++] & 077; while (len > 0) { if (s < strend && ISUUCHAR(*s)) a = uudmap[*s++] & 077; @@ -4213,7 +4232,8 @@ PP(pp_pack) fromstr = NEXTFROM; auint = SvUV(fromstr); SvGROW(cat, SvCUR(cat) + 10); - SvCUR_set(cat, uv_to_utf8(SvEND(cat), auint) - SvPVX(cat)); + SvCUR_set(cat, (char*)uv_to_utf8((U8*)SvEND(cat),auint) + - SvPVX(cat)); } *SvEND(cat) = '\0'; break;