[前][次][番号順一覧][スレッド一覧]

ruby-changes:12853

From: matz <ko1@a...>
Date: Thu, 20 Aug 2009 01:10:23 +0900 (JST)
Subject: [ruby-changes:12853] Ruby:r24585 (trunk): * dir.c (DEFINE_STRUCT_DIRENT): use union to allocate sufficient

matz	2009-08-20 01:10:06 +0900 (Thu, 20 Aug 2009)

  New Revision: 24585

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=24585

  Log:
    * dir.c (DEFINE_STRUCT_DIRENT): use union to allocate sufficient
      memory space for Solaris.  a patch from Naohisa GOTO
      <ngoto at gen-info.osaka-u.ac.jp> in [ruby-dev:39132].
      [ruby-dev:39062]
    * configure.in (SIZEOF_STRUCT_DIRENT_TOO_SMALL): Solaris dirent
      check.

  Modified files:
    trunk/ChangeLog
    trunk/configure.in
    trunk/dir.c

Index: configure.in
===================================================================
--- configure.in	(revision 24584)
+++ configure.in	(revision 24585)
@@ -750,6 +750,10 @@
 esac
 
 case "$target_os" in
+when(solaris*)
+		AC_DEFINE(SIZEOF_STRUCT_DIRENT_TOO_SMALL, 1)
+		LIBS="-lm $LIBS"
+		;;
 when(nextstep*)	;;
 when(openstep*)	;;
 when(rhapsody*)	;;
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 24584)
+++ ChangeLog	(revision 24585)
@@ -1,3 +1,13 @@
+Thu Aug 20 01:06:48 2009  Yukihiro Matsumoto  <matz@r...>
+
+	* dir.c (DEFINE_STRUCT_DIRENT): use union to allocate sufficient
+	  memory space for Solaris.  a patch from Naohisa GOTO
+	  <ngoto at gen-info.osaka-u.ac.jp> in [ruby-dev:39132].
+	  [ruby-dev:39062]
+
+	* configure.in (SIZEOF_STRUCT_DIRENT_TOO_SMALL): Solaris dirent
+	  check.
+
 Wed Aug 19 11:32:43 2009  Nobuyoshi Nakada  <nobu@r...>
 
 	* enc/unicode.c (CodeRanges): initialized statically.
Index: dir.c
===================================================================
--- dir.c	(revision 24584)
+++ dir.c	(revision 24585)
@@ -491,6 +491,39 @@
 # define IF_HAVE_READDIR_R(something) /* nothing */
 #endif
 
+#if defined SIZEOF_STRUCT_DIRENT_TOO_SMALL
+# include <limits.h>
+# define NAME_MAX_FOR_STRUCT_DIRENT 255
+# if defined NAME_MAX
+#  if NAME_MAX_FOR_STRUCT_DIRENT < NAME_MAX
+#   undef  NAME_MAX_FOR_STRUCT_DIRENT
+#   define NAME_MAX_FOR_STRUCT_DIRENT NAME_MAX
+#  endif
+# endif
+# if defined _POSIX_NAME_MAX
+#  if NAME_MAX_FOR_STRUCT_DIRENT < _POSIX_NAME_MAX
+#   undef  NAME_MAX_FOR_STRUCT_DIRENT
+#   define NAME_MAX_FOR_STRUCT_DIRENT _POSIX_NAME_MAX
+#  endif
+# endif
+# if defined _XOPEN_NAME_MAX
+#  if NAME_MAX_FOR_STRUCT_DIRENT < _XOPEN_NAME_MAX
+#   undef  NAME_MAX_FOR_STRUCT_DIRENT
+#   define NAME_MAX_FOR_STRUCT_DIRENT _XOPEN_NAME_MAX
+#  endif
+# endif
+# define DEFINE_STRUCT_DIRENT \
+  union { \
+    struct dirent dirent; \
+    char dummy[offsetof(struct dirent, d_name) + \
+	       NAME_MAX_FOR_STRUCT_DIRENT + 1]; \
+  }
+# define STRUCT_DIRENT(entry) ((entry).dirent)
+#else
+# define DEFINE_STRUCT_DIRENT struct dirent
+# define STRUCT_DIRENT(entry) (entry)
+#endif
+
 /*
  *  call-seq:
  *     dir.read => string or nil
@@ -508,11 +541,11 @@
 {
     struct dir_data *dirp;
     struct dirent *dp;
-    IF_HAVE_READDIR_R(struct dirent entry);
+    IF_HAVE_READDIR_R(DEFINE_STRUCT_DIRENT entry);
 
     GetDIR(dir, dirp);
     errno = 0;
-    if (READDIR(dirp->dir, dirp->enc, &entry, dp)) {
+    if (READDIR(dirp->dir, dirp->enc, &STRUCT_DIRENT(entry), dp)) {
 	return rb_external_str_new_with_enc(dp->d_name, NAMLEN(dp), dirp->enc);
     }
     else if (errno == 0) {	/* end of stream */
@@ -546,12 +579,12 @@
 {
     struct dir_data *dirp;
     struct dirent *dp;
-    IF_HAVE_READDIR_R(struct dirent entry);
+    IF_HAVE_READDIR_R(DEFINE_STRUCT_DIRENT entry);
 
     RETURN_ENUMERATOR(dir, 0, 0);
     GetDIR(dir, dirp);
     rewinddir(dirp->dir);
-    while (READDIR(dirp->dir, dirp->enc, &entry, dp)) {
+    while (READDIR(dirp->dir, dirp->enc, &STRUCT_DIRENT(entry), dp)) {
 	rb_yield(rb_external_str_new_with_enc(dp->d_name, NAMLEN(dp), dirp->enc));
 	if (dirp->dir == NULL) dir_closed();
     }
@@ -1270,11 +1303,11 @@
     if (magical || recursive) {
 	struct dirent *dp;
 	DIR *dirp;
-	IF_HAVE_READDIR_R(struct dirent entry);
+	IF_HAVE_READDIR_R(DEFINE_STRUCT_DIRENT entry);
 	dirp = do_opendir(*path ? path : ".", flags);
 	if (dirp == NULL) return 0;
 
-	while (READDIR(dirp, enc, &entry, dp)) {
+	while (READDIR(dirp, enc, &STRUCT_DIRENT(entry), dp)) {
 	    char *buf = join_path(path, dirsep, dp->d_name);
 	    enum answer new_isdir = UNKNOWN;
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]