Fix test for overload in given() with smart match after last change
[p5sagit/p5-mst-13.2.git] / t / op / threads.t
index cb6fda6..c8ed34a 100644 (file)
@@ -1,25 +1,26 @@
-#!./perl
+#!perl
+
 BEGIN {
      chdir 't' if -d 't';
      @INC = '../lib';
      require './test.pl';
      $| = 1;
-}
-
-use strict;
-use Config;
 
-BEGIN {
-     if (!$Config{useithreads}) {
-       print "1..0 # Skip: no ithreads\n";
-       exit 0;
+     require Config;
+     if (!$Config::Config{useithreads}) {
+        print "1..0 # Skip: no ithreads\n";
+        exit 0;
      }
      if ($ENV{PERL_CORE_MINITEST}) {
        print "1..0 # Skip: no dynamic loading on miniperl, no threads\n";
        exit 0;
      }
-     plan(11);
+
+     plan(14);
 }
+
+use strict;
+use warnings;
 use threads;
 
 # test that we don't get:
@@ -119,22 +120,6 @@ TODO: {
     no strict 'vars';   # Accessing $TODO from test.pl
     local $TODO = 'refcount issues with threads';
 
-# Attempt to free unreferenced scalar...
-fresh_perl_is(<<'EOI', 'ok', { }, 'thread sub via scalar');
-    use threads;
-    my $test = sub {};
-    threads->create($test)->join();
-    print 'ok';
-EOI
-
-# Attempt to free unreferenced scalar...
-fresh_perl_is(<<'EOI', 'ok', { }, 'thread sub via $_[0]');
-    use threads;
-    sub thr { threads->new($_[0]); }
-    thr(sub { })->join;
-    print 'ok';
-EOI
-
 # Scalars leaked: 1
 foreach my $BLOCK (qw(CHECK INIT)) {
     fresh_perl_is(<<EOI, 'ok', { }, "threads in $BLOCK block");
@@ -158,4 +143,52 @@ EOI
 
 } # TODO
 
+# [perl #45053] Memory corruption with heavy module loading in threads
+#
+# run-time usage of newCONSTSUB (as done by the IO boot code) wasn't
+# thread-safe - got occasional coredumps or malloc corruption
+{
+    local $SIG{__WARN__} = sub {};   # Ignore any thread creation failure warnings
+    my @t;
+    for (1..100) {
+        my $thr = threads->create( sub { require IO });
+        last if !defined($thr);      # Probably ran out of memory
+        push(@t, $thr);
+    }
+    $_->join for @t;
+    ok(1, '[perl #45053]');
+}
+
+sub matchit {
+    is (ref $_[1], "Regexp");
+    like ($_[0], $_[1]);
+}
+
+threads->new(\&matchit, "Pie", qr/pie/i)->join();
+
+# tests in threads don't get counted, so
+curr_test(curr_test() + 2);
+
+
+# the seen_evals field of a regexp was getting zeroed on clone, so
+# within a thread it didn't  know that a regex object contrained a 'safe'
+# re_eval expression, so it later died with 'Eval-group not allowed' when
+# you tried to interpolate the object
+
+sub safe_re {
+    my $re = qr/(?{1})/;       # this is literal, so safe
+    eval { "a" =~ /$re$re/ };  # interpolating safe values, so safe
+    ok($@ eq "", 'clone seen-evals');
+}
+threads->new(\&safe_re)->join();
+
+# tests in threads don't get counted, so
+curr_test(curr_test() + 1);
+
+# This used to crash in 5.10.0 [perl #64954]
+
+undef *a;
+threads->new(sub {})->join;
+pass("undefing a typeglob doesn't cause a crash during cloning");
+
 # EOF