This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Integrate:
[perl5.git] / pp.c
diff --git a/pp.c b/pp.c
index 754d4fb..82baf1e 100644 (file)
--- a/pp.c
+++ b/pp.c
@@ -1,6 +1,7 @@
 /*    pp.c
  *
- *    Copyright (c) 1991-2003, Larry Wall
+ *    Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
+ *    2000, 2001, 2002, 2003, by Larry Wall and others
  *
  *    You may distribute under the terms of either the GNU General Public
  *    License or the Artistic License, as specified in the README file.
@@ -106,6 +107,9 @@ PP(pp_padhv)
     }
     else if (gimme == G_SCALAR) {
        SV* sv = sv_newmortal();
+        if (SvRMAGICAL(TARG) && mg_find(TARG, PERL_MAGIC_tied))
+            Perl_croak(aTHX_ "Can't provide tied hash usage; "
+                       "use keys(%%hash) to test if empty");
        if (HvFILL((HV*)TARG))
            Perl_sv_setpvf(aTHX_ sv, "%ld/%ld",
                      (long)HvFILL((HV*)TARG), (long)HvMAX((HV*)TARG) + 1);
@@ -858,6 +862,7 @@ PP(pp_postinc)
     else
        sv_inc(TOPs);
     SvSETMAGIC(TOPs);
+    /* special case for undef: see thread at 2003-03/msg00536.html in archive */
     if (!SvOK(TARG))
        sv_setiv(TARG, 0);
     SETs(TARG);
@@ -1237,7 +1242,7 @@ PP(pp_divide)
                     }
                     RETURN;
                 } /* tried integer divide but it was not an integer result */
-            } /* else (abs(result) < 1.0) or (both UVs in range for NV) */
+            } /* else (PERL_ABS(result) < 1.0) or (both UVs in range for NV) */
         } /* left wasn't SvIOK */
     } /* right wasn't SvIOK */
 #endif /* PERL_TRY_UV_DIVIDE */
@@ -2472,25 +2477,23 @@ PP(pp_i_modulo_0)
      }
 }
 
+#if defined(__GLIBC__) && IVSIZE == 8
 STATIC
 PP(pp_i_modulo_1)
 {
-#ifdef __GLIBC__
      /* This is the i_modulo with the workaround for the _moddi3 bug
-      * in (at least) glibc 2.2.5 (the "right = -right" is the workaround).
+      * in (at least) glibc 2.2.5 (the PERL_ABS() the workaround).
       * See below for pp_i_modulo. */
      dSP; dATARGET; tryAMAGICbin(modulo,opASSIGN);
      {
          dPOPTOPiirl;
          if (!right)
               DIE(aTHX_ "Illegal modulus zero");
-         if (right < 0)
-              right = -right;
-         SETi( left % right );
+         SETi( left % PERL_ABS(right) );
          RETURN;
      }
-#endif
 }
+#endif
 
 PP(pp_i_modulo)
 {
@@ -2523,8 +2526,7 @@ PP(pp_i_modulo)
                         PL_ppaddr[OP_I_MODULO] =
                             &Perl_pp_i_modulo_1;
                    /* Make certain we work right this time, too. */
-                   if (right < 0)
-                        right = -right;
+                   right = PERL_ABS(right);
               }
          }
 #endif
@@ -2893,24 +2895,14 @@ PP(pp_int)
                  SETu(U_V(value));
              } else {
 #if defined(SPARC64_MODF_WORKAROUND)
-               (void)sparc64_workaround_modf(value, &value);
-#else
-#   if defined(HAS_MODFL) || defined(LONG_DOUBLE_EQUALS_DOUBLE)
-#       ifdef HAS_MODFL_POW32_BUG
+                  (void)sparc64_workaround_modf(value, &value);
+#elif defined(HAS_MODFL_POW32_BUG)
 /* some versions of glibc split (i + d) into (i-1, d+1) for 2^32 <= i < 2^64 */
-                {
-                    NV offset = Perl_modf(value, &value);
-                    (void)Perl_modf(offset, &offset);
-                    value += offset;
-                }
-#       else
-                 (void)Perl_modf(value, &value);
-#       endif
-#   else
-                 double tmp = (double)value;
-                 (void)Perl_modf(tmp, &tmp);
-                 value = (NV)tmp;
-#   endif
+                  NV offset = Perl_modf(value, &value);
+                  (void)Perl_modf(offset, &offset);
+                  value += offset;
+#else
+                  (void)Perl_modf(value, &value);
 #endif
                  SETn(value);
              }
