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]

[Patch] Fix libstdc++/14775


Hi,

the below is what I have prepared and tested on x86/x86_64 linux.

Most of it is straightforward except, perhaps:

1- GLIBCXX_CHECK_SETRLIMIT is not only about memory limits,
but about setting resource limits, in general, now is more
obvious. I renamed the correspoding _GLIBCXX_MEM_LIMITS to
_GLIBCXX_RES_LIMITS.
2- I haven't questioned our practice of not checking the return
value of setrlimit. Interestingly, since in the test we are
only doing a /seek/, a large file is never actually created
and setrlimit is not strictly necessary, luckily. I'm saying
luckily, because some systems (my own ;) come with an HARD
limit (rlim_max) on FSIZE which cannot be raised by a normal
user: things would be much more difficult if we were to test
actually /writing/ a large file...


Will wait one/two days for comments.

Paolo.

//////////////
2004-03-31  Paolo Carlini  <pcarlini@suse.de>

	PR libstdc++/14775
	* acconfig.h: Rename _GLIBCXX_MEM_LIMITS to _GLIBCXX_RES_LIMITS.
	* acinclude.m4 (GLIBCXX_CHECK_SETRLIMIT): Call
	GLIBCXX_CHECK_SETRLIMIT_ancilliary for FSIZE too, adjust define
	to _GLIBCXX_RES_LIMITS.
	(GLIBCXX_CHECK_SETRLIMIT_ancilliary): Rename HAVE_MEMLIMIT_* to
	HAVE_LIMIT_*.
	* testsuite/testsuite_hooks.h: Declare set_file_limit.
	* testsuite/testsuite_hooks.cc: Define it, using getrlimit
	and setrlimit(RLIMIT_FSIZE).
	* testsuite/27_io/fpos/14775.cc: New.
	* config.h.in: Regenerate.
	* configure: Likewise.
diff -urN libstdc++-v3-orig/acconfig.h libstdc++-v3/acconfig.h
--- libstdc++-v3-orig/acconfig.h	2004-03-02 19:29:56.000000000 +0100
+++ libstdc++-v3/acconfig.h	2004-03-31 16:56:20.000000000 +0200
@@ -25,8 +25,8 @@
 // Define if code specialized for wchar_t should be used.
 #undef _GLIBCXX_USE_WCHAR_T
 
-// Define if using setrlimit to limit memory usage during 'make check'.
-#undef _GLIBCXX_MEM_LIMITS
+// Define if using setrlimit to set resource limits during 'make check'.
+#undef _GLIBCXX_RES_LIMITS
 
 // Define to use concept checking code from the boost libraries.
 #undef _GLIBCXX_CONCEPT_CHECKS
diff -urN libstdc++-v3-orig/acinclude.m4 libstdc++-v3/acinclude.m4
--- libstdc++-v3-orig/acinclude.m4	2004-03-21 12:18:31.000000000 +0100
+++ libstdc++-v3/acinclude.m4	2004-03-31 17:47:35.000000000 +0200
@@ -454,8 +454,8 @@
 dnl Used only in testsuite_hooks.h.  Called from GLIBCXX_CONFIGURE_TESTSUITE.
 dnl
 dnl Defines:
-dnl  _GLIBCXX_MEM_LIMITS if we can set artificial limits on memory
-dnl  various HAVE_MEMLIMIT_* for individual limit names
+dnl  _GLIBCXX_RES_LIMITS if we can set artificial resource limits 
+dnl  various HAVE_LIMIT_* for individual limit names
 dnl
 AC_DEFUN([GLIBCXX_CHECK_SETRLIMIT_ancilliary], [
   AC_TRY_COMPILE(
@@ -465,7 +465,7 @@
     ],
     [ int f = RLIMIT_$1 ; ],
     [glibcxx_mresult=1], [glibcxx_mresult=0])
-  AC_DEFINE_UNQUOTED(HAVE_MEMLIMIT_$1, $glibcxx_mresult,
+  AC_DEFINE_UNQUOTED(HAVE_LIMIT_$1, $glibcxx_mresult,
                      [Only used in build directory testsuite_hooks.h.])
 ])
 
