summaryrefslogtreecommitdiffstats
path: root/unix
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2012-08-07 20:57:08 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2012-08-07 20:57:08 (GMT)
commit0fe2d45ae44323638f143bf320c77a5cb6df2a01 (patch)
tree01529af3ee161f7c70fd8f14ba581054bd52155c /unix
parent00acd83312b7bcc144212b7bd1a47436719b0d2c (diff)
downloadtcl-0fe2d45ae44323638f143bf320c77a5cb6df2a01.zip
tcl-0fe2d45ae44323638f143bf320c77a5cb6df2a01.tar.gz
tcl-0fe2d45ae44323638f143bf320c77a5cb6df2a01.tar.bz2
Minor changes to improve style (C89 declarations, consistent indentation,
clarification of #endifs, reduction of unnecessary casts, use of array syntax for reading array elements, etc.)
Diffstat (limited to 'unix')
-rw-r--r--unix/tclLoadOSF.c14
-rw-r--r--unix/tclLoadShl.c17
-rw-r--r--unix/tclUnixFile.c51
-rw-r--r--unix/tclUnixNotfy.c175
4 files changed, 142 insertions, 115 deletions
diff --git a/unix/tclLoadOSF.c b/unix/tclLoadOSF.c
index 6515b89..6e76b55 100644
--- a/unix/tclLoadOSF.c
+++ b/unix/tclLoadOSF.c
@@ -35,12 +35,14 @@
#include "tclInt.h"
#include <sys/types.h>
#include <loader.h>
-
-/* Static functions defined within this file */
-static void* FindSymbol(Tcl_Interp* interp, Tcl_LoadHandle loadHandle,
- const char* symbol);
-static void UnloadFile(Tcl_LoadHandle handle);
+/*
+ * Static functions defined within this file.
+ */
+
+static void * FindSymbol(Tcl_Interp *interp,
+ Tcl_LoadHandle loadHandle, const char* symbol);
+static void UnloadFile(Tcl_LoadHandle handle);
/*
*----------------------------------------------------------------------
@@ -105,7 +107,7 @@ TclpDlopen(
if (lm == LDR_NULL_MODULE) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"couldn't load file \"%s\": %s",
- fileName, Tcl_PosixError(interp));
+ fileName, Tcl_PosixError(interp)));
return TCL_ERROR;
}
diff --git a/unix/tclLoadShl.c b/unix/tclLoadShl.c
index 968f232..7b80bcc 100644
--- a/unix/tclLoadShl.c
+++ b/unix/tclLoadShl.c
@@ -22,14 +22,14 @@
#endif
#include "tclInt.h"
-
-/* Static functions defined within this file */
-static void* FindSymbol(Tcl_Interp* interp, Tcl_LoadHandle loadHandle,
- const char* symbol);
-static void
-UnloadFile(Tcl_LoadHandle handle);
+/*
+ * Static functions defined within this file.
+ */
+static void * FindSymbol(Tcl_Interp *interp,
+ Tcl_LoadHandle loadHandle, const char *symbol);
+static void UnloadFile(Tcl_LoadHandle handle);
/*
*----------------------------------------------------------------------
@@ -137,7 +137,7 @@ FindSymbol(
{
Tcl_DString newName;
Tcl_PackageInitProc *proc = NULL;
- shl_t handle = (shl_t)(loadHandle->clientData);
+ shl_t handle = (shl_t) loadHandle->clientData;
/*
* Some versions of the HP system software still use "_" at the beginning
@@ -187,9 +187,8 @@ UnloadFile(
* TclpDlopen(). The loadHandle is a token
* that represents the loaded file. */
{
- shl_t handle;
+ shl_t handle = (shl_t) loadHandle->clientData;
- handle = (shl_t) (loadHandle -> clientData);
shl_unload(handle);
ckfree(loadHandle);
}
diff --git a/unix/tclUnixFile.c b/unix/tclUnixFile.c
index 01fc6fe..38504d9 100644
--- a/unix/tclUnixFile.c
+++ b/unix/tclUnixFile.c
@@ -470,7 +470,7 @@ NativeMatchType(
#ifndef MAC_OSX_TCL
|| ((types->perm & TCL_GLOB_PERM_HIDDEN) &&
(*nativeName != '.'))
-#endif
+#endif /* MAC_OSX_TCL */
) {
return 0;
}
@@ -488,12 +488,10 @@ NativeMatchType(
* check that here:
*/
- if (types->type & TCL_GLOB_TYPE_LINK) {
- if (TclOSlstat(nativeEntry, &buf) == 0) {
- if (S_ISLNK(buf.st_mode)) {
- return 1;
- }
- }
+ if ((types->type & TCL_GLOB_TYPE_LINK)
+ && (TclOSlstat(nativeEntry, &buf) == 0)
+ && S_ISLNK(buf.st_mode)) {
+ return 1;
}
return 0;
}
@@ -516,12 +514,10 @@ NativeMatchType(
*/
} else {
#ifdef S_ISLNK
- if (types->type & TCL_GLOB_TYPE_LINK) {
- if (TclOSlstat(nativeEntry, &buf) == 0) {
- if (S_ISLNK(buf.st_mode)) {
- goto filetypeOK;
- }
- }
+ if ((types->type & TCL_GLOB_TYPE_LINK)
+ && (TclOSlstat(nativeEntry, &buf) == 0)
+ && S_ISLNK(buf.st_mode)) {
+ goto filetypeOK;
}
#endif /* S_ISLNK */
return 0;
@@ -717,9 +713,9 @@ TclpGetNativeCwd(
if (getcwd(buffer, MAXPATHLEN+1) == NULL) { /* INTL: Native. */
return NULL;
}
-#endif
+#endif /* USEGETWD */
- if ((clientData == NULL) || strcmp(buffer, (const char*)clientData)) {
+ if ((clientData == NULL) || strcmp(buffer, (const char *) clientData)) {
char *newCd = ckalloc(strlen(buffer) + 1);
strcpy(newCd, buffer);
@@ -767,7 +763,7 @@ TclpGetCwd(
if (getwd(buffer) == NULL) /* INTL: Native. */
#else
if (getcwd(buffer, MAXPATHLEN+1) == NULL) /* INTL: Native. */
-#endif
+#endif /* USEGETWD */
{
if (interp != NULL) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
@@ -823,7 +819,7 @@ TclpReadlink(
return Tcl_DStringValue(linkPtr);
#else
return NULL;
-#endif
+#endif /* !DJGPP */
}
/*
@@ -857,7 +853,7 @@ TclpObjStat(
#ifdef S_IFLNK
-Tcl_Obj*
+Tcl_Obj *
TclpObjLink(
Tcl_Obj *pathPtr,
Tcl_Obj *toPtr,
@@ -1179,10 +1175,17 @@ TclpUtime(
{
return utime(Tcl_FSGetNativePath(pathPtr), tval);
}
+
#ifdef __CYGWIN__
-int TclOSstat(const char *name, Tcl_StatBuf *statBuf) {
+
+int
+TclOSstat(
+ const char *name,
+ Tcl_StatBuf *statBuf)
+{
struct stat buf;
int result = stat(name, &buf);
+
statBuf->st_mode = buf.st_mode;
statBuf->st_ino = buf.st_ino;
statBuf->st_dev = buf.st_dev;
@@ -1196,9 +1199,15 @@ int TclOSstat(const char *name, Tcl_StatBuf *statBuf) {
statBuf->st_ctime = buf.st_ctime;
return result;
}
-int TclOSlstat(const char *name, Tcl_StatBuf *statBuf) {
+
+int
+TclOSlstat(
+ const char *name,
+ Tcl_StatBuf *statBuf)
+{
struct stat buf;
int result = lstat(name, &buf);
+
statBuf->st_mode = buf.st_mode;
statBuf->st_ino = buf.st_ino;
statBuf->st_dev = buf.st_dev;
@@ -1212,7 +1221,7 @@ int TclOSlstat(const char *name, Tcl_StatBuf *statBuf) {
statBuf->st_ctime = buf.st_ctime;
return result;
}
-#endif
+#endif /* CYGWIN */
/*
* Local Variables:
diff --git a/unix/tclUnixNotfy.c b/unix/tclUnixNotfy.c
index ca95f40..b87af1b 100644
--- a/unix/tclUnixNotfy.c
+++ b/unix/tclUnixNotfy.c
@@ -96,7 +96,7 @@ typedef struct ThreadSpecificData {
* that an event is ready to be processed
* by sending this event. */
void *hwnd; /* Messaging window. */
-#else /* !__CYGWIN__ */
+#else
Tcl_Condition waitCV; /* Any other thread alerts a notifier that an
* event is ready to be processed by signaling
* this condition variable. */
@@ -104,7 +104,7 @@ typedef struct ThreadSpecificData {
int eventReady; /* True if an event is ready to be processed.
* Used as condition flag together with waitCV
* above. */
-#endif
+#endif /* TCL_THREADS */
} ThreadSpecificData;
static Tcl_ThreadDataKey dataKey;
@@ -187,25 +187,12 @@ static Tcl_ThreadId notifierThread;
static void NotifierThreadProc(ClientData clientData);
#endif
static int FileHandlerEventProc(Tcl_Event *evPtr, int flags);
-
+
/*
- *----------------------------------------------------------------------
- *
- * Tcl_InitNotifier --
- *
- * Initializes the platform specific notifier state.
- *
- * Results:
- * Returns a handle to the notifier state for this thread.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
+ * Import of Windows API when building threaded with Cygwin.
*/
#if defined(TCL_THREADS) && defined(__CYGWIN__)
-
typedef struct {
void *hwnd;
unsigned int *message;
@@ -217,34 +204,60 @@ typedef struct {
} MSG;
typedef struct {
- unsigned int style;
- void *lpfnWndProc;
- int cbClsExtra;
- int cbWndExtra;
- void *hInstance;
- void *hIcon;
- void *hCursor;
- void *hbrBackground;
- void *lpszMenuName;
- void *lpszClassName;
+ unsigned int style;
+ void *lpfnWndProc;
+ int cbClsExtra;
+ int cbWndExtra;
+ void *hInstance;
+ void *hIcon;
+ void *hCursor;
+ void *hbrBackground;
+ void *lpszMenuName;
+ void *lpszClassName;
} WNDCLASS;
-extern unsigned char __stdcall PeekMessageW(MSG *, void *, int, int, int);
-extern unsigned char __stdcall GetMessageW(MSG *, void *, int, int);
-extern unsigned char __stdcall TranslateMessage(const MSG *);
-extern int __stdcall DispatchMessageW(const MSG *);
-extern void __stdcall PostQuitMessage(int);
-extern void * __stdcall CreateWindowExW(void *, void *, void *, DWORD, int, int, int, int, void *, void *, void *, void *);
-extern unsigned char __stdcall DestroyWindow(void *);
-extern unsigned char __stdcall PostMessageW(void *, unsigned int, void *, void *);
-extern void *__stdcall RegisterClassW(const WNDCLASS *);
-extern DWORD __stdcall DefWindowProcW(void *, int, void *, void *);
-extern void *__stdcall CreateEventW(void *, unsigned char, unsigned char, void *);
-extern void __stdcall CloseHandle(void *);
-extern void __stdcall MsgWaitForMultipleObjects(DWORD, void *, unsigned char, DWORD, DWORD);
-extern unsigned char __stdcall ResetEvent(void *);
+extern void __stdcall CloseHandle(void *);
+extern void *__stdcall CreateEventW(void *, unsigned char, unsigned char,
+ void *);
+extern void * __stdcall CreateWindowExW(void *, void *, void *, DWORD, int,
+ int, int, int, void *, void *, void *, void *);
+extern DWORD __stdcall DefWindowProcW(void *, int, void *, void *);
+extern unsigned char __stdcall DestroyWindow(void *);
+extern int __stdcall DispatchMessageW(const MSG *);
+extern unsigned char __stdcall GetMessageW(MSG *, void *, int, int);
+extern void __stdcall MsgWaitForMultipleObjects(DWORD, void *,
+ unsigned char, DWORD, DWORD);
+extern unsigned char __stdcall PeekMessageW(MSG *, void *, int, int, int);
+extern unsigned char __stdcall PostMessageW(void *, unsigned int, void *,
+ void *);
+extern void __stdcall PostQuitMessage(int);
+extern void *__stdcall RegisterClassW(const WNDCLASS *);
+extern unsigned char __stdcall ResetEvent(void *);
+extern unsigned char __stdcall TranslateMessage(const MSG *);
-#endif
+/*
+ * Threaded-cygwin specific functions in this file:
+ */
+
+static DWORD __stdcall NotifierProc(void *hwnd, unsigned int message,
+ void *wParam, void *lParam);
+#endif /* TCL_THREADS && __CYGWIN__ */
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * Tcl_InitNotifier --
+ *
+ * Initializes the platform specific notifier state.
+ *
+ * Results:
+ * Returns a handle to the notifier state for this thread.
+ *
+ * Side effects:
+ * None.
+ *
+ *----------------------------------------------------------------------
+ */
ClientData
Tcl_InitNotifier(void)
@@ -403,11 +416,11 @@ Tcl_AlertNotifier(
Tcl_MutexLock(&notifierMutex);
tsdPtr->eventReady = 1;
-#ifdef __CYGWIN__
+# ifdef __CYGWIN__
PostMessageW(tsdPtr->hwnd, 1024, 0, 0);
-#else
+# else
Tcl_ConditionNotify(&tsdPtr->waitCV);
-#endif
+# endif /* __CYGWIN__ */
Tcl_MutexUnlock(&notifierMutex);
#endif /* TCL_THREADS */
}
@@ -732,12 +745,12 @@ NotifierProc(
* Process all of the runnable events.
*/
- tsdPtr->eventReady = 1;
+ tsdPtr->eventReady = 1;
Tcl_ServiceAll();
return 0;
}
-#endif /* __CYGWIN__ */
-
+#endif /* TCL_THREADS && __CYGWIN__ */
+
/*
*----------------------------------------------------------------------
*
@@ -768,9 +781,9 @@ Tcl_WaitForEvent(
Tcl_Time vTime;
#ifdef TCL_THREADS
int waitForFiles;
-# ifdef __CYGWIN__
- MSG msg;
-# endif
+# ifdef __CYGWIN__
+ MSG msg;
+# endif /* __CYGWIN__ */
#else
/*
* Impl. notes: timeout & timeoutPtr are used if, and only if threads
@@ -792,8 +805,8 @@ Tcl_WaitForEvent(
if (timePtr != NULL) {
/*
* TIP #233 (Virtualized Time). Is virtual time in effect? And do
- * we actually have something to scale? If yes to both then we call
- * the handler to do this scaling.
+ * we actually have something to scale? If yes to both then we
+ * call the handler to do this scaling.
*/
if (timePtr->sec != 0 || timePtr->usec != 0) {
@@ -807,17 +820,17 @@ Tcl_WaitForEvent(
timeoutPtr = &timeout;
} else if (tsdPtr->numFdBits == 0) {
/*
- * If there are no threads, no timeout, and no fds registered, then
- * there are no events possible and we must avoid deadlock. Note
- * that this is not entirely correct because there might be a
- * signal that could interrupt the select call, but we don't handle
- * that case if we aren't using threads.
+ * If there are no threads, no timeout, and no fds registered,
+ * then there are no events possible and we must avoid deadlock.
+ * Note that this is not entirely correct because there might be a
+ * signal that could interrupt the select call, but we don't
+ * handle that case if we aren't using threads.
*/
return -1;
} else {
timeoutPtr = NULL;
-#endif /* TCL_THREADS */
+#endif /* !TCL_THREADS */
}
#ifdef TCL_THREADS
@@ -828,7 +841,7 @@ Tcl_WaitForEvent(
#ifdef __CYGWIN__
if (!tsdPtr->hwnd) {
- WNDCLASS class;
+ WNDCLASS class;
class.style = 0;
class.cbClsExtra = 0;
@@ -842,24 +855,24 @@ Tcl_WaitForEvent(
class.hCursor = NULL;
RegisterClassW(&class);
- tsdPtr->hwnd = CreateWindowExW(NULL, class.lpszClassName, class.lpszClassName,
- 0, 0, 0, 0, 0, NULL, NULL, TclWinGetTclInstance(), NULL);
+ tsdPtr->hwnd = CreateWindowExW(NULL, class.lpszClassName,
+ class.lpszClassName, 0, 0, 0, 0, 0, NULL, NULL,
+ TclWinGetTclInstance(), NULL);
tsdPtr->event = CreateEventW(NULL, 1 /* manual */,
0 /* !signaled */, NULL);
- }
-
-#endif
+ }
+#endif /* __CYGWIN */
Tcl_MutexLock(&notifierMutex);
if (timePtr != NULL && timePtr->sec == 0 && (timePtr->usec == 0
#if defined(__APPLE__) && defined(__LP64__)
/*
- * On 64-bit Darwin, pthread_cond_timedwait() appears to have a
- * bug that causes it to wait forever when passed an absolute
- * time which has already been exceeded by the system time; as
- * a workaround, when given a very brief timeout, just do a
- * poll. [Bug 1457797]
+ * On 64-bit Darwin, pthread_cond_timedwait() appears to have
+ * a bug that causes it to wait forever when passed an
+ * absolute time which has already been exceeded by the system
+ * time; as a workaround, when given a very brief timeout,
+ * just do a poll. [Bug 1457797]
*/
|| timePtr->usec < 10
#endif /* __APPLE__ && __LP64__ */
@@ -883,8 +896,8 @@ Tcl_WaitForEvent(
if (waitForFiles) {
/*
* Add the ThreadSpecificData structure of this thread to the list
- * of ThreadSpecificData structures of all threads that are waiting
- * on file events.
+ * of ThreadSpecificData structures of all threads that are
+ * waiting on file events.
*/
tsdPtr->nextPtr = waitingListPtr;
@@ -909,6 +922,7 @@ Tcl_WaitForEvent(
#ifdef __CYGWIN__
if (!PeekMessageW(&msg, NULL, 0, 0, 0)) {
DWORD timeout;
+
if (timePtr) {
timeout = timePtr->sec * 1000 + timePtr->usec / 1000;
} else {
@@ -920,7 +934,7 @@ Tcl_WaitForEvent(
}
#else
Tcl_ConditionWait(&tsdPtr->waitCV, &notifierMutex, timePtr);
-#endif
+#endif /* __CYGWIN__ */
}
tsdPtr->eventReady = 0;
@@ -929,17 +943,20 @@ Tcl_WaitForEvent(
/*
* Retrieve and dispatch the message.
*/
+
DWORD result = GetMessageW(&msg, NULL, 0, 0);
+
if (result == 0) {
PostQuitMessage(msg.wParam);
/* What to do here? */
- } else if (result != (DWORD)-1) {
+ } else if (result != (DWORD) -1) {
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
}
ResetEvent(tsdPtr->event);
-#endif
+#endif /* __CYGWIN__ */
+
if (waitForFiles && tsdPtr->onList) {
/*
* Remove the ThreadSpecificData structure of this thread from the
@@ -1211,9 +1228,9 @@ NotifierThreadProc(
tsdPtr->pollState = 0;
}
#ifdef __CYGWIN__
- PostMessageW(tsdPtr->hwnd, 1024, 0, 0);
-#else /* __CYGWIN__ */
- Tcl_ConditionNotify(&tsdPtr->waitCV);
+ PostMessageW(tsdPtr->hwnd, 1024, 0, 0);
+#else
+ Tcl_ConditionNotify(&tsdPtr->waitCV);
#endif /* __CYGWIN__ */
}
}
@@ -1255,7 +1272,7 @@ NotifierThreadProc(
}
#endif /* TCL_THREADS */
-#endif /* HAVE_COREFOUNDATION */
+#endif /* !HAVE_COREFOUNDATION */
/*
* Local Variables: