From stdcxx-commits-return-304-apmail-incubator-stdcxx-commits-archive=incubator.apache.org@incubator.apache.org Mon Jan 09 19:06:01 2006 Return-Path: Delivered-To: apmail-incubator-stdcxx-commits-archive@www.apache.org Received: (qmail 53558 invoked from network); 9 Jan 2006 19:06:00 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 9 Jan 2006 19:06:00 -0000 Received: (qmail 92584 invoked by uid 500); 9 Jan 2006 19:06:00 -0000 Delivered-To: apmail-incubator-stdcxx-commits-archive@incubator.apache.org Received: (qmail 92566 invoked by uid 500); 9 Jan 2006 19:06:00 -0000 Mailing-List: contact stdcxx-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: stdcxx-dev@incubator.apache.org Delivered-To: mailing list stdcxx-commits@incubator.apache.org Received: (qmail 92552 invoked by uid 500); 9 Jan 2006 19:05:59 -0000 Delivered-To: apmail-incubator-stdcxx-cvs@incubator.apache.org Received: (qmail 92549 invoked by uid 99); 9 Jan 2006 19:05:59 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 09 Jan 2006 11:05:59 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Mon, 09 Jan 2006 11:05:59 -0800 Received: (qmail 53436 invoked by uid 65534); 9 Jan 2006 19:05:39 -0000 Message-ID: <20060109190539.53435.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r367363 - /incubator/stdcxx/trunk/src/memattr.cpp Date: Mon, 09 Jan 2006 19:05:38 -0000 To: stdcxx-cvs@incubator.apache.org From: sebor@apache.org X-Mailer: svnmailer-1.0.5 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: sebor Date: Mon Jan 9 11:05:32 2006 New Revision: 367363 URL: http://svn.apache.org/viewcvs?rev=367363&view=rev Log: 2006-01-09 Martin Sebor STDCXX-106 * memattr.cpp (__rw_memattr): Used getpagesize(3) instead of sysconf(3) when neither _SC_PAGE_SIZE or _SC_PAGESIZE is #defined in (e.g., on BSD UNIX). Restored errno to its original value if it got clobbered by one of the called functions. Modified: incubator/stdcxx/trunk/src/memattr.cpp Modified: incubator/stdcxx/trunk/src/memattr.cpp URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/src/memattr.cpp?rev=367363&r1=367362&r2=367363&view=diff ============================================================================== --- incubator/stdcxx/trunk/src/memattr.cpp (original) +++ incubator/stdcxx/trunk/src/memattr.cpp Mon Jan 9 11:05:32 2006 @@ -35,15 +35,21 @@ // working around SunOS bug #568 # include # endif -# include // for sysconf -# include // for mincore +# include // for getpagesize(), sysconf() +# include // for mincore() # include # ifndef _SC_PAGE_SIZE - // fall back on the alternative -# define _SC_PAGE_SIZE _SC_PAGESIZE -# endif - + // fall back on the alternative macro if it exists, + // or use getpagesize() otherwise +# ifndef _SC_PAGESIZE +# define GETPAGESIZE() getpagesize () +# else +# define GETPAGESIZE() sysconf (_SC_PAGESIZE) +# endif +# else +# define GETPAGESIZE() sysconf (_SC_PAGE_SIZE) +# endif // _SC_PAGE_SIZE #else # include // for everything (ugh) #endif // _WIN{32,64} @@ -83,8 +89,10 @@ #if !defined (_WIN32) && !defined (_WIN64) + const int errno_save = errno; + // determine the system page size in bytes - static const _RWSTD_SIZE_T pgsz = size_t (sysconf (_SC_PAGE_SIZE)); + static const _RWSTD_SIZE_T pgsz = size_t (GETPAGESIZE ()); // compute the address of the beginning of the page // to which the address `addr' belongs @@ -108,16 +116,28 @@ // on Solaris use mincore() instead of madvise() since // the latter is unreliable - if (-1 == mincore (next, 1, &dummy) && ENOMEM == errno) - return next == page ? -1 : DIST (next, addr); + if (-1 == mincore (next, 1, &dummy)) { + + const int err = errno; + errno = errno_save; + + if (ENOMEM == err) + return next == page ? -1 : DIST (next, addr); + } # elif !defined (_RWSTD_NO_MADVISE) // on HP-UX, Linux, use madvise() as opposed to mincore() // since the latter fails for address ranges that aren't // backed by a file (such as stack variables) - if (-1 == madvise (next, 1, MADV_WILLNEED) && ENOMEM == errno) - return next == page ? -1 : DIST (next, addr); + if (-1 == madvise (next, 1, MADV_WILLNEED)) { + + const int err = errno; + errno = errno_save; + + if (ENOMEM == err) + return next == page ? -1 : DIST (next, addr); + } # endif