bug-gnulib
[Top][All Lists]
Advanced

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

Re: Patch for the getpagesize module


From: Martin Lambers
Subject: Re: Patch for the getpagesize module
Date: Wed, 28 Nov 2007 20:53:05 +0100
User-agent: Mutt/1.5.13 (2006-08-11)

On Tue, 27. Nov 2007, 18:38:13 +0100, Bruno Haible wrote:
> Martin Lambers wrote:
> > If a macro is used instead, should its definition go into
> > lib/unistd.h.in directly, or should it stay in a separate
> > lib/getpagesize.h, which is then included in lib/unistd.h.in?
> 
> It should go into lib/unistd.in.h. You can use blank lines or other kinds
> of separator lines or headlines in comments, to separate it from the other
> contents of unistd.in.h.
> 
> > I also was not sure if it's okay to include additional system headers
> > like <OS.h> in the middle of gnulibs unistd.h.
> 
> Good point; this brings a certain amount of namespace pollution.
> Nevertheless, I'd try first to continue using a macro, and include
> <OS.h> from unistd.h, and switch to a function instead only when we
> see that it's needed.

Thank you very much for your comments!

I attached an updated patch. It now only does the following:

- Do not provide getpagesize.h; modify gnulibs unistd.h instead.
- Provide a getpagesize declaration if the system does not provide one
  (needed on MinGW).

I removed the untested MSVC implementation from the previous patch. In
this patch, the original getpagesize macro logic was moved from
getpagesize.h to unistd.in.h unaltered.

I tested this on GNU/Linux and MinGW. I don't have access to a system
that lacks getpagesize().

Martin


diff -uNr gnulib.orig/lib/getpagesize.h gnulib/lib/getpagesize.h
--- gnulib.orig/lib/getpagesize.h       2007-11-26 16:56:13.000000000 +0100
+++ gnulib/lib/getpagesize.h    1970-01-01 01:00:00.000000000 +0100
@@ -1,66 +0,0 @@
-/* Emulate getpagesize on systems that lack it.
-   Copyright (C) 1999, 2000, 2004, 2005 Free Software Foundation, Inc.
-
-   This program 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 3 of the License, or
-   (at your option) any later version.
-
-   This program 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 program.  If not, see <http://www.gnu.org/licenses/>.  */
-
-#ifndef HAVE_GETPAGESIZE
-
-#include <unistd.h>
-
-#if !defined getpagesize && defined _SC_PAGESIZE
-# if ! (defined __VMS && __VMS_VER < 70000000)
-#  define getpagesize() sysconf (_SC_PAGESIZE)
-# endif
-#endif
-
-#if !defined getpagesize && defined __VMS
-# ifdef __ALPHA
-#  define getpagesize() 8192
-# else
-#  define getpagesize() 512
-# endif
-#endif
-
-/* This is for BeOS.  */
-#if !defined getpagesize && HAVE_OS_H
-# include <OS.h>
-# if defined B_PAGE_SIZE
-#  define getpagesize() B_PAGE_SIZE
-# endif
-#endif
-
-/* This is for AmigaOS4.0.  */
-#if !defined getpagesize && defined __amigaos4__
-# define getpagesize() 2048
-#endif
-
-#if !defined getpagesize && HAVE_SYS_PARAM_H
-# include <sys/param.h>
-# ifdef EXEC_PAGESIZE
-#  define getpagesize() EXEC_PAGESIZE
-# else
-#  ifdef NBPG
-#   ifndef CLSIZE
-#    define CLSIZE 1
-#   endif
-#   define getpagesize() (NBPG * CLSIZE)
-#  else
-#   ifdef NBPC
-#    define getpagesize() NBPC
-#   endif
-#  endif
-# endif
-#endif
-
-#endif /* not HAVE_GETPAGESIZE */
diff -uNr gnulib.orig/lib/unistd.in.h gnulib/lib/unistd.in.h
--- gnulib.orig/lib/unistd.in.h 2007-11-26 16:56:14.000000000 +0100
+++ gnulib/lib/unistd.in.h      2007-11-28 10:09:42.000000000 +0100
@@ -180,6 +180,61 @@
 #endif
 
 
