From 91e8b8180d5a21ab034044953e0571ecd1f8a154 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Sun, 23 Jun 2013 23:51:44 +0200 Subject: [PATCH 1/3] Check for correct macro, code uses S_ISDIR(). --- Modules/_io/fileio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c index 8c1fabe360c..2d0239e50bb 100644 --- a/Modules/_io/fileio.c +++ b/Modules/_io/fileio.c @@ -171,7 +171,7 @@ fileio_new(PyTypeObject *type, PyObject *args, PyObject *kwds) static int dircheck(fileio* self, PyObject *nameobj) { -#if defined(HAVE_FSTAT) && defined(S_IFDIR) && defined(EISDIR) +#if defined(HAVE_FSTAT) && defined(S_ISDIR) && defined(EISDIR) struct stat buf; if (self->fd < 0) return 0; From 99d6135a157f6626fddd5d61007d363b3a14990d Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Sun, 23 Jun 2013 23:56:05 +0200 Subject: [PATCH 2/3] Define S_IFMT and S_IFLNK in pyport.h so posixmodule.c can use named constants instead of arbitrary looking numbers. --- Include/pyport.h | 15 ++++++++------- Modules/posixmodule.c | 4 ++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Include/pyport.h b/Include/pyport.h index 4b9c238b9f3..f16cce9c496 100644 --- a/Include/pyport.h +++ b/Include/pyport.h @@ -393,9 +393,15 @@ typedef size_t Py_uhash_t; #include #endif -#if defined(PYCC_VACPP) +#ifndef S_IFMT /* VisualAge C/C++ Failed to Define MountType Field in sys/stat.h */ -#define S_IFMT (S_IFDIR|S_IFCHR|S_IFREG) +#define S_IFMT 0170000 +#endif + +#ifndef S_IFLNK +/* Windows doesn't define S_IFLNK but posixmodule.c maps + * IO_REPARSE_TAG_SYMLINK to S_IFLNK */ +# define S_IFLNK 0120000 #endif #ifndef S_ISREG @@ -410,11 +416,6 @@ typedef size_t Py_uhash_t; #define S_ISCHR(x) (((x) & S_IFMT) == S_IFCHR) #endif -#ifndef S_ISBLK -#define S_ISBLK(x) (((x) & S_IFMT) == S_IFBLK) -#endif - - #ifdef __cplusplus /* Move this down here since some C++ #include's don't like to be included inside an extern "C" */ diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 738bf0a4725..baad29918b8 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -1405,9 +1405,9 @@ attribute_data_to_stat(BY_HANDLE_FILE_INFORMATION *info, ULONG reparse_tag, stru result->st_ino = (((__int64)info->nFileIndexHigh)<<32) + info->nFileIndexLow; if (reparse_tag == IO_REPARSE_TAG_SYMLINK) { /* first clear the S_IFMT bits */ - result->st_mode ^= (result->st_mode & 0170000); + result->st_mode ^= (result->st_mode & S_IFMT); /* now set the bits that make this a symlink */ - result->st_mode |= 0120000; + result->st_mode |= S_IFLNK; } return 0; From 5b2f18411b49b27ce2f36e567b0096f6e50de562 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Mon, 24 Jun 2013 00:13:14 +0200 Subject: [PATCH 3/3] Issue #11016: Don't define macros and constants that are already set by pyport.h --- Modules/_stat.c | 36 +++++------------------------------- 1 file changed, 5 insertions(+), 31 deletions(-) diff --git a/Modules/_stat.c b/Modules/_stat.c index eafd726c3ab..a301fa8840c 100644 --- a/Modules/_stat.c +++ b/Modules/_stat.c @@ -39,35 +39,18 @@ typedef unsigned short mode_t; * * Only the names are defined by POSIX but not their value. All common file * types seems to have the same numeric value on all platforms, though. + * + * pyport.h guarantees S_IFMT, S_IFDIR, S_IFCHR, S_IFREG and S_IFLNK */ -#ifndef S_IFMT -# define S_IFMT 0170000 -#endif - -#ifndef S_IFDIR -# define S_IFDIR 0040000 -#endif - -#ifndef S_IFCHR -# define S_IFCHR 0020000 -#endif #ifndef S_IFBLK # define S_IFBLK 0060000 #endif -#ifndef S_IFREG -# define S_IFREG 0100000 -#endif - #ifndef S_IFIFO # define S_IFIFO 0010000 #endif -#ifndef S_IFLNK -# define S_IFLNK 0120000 -#endif - #ifndef S_IFSOCK # define S_IFSOCK 0140000 #endif @@ -85,23 +68,14 @@ typedef unsigned short mode_t; #endif -/* S_ISXXX() */ -#ifndef S_ISDIR -# define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) -#endif - -#ifndef S_ISCHR -# define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR) -#endif +/* S_ISXXX() + * pyport.h defines S_ISDIR(), S_ISREG() and S_ISCHR() + */ #ifndef S_ISBLK # define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK) #endif -#ifndef S_ISREG -# define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG) -#endif - #ifndef S_ISFIFO # define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO) #endif