From cfd7c9a5bdcc7f7c414b408d19c8a39a2917eec8 Mon Sep 17 00:00:00 2001 From: Ian Lynagh Date: Wed, 11 Feb 2009 18:29:06 +0000 Subject: Don't put inline'd functions in HsUnix.h; fixes trac #2969 If they are included into a C file which also has certain symbols defined, then the behaviour of the HsUnix.h functions can change (e.g. lstat can become the 32bit, rather than 64bit, version). --- cbits/HsUnix.c | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- include/HsUnix.h | 98 +++++++++++-------------------------------------- 2 files changed, 127 insertions(+), 80 deletions(-) diff --git a/cbits/HsUnix.c b/cbits/HsUnix.c index 5b62798..c56b804 100644 --- a/cbits/HsUnix.c +++ b/cbits/HsUnix.c @@ -1,5 +1,4 @@ /* ----------------------------------------------------------------------------- - * $Id: HsUnix.c,v 1.1 2002/09/12 16:38:22 simonmar Exp $ * * (c) The University of Glasgow 2002 * @@ -7,7 +6,111 @@ * * ---------------------------------------------------------------------------*/ -// Out-of-line versions of all the inline functions from HsUnix.h -#define INLINE /* nothing */ #include "HsUnix.h" +int __hsunix_wifexited (int stat) { return WIFEXITED(stat); } +int __hsunix_wexitstatus (int stat) { return WEXITSTATUS(stat); } +int __hsunix_wifsignaled (int stat) { return WIFSIGNALED(stat); } +int __hsunix_wtermsig (int stat) { return WTERMSIG(stat); } +int __hsunix_wifstopped (int stat) { return WIFSTOPPED(stat); } +int __hsunix_wstopsig (int stat) { return WSTOPSIG(stat); } + +#ifdef HAVE_RTLDNEXT +void *__hsunix_rtldNext (void) {return RTLD_NEXT;} +#endif + +#ifdef HAVE_RTLDDEFAULT +void *__hsunix_rtldDefault (void) {return RTLD_DEFAULT;} +#endif + +#ifdef SIGINFO +int __hsunix_SIGINFO() { return SIGINFO; } +#endif +#ifdef SIGWINCH +int __hsunix_SIGWINCH() { return SIGWINCH; } +#endif + +// lstat is a macro on some platforms, so we need a wrapper: +int __hsunix_lstat(const char *path, struct stat *buf) +{ + return lstat(path,buf); +} + +// mknod is a macro on some platforms, so we need a wrapper: +int __hsunix_mknod(const char *pathname, mode_t mode, dev_t dev) +{ + return mknod(pathname,mode,dev); +} + +#ifdef HAVE_PTSNAME +// I cannot figure out how to make the definitions of the following +// functions visible in on Linux. But these definitions +// follow the POSIX specs, and everything links and runs. + +char *__hsunix_ptsname(int fd) +{ + extern char *ptsname(int); + return ptsname(fd); +} + +int __hsunix_grantpt(int fd) +{ + extern int grantpt(int); + return grantpt(fd); +} + +int __hsunix_unlockpt(int fd) +{ + extern int unlockpt(int); + return unlockpt(fd); +} +#endif + +// push a SVR4 STREAMS module; do nothing if STREAMS not available +int __hsunix_push_module(int fd, const char *module) +{ +#if defined(I_PUSH) && !defined(__CYGWIN__) && !defined(HAVE_DEV_PTC) + return ioctl(fd, I_PUSH, module); +#else + return 0; +#endif +} + +#if !defined(__MINGW32__) +int __hscore_mkstemp(char *filetemplate) { + return (mkstemp(filetemplate)); +} +#endif + +#if !defined(__MINGW32__) && !defined(irix_HOST_OS) +int __hscore_getrlimit(int resource, struct rlimit *rlim) { + return (getrlimit(resource, rlim)); +} + +int __hscore_setrlimit(int resource, struct rlimit *rlim) { + return (setrlimit(resource, rlim)); +} +#endif + +int __hsunix_unsetenv(const char *name) +{ +#ifdef UNSETENV_RETURNS_VOID + unsetenv(name); + return 0; +#else + return unsetenv(name); +#endif +} + +/* A size that will contain many path names, but not necessarily all + * (PATH_MAX is not defined on systems with unlimited path length, + * e.g. the Hurd). + */ +HsInt __hsunix_long_path_size() { +#ifdef PATH_MAX + return PATH_MAX; +#else + return 4096; +#endif +} + diff --git a/include/HsUnix.h b/include/HsUnix.h index 5acdb74..d460698 100644 --- a/include/HsUnix.h +++ b/include/HsUnix.h @@ -93,27 +93,19 @@ extern char **environ; -#ifndef INLINE -# if defined(__GNUC__) -# define INLINE extern inline -# else -# define INLINE inline -# endif -#endif - -INLINE int __hsunix_wifexited (int stat) { return WIFEXITED(stat); } -INLINE int __hsunix_wexitstatus (int stat) { return WEXITSTATUS(stat); } -INLINE int __hsunix_wifsignaled (int stat) { return WIFSIGNALED(stat); } -INLINE int __hsunix_wtermsig (int stat) { return WTERMSIG(stat); } -INLINE int __hsunix_wifstopped (int stat) { return WIFSTOPPED(stat); } -INLINE int __hsunix_wstopsig (int stat) { return WSTOPSIG(stat); } +int __hsunix_wifexited (int stat); +int __hsunix_wexitstatus (int stat); +int __hsunix_wifsignaled (int stat); +int __hsunix_wtermsig (int stat); +int __hsunix_wifstopped (int stat); +int __hsunix_wstopsig (int stat); #ifdef HAVE_RTLDNEXT -INLINE void *__hsunix_rtldNext (void) {return RTLD_NEXT;} +void *__hsunix_rtldNext (void); #endif #ifdef HAVE_RTLDDEFAULT -INLINE void *__hsunix_rtldDefault (void) {return RTLD_DEFAULT;} +void *__hsunix_rtldDefault (void); #endif /* O_SYNC doesn't exist on Mac OS X and (at least some versions of) FreeBSD, @@ -123,94 +115,46 @@ fall back to O_FSYNC, which should be the same */ #endif #ifdef SIGINFO -INLINE int __hsunix_SIGINFO() { return SIGINFO; } +int __hsunix_SIGINFO(); #endif #ifdef SIGWINCH -INLINE int __hsunix_SIGWINCH() { return SIGWINCH; } +int __hsunix_SIGWINCH(); #endif // lstat is a macro on some platforms, so we need a wrapper: -INLINE int __hsunix_lstat(const char *path, struct stat *buf) -{ - return lstat(path,buf); -} +int __hsunix_lstat(const char *path, struct stat *buf); // lstat is a macro on some platforms, so we need a wrapper: -INLINE int __hsunix_mknod(const char *pathname, mode_t mode, dev_t dev) -{ - return mknod(pathname,mode,dev); -} +int __hsunix_mknod(const char *pathname, mode_t mode, dev_t dev); #ifdef HAVE_PTSNAME // I cannot figure out how to make the definitions of the following // functions visible in on Linux. But these definitions // follow the POSIX specs, and everything links and runs. -INLINE char *__hsunix_ptsname(int fd) -{ - extern char *ptsname(int); - return ptsname(fd); -} - -INLINE int __hsunix_grantpt(int fd) -{ - extern int grantpt(int); - return grantpt(fd); -} - -INLINE int __hsunix_unlockpt(int fd) -{ - extern int unlockpt(int); - return unlockpt(fd); -} +char *__hsunix_ptsname(int fd); +int __hsunix_grantpt(int fd); +int __hsunix_unlockpt(int fd); #endif // push a SVR4 STREAMS module; do nothing if STREAMS not available -INLINE int __hsunix_push_module(int fd, const char *module) -{ -#if defined(I_PUSH) && !defined(__CYGWIN__) && !defined(HAVE_DEV_PTC) - return ioctl(fd, I_PUSH, module); -#else - return 0; -#endif -} +int __hsunix_push_module(int fd, const char *module); #if !defined(__MINGW32__) -INLINE int __hscore_mkstemp(char *filetemplate) { - return (mkstemp(filetemplate)); -} +int __hscore_mkstemp(char *filetemplate); #endif #if !defined(__MINGW32__) && !defined(irix_HOST_OS) -INLINE int __hscore_getrlimit(int resource, struct rlimit *rlim) { - return (getrlimit(resource, rlim)); -} - -INLINE int __hscore_setrlimit(int resource, struct rlimit *rlim) { - return (setrlimit(resource, rlim)); -} +int __hscore_getrlimit(int resource, struct rlimit *rlim); +int __hscore_setrlimit(int resource, struct rlimit *rlim); #endif -INLINE int __hsunix_unsetenv(const char *name) -{ -#ifdef UNSETENV_RETURNS_VOID - unsetenv(name); - return 0; -#else - return unsetenv(name); -#endif -} +int __hsunix_unsetenv(const char *name); /* A size that will contain many path names, but not necessarily all * (PATH_MAX is not defined on systems with unlimited path length, * e.g. the Hurd). */ -INLINE HsInt __hsunix_long_path_size() { -#ifdef PATH_MAX - return PATH_MAX; -#else - return 4096; -#endif -} +HsInt __hsunix_long_path_size(); #endif -- cgit v1.2.3