+#if @GNULIB_GETPAGESIZE@
+# if address@hidden@ && @HAVE_GETPAGESIZE@
+/* Returns the memory page size.  */
+extern int getpagesize (void);
+# elif address@hidden@
+#  if !defined getpagesize && defined _SC_PAGESIZE
+#   if ! (defined __VMS && __VMS_VER < 70000000)
+#    define getpagesize() sysconf (_SC_PAGESIZE)
+#   endif
+#  endif
+#  if !defined getpagesize && defined __VMS
+#   ifdef __ALPHA
+#    define getpagesize() 8192
+#   else
+#    define getpagesize() 512
+#   endif
+#  endif
+/* This is for BeOS.  */
+#  if !defined getpagesize && HAVE_OS_H
+#   include <OS.h>
+#   if defined B_PAGE_SIZE
+#    define getpagesize() B_PAGE_SIZE
+#   endif
+#  endif
+/* This is for AmigaOS4.0.  */
+#  if !defined getpagesize && defined __amigaos4__
+#   define getpagesize() 2048
+#  endif
+#  if !defined getpagesize && HAVE_SYS_PARAM_H
+#   include <sys/param.h>
+#   ifdef EXEC_PAGESIZE
+#    define getpagesize() EXEC_PAGESIZE
+#   else
+#    ifdef NBPG
+#     ifndef CLSIZE
+#      define CLSIZE 1
+#     endif
+#     define getpagesize() (NBPG * CLSIZE)
+#    else
+#     ifdef NBPC
+#      define getpagesize() NBPC
+#     endif
+#    endif
+#   endif
+#  endif
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef getpagesize
+# define getpagesize() \
+    (GL_LINK_WARNING ("getpagesize is unportable - " \
+                      "use gnulib module getpagesize for portability"), \
+     getpagesize ())
+#endif
+
+
 #if @GNULIB_LCHOWN@
 # if @REPLACE_LCHOWN@
 /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
diff -uNr gnulib.orig/m4/getpagesize.m4 gnulib/m4/getpagesize.m4
--- gnulib.orig/m4/getpagesize.m4       2007-11-26 16:56:14.000000000 +0100
+++ gnulib/m4/getpagesize.m4    2007-11-28 09:57:06.000000000 +0100
@@ -1,13 +1,26 @@
-# getpagesize.m4 serial 6
-dnl Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
+# getpagesize.m4 serial 7
+dnl Copyright (C) 2002, 2004, 2005, 2007 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
 dnl with or without modifications, as long as this notice is preserved.
 
