From d0288f61d325f0fca40f7b1284e05378c849a42e Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Mon, 23 Aug 2021 09:59:26 +0000 Subject: Code formatting --- unix/tclUnixPort.h | 440 ++++++++++++++++++++++++++++++++--------------------- win/tclWinPort.h | 6 +- 2 files changed, 270 insertions(+), 176 deletions(-) diff --git a/unix/tclUnixPort.h b/unix/tclUnixPort.h index 0e1bce8..fc0acef 100644 --- a/unix/tclUnixPort.h +++ b/unix/tclUnixPort.h @@ -1,23 +1,22 @@ /* * tclUnixPort.h -- * - * This header file handles porting issues that occur because - * of differences between systems. It reads in UNIX-related - * header files and sets up UNIX-related macros for Tcl's UNIX - * core. It should be the only file that contains #ifdefs to - * handle different flavors of UNIX. This file sets up the - * union of all UNIX-related things needed by any of the Tcl - * core files. This file depends on configuration #defines such - * as NO_DIRENT_H that are set up by the "configure" script. + * This header file handles porting issues that occur because of + * differences between systems. It reads in UNIX-related header files and + * sets up UNIX-related macros for Tcl's UNIX core. It should be the only + * file that contains #ifdefs to handle different flavors of UNIX. This + * file sets up the union of all UNIX-related things needed by any of the + * Tcl core files. This file depends on configuration #defines such as + * NO_DIRENT_H that are set up by the "configure" script. * - * Much of the material in this file was originally contributed - * by Karl Lehenbauer, Mark Diekhans and Peter da Silva. + * Much of the material in this file was originally contributed by Karl + * Lehenbauer, Mark Diekhans and Peter da Silva. * * Copyright (c) 1991-1994 The Regents of the University of California. * Copyright (c) 1994-1997 Sun Microsystems, Inc. * - * See the file "license.terms" for information on usage and redistribution - * of this file, and for a DISCLAIMER OF ALL WARRANTIES. + * See the file "license.terms" for information on usage and redistribution of + * this file, and for a DISCLAIMER OF ALL WARRANTIES. */ #ifndef _TCLUNIXPORT @@ -87,21 +86,31 @@ typedef off_t Tcl_SeekOffset; #endif #ifdef __CYGWIN__ - +#ifdef __cplusplus +extern "C" { +#endif /* Make some symbols available without including */ # define DWORD unsigned int # define CP_UTF8 65001 # define GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS 0x00000004 # define HANDLE void * # define HINSTANCE void * +# define HMODULE void * +# define MAX_PATH 260 # define SOCKET unsigned int # define WSAEWOULDBLOCK 10035 - __declspec(dllimport) extern __stdcall int GetModuleHandleExW(unsigned int, const char *, void *); - __declspec(dllimport) extern __stdcall int GetModuleFileNameW(void *, const char *, int); - __declspec(dllimport) extern __stdcall int WideCharToMultiByte(int, int, const char *, int, - const char *, int, const char *, const char *); - +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wignored-attributes" +#endif + __declspec(dllimport) extern __stdcall int GetModuleHandleExW(unsigned int, const void *, void *); + __declspec(dllimport) extern __stdcall int GetModuleFileNameW(void *, const void *, int); + __declspec(dllimport) extern __stdcall int WideCharToMultiByte(int, int, const void *, int, + char *, int, const char *, void *); __declspec(dllimport) extern int cygwin_conv_path(int, const void *, void *, int); +#ifdef __clang__ +#pragma clang diagnostic pop +#endif /* On Cygwin, the environment is imported from the Cygwin DLL. */ #ifndef __x86_64__ # define environ __cygwin_environ @@ -111,12 +120,18 @@ typedef off_t Tcl_SeekOffset; extern int TclOSstat(const char *name, void *statBuf); extern int TclOSlstat(const char *name, void *statBuf); #elif defined(HAVE_STRUCT_STAT64) && !defined(__APPLE__) -# define TclOSstat stat64 -# define TclOSlstat lstat64 +# define TclOSstat(name, buf) stat64(name, (struct stat64 *)buf) +# define TclOSlstat(name,buf) lstat64(name, (struct stat64 *)buf) #else -# define TclOSstat stat -# define TclOSlstat lstat +# define TclOSstat(name, buf) stat(name, (struct stat *)buf) +# define TclOSlstat(name, buf) lstat(name, (struct stat *)buf) #endif + +/* + *--------------------------------------------------------------------------- + * Miscellaneous includes that might be missing. + *--------------------------------------------------------------------------- + */ #include #ifdef HAVE_SYS_SELECT_H @@ -127,7 +142,7 @@ typedef off_t Tcl_SeekOffset; # include # include #else -#if HAVE_SYS_TIME_H +#ifdef HAVE_SYS_TIME_H # include #else # include @@ -136,7 +151,7 @@ typedef off_t Tcl_SeekOffset; #ifndef NO_SYS_WAIT_H # include #endif -#if HAVE_INTTYPES_H +#ifdef HAVE_INTTYPES_H # include #endif #ifdef NO_LIMITS_H @@ -144,7 +159,7 @@ typedef off_t Tcl_SeekOffset; #else # include #endif -#if HAVE_STDINT_H +#ifdef HAVE_STDINT_H # include #endif #ifdef HAVE_UNISTD_H @@ -156,11 +171,14 @@ typedef off_t Tcl_SeekOffset; extern int TclUnixSetBlockingMode(int fd, int mode); #include - + /* - * Socket support stuff: This likely needs more work to parameterize for - * each system. + *--------------------------------------------------------------------------- + * Socket support stuff: This likely needs more work to parameterize for each + * system. + *--------------------------------------------------------------------------- */ + #include /* struct sockaddr, SOCK_STREAM, ... */ #ifndef NO_UNAME # include /* uname system call. */ @@ -168,11 +186,13 @@ extern int TclUnixSetBlockingMode(int fd, int mode); #include /* struct in_addr, struct sockaddr_in */ #include /* inet_ntoa() */ #include /* gethostbyname() */ - + /* - * Some platforms (e.g. SunOS) don't define FLT_MAX and FLT_MIN, so we - * look for an alternative definition. If no other alternative is available - * we use a reasonable guess. + *--------------------------------------------------------------------------- + * Some platforms (e.g. SunOS) don't define FLT_MAX and FLT_MIN, so we look + * for an alternative definition. If no other alternative is available we use + * a reasonable guess. + *--------------------------------------------------------------------------- */ #ifndef NO_FLOAT_H @@ -185,74 +205,84 @@ extern int TclUnixSetBlockingMode(int fd, int mode); #ifndef FLT_MAX # ifdef MAXFLOAT -# define FLT_MAX MAXFLOAT +# define FLT_MAX MAXFLOAT # else -# define FLT_MAX 3.402823466E+38F +# define FLT_MAX 3.402823466E+38F # endif #endif #ifndef FLT_MIN # ifdef MINFLOAT -# define FLT_MIN MINFLOAT +# define FLT_MIN MINFLOAT # else -# define FLT_MIN 1.175494351E-38F +# define FLT_MIN 1.175494351E-38F # endif #endif - + /* + *--------------------------------------------------------------------------- * NeXT doesn't define O_NONBLOCK, so #define it here if necessary. + *--------------------------------------------------------------------------- */ #ifndef O_NONBLOCK # define O_NONBLOCK 0x80 #endif - + /* - * The type of the status returned by wait varies from UNIX system - * to UNIX system. The macro below defines it: + *--------------------------------------------------------------------------- + * The type of the status returned by wait varies from UNIX system to UNIX + * system. The macro below defines it: + *--------------------------------------------------------------------------- */ #ifdef _AIX -# define WAIT_STATUS_TYPE pid_t +# define WAIT_STATUS_TYPE pid_t #else #ifndef NO_UNION_WAIT -# define WAIT_STATUS_TYPE union wait +# define WAIT_STATUS_TYPE union wait #else -# define WAIT_STATUS_TYPE int +# define WAIT_STATUS_TYPE int #endif #endif - + /* - * Supply definitions for macros to query wait status, if not already - * defined in header files above. + *--------------------------------------------------------------------------- + * Supply definitions for macros to query wait status, if not already defined + * in header files above. + *--------------------------------------------------------------------------- */ #ifndef WIFEXITED -# define WIFEXITED(stat) (((*((int *) &(stat))) & 0xFF) == 0) +# define WIFEXITED(stat) (((*((int *) &(stat))) & 0xFF) == 0) #endif #ifndef WEXITSTATUS -# define WEXITSTATUS(stat) (((*((int *) &(stat))) >> 8) & 0xFF) +# define WEXITSTATUS(stat) (((*((int *) &(stat))) >> 8) & 0xFF) #endif #ifndef WIFSIGNALED -# define WIFSIGNALED(stat) (((*((int *) &(stat)))) && ((*((int *) &(stat))) == ((*((int *) &(stat))) & 0xFF))) +# define WIFSIGNALED(stat) \ + (((*((int *) &(stat)))) && ((*((int *) &(stat))) \ + == ((*((int *) &(stat))) & 0x00FF))) #endif #ifndef WTERMSIG -# define WTERMSIG(stat) ((*((int *) &(stat))) & 0x7F) +# define WTERMSIG(stat) ((*((int *) &(stat))) & 0x7F) #endif #ifndef WIFSTOPPED -# define WIFSTOPPED(stat) (((*((int *) &(stat))) & 0xFF) == 0177) +# define WIFSTOPPED(stat) (((*((int *) &(stat))) & 0xFF) == 0177) #endif #ifndef WSTOPSIG -# define WSTOPSIG(stat) (((*((int *) &(stat))) >> 8) & 0xFF) +# define WSTOPSIG(stat) (((*((int *) &(stat))) >> 8) & 0xFF) #endif - + /* - * Define constants for waitpid() system call if they aren't defined - * by a system header file. + *--------------------------------------------------------------------------- + * Define constants for waitpid() system call if they aren't defined by a + * system header file. + *--------------------------------------------------------------------------- */ #ifndef WNOHANG @@ -261,10 +291,12 @@ extern int TclUnixSetBlockingMode(int fd, int mode); #ifndef WUNTRACED # define WUNTRACED 2 #endif - + /* - * Supply macros for seek offsets, if they're not already provided by - * an include file. + *--------------------------------------------------------------------------- + * Supply macros for seek offsets, if they're not already provided by an + * include file. + *--------------------------------------------------------------------------- */ #ifndef SEEK_SET @@ -276,10 +308,12 @@ extern int TclUnixSetBlockingMode(int fd, int mode); #ifndef SEEK_END # define SEEK_END 2 #endif - + /* - * The stuff below is needed by the "time" command. If this system has no + *--------------------------------------------------------------------------- + * The stuff below is needed by the "time" command. If this system has no * gettimeofday call, then must use times() instead. + *--------------------------------------------------------------------------- */ #ifdef NO_GETTOD @@ -287,39 +321,45 @@ extern int TclUnixSetBlockingMode(int fd, int mode); #endif #ifdef GETTOD_NOT_DECLARED -extern int gettimeofday (struct timeval *tp, +extern int gettimeofday(struct timeval *tp, struct timezone *tzp); #endif - + /* + *--------------------------------------------------------------------------- * Define access mode constants if they aren't already defined. + *--------------------------------------------------------------------------- */ #ifndef F_OK -# define F_OK 00 +# define F_OK 00 #endif #ifndef X_OK -# define X_OK 01 +# define X_OK 01 #endif #ifndef W_OK -# define W_OK 02 +# define W_OK 02 #endif #ifndef R_OK -# define R_OK 04 +# define R_OK 04 #endif - + /* - * Define FD_CLOEEXEC (the close-on-exec flag bit) if it isn't - * already defined. + *--------------------------------------------------------------------------- + * Define FD_CLOEEXEC (the close-on-exec flag bit) if it isn't already + * defined. + *--------------------------------------------------------------------------- */ #ifndef FD_CLOEXEC -# define FD_CLOEXEC 1 +# define FD_CLOEXEC 1 #endif - + /* - * On systems without symbolic links (i.e. S_IFLNK isn't defined) - * define "lstat" to use "stat" instead. + *--------------------------------------------------------------------------- + * On systems without symbolic links (i.e. S_IFLNK isn't defined) define + * "lstat" to use "stat" instead. + *--------------------------------------------------------------------------- */ #ifndef S_IFLNK @@ -328,82 +368,89 @@ extern int gettimeofday (struct timeval *tp, # define lstat64 stat64 # define TclOSlstat TclOSstat #endif - + /* - * Define macros to query file type bits, if they're not already - * defined. + *--------------------------------------------------------------------------- + * Define macros to query file type bits, if they're not already defined. + *--------------------------------------------------------------------------- */ #ifndef S_ISREG # ifdef S_IFREG -# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) +# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) # else -# define S_ISREG(m) 0 +# define S_ISREG(m) 0 # endif #endif /* !S_ISREG */ #ifndef S_ISDIR # ifdef S_IFDIR -# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) +# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) # else -# define S_ISDIR(m) 0 +# define S_ISDIR(m) 0 # endif #endif /* !S_ISDIR */ #ifndef S_ISCHR # ifdef S_IFCHR -# define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) +# define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) # else -# define S_ISCHR(m) 0 +# define S_ISCHR(m) 0 # endif #endif /* !S_ISCHR */ + #ifndef S_ISBLK # ifdef S_IFBLK -# define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) +# define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) # else -# define S_ISBLK(m) 0 +# define S_ISBLK(m) 0 # endif #endif /* !S_ISBLK */ + #ifndef S_ISFIFO # ifdef S_IFIFO -# define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) +# define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) # else -# define S_ISFIFO(m) 0 +# define S_ISFIFO(m) 0 # endif #endif /* !S_ISFIFO */ + #ifndef S_ISLNK # ifdef S_IFLNK -# define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) +# define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) # else -# define S_ISLNK(m) 0 +# define S_ISLNK(m) 0 # endif #endif /* !S_ISLNK */ + #ifndef S_ISSOCK # ifdef S_IFSOCK -# define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK) +# define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK) # else -# define S_ISSOCK(m) 0 +# define S_ISSOCK(m) 0 # endif #endif /* !S_ISSOCK */ - + /* + *--------------------------------------------------------------------------- * Make sure that MAXPATHLEN and MAXNAMLEN are defined. + *--------------------------------------------------------------------------- */ #ifndef MAXPATHLEN # ifdef PATH_MAX -# define MAXPATHLEN PATH_MAX +# define MAXPATHLEN PATH_MAX # else -# define MAXPATHLEN 2048 +# define MAXPATHLEN 2048 # endif #endif #ifndef MAXNAMLEN # ifdef NAME_MAX -# define MAXNAMLEN NAME_MAX +# define MAXNAMLEN NAME_MAX # else -# define MAXNAMLEN 255 +# define MAXNAMLEN 255 # endif #endif - + /* * Make sure that L_tmpnam is defined. */ @@ -413,88 +460,102 @@ extern int gettimeofday (struct timeval *tp, #endif /* - * The following macro defines the type of the mask arguments to - * select: + *--------------------------------------------------------------------------- + * The following macro defines the type of the mask arguments to select: + *--------------------------------------------------------------------------- */ #ifndef NO_FD_SET -# define SELECT_MASK fd_set +# define SELECT_MASK fd_set #else /* NO_FD_SET */ # ifndef _AIX - typedef long fd_mask; + typedef long fd_mask; # endif /* !AIX */ # if defined(_IBMR2) -# define SELECT_MASK void +# define SELECT_MASK void # else /* !defined(_IBMR2) */ -# define SELECT_MASK int +# define SELECT_MASK int # endif /* defined(_IBMR2) */ #endif /* !NO_FD_SET */ - + /* + *--------------------------------------------------------------------------- * Define "NBBY" (number of bits per byte) if it's not already defined. + *--------------------------------------------------------------------------- */ #ifndef NBBY -# define NBBY 8 +# define NBBY 8 #endif - + /* + *--------------------------------------------------------------------------- * The following macro defines the number of fd_masks in an fd_set: + *--------------------------------------------------------------------------- */ #ifndef FD_SETSIZE # ifdef OPEN_MAX -# define FD_SETSIZE OPEN_MAX +# define FD_SETSIZE OPEN_MAX # else -# define FD_SETSIZE 256 +# define FD_SETSIZE 256 # endif #endif /* FD_SETSIZE */ -#if !defined(howmany) -# define howmany(x, y) (((x)+((y)-1))/(y)) + +#ifndef howmany +# define howmany(x, y) (((x)+((y)-1))/(y)) #endif /* !defined(howmany) */ + #ifndef NFDBITS -# define NFDBITS NBBY*sizeof(fd_mask) +# define NFDBITS NBBY*sizeof(fd_mask) #endif /* NFDBITS */ -#define MASK_SIZE howmany(FD_SETSIZE, NFDBITS) +#define MASK_SIZE howmany(FD_SETSIZE, NFDBITS) + /* - * Not all systems declare the errno variable in errno.h. so this - * file does it explicitly. The list of system error messages also - * isn't generally declared in a header file anywhere. + *--------------------------------------------------------------------------- + * Not all systems declare the errno variable in errno.h. so this file does it + * explicitly. The list of system error messages also isn't generally declared + * in a header file anywhere. + *--------------------------------------------------------------------------- */ #ifdef NO_ERRNO extern int errno; #endif /* NO_ERRNO */ - + /* - * Not all systems declare all the errors that Tcl uses! Provide some + *--------------------------------------------------------------------------- + * Not all systems declare all the errors that Tcl uses! Provide some * work-arounds... + *--------------------------------------------------------------------------- */ #ifndef EOVERFLOW # ifdef EFBIG -# define EOVERFLOW EFBIG +# define EOVERFLOW EFBIG # else /* !EFBIG */ -# define EOVERFLOW EINVAL +# define EOVERFLOW EINVAL # endif /* EFBIG */ #endif /* EOVERFLOW */ - + /* + *--------------------------------------------------------------------------- * Variables provided by the C library: + *--------------------------------------------------------------------------- */ #if defined(__APPLE__) && defined(__DYNAMIC__) # include -# define environ (*_NSGetEnviron()) -# define USE_PUTENV 1 +# define environ (*_NSGetEnviron()) +# define USE_PUTENV 1 #else # if defined(_sgi) || defined(__sgi) -# define environ _environ +# define environ _environ # endif -extern char **environ; +extern char ** environ; #endif - + /* * There is no platform-specific panic routine for Unix in the Tcl internals. */ @@ -502,24 +563,31 @@ extern char **environ; #define TclpPanic ((Tcl_PanicProc *) NULL) /* + *--------------------------------------------------------------------------- * Darwin specifc configure overrides. + *--------------------------------------------------------------------------- */ #ifdef __APPLE__ + /* + *--------------------------------------------------------------------------- * Support for fat compiles: configure runs only once for multiple architectures + *--------------------------------------------------------------------------- */ + # if defined(__LP64__) && defined (NO_COREFOUNDATION_64) -# undef HAVE_COREFOUNDATION -# endif /* __LP64__ && NO_COREFOUNDATION_64 */ +# undef HAVE_COREFOUNDATION +# endif /* __LP64__ && NO_COREFOUNDATION_64 */ # include # ifdef __DARWIN_UNIX03 -# if __DARWIN_UNIX03 -# undef HAVE_PUTENV_THAT_COPIES -# else -# define HAVE_PUTENV_THAT_COPIES 1 -# endif +# if __DARWIN_UNIX03 +# undef HAVE_PUTENV_THAT_COPIES +# else +# define HAVE_PUTENV_THAT_COPIES 1 +# endif # endif /* __DARWIN_UNIX03 */ + /* * The termios configure test program relies on the configure script being run * from a terminal, which is not the case e.g. when configuring from Xcode. @@ -530,68 +598,83 @@ extern char **environ; # undef USE_TERMIO # undef USE_SGTTY /* + *--------------------------------------------------------------------------- * Include AvailabilityMacros.h here (when available) to ensure any symbolic * MAC_OS_X_VERSION_* constants passed on the command line are translated. + *--------------------------------------------------------------------------- */ + # ifdef HAVE_AVAILABILITYMACROS_H -# include +# include # endif + /* + *--------------------------------------------------------------------------- * Support for weak import. + *--------------------------------------------------------------------------- */ + # ifdef HAVE_WEAK_IMPORT -# if !defined(HAVE_AVAILABILITYMACROS_H) || !defined(MAC_OS_X_VERSION_MIN_REQUIRED) -# undef HAVE_WEAK_IMPORT -# else -# ifndef WEAK_IMPORT_ATTRIBUTE -# define WEAK_IMPORT_ATTRIBUTE __attribute__((weak_import)) -# endif -# endif +# if !defined(HAVE_AVAILABILITYMACROS_H) || !defined(MAC_OS_X_VERSION_MIN_REQUIRED) +# undef HAVE_WEAK_IMPORT +# else +# ifndef WEAK_IMPORT_ATTRIBUTE +# define WEAK_IMPORT_ATTRIBUTE __attribute__((weak_import)) +# endif +# endif # endif /* HAVE_WEAK_IMPORT */ + /* + *--------------------------------------------------------------------------- * Support for MAC_OS_X_VERSION_MAX_ALLOWED define from AvailabilityMacros.h: * only use API available in the indicated OS version or earlier. + *--------------------------------------------------------------------------- */ + # ifdef MAC_OS_X_VERSION_MAX_ALLOWED -# if MAC_OS_X_VERSION_MAX_ALLOWED < 1050 && defined(__LP64__) -# undef HAVE_COREFOUNDATION -# endif -# if MAC_OS_X_VERSION_MAX_ALLOWED < 1040 -# undef HAVE_OSSPINLOCKLOCK -# undef HAVE_PTHREAD_ATFORK -# undef HAVE_COPYFILE -# endif -# if MAC_OS_X_VERSION_MAX_ALLOWED < 1030 -# ifdef TCL_THREADS +# if MAC_OS_X_VERSION_MAX_ALLOWED < 1050 && defined(__LP64__) +# undef HAVE_COREFOUNDATION +# endif +# if MAC_OS_X_VERSION_MAX_ALLOWED < 1040 +# undef HAVE_OSSPINLOCKLOCK +# undef HAVE_PTHREAD_ATFORK +# undef HAVE_COPYFILE +# endif +# if MAC_OS_X_VERSION_MAX_ALLOWED < 1030 +# ifdef TCL_THREADS /* prior to 10.3, realpath is not threadsafe, c.f. bug 711232 */ -# define NO_REALPATH 1 -# endif -# undef HAVE_LANGINFO -# endif +# define NO_REALPATH 1 +# endif +# undef HAVE_LANGINFO +# endif # endif /* MAC_OS_X_VERSION_MAX_ALLOWED */ # if defined(HAVE_COREFOUNDATION) && defined(__LP64__) && \ defined(HAVE_WEAK_IMPORT) && MAC_OS_X_VERSION_MIN_REQUIRED < 1050 -# warning "Weak import of 64-bit CoreFoundation is not supported, will not run on Mac OS X < 10.5." +# warning "Weak import of 64-bit CoreFoundation is not supported, will not run on Mac OS X < 10.5." # endif + /* + *--------------------------------------------------------------------------- * At present, using vfork() instead of fork() causes execve() to fail * intermittently on Darwin x86_64. rdar://4685553 + *--------------------------------------------------------------------------- */ + # if defined(__x86_64__) && !defined(FIXED_RDAR_4685553) -# undef USE_VFORK +# undef USE_VFORK # endif /* __x86_64__ */ /* Workaround problems with vfork() when building with llvm-gcc-4.2 */ # if defined (__llvm__) && \ (__GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ > 2 || \ (__GNUC_MINOR__ == 2 && __GNUC_PATCHLEVEL__ > 0)))) -# undef USE_VFORK +# undef USE_VFORK # endif /* __llvm__ */ #endif /* __APPLE__ */ - + /* *--------------------------------------------------------------------------- * The following macros and declarations represent the interface between - * generic and unix-specific parts of Tcl. Some of the macros may override + * generic and unix-specific parts of Tcl. Some of the macros may override * functions declared in tclInt.h. *--------------------------------------------------------------------------- */ @@ -606,28 +689,33 @@ typedef int socklen_t; #else #define TCL_PLATFORM_TRANSLATION TCL_TRANSLATE_LF #endif - + /* + *--------------------------------------------------------------------------- * The following macros have trivial definitions, allowing generic code to * address platform-specific issues. + *--------------------------------------------------------------------------- */ #define TclpReleaseFile(file) /* Nothing. */ - + /* + *--------------------------------------------------------------------------- * The following defines wrap the system memory allocation routines. + *--------------------------------------------------------------------------- */ -#define TclpSysAlloc(size, isBin) malloc((size_t)size) -#define TclpSysFree(ptr) free((char*)ptr) -#define TclpSysRealloc(ptr, size) realloc((char*)ptr, (size_t)size) - +#define TclpSysAlloc(size, isBin) malloc((size_t)(size)) +#define TclpSysFree(ptr) free((char *)(ptr)) +#define TclpSysRealloc(ptr, size) realloc((char *)(ptr), (size_t)(size)) + /* - * The following macros and declaration wrap the C runtime library - * functions. + *--------------------------------------------------------------------------- + * The following macros and declaration wrap the C runtime library functions. + *--------------------------------------------------------------------------- */ -#define TclpExit exit +#define TclpExit exit #ifdef TCL_THREADS # include @@ -653,13 +741,13 @@ extern int pthread_getattr_np (pthread_t, pthread_attr_t *); # endif /* HAVE_PTHREAD_GETATTR_NP */ # endif /* HAVE_PTHREAD_ATTR_GET_NP */ #endif /* TCL_THREADS */ - + /* - * Set of MT-safe implementations of some - * known-to-be-MT-unsafe library calls. - * Instead of returning pointers to the - * static storage, those return pointers + *--------------------------------------------------------------------------- + * Set of MT-safe implementations of some known-to-be-MT-unsafe library calls. + * Instead of returning pointers to the static storage, those return pointers * to the TSD data. + *--------------------------------------------------------------------------- */ #include @@ -672,3 +760,11 @@ extern struct hostent* TclpGetHostByName(const char *name); extern struct hostent* TclpGetHostByAddr(const char *addr, int length, int type); #endif /* _TCLUNIXPORT */ + +/* + * Local Variables: + * mode: c + * c-basic-offset: 4 + * fill-column: 78 + * End: + */ diff --git a/win/tclWinPort.h b/win/tclWinPort.h index d3dbb1b..9c0a3d3 100644 --- a/win/tclWinPort.h +++ b/win/tclWinPort.h @@ -14,7 +14,6 @@ #ifndef _TCLWINPORT #define _TCLWINPORT - #if !defined(_WIN64) && !defined(__MINGW_USE_VC2005_COMPAT) /* See [Bug 3354324]: file mtime sets wrong time */ # define __MINGW_USE_VC2005_COMPAT @@ -230,7 +229,7 @@ typedef DWORD_PTR * PDWORD_PTR; #endif #ifndef WTERMSIG -# define WTERMSIG(stat) ((*((int *) &(stat))) & 0x7f) +# define WTERMSIG(stat) ((*((int *) &(stat))) & 0x7F) #endif #ifndef WIFSTOPPED @@ -238,7 +237,7 @@ typedef DWORD_PTR * PDWORD_PTR; #endif #ifndef WSTOPSIG -# define WSTOPSIG(stat) (((*((int *) &(stat))) >> 8) & 0xff) +# define WSTOPSIG(stat) (((*((int *) &(stat))) >> 8) & 0xFF) #endif /* @@ -396,7 +395,6 @@ typedef DWORD_PTR * PDWORD_PTR; # endif #endif - /* * There is no platform-specific panic routine for Windows in the Tcl internals. */ -- cgit v0.12 From 4c3b4b2a2b133094b98d27616e7728d99097a57f Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Mon, 23 Aug 2021 10:01:35 +0000 Subject: Add FALLTHRU markers, to help GCC emit less false warnings --- generic/regc_lex.c | 4 +--- generic/regcomp.c | 4 ++-- generic/tclBasic.c | 2 +- generic/tclCmdMZ.c | 1 + generic/tclDictObj.c | 1 + generic/tclInterp.c | 2 ++ generic/tclParse.c | 1 + generic/tclPathObj.c | 3 ++- generic/tclProc.c | 6 ++---- generic/tclScan.c | 11 +++++------ generic/tclStrToD.c | 14 ++++++++------ generic/tclStringObj.c | 2 ++ unix/tclUnixFile.c | 29 +++++++++++++++++++++-------- win/tclWinFile.c | 12 ++++++------ win/tclWinTest.c | 2 +- win/tclWinTime.c | 38 +++++++++++++++++++++----------------- 16 files changed, 77 insertions(+), 55 deletions(-) diff --git a/generic/regc_lex.c b/generic/regc_lex.c index 0cc62a2..992f5fd 100644 --- a/generic/regc_lex.c +++ b/generic/regc_lex.c @@ -909,9 +909,7 @@ lexescape( v->now = save; - /* - * And fall through into octal number. - */ + /* FALLTHRU */ case CHR('0'): NOTE(REG_UUNPORT); diff --git a/generic/regcomp.c b/generic/regcomp.c index fda40e0..1a3e334 100644 --- a/generic/regcomp.c +++ b/generic/regcomp.c @@ -605,7 +605,7 @@ makesearch( break; } } - + /* * We want to mark states as being in the list already by having non * NULL tmp fields, but we can't just store the old slist value in tmp @@ -922,7 +922,7 @@ parseqatom( */ NOTE(REG_UPBOTCH); - /* fallthrough into case PLAIN */ + /* FALLTHRU */ case PLAIN: onechr(v, v->nextvalue, lp, rp); okcolors(v->nfa, v->cm); diff --git a/generic/tclBasic.c b/generic/tclBasic.c index 52e0ce5..e37ef13 100644 --- a/generic/tclBasic.c +++ b/generic/tclBasic.c @@ -5586,8 +5586,8 @@ Tcl_ExprLongObj( return TCL_ERROR; } resultPtr = Tcl_NewBignumObj(&big); - /* FALLTHROUGH */ } + /* FALLTHRU */ case TCL_NUMBER_LONG: case TCL_NUMBER_WIDE: case TCL_NUMBER_BIG: diff --git a/generic/tclCmdMZ.c b/generic/tclCmdMZ.c index f6bdd3e..0629a81 100644 --- a/generic/tclCmdMZ.c +++ b/generic/tclCmdMZ.c @@ -4267,6 +4267,7 @@ Tcl_TimeRateObjCmd( */ threshold = 1; maxcnt = 0; + /* FALLTHRU */ case TCL_CONTINUE: result = TCL_OK; break; diff --git a/generic/tclDictObj.c b/generic/tclDictObj.c index 4fec2c1..bde8162 100644 --- a/generic/tclDictObj.c +++ b/generic/tclDictObj.c @@ -2772,6 +2772,7 @@ DictFilterCmd( Tcl_ResetResult(interp); Tcl_DictObjDone(&search); + /* FALLTHRU */ case TCL_CONTINUE: result = TCL_OK; break; diff --git a/generic/tclInterp.c b/generic/tclInterp.c index dbbf10a..b00df59 100644 --- a/generic/tclInterp.c +++ b/generic/tclInterp.c @@ -923,6 +923,7 @@ Tcl_InterpObjCmd( return SlaveTimeLimitCmd(interp, slaveInterp, 4, objc, objv); } } + break; case OPT_MARKTRUSTED: { Tcl_Interp *slaveInterp; @@ -2433,6 +2434,7 @@ SlaveObjCmd( return SlaveTimeLimitCmd(interp, slaveInterp, 3, objc, objv); } } + break; case OPT_MARKTRUSTED: if (objc != 2) { Tcl_WrongNumArgs(interp, 2, objv, NULL); diff --git a/generic/tclParse.c b/generic/tclParse.c index 48d86ef..9c3dbe8 100644 --- a/generic/tclParse.c +++ b/generic/tclParse.c @@ -2160,6 +2160,7 @@ Tcl_SubstObj( return NULL; case TCL_BREAK: tokensLeft = 0; /* Halt substitution */ + /* FALLTHRU */ default: Tcl_AppendObjToObj(result, Tcl_GetObjResult(interp)); } diff --git a/generic/tclPathObj.c b/generic/tclPathObj.c index d8be51a..f97c36a 100644 --- a/generic/tclPathObj.c +++ b/generic/tclPathObj.c @@ -861,7 +861,7 @@ TclJoinPath( Tcl_PathType type; char *strElt, *ptr; Tcl_Obj *driveName = NULL; - + elt = objv[i]; /* @@ -1358,6 +1358,7 @@ TclNewFSPathObj( count = 0; state = 1; } + break; case 1: /* Scanning for next dirsep */ switch (*p) { case '/': diff --git a/generic/tclProc.c b/generic/tclProc.c index 2ee2456..432ee64 100644 --- a/generic/tclProc.c +++ b/generic/tclProc.c @@ -722,7 +722,7 @@ TclGetFrame( } level = curLevel - level; } else { - /* + /* * (historical, TODO) If name does not contain a level (#0 or 1), * TclGetFrame and Tcl_UpVar2 uses current level - 1 */ @@ -1808,9 +1808,7 @@ TclObjInterpProcCore( "\" outside of a loop", NULL); result = TCL_ERROR; - /* - * Fall through to the TCL_ERROR handling code. - */ + /* FALLTHRU */ case TCL_ERROR: /* diff --git a/generic/tclScan.c b/generic/tclScan.c index 229f3fa..09dffd3 100644 --- a/generic/tclScan.c +++ b/generic/tclScan.c @@ -358,8 +358,10 @@ ValidateFormat( format += Tcl_UtfToUniChar(format, &ch); break; } + /* FALLTHRU */ case 'L': flags |= SCAN_LONGER; + /* FALLTHRU */ case 'h': format += Tcl_UtfToUniChar(format, &ch); } @@ -380,9 +382,7 @@ ValidateFormat( TCL_STATIC); goto error; } - /* - * Fall through! - */ + /* FALLTHRU */ case 'n': case 's': if (flags & (SCAN_LONGER|SCAN_BIG)) { @@ -694,11 +694,10 @@ Tcl_ScanObjCmd( format += Tcl_UtfToUniChar(format, &ch); break; } + /* FALLTHRU */ case 'L': flags |= SCAN_LONGER; - /* - * Fall through so we skip to the next character. - */ + /* FALLTHRU */ case 'h': format += Tcl_UtfToUniChar(format, &ch); } diff --git a/generic/tclStrToD.c b/generic/tclStrToD.c index 3776521..ea73e09 100644 --- a/generic/tclStrToD.c +++ b/generic/tclStrToD.c @@ -801,6 +801,7 @@ TclParseNumber( acceptState = state; acceptPoint = p; acceptLen = len; + /* FALLTHRU */ case ZERO_B: if (c == '0') { numTrailZeros++; @@ -1150,6 +1151,7 @@ TclParseNumber( #endif Tcl_Panic("TclParseNumber: bad acceptState %d parsing '%s'", acceptState, bytes); + break; case BINARY: shift = numTrailZeros; if (!significandOverflow && significandWide != 0 && @@ -1307,9 +1309,9 @@ TclParseNumber( objPtr->typePtr = &tclDoubleType; if (exponentSignum) { - /* + /* * At this point exponent>=0, so the following calculation - * cannot underflow. + * cannot underflow. */ exponent = -exponent; } @@ -1335,7 +1337,7 @@ TclParseNumber( } } - /* + /* * The desired number is now significandWide * 10**exponent * or significandBig * 10**exponent, depending on whether * the significand has overflowed a wide int. @@ -1885,7 +1887,7 @@ RefineApproximation( /* * Compute twoMv as 2*M*v, where v is the approximate value. - * This is done by bit-whacking to calculate 2**(M2+1)*significand, + * This is done by bit-whacking to calculate 2**(M2+1)*significand, * and then multiplying by 5**M5. */ @@ -1920,7 +1922,7 @@ RefineApproximation( } mp_mul_2d(&twoMd, M2+exponent+1, &twoMd); - /* + /* * Now let twoMd = twoMd - twoMv, the difference between the exact and * approximate values. */ @@ -1988,7 +1990,7 @@ RefineApproximation( } } - /* + /* * Reduce the numerator and denominator of the corrector term so that * they will fit in the floating point precision. */ diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c index d62fc72..519afce 100644 --- a/generic/tclStringObj.c +++ b/generic/tclStringObj.c @@ -2077,6 +2077,7 @@ Tcl_AppendFormatToObj( msg = "unsigned bignum format is invalid"; goto errorMsg; } + /* FALLTHRU */ case 'd': case 'o': case 'x': @@ -2651,6 +2652,7 @@ AppendPrintfToObjVA( break; case 'h': size = -1; + /* FALLTHRU */ default: p++; } diff --git a/unix/tclUnixFile.c b/unix/tclUnixFile.c index f2a6b23..5fe7238 100644 --- a/unix/tclUnixFile.c +++ b/unix/tclUnixFile.c @@ -42,9 +42,11 @@ TclpFindExecutable( Tcl_Encoding encoding; #ifdef __CYGWIN__ int length; - char buf[PATH_MAX * 2]; + wchar_t buf[PATH_MAX] = L""; char name[PATH_MAX * 3 + 1]; - GetModuleFileNameW(NULL, buf, sizeof(buf)/2); + (void)argv0; + + GetModuleFileNameW(NULL, (void *)buf, sizeof(buf)/sizeof(wchar_t)); cygwin_conv_path(3, buf, name, sizeof(name)); length = strlen(name); if ((length > 4) && !strcasecmp(name + length - 4, ".exe")) { @@ -1188,13 +1190,18 @@ TclpUtime( Tcl_Obj *pathPtr, /* File to modify */ struct utimbuf *tval) /* New modification date structure */ { - return utime(Tcl_FSGetNativePath(pathPtr), tval); + return utime((const char *)Tcl_FSGetNativePath(pathPtr), tval); } #ifdef __CYGWIN__ -int TclOSstat(const char *name, void *cygstat) { +int +TclOSstat( + const char *name, + void *cygstat) +{ struct stat buf; - Tcl_StatBuf *statBuf = cygstat; + Tcl_StatBuf *statBuf = (Tcl_StatBuf *)cygstat; int result = stat(name, &buf); + statBuf->st_mode = buf.st_mode; statBuf->st_ino = buf.st_ino; statBuf->st_dev = buf.st_dev; @@ -1208,10 +1215,16 @@ int TclOSstat(const char *name, void *cygstat) { statBuf->st_ctime = buf.st_ctime; return result; } -int TclOSlstat(const char *name, void *cygstat) { + +int +TclOSlstat( + const char *name, + void *cygstat) +{ struct stat buf; - Tcl_StatBuf *statBuf = cygstat; + Tcl_StatBuf *statBuf = (Tcl_StatBuf *)cygstat; int result = lstat(name, &buf); + statBuf->st_mode = buf.st_mode; statBuf->st_ino = buf.st_ino; statBuf->st_dev = buf.st_dev; @@ -1225,7 +1238,7 @@ int TclOSlstat(const char *name, void *cygstat) { statBuf->st_ctime = buf.st_ctime; return result; } -#endif +#endif /* CYGWIN */ /* * Local Variables: diff --git a/win/tclWinFile.c b/win/tclWinFile.c index 32c674c..d3c2e68 100644 --- a/win/tclWinFile.c +++ b/win/tclWinFile.c @@ -1467,7 +1467,7 @@ TclpGetUserHome( GetProcAddress(handle, "GetProfilesDirectoryW"); Tcl_CreateExitHandler(FreeLoadLibHandle, handle); } - + apistubs = -1; if ( (netUserGetInfoProc != NULL) && (netGetDCNameProc != NULL) && (netApiBufferFreeProc != NULL) && (getProfilesDirectoryProc != NULL) @@ -1492,9 +1492,9 @@ TclpGetUserHome( domain = Tcl_UtfFindFirst(name, '@'); if (domain == NULL) { const char *ptr; - + /* no domain - firstly check it's the current user */ - if ( (ptr = TclpGetUserName(&ds)) != NULL + if ( (ptr = TclpGetUserName(&ds)) != NULL && strcasecmp(name, ptr) == 0 ) { /* try safest and fastest way to get current user home */ @@ -1518,7 +1518,7 @@ TclpGetUserHome( wName = Tcl_UtfToUniCharDString(name, nameLen, &ds); while ((netUserGetInfoProc)(wDomain, wName, 1, (LPBYTE *) &uiPtr) != 0) { - /* + /* * user does not exists - if domain was not specified, * try again using current domain. */ @@ -1634,7 +1634,7 @@ NativeAccess( return 0; } - /* + /* * If it's not a directory (assume file), do several fast checks: */ if (!(attr & FILE_ATTRIBUTE_DIRECTORY)) { @@ -2100,7 +2100,7 @@ NativeStat( */ fileHandle = (tclWinProcs->createFileProc)(nativePath, GENERIC_READ, - FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, NULL); diff --git a/win/tclWinTest.c b/win/tclWinTest.c index 7f49b63..9088f59 100644 --- a/win/tclWinTest.c +++ b/win/tclWinTest.c @@ -671,7 +671,7 @@ TestplatformChmod( */ if (set_readOnly == acl_readOnly_found || setNamedSecurityInfoProc( - (LPSTR) nativePath, SE_FILE_OBJECT, + (LPSTR) nativePath, SE_FILE_OBJECT, DACL_SECURITY_INFORMATION /*| PROTECTED_DACL_SECURITY_INFORMATION*/, NULL, NULL, newAcl, NULL) == ERROR_SUCCESS) { res = 0; diff --git a/win/tclWinTime.c b/win/tclWinTime.c index 1204ec7..e4a6a8a 100644 --- a/win/tclWinTime.c +++ b/win/tclWinTime.c @@ -120,9 +120,10 @@ static TimeInfo timeInfo = { */ static struct { int initialized; /* 1 if initialized, 0 otherwise */ - int perfCounter; /* 1 if performance counter usable for wide clicks */ + int perfCounter; /* 1 if performance counter usable for wide + * clicks */ double microsecsScale; /* Denominator scale between clock / microsecs */ -} wideClick = {0, 0.0}; +} wideClick = {0, 0, 0.0}; /* @@ -257,7 +258,7 @@ TclpGetWideClicks(void) /* * The frequency of the performance counter is fixed at system boot and - * is consistent across all processors. Therefore, the frequency need + * is consistent across all processors. Therefore, the frequency need * only be queried upon application initialization. */ if (QueryPerformanceFrequency(&perfCounterFreq)) { @@ -268,7 +269,7 @@ TclpGetWideClicks(void) wideClick.perfCounter = 0; wideClick.microsecsScale = 1; } - + wideClick.initialized = 1; } if (wideClick.perfCounter) { @@ -289,7 +290,7 @@ TclpGetWideClicks(void) * * TclpWideClickInMicrosec -- * - * This procedure return scale to convert wide click values from the + * This procedure return scale to convert wide click values from the * TclpGetWideClicks native resolution to microsecond resolution * and back. * @@ -328,7 +329,7 @@ TclpWideClickInMicrosec(void) *---------------------------------------------------------------------- */ -Tcl_WideInt +Tcl_WideInt TclpGetMicroseconds(void) { Tcl_WideInt usecSincePosixEpoch; @@ -476,7 +477,7 @@ NativeCalc100NsTicks( LONGLONG curCounterFreq, LONGLONG curCounter ) { - return fileTimeLastCall + + return fileTimeLastCall + ((curCounter - perfCounterLastCall) * 10000000 / curCounterFreq); } @@ -493,7 +494,6 @@ NativeGetMicroseconds(void) if (!timeInfo.initialized) { TclpInitLock(); if (!timeInfo.initialized) { - timeInfo.posixEpoch.LowPart = 0xD53E8000; timeInfo.posixEpoch.HighPart = 0x019DB1DE; @@ -624,8 +624,12 @@ NativeGetMicroseconds(void) /* * If calibration cycle occurred after we get curCounter */ + if (curCounter.QuadPart <= perfCounterLastCall) { - /* Calibrated file-time is saved from posix in 100-ns ticks */ + /* + * Calibrated file-time is saved from posix in 100-ns ticks + */ + return fileTimeLastCall / 10; } @@ -1127,7 +1131,6 @@ CalibrationThread( UpdateTimeEachSecond(); } - /* lint */ return (DWORD) 0; } @@ -1158,7 +1161,8 @@ UpdateTimeEachSecond(void) /* Current value returned from * QueryPerformanceCounter. */ FILETIME curSysTime; /* Current system time. */ - static LARGE_INTEGER lastFileTime; /* File time of the previous calibration */ + static LARGE_INTEGER lastFileTime; + /* File time of the previous calibration */ LARGE_INTEGER curFileTime; /* File time at the time this callback was * scheduled. */ Tcl_WideInt estFreq; /* Estimated perf counter frequency. */ @@ -1186,7 +1190,7 @@ UpdateTimeEachSecond(void) return; } QueryPerformanceCounter(&curPerfCounter); - + lastFileTime.QuadPart = curFileTime.QuadPart; /* @@ -1254,7 +1258,7 @@ UpdateTimeEachSecond(void) /* calculate new frequency and estimate drift to the next second */ vt1 = 20000000 + curFileTime.QuadPart; driftFreq = (estFreq * 20000000 / (vt1 - vt0)); - /* + /* * Avoid too large drifts (only half of the current difference), * that allows also be more accurate (aspire to the smallest tdiff), * so then we can prolong calibration interval by tdiff < 100000 @@ -1262,13 +1266,13 @@ UpdateTimeEachSecond(void) driftFreq = timeInfo.curCounterFreq.QuadPart + (driftFreq - timeInfo.curCounterFreq.QuadPart) / 2; - /* + /* * Average between estimated, 2 current and 5 drifted frequencies, * (do the soft drifting as possible) */ estFreq = (estFreq + 2 * timeInfo.curCounterFreq.QuadPart + 5 * driftFreq) / 8; } - + /* Avoid too large discrepancy from nominal frequency */ if (estFreq > 1003*timeInfo.nominalFreq.QuadPart/1000) { estFreq = 1003*timeInfo.nominalFreq.QuadPart/1000; @@ -1277,9 +1281,9 @@ UpdateTimeEachSecond(void) estFreq = 997*timeInfo.nominalFreq.QuadPart/1000; vt0 = curFileTime.QuadPart; } else if (vt0 != curFileTime.QuadPart) { - /* + /* * Be sure the clock ticks never backwards (avoid it by negative drifting) - * just compare native time (in 100-ns) before and hereafter using + * just compare native time (in 100-ns) before and hereafter using * new calibrated values) and do a small adjustment (short time freeze) */ LARGE_INTEGER newPerfCounter; -- cgit v0.12