diff options
author | dkf <donal.k.fellows@manchester.ac.uk> | 2004-06-18 13:42:39 (GMT) |
---|---|---|
committer | dkf <donal.k.fellows@manchester.ac.uk> | 2004-06-18 13:42:39 (GMT) |
commit | 24852b45e7e8cfca94b0fdc026236119e87b60d6 (patch) | |
tree | a8b0859a71c6cb5c1070861a256f491e5e419e58 /win/tclWinInit.c | |
parent | 9c324c95dca16f94b271dad6051d928e7275999c (diff) | |
download | tcl-24852b45e7e8cfca94b0fdc026236119e87b60d6.zip tcl-24852b45e7e8cfca94b0fdc026236119e87b60d6.tar.gz tcl-24852b45e7e8cfca94b0fdc026236119e87b60d6.tar.bz2 |
Fix tclWinInit.c for KBK, adding comments as I go. :^)
Diffstat (limited to 'win/tclWinInit.c')
-rw-r--r-- | win/tclWinInit.c | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/win/tclWinInit.c b/win/tclWinInit.c index e9b1255..bae876e 100644 --- a/win/tclWinInit.c +++ b/win/tclWinInit.c @@ -7,7 +7,7 @@ * Copyright (c) 1998-1999 by Scriptics Corporation. * All rights reserved. * - * RCS: @(#) $Id: tclWinInit.c,v 1.56 2004/06/17 22:13:00 dgp Exp $ + * RCS: @(#) $Id: tclWinInit.c,v 1.57 2004/06/18 13:42:42 dkf Exp $ */ #include "tclWinInt.h" @@ -159,29 +159,44 @@ SetDefaultLibraryDir(directory) Tcl_GetThreadData(&defaultLibraryDirKey, (int)sizeof(Tcl_Obj *)); Tcl_IncrRefCount(directory); - if (NULL == *savedDirectoryPtr) { - /* First call in this thread, set up the thread exit handler */ + if (*savedDirectoryPtr == NULL) { + /* + * First call in this thread, set up the thread exit handler + */ Tcl_CreateThreadExitHandler(FreeThreadDefaultLibraryDir, (ClientData) savedDirectoryPtr); } else { - /* Called SetDLD after a previous SetDLD or GetDLD in this thread ?! */ + /* + * Called SetDLD after a previous SetDLD or GetDLD in this thread ?! + */ Tcl_DecrRefCount(*savedDirectoryPtr); } *savedDirectoryPtr = directory; - /* No Mutex protection, as the only caller is already in TclpInitLock */ + /* + * No Mutex protection, as the only caller is already in TclpInitLock + */ bytes = Tcl_GetStringFromObj(directory, &numBytes); - if (NULL == defaultLibraryDir) { - /* First call from any thread; set up exit handler */ - Tcl_CreateExitHandler(FreeDefaultLibraryDir, NULL); - } else { - if ((defaultLibraryDirLength != numBytes) - || (0 != strcmp(defaultLibraryDir, bytes, numBytes))) { - Tcl_Panic("Attempt to overwrite defaultLibraryDir"); + if (defaultLibraryDir != NULL) { + /* + * This function has been called before. We only ever want to + * set up the default library directory once, but if it is set + * multiple times to the same value that's not harmful. + */ + if (defaultLibraryDirLength != numBytes + || memcmp(defaultLibraryDir, bytes, numBytes) != 0) { + Tcl_Panic("Attempt to modify defaultLibraryDir"); } return; } + + /* + * First call from any thread; set up exit handler + */ + + Tcl_CreateExitHandler(FreeDefaultLibraryDir, NULL); + defaultLibraryDirLength = numBytes; defaultLibraryDir = ckalloc((unsigned int) numBytes + 1); memcpy(defaultLibraryDir, bytes, (unsigned int) numBytes + 1); |