-AC_DEFUN([gl_GETPAGESIZE],
+AC_DEFUN([gl_FUNC_GETPAGESIZE],
 [
-  dnl Prerequisites of lib/getpagesize.h.
-  AC_CHECK_HEADERS_ONCE(sys/param.h)
-  AC_CHECK_HEADERS(OS.h)
-  AC_CHECK_FUNCS(getpagesize)
+  AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
+  AC_CHECK_DECLS_ONCE([getpagesize])
+  if test $ac_cv_have_decl_getpagesize = no; then
+    HAVE_DECL_GETPAGESIZE=0
+  fi
+  AC_CHECK_FUNCS_ONCE([getpagesize])
+  if test $ac_cv_func_getpagesize = no; then
+    HAVE_GETPAGESIZE=0
+    gl_PREREQ_GETPAGESIZE
+  fi
+])
+
+# Prerequisites of getpagesize in <unistd.h>
+AC_DEFUN([gl_PREREQ_GETPAGESIZE],
+[
+  AC_CHECK_HEADERS_ONCE([sys/param.h])
+  AC_CHECK_HEADERS([OS.h])
 ])
diff -uNr gnulib.orig/m4/unistd_h.m4 gnulib/m4/unistd_h.m4
--- gnulib.orig/m4/unistd_h.m4  2007-11-26 16:56:14.000000000 +0100
+++ gnulib/m4/unistd_h.m4       2007-11-28 09:58:33.000000000 +0100
@@ -1,4 +1,4 @@
-# unistd_h.m4 serial 9
+# unistd_h.m4 serial 10
 dnl Copyright (C) 2006-2007 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -32,25 +32,28 @@
 
 AC_DEFUN([gl_UNISTD_H_DEFAULTS],
 [
-  GNULIB_CHOWN=0;         AC_SUBST([GNULIB_CHOWN])
-  GNULIB_DUP2=0;          AC_SUBST([GNULIB_DUP2])
-  GNULIB_FCHDIR=0;        AC_SUBST([GNULIB_FCHDIR])
-  GNULIB_FTRUNCATE=0;     AC_SUBST([GNULIB_FTRUNCATE])
-  GNULIB_GETCWD=0;        AC_SUBST([GNULIB_GETCWD])
-  GNULIB_GETLOGIN_R=0;    AC_SUBST([GNULIB_GETLOGIN_R])
-  GNULIB_LCHOWN=0;        AC_SUBST([GNULIB_LCHOWN])
-  GNULIB_LSEEK=0;         AC_SUBST([GNULIB_LSEEK])
-  GNULIB_READLINK=0;      AC_SUBST([GNULIB_READLINK])
-  GNULIB_SLEEP=0;         AC_SUBST([GNULIB_SLEEP])
+  GNULIB_CHOWN=0;          AC_SUBST([GNULIB_CHOWN])
+  GNULIB_DUP2=0;           AC_SUBST([GNULIB_DUP2])
+  GNULIB_FCHDIR=0;         AC_SUBST([GNULIB_FCHDIR])
+  GNULIB_FTRUNCATE=0;      AC_SUBST([GNULIB_FTRUNCATE])
+  GNULIB_GETCWD=0;         AC_SUBST([GNULIB_GETCWD])
+  GNULIB_GETLOGIN_R=0;     AC_SUBST([GNULIB_GETLOGIN_R])
+  GNULIB_GETPAGESIZE=0;    AC_SUBST([GNULIB_GETPAGESIZE])
+  GNULIB_LCHOWN=0;         AC_SUBST([GNULIB_LCHOWN])
+  GNULIB_LSEEK=0;          AC_SUBST([GNULIB_LSEEK])
+  GNULIB_READLINK=0;       AC_SUBST([GNULIB_READLINK])
+  GNULIB_SLEEP=0;          AC_SUBST([GNULIB_SLEEP])
   dnl Assume proper GNU behavior unless another module says otherwise.
-  HAVE_DUP2=1;            AC_SUBST([HAVE_DUP2])
-  HAVE_FTRUNCATE=1;       AC_SUBST([HAVE_FTRUNCATE])
-  HAVE_READLINK=1;        AC_SUBST([HAVE_READLINK])
-  HAVE_SLEEP=1;           AC_SUBST([HAVE_SLEEP])
-  HAVE_DECL_GETLOGIN_R=1; AC_SUBST([HAVE_DECL_GETLOGIN_R])
-  REPLACE_CHOWN=0;        AC_SUBST([REPLACE_CHOWN])
-  REPLACE_FCHDIR=0;       AC_SUBST([REPLACE_FCHDIR])
-  REPLACE_GETCWD=0;       AC_SUBST([REPLACE_GETCWD])
-  REPLACE_LCHOWN=0;       AC_SUBST([REPLACE_LCHOWN])
-  REPLACE_LSEEK=0;        AC_SUBST([REPLACE_LSEEK])
+  HAVE_DUP2=1;             AC_SUBST([HAVE_DUP2])
+  HAVE_FTRUNCATE=1;        AC_SUBST([HAVE_FTRUNCATE])
+  HAVE_GETPAGESIZE=1;      AC_SUBST([HAVE_GETPAGESIZE])
+  HAVE_READLINK=1;         AC_SUBST([HAVE_READLINK])
+  HAVE_SLEEP=1;            AC_SUBST([HAVE_SLEEP])
+  HAVE_DECL_GETLOGIN_R=1;  AC_SUBST([HAVE_DECL_GETLOGIN_R])
+  HAVE_DECL_GETPAGESIZE=1; AC_SUBST([HAVE_DECL_GETPAGESIZE])
+  REPLACE_CHOWN=0;         AC_SUBST([REPLACE_CHOWN])
+  REPLACE_FCHDIR=0;        AC_SUBST([REPLACE_FCHDIR])
+  REPLACE_GETCWD=0;        AC_SUBST([REPLACE_GETCWD])
+  REPLACE_LCHOWN=0;        AC_SUBST([REPLACE_LCHOWN])
+  REPLACE_LSEEK=0;         AC_SUBST([REPLACE_LSEEK])
 ])
diff -uNr gnulib.orig/modules/getpagesize gnulib/modules/getpagesize
--- gnulib.orig/modules/getpagesize     2007-11-26 16:56:14.000000000 +0100
+++ gnulib/modules/getpagesize  2007-11-28 09:55:05.000000000 +0100
@@ -2,18 +2,19 @@
 getpagesize() function: Return memory page size.
 
 Files:
-lib/getpagesize.h
 m4/getpagesize.m4
 
 Depends-on:
+unistd
 
 configure.ac:
-gl_GETPAGESIZE
+gl_FUNC_GETPAGESIZE
+gl_UNISTD_MODULE_INDICATOR([getpagesize])
 
 Makefile.am:
 
 Include:
-"getpagesize.h"
+<unistd.h>
 
 License:
 LGPL
diff -uNr gnulib.orig/modules/unistd gnulib/modules/unistd
--- gnulib.orig/modules/unistd  2007-11-26 16:56:14.000000000 +0100
+++ gnulib/modules/unistd       2007-11-28 09:59:38.000000000 +0100
@@ -29,15 +29,18 @@
              -e 's|@''GNULIB_FTRUNCATE''@|$(GNULIB_FTRUNCATE)|g' \
              -e 's|@''GNULIB_GETCWD''@|$(GNULIB_GETCWD)|g' \
              -e 's|@''GNULIB_GETLOGIN_R''@|$(GNULIB_GETLOGIN_R)|g' \
+             -e 's|@''GNULIB_GETPAGESIZE''@|$(GNULIB_GETPAGESIZE)|g' \
              -e 's|@''GNULIB_LCHOWN''@|$(GNULIB_LCHOWN)|g' \
              -e 's|@''GNULIB_LSEEK''@|$(GNULIB_LSEEK)|g' \
              -e 's|@''GNULIB_READLINK''@|$(GNULIB_READLINK)|g' \
              -e 's|@''GNULIB_SLEEP''@|$(GNULIB_SLEEP)|g' \
              -e 's|@''HAVE_DUP2''@|$(HAVE_DUP2)|g' \
              -e 's|@''HAVE_FTRUNCATE''@|$(HAVE_FTRUNCATE)|g' \
+             -e 's|@''HAVE_GETPAGESIZE''@|$(HAVE_GETPAGESIZE)|g' \
              -e 's|@''HAVE_READLINK''@|$(HAVE_READLINK)|g' \
              -e 's|@''HAVE_SLEEP''@|$(HAVE_SLEEP)|g' \
              -e 's|@''HAVE_DECL_GETLOGIN_R''@|$(HAVE_DECL_GETLOGIN_R)|g' \
+             -e 's|@''HAVE_DECL_GETPAGESIZE''@|$(HAVE_DECL_GETPAGESIZE)|g' \
              -e 's|@''REPLACE_CHOWN''@|$(REPLACE_CHOWN)|g' \
              -e 's|@''REPLACE_FCHDIR''@|$(REPLACE_FCHDIR)|g' \
              -e 's|@''REPLACE_GETCWD''@|$(REPLACE_GETCWD)|g' \




reply via email to

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