@@ -482,6 +482,7 @@
     GLIBCXX_CHECK_SETRLIMIT_ancilliary(RSS)
     GLIBCXX_CHECK_SETRLIMIT_ancilliary(VMEM)
     GLIBCXX_CHECK_SETRLIMIT_ancilliary(AS)
+    GLIBCXX_CHECK_SETRLIMIT_ancilliary(FSIZE)
 
     # Check for rlimit, setrlimit.
     AC_CACHE_VAL(ac_setrlimit, [
@@ -496,14 +497,14 @@
     ])
   fi
 
-  AC_MSG_CHECKING([for testsuite memory limit support])
+  AC_MSG_CHECKING([for testsuite resource limits support])
   if test $setrlimit_have_headers = yes && test $ac_setrlimit = yes; then
-    ac_mem_limits=yes
-    AC_DEFINE(_GLIBCXX_MEM_LIMITS)
+    ac_res_limits=yes
+    AC_DEFINE(_GLIBCXX_RES_LIMITS)
   else
-    ac_mem_limits=no
+    ac_res_limits=no
   fi
-  AC_MSG_RESULT($ac_mem_limits)
+  AC_MSG_RESULT($ac_res_limits)
 ])
 
 
@@ -634,7 +635,7 @@
 dnl
 AC_DEFUN([GLIBCXX_CONFIGURE_TESTSUITE], [
   if $GLIBCXX_IS_NATIVE && test $is_hosted = yes; then
-    # Do checks for memory limit functions.
+    # Do checks for resource limit functions.
     GLIBCXX_CHECK_SETRLIMIT
 
     # Look for setenv, so that extended locale tests can be performed.
diff -urN libstdc++-v3-orig/testsuite/27_io/fpos/14775.cc libstdc++-v3/testsuite/27_io/fpos/14775.cc
--- libstdc++-v3-orig/testsuite/27_io/fpos/14775.cc	1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/27_io/fpos/14775.cc	2004-03-31 18:01:33.000000000 +0200
@@ -0,0 +1,55 @@
+// 2004-03-31  Paolo Carlini  <pcarlini@suse.de>
+
+// Copyright (C) 2004 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
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// 27.4.3 fpos
+
+#include <fstream>
+#include <testsuite_hooks.h>
+
+#define TWO_GB 2147483648UL
+
+// Basic test for LFS support.
+void test01()
+{
+#ifdef _GLIBCXX_USE_LFS
+  using namespace std;
+  bool test __attribute__((unused)) = true;
+
+  typedef filebuf::pos_type 	pos_type;
+  typedef filebuf::off_type 	off_type;
+
+  __gnu_test::set_file_limit(TWO_GB + 200);
+
+  basic_filebuf<char> fb;
+  fb.open("14775_tmp", ios_base::out | ios_base::in | ios_base::trunc);
+
+  pos_type ret = fb.pubseekoff(TWO_GB + 100, ios_base::beg);
+  VERIFY( ret != pos_type(off_type(-1)) );
+
+  fb.close();
+#endif
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
+
diff -urN libstdc++-v3-orig/testsuite/testsuite_hooks.cc libstdc++-v3/testsuite/testsuite_hooks.cc
--- libstdc++-v3-orig/testsuite/testsuite_hooks.cc	2004-02-21 21:34:38.000000000 +0100
+++ libstdc++-v3/testsuite/testsuite_hooks.cc	2004-03-31 18:16:03.000000000 +0200
@@ -30,7 +30,7 @@
 
 #include <testsuite_hooks.h>
 
-#ifdef _GLIBCXX_MEM_LIMITS
+#ifdef _GLIBCXX_RES_LIMITS
 #include <unistd.h>
 #include <sys/time.h>
 #include <sys/resource.h>
@@ -44,7 +44,7 @@
 
 namespace __gnu_test
 {
-#ifdef _GLIBCXX_MEM_LIMITS
+#ifdef _GLIBCXX_RES_LIMITS
   void 
   set_memory_limits(float size)
   {
@@ -53,21 +53,21 @@
     __typeof__ (r.rlim_cur) limit = (__typeof__ (r.rlim_cur))(size * 1048576);
 
     // Heap size, seems to be common.
-#if _GLIBCXX_HAVE_MEMLIMIT_DATA
+#if _GLIBCXX_HAVE_LIMIT_DATA
     getrlimit(RLIMIT_DATA, &r);
     r.rlim_cur = limit;
     setrlimit(RLIMIT_DATA, &r);
 #endif
 
     // Resident set size.
-#if _GLIBCXX_HAVE_MEMLIMIT_RSS
+#if _GLIBCXX_HAVE_LIMIT_RSS
     getrlimit(RLIMIT_RSS, &r);
     r.rlim_cur = limit;
     setrlimit(RLIMIT_RSS, &r);
 #endif
 
     // Mapped memory (brk + mmap).
-#if _GLIBCXX_HAVE_MEMLIMIT_VMEM
+#if _GLIBCXX_HAVE_LIMIT_VMEM
     getrlimit(RLIMIT_VMEM, &r);
     r.rlim_cur = limit;
     setrlimit(RLIMIT_VMEM, &r);
@@ -77,7 +77,7 @@
     // On HP-UX 11.23, a trivial C++ program that sets RLIMIT_AS to
     // anything less than 128MB cannot "malloc" even 1K of memory.
     // Therefore, we skip RLIMIT_AS on HP-UX.
-#if _GLIBCXX_HAVE_MEMLIMIT_AS && !defined(__hpux__)
+#if _GLIBCXX_HAVE_LIMIT_AS && !defined(__hpux__)
     getrlimit(RLIMIT_AS, &r);
     r.rlim_cur = limit;
     setrlimit(RLIMIT_AS, &r);
@@ -89,6 +89,25 @@
   set_memory_limits(float) { }
 #endif 
 
+#ifdef _GLIBCXX_RES_LIMITS
+  void 
+  set_file_limit(unsigned long size)
+  {
+#if _GLIBCXX_HAVE_LIMIT_FSIZE
+    struct rlimit r;
+    // Cater to the absence of rlim_t.
+    __typeof__ (r.rlim_cur) limit = (__typeof__ (r.rlim_cur))(size);
+
+    getrlimit(RLIMIT_FSIZE, &r);
+    r.rlim_cur = limit;
+    setrlimit(RLIMIT_FSIZE, &r);
+#endif
+  }
+
+#else
+  void
+  set_file_limit(unsigned long) { }
+#endif 
 
   void 
   verify_demangle(const char* mangled, const char* wanted)
diff -urN libstdc++-v3-orig/testsuite/testsuite_hooks.h libstdc++-v3/testsuite/testsuite_hooks.h
--- libstdc++-v3-orig/testsuite/testsuite_hooks.h	2004-03-06 10:00:14.000000000 +0100
+++ libstdc++-v3/testsuite/testsuite_hooks.h	2004-03-31 17:15:24.000000000 +0200
@@ -39,7 +39,7 @@
 //   set_memory_limits() uses setrlimit() to restrict dynamic memory
 //   allocation.  We provide a default memory limit if none is passed by the
 //   calling application.  The argument to set_memory_limits() is the
-//   limit in megabytes (a floating-point number).  If _GLIBCXX_MEM_LIMITS is
+//   limit in megabytes (a floating-point number).  If _GLIBCXX_RES_LIMITS is
 //   not #defined before including this header, then no limiting is attempted.
 //
 // 3)  counter
@@ -86,7 +86,7 @@
   // from c++config.h
 
   // Set memory limits if possible, if not set to 0.
-#ifndef _GLIBCXX_MEM_LIMITS
+#ifndef _GLIBCXX_RES_LIMITS
 #  define MEMLIMIT_MB 0
 #else
 # ifndef MEMLIMIT_MB
@@ -96,12 +96,13 @@
   extern void
   set_memory_limits(float __size = MEMLIMIT_MB);
 
+  extern void
+  set_file_limit(unsigned long __size);
 
   // Check mangled name demangles (using __cxa_demangle) as expected.
   void
   verify_demangle(const char* mangled, const char* wanted);
 
-
   // Simple callback structure for variable numbers of tests (all with
   // same signature).  Assume all unit tests are of the signature
   // void test01(); 

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