bug-guile
[Top][All Lists]
Advanced

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

CVS-060720 compilation failure on Mac OS X 10.4, patch (dirfd)


From: Claes Wallin
Subject: CVS-060720 compilation failure on Mac OS X 10.4, patch (dirfd)
Date: Thu, 20 Jul 2006 16:09:35 +0200
User-agent: Thunderbird 1.5.0.4 (Macintosh/20060516)

When trying to compile CVS-060720 on Mac OS X 10.4, compilation fails
with conflicting defines, because configure doesn't recognize the dirfd
macro, it merely looks for a function in the library.

Using gnulib dirfd, the problem disappears.

This patch is tested on Mac OS X 10.4 and Solaris 10. The Solaris 10
patch I submitted earlier today is also needed, since Mac OS X has the
same problems with Linux-specific pthread_*_np functions.

Both platforms now compile (with -O2) and pass all tests except
regexp.tests.

   /c
2006-07-20  Claes Wallin  <address@hidden>

        On Mac OS X 10.4 dirfd is a macro, not a function. This confuces 
AC_CHECK_FUNCS.
        Use gl_Func_DIRFD from gnulib instead, which does a more thorough check.

        * configure.in:
          Replace AC_CHECK_FUNCS([dirfd]) with gl_FUNC_DIRFD.

        * guile-config/dirfd.m4:
        * libguile/dirfd.c:
        * libguile/dirfd.h:
          Imports from gnulib providing gl_FUNC_DIRFD and associated code.

        * libguile/filesys.c:
          Replace '#define dirfd ...' with '#include "dirfd.h"'

        * test-suite/tests/dirfd.test:
          Since dirfd is used by readdir on platforms that have it, this test
          does an opendir and two consecutive readdirs, expecting "." and "..".
          Not sure if this works on non-posix platforms.
