This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Recent 4.1 breakage...


Loren James Rittle wrote:

Here is my proposed patch to address the semaphore leak issue only:

	* testsuite/27_io/basic_filebuf/seekoff/char/26777.cc (test01):
	Restructure so that no VERIFY check is ever made by the initial
	process while a semaphore lives.  Report child VERIFY check
	failure.

[I think that this code was and is still buggy since if
VERIFY( fbout.is_open() ) ever fails, then a deadlock would occur.]


Humpf, I'm sorry, in the meanwhile I was testing the below, and I would be rather happy with it ;) I'm simply putting to good use our VERIFY machinery (*finally*, some people would add, I'm sure). The patch is very safe, basically the tests themselves are unchanged, and could still be run with _GLIBCXX_ASSERT defined, in case of need. Is it fine with you?

Well, I'm confused on the expected behavior of 26777 (even after
reading the PR) and exactly what I see on FreeBSD 5.  Here is the read
on the fifo and the lseek from a truss log:

82979: read(0x3,0x804d000,0x3ff)                 = 8 (0x8)
82979: lseek(3,0xfffffffffffffff8,SEEK_CUR)      = 0 (0x0)

Paolo, make any sense to you?


Not really, *on the spot*, sorry (it's late here in Italy...). But I want to understand what's going on. Can you print to cout the failing oss.str()? Is it empty or not? Out of curiosity, which is the value of BUFSIZ on FreeBSD?

Thanks for now,
Paolo.

//////////////////
2006-05-XX  Paolo Carlini  <pcarlini@suse.de>

	* testsuite/27_io/objects/wchar_t/9661-1.cc: Don't leak the
	semaphores if a VERIFY fails.
	* testsuite/27_io/objects/wchar_t/7.cc: Likewise.
	* testsuite/27_io/objects/char/9661-1.cc: Likewise.
	* testsuite/27_io/objects/char/7.cc: Likewise.
	* testsuite/27_io/basic_filebuf/seekoff/char/26777.cc: Likewise.
	* testsuite/27_io/basic_filebuf/imbue/wchar_t/14975-2.cc: Likewise.
	* testsuite/27_io/basic_filebuf/imbue/char/13171-2.cc: Likewise.
	* testsuite/27_io/basic_filebuf/close/char/4879.cc: Likewise.
	* testsuite/27_io/basic_filebuf/close/char/9964.cc: Likewise.
	* testsuite/27_io/basic_filebuf/underflow/char/10097.cc: Likewise.
Index: testsuite/27_io/objects/wchar_t/9661-1.cc
===================================================================
--- testsuite/27_io/objects/wchar_t/9661-1.cc	(revision 113884)
+++ testsuite/27_io/objects/wchar_t/9661-1.cc	(working copy)
@@ -30,10 +30,13 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 
+// Avoid leaking the semaphores if a VERIFY fails.
+#undef _GLIBCXX_ASSERT
+
 // Check that wcin.rdbuf()->sputbackc() puts characters back to stdin.
 // If wcin.rdbuf() is a filebuf, this succeeds when stdin is a regular
 // file, but fails otherwise, hence the named fifo.
-void test01()
+bool test01()
 {
   using namespace std;
   using namespace __gnu_test;
@@ -83,11 +86,12 @@
   VERIFY( c5 != WEOF );
   VERIFY( c5 == c4 );
   s2.signal();
-  s1.wait(); 
+  s1.wait();
+
+  return test;
 }
 
 int main()
 {
-  test01();
-  return 0;
+  return !test01();
 }
Index: testsuite/27_io/objects/wchar_t/7.cc
===================================================================
--- testsuite/27_io/objects/wchar_t/7.cc	(revision 113884)
+++ testsuite/27_io/objects/wchar_t/7.cc	(working copy)
@@ -3,7 +3,7 @@
 
 // 2003-05-01 Petur Runolfsson  <peturr02@ru.is>
 
-// Copyright (C) 2003, 2005 Free Software Foundation, Inc.
+// Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the
@@ -32,8 +32,11 @@
 #include <sys/stat.h>
 #include <testsuite_hooks.h>
 
+// Avoid leaking the semaphore if a VERIFY fails.
+#undef _GLIBCXX_ASSERT
+
 // Check that wcout.flush() is called when last ios_base::Init is destroyed.
-void test07()
+bool test07()
 {
   using namespace std;
   using namespace __gnu_test;
@@ -46,7 +49,7 @@
   unlink(name);  
   mkfifo(name, S_IRWXU);
   semaphore s1;
-  
+
   int child = fork();
   VERIFY( child != -1 );
 
@@ -63,17 +66,18 @@
   
   wfilebuf fbin;
   fbin.open(name, ios_base::in);
-  s1.signal ();
+  s1.signal();
   wfilebuf::int_type c = fbin.sbumpc();
   VERIFY( c != wfilebuf::traits_type::eof() );
   VERIFY( c == wfilebuf::traits_type::to_int_type(L'a') );
 
   fbin.close();
+
+  return test;
 }
 
 int
 main()
 {
-  test07();
-  return 0;
+  return !test07();
 }
Index: testsuite/27_io/objects/char/9661-1.cc
===================================================================
--- testsuite/27_io/objects/char/9661-1.cc	(revision 113884)
+++ testsuite/27_io/objects/char/9661-1.cc	(working copy)
@@ -30,10 +30,13 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 
+// Avoid leaking the semaphores if a VERIFY fails.
+#undef _GLIBCXX_ASSERT
+
 // Check that cin.rdbuf()->sputbackc() puts characters back to stdin.
 // If cin.rdbuf() is a filebuf, this succeeds when stdin is a regular
 // file, but fails otherwise, hence the named fifo.
-void test01()
+bool test01()
 {
   using namespace std;
   using namespace __gnu_test;
@@ -54,7 +57,7 @@
   if (child == 0)
     {
       FILE* file = fopen(name, "r+");
-      VERIFY (file != NULL);
+      VERIFY( file != NULL );
       fputs("Whatever\n", file);
       fflush(file);
       s1.signal();
@@ -85,10 +88,11 @@
   VERIFY( c5 == c4 );
   s2.signal();
   s1.wait();
+
+  return test;
 }
 
 int main()
 {
-  test01();
-  return 0;
+  return !test01();
 }
Index: testsuite/27_io/objects/char/7.cc
===================================================================
--- testsuite/27_io/objects/char/7.cc	(revision 113884)
+++ testsuite/27_io/objects/char/7.cc	(working copy)
@@ -3,7 +3,7 @@
 
 // 2003-04-26 Petur Runolfsson  <peturr02@ru.is>
 
-// Copyright (C) 2003, 2005 Free Software Foundation, Inc.
+// Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the
@@ -32,8 +32,11 @@
 #include <sys/stat.h>
 #include <testsuite_hooks.h>
 
+// Avoid leaking the semaphore if a VERIFY fails.
+#undef _GLIBCXX_ASSERT
+
 // Check that cout.flush() is called when last ios_base::Init is destroyed.
-void test07()
+bool test07()
 {
   using namespace std;
   using namespace __gnu_test;
@@ -54,8 +57,8 @@
     {
       filebuf fbout;
       fbout.open(name, ios_base::in|ios_base::out);
-      s1.wait ();
-      VERIFY ( fbout.is_open() );
+      VERIFY( fbout.is_open() );
+      s1.wait();
       cout.rdbuf(&fbout);
       fbout.sputc('a');
       // NB: fbout is *not* destroyed here!
@@ -64,17 +67,18 @@
   
   filebuf fbin;
   fbin.open(name, ios_base::in);
-  s1.signal ();
+  s1.signal();
   filebuf::int_type c = fbin.sbumpc();
   VERIFY( c != filebuf::traits_type::eof() );
   VERIFY( c == filebuf::traits_type::to_int_type('a') );
 
   fbin.close();
+
+  return test;
 }
 
 int
 main()
 {
-  test07();
-  return 0;
+  return !test07();
 }
Index: testsuite/27_io/basic_filebuf/seekoff/char/26777.cc
===================================================================
--- testsuite/27_io/basic_filebuf/seekoff/char/26777.cc	(revision 113884)
+++ testsuite/27_io/basic_filebuf/seekoff/char/26777.cc	(working copy)
@@ -30,8 +30,11 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 
+// Avoid leaking the semaphores if a VERIFY fails.
+#undef _GLIBCXX_ASSERT
+
 // libstdc++/26777
-void test01()
+bool test01()
 {
   using namespace std;
   using namespace __gnu_test;
@@ -77,10 +80,11 @@
   fbin.close();
 
   VERIFY( oss.str() == "Whatever" );
+
+  return test;
 }
 
 int main()
 {
-  test01();
-  return 0;
+  return !test01();
 }
Index: testsuite/27_io/basic_filebuf/imbue/wchar_t/14975-2.cc
===================================================================
--- testsuite/27_io/basic_filebuf/imbue/wchar_t/14975-2.cc	(revision 113884)
+++ testsuite/27_io/basic_filebuf/imbue/wchar_t/14975-2.cc	(working copy)
@@ -4,7 +4,7 @@
 
 // 2004-04-16  Petur Runolfsson  <peturr02@ru.is>
 
-// Copyright (C) 2004, 2005 Free Software Foundation, Inc.
+// Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the
@@ -31,8 +31,11 @@
 #include <sys/stat.h>
 #include <testsuite_hooks.h>
 
+// Avoid leaking the semaphore if a VERIFY fails.
+#undef _GLIBCXX_ASSERT
+
 // libstdc++/14975
-void test01()
+bool test01()
 {
   using namespace std;
   using namespace __gnu_test;
@@ -57,7 +60,7 @@
 	filebuf fbin;
 	fbin.open(name, ios_base::in);
       }
-      s1.signal ();
+      s1.signal();
       exit(0);
     }
   
@@ -67,7 +70,7 @@
   VERIFY( ret != NULL );
   VERIFY( fb.is_open() );
 
-  s1.wait ();
+  s1.wait();
 
   try
     {
@@ -80,10 +83,11 @@
   catch (std::exception&)
     {
     }
+
+  return test;
 }
 
 int main()
 {
-  test01();
-  return 0;
+  return !test01();
 }
Index: testsuite/27_io/basic_filebuf/imbue/char/13171-2.cc
===================================================================
--- testsuite/27_io/basic_filebuf/imbue/char/13171-2.cc	(revision 113884)
+++ testsuite/27_io/basic_filebuf/imbue/char/13171-2.cc	(working copy)
@@ -30,8 +30,11 @@
 
 #include <testsuite_hooks.h>
 
+// Avoid leaking the semaphores if a VERIFY fails.
+#undef _GLIBCXX_ASSERT
+
 // libstdc++/13171
-void test01()
+bool test01()
 {
   bool test __attribute__((unused)) = true;
   using namespace std;
@@ -52,8 +55,8 @@
       fb.open(name, ios_base::out);
       fb.sputc('S');
       fb.pubsync();
-      s1.signal ();
-      s2.wait ();
+      s1.signal();
+      s2.wait();
       fb.close();
       exit(0);
     }
@@ -61,17 +64,18 @@
   filebuf fb;
   fb.pubimbue(loc_fr);
   fb.open(name, ios_base::in);
-  s1.wait ();
+  s1.wait();
   VERIFY( fb.is_open() );
   fb.pubimbue(loc_en);
   filebuf::int_type c = fb.sgetc();
   fb.close();
   VERIFY( c == 'S' );
-  s2.signal ();
+  s2.signal();
+
+  return test;
 }
 
 int main()
 {
-  test01();
-  return 0;
+  return !test01();
 }
Index: testsuite/27_io/basic_filebuf/close/char/4879.cc
===================================================================
--- testsuite/27_io/basic_filebuf/close/char/4879.cc	(revision 113884)
+++ testsuite/27_io/basic_filebuf/close/char/4879.cc	(working copy)
@@ -1,7 +1,8 @@
 // { dg-require-fork "" }
 // { dg-require-mkfifo "" }
  
-// Copyright (C) 2001, 2002, 2003, 2005 Free Software Foundation, Inc.
+// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006
+// Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the
@@ -35,9 +36,12 @@
 #include <sys/stat.h>
 #include <testsuite_hooks.h>
 
+// Avoid leaking the semaphores if a VERIFY fails.
+#undef _GLIBCXX_ASSERT
+
 // libstdc++/2913, libstdc++/4879
 // John Fardo  <jfardo@laurelnetworks.com>, Brad Garcia <garsh@attbi.com>
-void
+bool
 test_04()
 {
   using namespace __gnu_test;
@@ -60,20 +64,20 @@
     {
       std::cerr << "failed to fork" << std::endl;
       unlink(name);
-      exit(-1);
+      return false;
     }
   else if (fval == 0)
     {
       std::ifstream ifs(name);
-      s1.wait ();
+      s1.wait();
       ifs.close();
-      s2.signal ();
+      s2.signal();
       exit(0);
     }
 
   std::ofstream ofs(name);
-  s1.signal ();
-  s2.wait ();
+  s1.signal();
+  s2.wait();
   ofs.put('t');
 
   /*
@@ -89,18 +93,15 @@
     {
       test = false;
       VERIFY( test );
-      unlink(name);
-      exit(-1);
     }
 
   unlink(name);
+
+  return test;
 }
 
 int
 main()
 {
-  test_04();
-  return 0;
+  return !test_04();
 }
-
-
Index: testsuite/27_io/basic_filebuf/close/char/9964.cc
===================================================================
--- testsuite/27_io/basic_filebuf/close/char/9964.cc	(revision 113884)
+++ testsuite/27_io/basic_filebuf/close/char/9964.cc	(working copy)
@@ -1,7 +1,8 @@
 // { dg-require-fork "" }
 // { dg-require-mkfifo "" }
 
-// Copyright (C) 2001, 2002, 2003, 2005 Free Software Foundation, Inc.
+// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006
+// Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the
@@ -34,8 +35,11 @@
 #include <sys/stat.h>
 #include <testsuite_hooks.h>
 
+// Avoid leaking the semaphores if a VERIFY fails.
+#undef _GLIBCXX_ASSERT
+
 // libstdc++/9964
-void test_07()
+bool test_07()
 {
   using namespace std;
   using namespace __gnu_test;
@@ -56,9 +60,9 @@
     {
       filebuf fbin;
       fbin.open(name, ios_base::in);
-      s1.wait ();
+      s1.wait();
       fbin.close();
-      s2.signal ();
+      s2.signal();
       exit(0);
     }
   
@@ -66,18 +70,19 @@
   filebuf* ret = fb.open(name, ios_base::in | ios_base::out);
   VERIFY( ret != NULL );
   VERIFY( fb.is_open() );
-  s1.signal ();
-  s2.wait ();
+  s1.signal();
+  s2.wait();
   fb.sputc('a');
 
   ret = fb.close();
   VERIFY( ret != NULL );
   VERIFY( !fb.is_open() );
+
+  return test;
 }
 
 int
 main()
 {
-  test_07();
-  return 0;
+  return !test_07();
 }
Index: testsuite/27_io/basic_filebuf/underflow/char/10097.cc
===================================================================
--- testsuite/27_io/basic_filebuf/underflow/char/10097.cc	(revision 113884)
+++ testsuite/27_io/basic_filebuf/underflow/char/10097.cc	(working copy)
@@ -32,6 +32,9 @@
 #include <sys/stat.h>
 #include <testsuite_hooks.h>
 
+// Avoid leaking the semaphores if a VERIFY fails.
+#undef _GLIBCXX_ASSERT
+
 class UnderBuf : public std::filebuf
 {
 public:
@@ -46,7 +49,7 @@
 
 // libstdc++/10097
 // filebuf::underflow drops characters.
-void test16()
+bool test16()
 {
   using namespace std;
   using namespace __gnu_test;
@@ -84,7 +87,7 @@
 
   UnderBuf fb;
   fb.open(name, ios_base::in);
-  
+
   fb.sgetc();
   streamsize n = fb.pub_showmanyc();
 
@@ -101,10 +104,11 @@
   fb.close();
   s1.signal();
   s2.wait();
+
+  return test;
 }
 
 int main() 
 {
-  test16();
-  return 0;
+  return !test16();
 }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]