@@ -2919,24 +2911,17 @@ PP(pp_int)
              if (value > (NV)IV_MIN - 0.5) {
                  SETi(I_V(value));
              } else {
-#if defined(HAS_MODFL) || defined(LONG_DOUBLE_EQUALS_DOUBLE)
-#   ifdef HAS_MODFL_POW32_BUG
+#if defined(SPARC64_MODF_WORKAROUND)
+                  (void)sparc64_workaround_modf(-value, &value);
+#elif defined(HAS_MODFL_POW32_BUG)
 /* some versions of glibc split (i + d) into (i-1, d+1) for 2^32 <= i < 2^64 */
-                 {
-                     NV offset = Perl_modf(-value, &value);
-                     (void)Perl_modf(offset, &offset);
-                     value += offset;
-                 }
-#   else
-                 (void)Perl_modf(-value, &value);
-#   endif
-                 value = -value;
+                  NV offset = Perl_modf(-value, &value);
+                  (void)Perl_modf(offset, &offset);
+                  value += offset;
 #else
-                 double tmp = (double)value;
-                 (void)Perl_modf(-tmp, &tmp);
-                 value = -(NV)tmp;
+                 (void)Perl_modf(-value, &value);
 #endif
-                 SETn(value);
+                 SETn(-value);
              }
          }
       }
@@ -3390,7 +3375,8 @@ PP(pp_chr)
        tmps = SvPVX(TARG);
        if (SvCUR(TARG) == 0 || !is_utf8_string((U8*)tmps, SvCUR(TARG)) ||
            memEQ(tmps, "\xef\xbf\xbd\0", 4)) {
-           SvGROW(TARG,3);
+           SvGROW(TARG, 3);
+           tmps = SvPVX(TARG);
            SvCUR_set(TARG, 2);
            *tmps++ = (U8)UTF8_EIGHT_BIT_HI(value);
            *tmps++ = (U8)UTF8_EIGHT_BIT_LO(value);
@@ -3421,6 +3407,24 @@ PP(pp_crypt)
         sv_utf8_downgrade(tsv, FALSE);
         tmps = SvPVX(tsv);
     }
+#   ifdef USE_ITHREADS
+#     ifdef HAS_CRYPT_R
+    if (!PL_reentrant_buffer->_crypt_struct_buffer) {
+      /* This should be threadsafe because in ithreads there is only
+       * one thread per interpreter.  If this would not be true,
+       * we would need a mutex to protect this malloc. */
+        PL_reentrant_buffer->_crypt_struct_buffer =
+         (struct crypt_data *)safemalloc(sizeof(struct crypt_data));
+#if defined(__GLIBC__) || defined(__EMX__)
+       if (PL_reentrant_buffer->_crypt_struct_buffer) {
+           PL_reentrant_buffer->_crypt_struct_buffer->initialized = 0;
+           /* work around glibc-2.2.5 bug */
+           PL_reentrant_buffer->_crypt_struct_buffer->current_saltbits = 0;
+       }
+#endif
+    }
+#     endif /* HAS_CRYPT_R */
+#   endif /* USE_ITHREADS */
 #   ifdef FCRYPT
     sv_setpv(TARG, fcrypt(tmps, SvPV(right, n_a)));
 #   else
@@ -4787,12 +4791,10 @@ PP(pp_split)
        if (gimme == G_ARRAY)
            RETURN;
     }
-    if (iters || !pm->op_pmreplroot) {
-       GETTARGET;
-       PUSHi(iters);
-       RETURN;
-    }
-    RETPUSHUNDEF;
+
+    GETTARGET;
+    PUSHi(iters);
+    RETURN;
 }
 
 #ifdef USE_5005THREADS