Change 19122 by [EMAIL PROTECTED] on 2003/04/01 16:36:52

        Integrate:
        [ 19119]
        Address "[EMAIL PROTECTED]: crypt_r() takes 128K per thread".

Affected files ...

... //depot/perl/pp.c#376 integrate
... //depot/perl/reentr.c#13 integrate
... //depot/perl/reentr.h#14 integrate
... //depot/perl/reentr.pl#27 integrate

Differences ...

==== //depot/perl/pp.c#376 (text) ====
Index: perl/pp.c
--- perl/pp.c#375~19047~        Sun Mar 23 09:54:33 2003
+++ perl/pp.c   Tue Apr  1 08:36:52 2003
@@ -3418,6 +3418,24 @@
         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

==== //depot/perl/reentr.c#13 (text) ====
Index: perl/reentr.c
--- perl/reentr.c#12~19120~     Tue Apr  1 08:32:03 2003
+++ perl/reentr.c       Tue Apr  1 08:36:52 2003
@@ -146,10 +146,8 @@
        New(31338, PL_reentrant_buffer->_asctime_buffer, 
PL_reentrant_buffer->_asctime_size, char);
 #endif /* HAS_ASCTIME_R */
 #ifdef HAS_CRYPT_R
-#if defined(__GLIBC__) || defined(__EMX__)
-       PL_reentrant_buffer->_crypt_struct.initialized = 0;
-       /* work around glibc-2.2.5 bug */
-       PL_reentrant_buffer->_crypt_struct.current_saltbits = 0;
+#if CRYPT_R_PROTO != REENTRANT_PROTO_B_CCD
+       PL_reentrant_buffer->_crypt_struct_buffer = 0;
 #endif
 #endif /* HAS_CRYPT_R */
 #ifdef HAS_CTIME_R
@@ -230,6 +228,9 @@
        Safefree(PL_reentrant_buffer->_asctime_buffer);
 #endif /* HAS_ASCTIME_R */
 #ifdef HAS_CRYPT_R
+#if CRYPT_R_PROTO != REENTRANT_PROTO_B_CCD
+       Safefree(PL_reentrant_buffer->_crypt_struct_buffer);
+#endif
 #endif /* HAS_CRYPT_R */
 #ifdef HAS_CTIME_R
        Safefree(PL_reentrant_buffer->_ctime_buffer);

==== //depot/perl/reentr.h#14 (text) ====
Index: perl/reentr.h
--- perl/reentr.h#13~19120~     Tue Apr  1 08:32:03 2003
+++ perl/reentr.h       Tue Apr  1 08:36:52 2003
@@ -604,7 +604,7 @@
 #if CRYPT_R_PROTO == REENTRANT_PROTO_B_CCD
        CRYPTD* _crypt_data;
 #else
-       struct crypt_data _crypt_struct;
+       struct crypt_data *_crypt_struct_buffer;
 #endif
 #endif /* HAS_CRYPT_R */
 #ifdef HAS_CTIME_R
@@ -781,7 +781,7 @@
 #ifdef HAS_CRYPT_R
 #   undef crypt
 #   if !defined(crypt) && CRYPT_R_PROTO == REENTRANT_PROTO_B_CCS
-#       define crypt(a, b) crypt_r(a, b, &PL_reentrant_buffer->_crypt_struct)
+#       define crypt(a, b) crypt_r(a, b, PL_reentrant_buffer->_crypt_struct_buffer)
 #   endif
 #   if !defined(crypt) && CRYPT_R_PROTO == REENTRANT_PROTO_B_CCD
 #       define crypt(a, b) crypt_r(a, b, &PL_reentrant_buffer->_crypt_data)

==== //depot/perl/reentr.pl#27 (text) ====
Index: perl/reentr.pl
--- perl/reentr.pl#26~19120~    Tue Apr  1 08:32:03 2003
+++ perl/reentr.pl      Tue Apr  1 08:36:52 2003
@@ -453,14 +453,17 @@
 #if CRYPT_R_PROTO == REENTRANT_PROTO_B_CCD
        $seend{$func} _${func}_data;
 #else
-       $seent{$func} _${func}_struct;
+       $seent{$func} *_${func}_struct_buffer;
 #endif
 EOF
            push @init, <<EOF;
-#if defined(__GLIBC__) || defined(__EMX__)
-       PL_reentrant_buffer->_${func}_struct.initialized = 0;
-       /* work around glibc-2.2.5 bug */
-       PL_reentrant_buffer->_${func}_struct.current_saltbits = 0;
+#if CRYPT_R_PROTO != REENTRANT_PROTO_B_CCD
+       PL_reentrant_buffer->_${func}_struct_buffer = 0;
+#endif
+EOF
+           push @free, <<EOF;
+#if CRYPT_R_PROTO != REENTRANT_PROTO_B_CCD
+       Safefree(PL_reentrant_buffer->_${func}_struct_buffer);
 #endif
 EOF
            pushssif $endif;
@@ -661,9 +664,11 @@
                             $_ eq 'D' ?
                                 "&PL_reentrant_buffer->_${genfunc}_data" :
                             $_ eq 'S' ?
-                                ($func =~ /^readdir/ ?
+                                ($func =~ /^readdir\d*$/ ?
                                  "PL_reentrant_buffer->_${genfunc}_struct" :
-                                 "&PL_reentrant_buffer->_${genfunc}_struct" ) :
+                                 $func =~ /^crypt$/ ?
+                                 "PL_reentrant_buffer->_${genfunc}_struct_buffer" :
+                                 "&PL_reentrant_buffer->_${genfunc}_struct") :
                             $_ eq 'T' && $func eq 'drand48' ?
                                 "&PL_reentrant_buffer->_${genfunc}_double" :
                             $_ =~ /^[ilt]$/ && $func eq 'random' ?
End of Patch.

Reply via email to