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

ruby-changes:71311

From: Yuta <ko1@a...>
Date: Wed, 2 Mar 2022 12:51:05 +0900 (JST)
Subject: [ruby-changes:71311] 0c90ca4dd0 (master): dir.c: use self-made IFTODT in rb_pathtype_t if available

https://git.ruby-lang.org/ruby.git/commit/?id=0c90ca4dd0

From 0c90ca4dd0abbd28d7bb34b9241d93995ab9cfb7 Mon Sep 17 00:00:00 2001
From: Yuta Saito <kateinoigakukun@g...>
Date: Fri, 25 Feb 2022 11:08:31 +0000
Subject: dir.c: use self-made IFTODT in rb_pathtype_t if available

dir.c defines IFTODT if the system doesn't have it. The macro is used
when comparing with rb_pathtype_t's cases. rb_pathtype_t's cases are
defined by DT_XXX macro if they are available, or defined using IFTODT.
Most POSIX-compatible platforms have both IFTODT and DT_XXX and most of
other platforms like MinGW have neither of them. On those platforms,
DT_XXX-oriented rb_pathtype_t is always compared with values converted
by system's IFTODT, and emulated-IFTODT-oriented rb_pathtype_t is always
compared with values converted by emulated-IFTODT.

However, when IFTODT is *not defined* and DT_XXX is *defined*, like
on wasi-libc, DT_XXX-oriented rb_pathtype_t was compared with values
converted by emulated-IFTODT, and they are not guaranteed to be
compatible.

This patch fixes such a situation by using emulated-IFTODT to define
rb_pathtype_t when either IFTODT or DT_XXX is not available.
---
 dir.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/dir.c b/dir.c
index 76c108a4a9..8c6d6fea56 100644
--- a/dir.c
+++ b/dir.c
@@ -187,12 +187,18 @@ has_nonascii(const char *ptr, size_t len) https://github.com/ruby/ruby/blob/trunk/dir.c#L187
 # define IF_NORMALIZE_UTF8PATH(something) /* nothing */
 #endif
 
-#ifndef IFTODT
+#if defined(IFTODT) && defined(DT_UNKNOWN)
+# define EMULATE_IFTODT 0
+#else
+# define EMULATE_IFTODT 1
+#endif
+
+#if EMULATE_IFTODT
 # define IFTODT(m)	(((m) & S_IFMT) / ((~S_IFMT & (S_IFMT-1)) + 1))
 #endif
 
 typedef enum {
-#ifdef DT_UNKNOWN
+#if !EMULATE_IFTODT
     path_exist     = DT_UNKNOWN,
     path_directory = DT_DIR,
     path_regular   = DT_REG,
-- 
cgit v1.2.1


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

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