[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gnulib] valloc()?

From: Derek Price
Subject: Re: [bug-gnulib] valloc()?
Date: Thu, 03 Mar 2005 16:22:45 -0500
User-agent: Mozilla Thunderbird 1.0 (Windows/20041206)

Bruno Haible wrote:

Derek Price wrote:

I've attached a patch to fix a few more nits

Committed, with small wording tweaks in the comments.


   - Note in the header that pagealign_alloc sets errno on failure.

But it doesn't do so if malloc() fails on non-POSIX systems (like mingw
or so). I think one should set errno = ENOMEM if malloc() fails.

How about the attached patch?

I had two further thoughts on the naming of mmap-anon.m4.  First, in my
original decision to name it mmap.m4, I did take into consideration that
there might be other mmap.m4 implementations but, ideally, I would hope
that their requirements could be merged into this mmap(-anon).m4, at the
least for simplicity's sake.

I don't have this hope: The requirements of different programs regarding
mmap are so different that, if all tests were merged into a common mmap.m4
file, some people would say "this test is insane - it disables mmap on
SVR4 [or Linux 1.2 or HP-UX or ...] although it is perfectly sane".
SVR4 had problems with PRIVATE READ-WRITE mappings of files.
Linux 1.2 didn't support MAP_SHARED on files.
HP-UX doesn't support mapping files at fixed addresses in most cases.

Okay, this makes sense.

Second, technically what we are currently
calling gl_FUNC_MMAP_ANON calls AC_FUNC_MMAP, so it also verifies that
private, fixed maps to files work as well, not just anonymous maps.

Yes, this is one of the problems with AC_FUNC_MMAP. But fortunately we
can ignore it because nowadays most systems have a working mmap(), therefore
not many people will complain "it disables mmap() on my system".

Ok.  If it becomes an issue, CVS could currently get by with a call to
AC_CHECK_FUNC([mmap]) here, assuming that there are not any systems that
have mmaps which break for readonly, private, non-fixed maps.  Of
course, I've been meaning to move to writable mmaps soon, but that
addition could be made with a separate call to AC_FUNC_MMAP.


Index: lib/pagealign_alloc.c
RCS file: /cvsroot/gnulib/gnulib/lib/pagealign_alloc.c,v
retrieving revision 1.4
diff -u -p -r1.4 pagealign_alloc.c
--- lib/pagealign_alloc.c       3 Mar 2005 20:38:38 -0000       1.4
+++ lib/pagealign_alloc.c       3 Mar 2005 21:13:29 -0000
@@ -147,9 +147,16 @@ pagealign_alloc (size_t size)
   size_t pagesize = getpagesize ();
-  void *unaligned_ptr = malloc (size + pagesize - 1);
+  void *unaligned_ptr;
+  errno = 0;
+  unaligned_ptr = malloc (size + pagesize - 1);
   if (unaligned_ptr == NULL)
-    return NULL;
+    {
+      /* Failed malloc on some non-posix systems (e.g. mingw) fail to set
+         errno.  */
+      if (!errno) errno = ENOMEM;
+      return NULL;
+    }
   ret = (char *) unaligned_ptr
         + ((- (unsigned long) unaligned_ptr) & (pagesize - 1));
   new_memnode (ret, unaligned_ptr);

Attachment: signature.asc
Description: OpenPGP digital signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]