=== added file 'guile-config/dirfd.m4'
--- guile-config/dirfd.m4       1970-01-01 00:00:00 +0000
+++ guile-config/dirfd.m4       2006-07-20 04:16:34 +0000
@@ -0,0 +1,76 @@
+#serial 13   -*- Autoconf -*-
+
+dnl Find out how to get the file descriptor associated with an open DIR*.
+
+# Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 Free Software
+# Foundation, Inc.
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+dnl From Jim Meyering
+
+AC_DEFUN([gl_FUNC_DIRFD],
+[
+  AC_LIBSOURCES([dirfd.c, dirfd.h])
+
+  dnl Work around a bug of AC_EGREP_CPP in autoconf-2.57.
+  AC_REQUIRE([AC_PROG_CPP])
+  AC_REQUIRE([AC_PROG_EGREP])
+  AC_CHECK_FUNCS(dirfd)
+  AC_CHECK_DECLS([dirfd], , ,
+    [#include <sys/types.h>
+     #include <dirent.h>])
+
+  AC_CACHE_CHECK([whether dirfd is a macro],
+    gl_cv_func_dirfd_macro,
+    [AC_EGREP_CPP([dirent_header_defines_dirfd], [
+#include <sys/types.h>
+#include <dirent.h>
+#ifdef dirfd
+ dirent_header_defines_dirfd
+#endif],
+       gl_cv_func_dirfd_macro=yes,
+       gl_cv_func_dirfd_macro=no)])
+
+  # Use the replacement only if we have no function, macro,
+  # or declaration with that name.
+  if test $ac_cv_func_dirfd,$ac_cv_have_decl_dirfd,$gl_cv_func_dirfd_macro \
+      = no,no,no; then
+    AC_REPLACE_FUNCS([dirfd])
+    AC_CACHE_CHECK(
+             [how to get the file descriptor associated with an open DIR*],
+                  gl_cv_sys_dir_fd_member_name,
+      [
+       dirfd_save_CFLAGS=$CFLAGS
+       for ac_expr in d_fd dd_fd; do
+
+         CFLAGS="$CFLAGS -DDIR_FD_MEMBER_NAME=$ac_expr"
+         AC_TRY_COMPILE(
+           [#include <sys/types.h>
+            #include <dirent.h>],
+           [DIR *dir_p = opendir("."); (void) dir_p->DIR_FD_MEMBER_NAME;],
+           dir_fd_found=yes
+         )
+         CFLAGS=$dirfd_save_CFLAGS
+         test "$dir_fd_found" = yes && break
+       done
+       test "$dir_fd_found" = yes || ac_expr=no_such_member
+
+       gl_cv_sys_dir_fd_member_name=$ac_expr
+      ]
+    )
+    if test $gl_cv_sys_dir_fd_member_name != no_such_member; then
+      AC_DEFINE_UNQUOTED(DIR_FD_MEMBER_NAME,
+       $gl_cv_sys_dir_fd_member_name,
+       [the name of the file descriptor member of DIR])
+    fi
+    AH_VERBATIM(DIR_TO_FD,
+               [#ifdef DIR_FD_MEMBER_NAME
+# define DIR_TO_FD(Dir_p) ((Dir_p)->DIR_FD_MEMBER_NAME)
+#else
+# define DIR_TO_FD(Dir_p) -1
+#endif
+])
+  fi
+])

=== added file 'libguile/dirfd.c'
--- libguile/dirfd.c    1970-01-01 00:00:00 +0000
+++ libguile/dirfd.c    2006-07-20 04:19:05 +0000
@@ -0,0 +1,30 @@
+/* dirfd.c -- return the file descriptor associated with an open DIR*
+   Copyright (C) 2001 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 2, 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, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+/* Written by Jim Meyering. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "dirfd.h"
+
+int
+dirfd (DIR const *dir_p)
+{
+  return DIR_TO_FD (dir_p);
+}

=== added file 'libguile/dirfd.h'
--- libguile/dirfd.h    1970-01-01 00:00:00 +0000
+++ libguile/dirfd.h    2006-07-20 04:16:34 +0000
@@ -0,0 +1,29 @@
+/* Declare dirfd, if necessary.
+   Copyright (C) 2001, 2002, 2006 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 2, 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, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+   Written by Jim Meyering.  */
+
+#include <sys/types.h>
+
+#include <dirent.h>
+
+#ifndef HAVE_DECL_DIRFD
+"this configure-time declaration test was not run"
+#endif
+#if !HAVE_DECL_DIRFD && !defined dirfd
+int dirfd (DIR const *);
+#endif

=== added file 'test-suite/tests/dirfd.test'
--- test-suite/tests/dirfd.test 1970-01-01 00:00:00 +0000
+++ test-suite/tests/dirfd.test 2006-07-20 05:22:11 +0000
@@ -0,0 +1,29 @@
+;;;; dirfd.test --- test suite for Guile's dir functions    -*- scheme -*-
+;;;;  Claes Wallin  <address@hidden>
+;;;;
+;;;;   Copyright (C) 2000, 2006 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 2, 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 software; see the file COPYING.  If not, write to
+;;;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;;;; Boston, MA 02110-1301 USA
+
+(use-modules (test-suite lib))
+
+(with-test-prefix "basic dir handling"
+
+  (with-test-prefix "readdir"
+
+    (let ((d (opendir ".")))
+      (pass-if (equal? "." (readdir d)))
+      (pass-if (equal? ".." (readdir d))))))

=== modified file 'configure.in'
--- configure.in        2006-07-20 01:41:06 +0000
+++ configure.in        2006-07-20 04:16:34 +0000
@@ -879,7 +879,8 @@
 #   dirfd - mainly BSD derived, not in older systems
 #   sincos - GLIBC extension
 #
-AC_CHECK_FUNCS(asinh acosh atanh copysign dirfd finite sincos trunc)
+AC_CHECK_FUNCS(asinh acosh atanh copysign finite sincos trunc)
+gl_FUNC_DIRFD
 
 # C99 specifies isinf and isnan as macros.
 # HP-UX provides only macros, no functions.

=== modified file 'libguile/filesys.c'
--- libguile/filesys.c  2006-07-20 03:01:09 +0000
+++ libguile/filesys.c  2006-07-20 04:16:34 +0000
@@ -204,11 +204,8 @@
 # define fchmod(fd, mode) (-1)
 #endif /* __MINGW32__ */
 
-/* This definition is for Solaris 10, it's probably not right elsewhere, but
-   that's ok, it shouldn't be used elsewhere.  */
-#if ! HAVE_DIRFD
-#define dirfd(dirstream) (dirstream->dd_fd)
-#endif
+/* When all else fails, get dirfd from gnulib */
+#include "dirfd.h"
 
 
 


reply via email to

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