summaryrefslogtreecommitdiffstats
path: root/unix
diff options
context:
space:
mode:
Diffstat (limited to 'unix')
-rw-r--r--unix/tclLoadDl.c10
-rw-r--r--unix/tclLoadDyld.c252
-rw-r--r--unix/tclLoadNext.c27
-rw-r--r--unix/tclLoadOSF.c12
-rw-r--r--unix/tclLoadShl.c11
-rw-r--r--unix/tclUnixChan.c75
-rw-r--r--unix/tclUnixFCmd.c81
-rw-r--r--unix/tclUnixFile.c13
-rw-r--r--unix/tclUnixPipe.c64
-rw-r--r--unix/tclUnixSock.c146
10 files changed, 308 insertions, 383 deletions
diff --git a/unix/tclLoadDl.c b/unix/tclLoadDl.c
index d86e7fd..f8fe6d3 100644
--- a/unix/tclLoadDl.c
+++ b/unix/tclLoadDl.c
@@ -112,8 +112,9 @@ TclpDlopen(
const char *errorStr = dlerror();
- Tcl_AppendResult(interp, "couldn't load file \"",
- Tcl_GetString(pathPtr), "\": ", errorStr, NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "couldn't load file \"%s\": %s",
+ Tcl_GetString(pathPtr), errorStr));
return TCL_ERROR;
}
newHandle = ckalloc(sizeof(*newHandle));
@@ -175,9 +176,8 @@ FindSymbol(
}
Tcl_DStringFree(&ds);
if (proc == NULL && interp != NULL) {
- Tcl_ResetResult(interp);
- Tcl_AppendResult(interp, "cannot find symbol \"", symbol, "\": ",
- dlerror(), NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "cannot find symbol \"%s\": %s", symbol, dlerror()));
Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "LOAD_SYMBOL", symbol,
NULL);
}
diff --git a/unix/tclLoadDyld.c b/unix/tclLoadDyld.c
index 31d15b2..95735a4 100644
--- a/unix/tclLoadDyld.c
+++ b/unix/tclLoadDyld.c
@@ -16,42 +16,36 @@
#include "tclInt.h"
#ifndef MODULE_SCOPE
-#define MODULE_SCOPE extern
+# define MODULE_SCOPE extern
#endif
-#ifndef TCL_DYLD_USE_DLFCN
/*
* Use preferred dlfcn API on 10.4 and later
*/
-# if !defined(NO_DLFCN_H) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1040
-# define TCL_DYLD_USE_DLFCN 1
-# else
+
+#ifndef TCL_DYLD_USE_DLFCN
+# ifdef NO_DLFCN_H
# define TCL_DYLD_USE_DLFCN 0
+# else
+# define TCL_DYLD_USE_DLFCN 1
# endif
#endif
-#ifndef TCL_DYLD_USE_NSMODULE
+
/*
* Use deprecated NSModule API only to support 10.3 and earlier:
*/
-# if MAC_OS_X_VERSION_MIN_REQUIRED < 1040
-# define TCL_DYLD_USE_NSMODULE 1
-# else
-# define TCL_DYLD_USE_NSMODULE 0
-# endif
+
+#ifndef TCL_DYLD_USE_NSMODULE
+# define TCL_DYLD_USE_NSMODULE 0
#endif
-#if TCL_DYLD_USE_DLFCN
-#include <dlfcn.h>
-#if defined(HAVE_WEAK_IMPORT) && MAC_OS_X_VERSION_MIN_REQUIRED < 1040
/*
- * Support for weakly importing dlfcn API.
+ * Use includes for the API we're using.
*/
-extern void *dlopen(const char *path, int mode) WEAK_IMPORT_ATTRIBUTE;
-extern void *dlsym(void *handle, const char *symbol) WEAK_IMPORT_ATTRIBUTE;
-extern int dlclose(void *handle) WEAK_IMPORT_ATTRIBUTE;
-extern char *dlerror(void) WEAK_IMPORT_ATTRIBUTE;
-#endif
-#endif
+
+#if TCL_DYLD_USE_DLFCN
+# include <dlfcn.h>
+#endif /* TCL_DYLD_USE_DLFCN */
#if TCL_DYLD_USE_NSMODULE || defined(TCL_LOAD_FROM_MEMORY)
#include <mach-o/dyld.h>
@@ -60,38 +54,23 @@ extern char *dlerror(void) WEAK_IMPORT_ATTRIBUTE;
#include <mach-o/arch.h>
#include <libkern/OSByteOrder.h>
#include <mach/mach.h>
-#include <stdbool.h>
typedef struct Tcl_DyldModuleHandle {
struct Tcl_DyldModuleHandle *nextPtr;
NSModule module;
} Tcl_DyldModuleHandle;
-#endif /* TCL_DYLD_USE_NSMODULE */
+#endif /* TCL_DYLD_USE_NSMODULE || TCL_LOAD_FROM_MEMORY */
-typedef struct Tcl_DyldLoadHandle {
-#if TCL_DYLD_USE_DLFCN
+typedef struct {
void *dlHandle;
-#endif
#if TCL_DYLD_USE_NSMODULE || defined(TCL_LOAD_FROM_MEMORY)
const struct mach_header *dyldLibHeader;
Tcl_DyldModuleHandle *modulePtr;
#endif
} Tcl_DyldLoadHandle;
-#if (TCL_DYLD_USE_DLFCN && MAC_OS_X_VERSION_MIN_REQUIRED < 1040) || \
- defined(TCL_LOAD_FROM_MEMORY)
-MODULE_SCOPE long tclMacOSXDarwinRelease;
-#endif
-
-#ifdef TCL_DEBUG_LOAD
-#define TclLoadDbgMsg(m, ...) \
- do { \
- fprintf(stderr, "%s:%d: %s(): " m ".\n", \
- strrchr(__FILE__, '/')+1, __LINE__, __func__, \
- ##__VA_ARGS__); \
- } while (0)
-#else
-#define TclLoadDbgMsg(m, ...)
+#if TCL_DYLD_USE_DLFCN || defined(TCL_LOAD_FROM_MEMORY)
+MODULE_SCOPE long tclMacOSXDarwinRelease;
#endif
/*
@@ -102,7 +81,6 @@ static void * FindSymbol(Tcl_Interp *interp,
Tcl_LoadHandle loadHandle, const char *symbol);
static void UnloadFile(Tcl_LoadHandle handle);
-#if TCL_DYLD_USE_NSMODULE || defined(TCL_LOAD_FROM_MEMORY)
/*
*----------------------------------------------------------------------
*
@@ -120,6 +98,7 @@ static void UnloadFile(Tcl_LoadHandle handle);
*----------------------------------------------------------------------
*/
+#if TCL_DYLD_USE_NSMODULE || defined(TCL_LOAD_FROM_MEMORY)
static const char *
DyldOFIErrorMsg(
int err)
@@ -141,7 +120,7 @@ DyldOFIErrorMsg(
return "unknown error";
}
}
-#endif /* TCL_DYLD_USE_NSMODULE */
+#endif /* TCL_DYLD_USE_NSMODULE || TCL_LOAD_FROM_MEMORY */
/*
*----------------------------------------------------------------------
@@ -176,9 +155,7 @@ TclpDlopen(
{
Tcl_DyldLoadHandle *dyldLoadHandle;
Tcl_LoadHandle newHandle;
-#if TCL_DYLD_USE_DLFCN
void *dlHandle = NULL;
-#endif
#if TCL_DYLD_USE_NSMODULE || defined(TCL_LOAD_FROM_MEMORY)
const struct mach_header *dyldLibHeader = NULL;
Tcl_DyldModuleHandle *modulePtr = NULL;
@@ -187,11 +164,10 @@ TclpDlopen(
NSLinkEditErrors editError;
int errorNumber;
const char *errorName, *objFileImageErrMsg = NULL;
-#endif
+#endif /* TCL_DYLD_USE_NSMODULE */
const char *errMsg = NULL;
int result;
Tcl_DString ds;
- char *fileName = NULL;
const char *nativePath, *nativeFileName = NULL;
/*
@@ -201,46 +177,36 @@ TclpDlopen(
*/
nativePath = Tcl_FSGetNativePath(pathPtr);
+ nativeFileName = Tcl_UtfToExternalDString(NULL, Tcl_GetString(pathPtr),
+ -1, &ds);
#if TCL_DYLD_USE_DLFCN
-#if MAC_OS_X_VERSION_MIN_REQUIRED < 1040
- if (tclMacOSXDarwinRelease >= 8)
-#endif
- {
/*
* Use (RTLD_NOW|RTLD_LOCAL) always, see [Bug #3216070]
*/
- dlHandle = dlopen(nativePath, RTLD_NOW | RTLD_LOCAL);
- if (!dlHandle) {
- /*
- * Let the OS loader examine the binary search path for whatever
- * string the user gave us which hopefully refers to a file on the
- * binary path.
- */
- fileName = Tcl_GetString(pathPtr);
- nativeFileName = Tcl_UtfToExternalDString(NULL, fileName, -1, &ds);
- /*
- * Use (RTLD_NOW|RTLD_LOCAL) always, see [Bug #3216070]
- */
- dlHandle = dlopen(nativeFileName, RTLD_NOW | RTLD_LOCAL);
- }
- if (dlHandle) {
- TclLoadDbgMsg("dlopen() successful");
- } else {
+ dlHandle = dlopen(nativePath, RTLD_NOW | RTLD_LOCAL);
+ if (!dlHandle) {
+ /*
+ * Let the OS loader examine the binary search path for whatever string
+ * the user gave us which hopefully refers to a file on the binary
+ * path.
+ *
+ * Use (RTLD_NOW|RTLD_LOCAL) always, see [Bug #3216070]
+ */
+
+ dlHandle = dlopen(nativeFileName, RTLD_NOW | RTLD_LOCAL);
+ if (!dlHandle) {
errMsg = dlerror();
- TclLoadDbgMsg("dlopen() failed: %s", errMsg);
}
}
- if (!dlHandle)
#endif /* TCL_DYLD_USE_DLFCN */
- {
+
+ if (!dlHandle) {
#if TCL_DYLD_USE_NSMODULE
dyldLibHeader = NSAddImage(nativePath,
NSADDIMAGE_OPTION_RETURN_ON_ERROR);
- if (dyldLibHeader) {
- TclLoadDbgMsg("NSAddImage() successful");
- } else {
+ if (!dyldLibHeader) {
NSLinkEditError(&editError, &errorNumber, &errorName, &errMsg);
if (editError == NSLinkEditFileAccessError) {
/*
@@ -249,20 +215,12 @@ TclpDlopen(
* which hopefully refers to a file on the binary path.
*/
- if (!fileName) {
- fileName = Tcl_GetString(pathPtr);
- nativeFileName = Tcl_UtfToExternalDString(NULL, fileName,
- -1, &ds);
- }
dyldLibHeader = NSAddImage(nativeFileName,
NSADDIMAGE_OPTION_WITH_SEARCHING |
NSADDIMAGE_OPTION_RETURN_ON_ERROR);
- if (dyldLibHeader) {
- TclLoadDbgMsg("NSAddImage() successful");
- } else {
+ if (!dyldLibHeader) {
NSLinkEditError(&editError, &errorNumber, &errorName,
&errMsg);
- TclLoadDbgMsg("NSAddImage() failed: %s", errMsg);
}
} else if ((editError == NSLinkEditFileFormatError
&& errorNumber == EBADMACHO)
@@ -279,8 +237,6 @@ TclpDlopen(
err = NSCreateObjectFileImageFromFile(nativePath,
&dyldObjFileImage);
if (err == NSObjectFileImageSuccess && dyldObjFileImage) {
- TclLoadDbgMsg("NSCreateObjectFileImageFromFile() "
- "successful");
module = NSLinkModule(dyldObjFileImage, nativePath,
NSLINKMODULE_OPTION_BINDNOW
| NSLINKMODULE_OPTION_RETURN_ON_ERROR);
@@ -289,37 +245,29 @@ TclpDlopen(
modulePtr = ckalloc(sizeof(Tcl_DyldModuleHandle));
modulePtr->module = module;
modulePtr->nextPtr = NULL;
- TclLoadDbgMsg("NSLinkModule() successful");
} else {
NSLinkEditError(&editError, &errorNumber, &errorName,
&errMsg);
- TclLoadDbgMsg("NSLinkModule() failed: %s", errMsg);
}
} else {
objFileImageErrMsg = DyldOFIErrorMsg(err);
- TclLoadDbgMsg("NSCreateObjectFileImageFromFile() failed: "
- "%s", objFileImageErrMsg);
}
}
}
#endif /* TCL_DYLD_USE_NSMODULE */
}
- if (0
-#if TCL_DYLD_USE_DLFCN
- || dlHandle
-#endif
+
+ if (dlHandle
#if TCL_DYLD_USE_NSMODULE
|| dyldLibHeader || modulePtr
-#endif
+#endif /* TCL_DYLD_USE_NSMODULE */
) {
dyldLoadHandle = ckalloc(sizeof(Tcl_DyldLoadHandle));
-#if TCL_DYLD_USE_DLFCN
dyldLoadHandle->dlHandle = dlHandle;
-#endif
#if TCL_DYLD_USE_NSMODULE || defined(TCL_LOAD_FROM_MEMORY)
dyldLoadHandle->dyldLibHeader = dyldLibHeader;
dyldLoadHandle->modulePtr = modulePtr;
-#endif
+#endif /* TCL_DYLD_USE_NSMODULE || TCL_LOAD_FROM_MEMORY */
newHandle = ckalloc(sizeof(*newHandle));
newHandle->clientData = dyldLoadHandle;
newHandle->findSymbolProcPtr = &FindSymbol;
@@ -328,18 +276,23 @@ TclpDlopen(
*loadHandle = newHandle;
result = TCL_OK;
} else {
- Tcl_AppendResult(interp, errMsg, NULL);
+ Tcl_Obj *errObj = Tcl_NewObj();
+
+ if (errMsg != NULL) {
+ Tcl_AppendToObj(errObj, errMsg, -1);
+ }
#if TCL_DYLD_USE_NSMODULE
if (objFileImageErrMsg) {
- Tcl_AppendResult(interp, "\nNSCreateObjectFileImageFromFile() "
- "error: ", objFileImageErrMsg, NULL);
+ Tcl_AppendPrintfToObj(errObj,
+ "\nNSCreateObjectFileImageFromFile() error: %s",
+ objFileImageErrMsg);
}
-#endif
+#endif /* TCL_DYLD_USE_NSMODULE */
+ Tcl_SetObjResult(interp, errObj);
result = TCL_ERROR;
}
- if(fileName) {
- Tcl_DStringFree(&ds);
- }
+
+ Tcl_DStringFree(&ds);
return result;
}
@@ -372,18 +325,14 @@ FindSymbol(
const char *native;
native = Tcl_UtfToExternalDString(NULL, symbol, -1, &ds);
-#if TCL_DYLD_USE_DLFCN
if (dyldLoadHandle->dlHandle) {
+#if TCL_DYLD_USE_DLFCN
proc = dlsym(dyldLoadHandle->dlHandle, native);
- if (proc) {
- TclLoadDbgMsg("dlsym() successful");
- } else {
+ if (!proc) {
errMsg = dlerror();
- TclLoadDbgMsg("dlsym() failed: %s", errMsg);
}
- } else
#endif /* TCL_DYLD_USE_DLFCN */
- {
+ } else {
#if TCL_DYLD_USE_NSMODULE || defined(TCL_LOAD_FROM_MEMORY)
NSSymbol nsSymbol = NULL;
Tcl_DString newName;
@@ -400,13 +349,12 @@ FindSymbol(
native, NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_NOW |
NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
if (nsSymbol) {
- TclLoadDbgMsg("NSLookupSymbolInImage() successful");
-#ifdef DYLD_SUPPORTS_DYLIB_UNLOADING
/*
* Until dyld supports unloading of MY_DYLIB binaries, the
* following is not needed.
*/
+#ifdef DYLD_SUPPORTS_DYLIB_UNLOADING
NSModule module = NSModuleForSymbol(nsSymbol);
Tcl_DyldModuleHandle *modulePtr = dyldLoadHandle->modulePtr;
@@ -429,32 +377,21 @@ FindSymbol(
const char *errorName;
NSLinkEditError(&editError, &errorNumber, &errorName, &errMsg);
- TclLoadDbgMsg("NSLookupSymbolInImage() failed: %s", errMsg);
}
} else if (dyldLoadHandle->modulePtr) {
nsSymbol = NSLookupSymbolInModule(
dyldLoadHandle->modulePtr->module, native);
- if (nsSymbol) {
- TclLoadDbgMsg("NSLookupSymbolInModule() successful");
- } else {
- TclLoadDbgMsg("NSLookupSymbolInModule() failed");
- }
}
if (nsSymbol) {
proc = NSAddressOfSymbol(nsSymbol);
- if (proc) {
- TclLoadDbgMsg("NSAddressOfSymbol() successful");
- } else {
- TclLoadDbgMsg("NSAddressOfSymbol() failed");
- }
}
Tcl_DStringFree(&newName);
#endif /* TCL_DYLD_USE_NSMODULE */
}
Tcl_DStringFree(&ds);
if (errMsg && (interp != NULL)) {
- Tcl_AppendResult(interp, "cannot find symbol \"", symbol, "\": ",
- errMsg, NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "cannot find symbol \"%s\": %s", symbol, errMsg));
Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "LOAD_SYMBOL", symbol,
NULL);
}
@@ -489,34 +426,19 @@ UnloadFile(
{
Tcl_DyldLoadHandle *dyldLoadHandle = loadHandle->clientData;
-#if TCL_DYLD_USE_DLFCN
if (dyldLoadHandle->dlHandle) {
- int result;
-
- result = dlclose(dyldLoadHandle->dlHandle);
- if (!result) {
- TclLoadDbgMsg("dlclose() successful");
- } else {
- TclLoadDbgMsg("dlclose() failed: %s", dlerror());
- }
- } else
+#if TCL_DYLD_USE_DLFCN
+ (void) dlclose(dyldLoadHandle->dlHandle);
#endif /* TCL_DYLD_USE_DLFCN */
- {
+ } else {
#if TCL_DYLD_USE_NSMODULE || defined(TCL_LOAD_FROM_MEMORY)
Tcl_DyldModuleHandle *modulePtr = dyldLoadHandle->modulePtr;
while (modulePtr != NULL) {
- void *ptr;
- bool result;
+ void *ptr = modulePtr;
- result = NSUnLinkModule(modulePtr->module,
+ (void) NSUnLinkModule(modulePtr->module,
NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES);
- if (result) {
- TclLoadDbgMsg("NSUnLinkModule() successful");
- } else {
- TclLoadDbgMsg("NSUnLinkModule() failed");
- }
- ptr = modulePtr;
modulePtr = modulePtr->nextPtr;
ckfree(ptr);
}
@@ -556,7 +478,6 @@ TclGuessPackageName(
return 0;
}
-#ifdef TCL_LOAD_FROM_MEMORY
/*
*----------------------------------------------------------------------
*
@@ -573,6 +494,7 @@ TclGuessPackageName(
*----------------------------------------------------------------------
*/
+#ifdef TCL_LOAD_FROM_MEMORY
MODULE_SCOPE void *
TclpLoadMemoryGetBuffer(
Tcl_Interp *interp, /* Used for error reporting. */
@@ -597,6 +519,7 @@ TclpLoadMemoryGetBuffer(
}
return buffer;
}
+#endif /* TCL_LOAD_FROM_MEMORY */
/*
*----------------------------------------------------------------------
@@ -616,6 +539,7 @@ TclpLoadMemoryGetBuffer(
*----------------------------------------------------------------------
*/
+#ifdef TCL_LOAD_FROM_MEMORY
MODULE_SCOPE int
TclpLoadMemory(
Tcl_Interp *interp, /* Used for error reporting. */
@@ -658,7 +582,7 @@ TclpLoadMemory(
# define mh_size sizeof(struct mach_header_64)
# define mh_magic MH_MAGIC_64
# define arch_abi CPU_ARCH_ABI64
-#endif
+#endif /* __LP64__ */
if ((size_t) codeSize >= sizeof(struct fat_header)
&& fh->magic == OSSwapHostToBigInt32(FAT_MAGIC)) {
@@ -668,7 +592,6 @@ TclpLoadMemory(
* Fat binary, try to find mach_header for our architecture
*/
- TclLoadDbgMsg("Fat binary, %d archs", fh_nfat_arch);
if ((size_t) codeSize >= sizeof(struct fat_header) +
fh_nfat_arch * sizeof(struct fat_arch)) {
void *fatarchs = (char*)buffer + sizeof(struct fat_header);
@@ -681,22 +604,15 @@ TclpLoadMemory(
fa = NXFindBestFatArch(arch->cputype | arch_abi,
arch->cpusubtype, fatarchs, fh_nfat_arch);
if (fa) {
- TclLoadDbgMsg("NXFindBestFatArch() successful: "
- "local cputype %d subtype %d, "
- "fat cputype %d subtype %d",
- arch->cputype | arch_abi, arch->cpusubtype,
- fa->cputype, fa->cpusubtype);
- mh = (void*)((char*)buffer + fa->offset);
+ mh = (void *)((char *) buffer + fa->offset);
ms = fa->size;
} else {
- TclLoadDbgMsg("NXFindBestFatArch() failed");
err = NSObjectFileImageInappropriateFile;
}
if (fh->magic != FAT_MAGIC) {
swap_fat_arch(fatarchs, fh_nfat_arch, arch->byteorder);
}
} else {
- TclLoadDbgMsg("Fat binary header failure");
err = NSObjectFileImageInappropriateFile;
}
} else {
@@ -704,26 +620,18 @@ TclpLoadMemory(
* Thin binary
*/
- TclLoadDbgMsg("Thin binary");
mh = buffer;
ms = codeSize;
}
if (ms && !(ms >= mh_size && mh->magic == mh_magic &&
mh->filetype == MH_BUNDLE)) {
- TclLoadDbgMsg("Inappropriate file: magic %x filetype %d",
- mh->magic, mh->filetype);
err = NSObjectFileImageInappropriateFile;
}
if (err == NSObjectFileImageSuccess) {
err = NSCreateObjectFileImageFromMemory(buffer, codeSize,
&dyldObjFileImage);
- if (err == NSObjectFileImageSuccess) {
- TclLoadDbgMsg("NSCreateObjectFileImageFromMemory() "
- "successful");
- } else {
+ if (err != NSObjectFileImageSuccess) {
objFileImageErrMsg = DyldOFIErrorMsg(err);
- TclLoadDbgMsg("NSCreateObjectFileImageFromMemory() failed: %s",
- objFileImageErrMsg);
}
} else {
objFileImageErrMsg = DyldOFIErrorMsg(err);
@@ -738,8 +646,9 @@ TclpLoadMemory(
if (dyldObjFileImage == NULL) {
vm_deallocate(mach_task_self(), (vm_address_t) buffer, size);
if (objFileImageErrMsg != NULL) {
- Tcl_AppendResult(interp, "NSCreateObjectFileImageFromMemory() "
- "error: ", objFileImageErrMsg, NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "NSCreateObjectFileImageFromMemory() error: ",
+ objFileImageErrMsg));
}
return TCL_ERROR;
}
@@ -751,16 +660,13 @@ TclpLoadMemory(
module = NSLinkModule(dyldObjFileImage, "[Memory Based Bundle]",
NSLINKMODULE_OPTION_BINDNOW | NSLINKMODULE_OPTION_RETURN_ON_ERROR);
NSDestroyObjectFileImage(dyldObjFileImage);
- if (module) {
- TclLoadDbgMsg("NSLinkModule() successful");
- } else {
+ if (!module) {
NSLinkEditErrors editError;
int errorNumber;
const char *errorName, *errMsg;
NSLinkEditError(&editError, &errorNumber, &errorName, &errMsg);
- TclLoadDbgMsg("NSLinkModule() failed: %s", errMsg);
- Tcl_AppendResult(interp, errMsg, NULL);
+ Tcl_SetObjResult(interp, Tcl_NewStringObj(errMsg, -1));
return TCL_ERROR;
}
@@ -772,9 +678,7 @@ TclpLoadMemory(
modulePtr->module = module;
modulePtr->nextPtr = NULL;
dyldLoadHandle = ckalloc(sizeof(Tcl_DyldLoadHandle));
-#if TCL_DYLD_USE_DLFCN
dyldLoadHandle->dlHandle = NULL;
-#endif
dyldLoadHandle->dyldLibHeader = NULL;
dyldLoadHandle->modulePtr = modulePtr;
newHandle = ckalloc(sizeof(*newHandle));
diff --git a/unix/tclLoadNext.c b/unix/tclLoadNext.c
index c74a29a..06df2db 100644
--- a/unix/tclLoadNext.c
+++ b/unix/tclLoadNext.c
@@ -16,10 +16,9 @@
/* Static procedures defined within this file */
-static void* FindSymbol(Tcl_Interp* interp, Tcl_LoadHandle loadHandle,
- const char* symbol);
-static void UnloadFile(Tcl_LoadHandle loadHandle);
-
+static void * FindSymbol(Tcl_Interp *interp,
+ Tcl_LoadHandle loadHandle, const char* symbol);
+static void UnloadFile(Tcl_LoadHandle loadHandle);
/*
*----------------------------------------------------------------------
@@ -93,15 +92,15 @@ TclpDlopen(
char *data;
int len, maxlen;
- NXGetMemoryBuffer(errorStream,&data,&len,&maxlen);
- Tcl_AppendResult(interp, "couldn't load file \"", fileName, "\": ",
- data, NULL);
+ NXGetMemoryBuffer(errorStream, &data, &len, &maxlen);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "couldn't load file \"%s\": %s", fileName, data));
NXCloseMemory(errorStream, NX_FREEBUFFER);
return TCL_ERROR;
}
NXCloseMemory(errorStream, NX_FREEBUFFER);
- newHandle = ckalloc(sizeof(*newHandle));
+ newHandle = ckalloc(sizeof(Tcl_LoadHandle));
newHandle->clientData = INT2PTR(1);
newHandle->findSymbolProcPtr = &FindSymbol;
newHandle->unloadFileProcPtr = &UnloadFile;
@@ -127,25 +126,25 @@ TclpDlopen(
*----------------------------------------------------------------------
*/
-static void*
+static void *
FindSymbol(
Tcl_Interp *interp,
Tcl_LoadHandle loadHandle,
const char *symbol)
{
Tcl_PackageInitProc *proc = NULL;
- if (symbol) {
+
+ if (symbol) {
char sym[strlen(symbol) + 2];
sym[0] = '_';
sym[1] = 0;
strcat(sym, symbol);
- rld_lookup(NULL, sym, (unsigned long *)&proc);
+ rld_lookup(NULL, sym, (unsigned long *) &proc);
}
if (proc == NULL && interp != NULL) {
- Tcl_ResetResult(interp);
- Tcl_AppendResult(interp, "cannot find symbol \"", symbol,
- "\"", NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "cannot find symbol \"%s\"", symbol));
Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "LOAD_SYMBOL", symbol, NULL);
}
return proc;
diff --git a/unix/tclLoadOSF.c b/unix/tclLoadOSF.c
index fbd4d5f..6515b89 100644
--- a/unix/tclLoadOSF.c
+++ b/unix/tclLoadOSF.c
@@ -103,8 +103,9 @@ TclpDlopen(
}
if (lm == LDR_NULL_MODULE) {
- Tcl_AppendResult(interp, "couldn't load file \"", fileName, "\": ",
- Tcl_PosixError(interp), NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "couldn't load file \"%s\": %s",
+ fileName, Tcl_PosixError(interp));
return TCL_ERROR;
}
@@ -155,10 +156,11 @@ FindSymbol(
Tcl_LoadHandle loadHandle,
const char *symbol)
{
- void* retval = ldr_lookup_package((char *)loadHandle, symbol);
+ void *retval = ldr_lookup_package((char *) loadHandle, symbol);
+
if (retval == NULL && interp != NULL) {
- Tcl_ResetResult(interp);
- Tcl_AppendResult(interp, "cannot find symbol\"", symbol, "\"", NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "cannot find symbol \"%s\"", symbol));
Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "LOAD_SYMBOL", symbol, NULL);
}
return retval;
diff --git a/unix/tclLoadShl.c b/unix/tclLoadShl.c
index eddd80a..968f232 100644
--- a/unix/tclLoadShl.c
+++ b/unix/tclLoadShl.c
@@ -100,8 +100,9 @@ TclpDlopen(
}
if (handle == NULL) {
- Tcl_AppendResult(interp, "couldn't load file \"", fileName, "\": ",
- Tcl_PosixError(interp), (char *) NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "couldn't load file \"%s\": %s",
+ fileName, Tcl_PosixError(interp)));
return TCL_ERROR;
}
newHandle = ckalloc(sizeof(*newHandle));
@@ -155,9 +156,9 @@ FindSymbol(
Tcl_DStringFree(&newName);
}
if (proc == NULL && interp != NULL) {
- Tcl_ResetResult(interp);
- Tcl_AppendResult(interp, "cannot find symbol\"", symbol, "\": ",
- Tcl_PosixError(interp), NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "cannot find symbol \"%s\": %s",
+ symbol, Tcl_PosixError(interp)));
}
return proc;
}
diff --git a/unix/tclUnixChan.c b/unix/tclUnixChan.c
index 3845c44..9ee37f1 100644
--- a/unix/tclUnixChan.c
+++ b/unix/tclUnixChan.c
@@ -136,10 +136,10 @@ typedef struct TtyAttrs {
#endif /* !SUPPORTS_TTY */
#define UNSUPPORTED_OPTION(detail) \
- if (interp) { \
- Tcl_AppendResult(interp, (detail), \
- " not supported for this platform", NULL); \
- Tcl_SetErrorCode(interp, "TCL", "UNSUPPORTED", NULL); \
+ if (interp) { \
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf( \
+ "%s not supported for this platform", (detail))); \
+ Tcl_SetErrorCode(interp, "TCL", "UNSUPPORTED", NULL); \
}
/*
@@ -697,9 +697,9 @@ TtySetOptionProc(
return TCL_ERROR;
} else {
if (interp) {
- Tcl_AppendResult(interp, "bad value for -handshake: "
- "must be one of xonxoff, rtscts, dtrdsr or none",
- NULL);
+ Tcl_SetObjResult(interp, Tcl_NewStringObj(
+ "bad value for -handshake: must be one of"
+ " xonxoff, rtscts, dtrdsr or none", -1));
Tcl_SetErrorCode(interp, "TCL", "OPERATION", "FCONFIGURE",
"VALUE", NULL);
}
@@ -720,8 +720,9 @@ TtySetOptionProc(
return TCL_ERROR;
} else if (argc != 2) {
if (interp) {
- Tcl_AppendResult(interp, "bad value for -xchar: "
- "should be a list of two elements", NULL);
+ Tcl_SetObjResult(interp, Tcl_NewStringObj(
+ "bad value for -xchar: should be a list of"
+ " two elements", -1));
Tcl_SetErrorCode(interp, "TCL", "OPERATION", "FCONFIGURE",
"VALUE", NULL);
}
@@ -773,8 +774,9 @@ TtySetOptionProc(
}
if ((argc % 2) == 1) {
if (interp) {
- Tcl_AppendResult(interp, "bad value for -ttycontrol: "
- "should be a list of signal,value pairs", NULL);
+ Tcl_SetObjResult(interp, Tcl_NewStringObj(
+ "bad value for -ttycontrol: should be a list of"
+ " signal,value pairs", -1));
Tcl_SetErrorCode(interp, "TCL", "OPERATION", "FCONFIGURE",
"VALUE", NULL);
}
@@ -822,9 +824,9 @@ TtySetOptionProc(
#endif /* SETBREAK */
} else {
if (interp) {
- Tcl_AppendResult(interp, "bad signal \"", argv[i],
- "\" for -ttycontrol: must be "
- "DTR, RTS or BREAK", NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "bad signal \"%s\" for -ttycontrol: must be"
+ " DTR, RTS or BREAK", argv[i]));
Tcl_SetErrorCode(interp, "TCL", "OPERATION", "FCONFIGURE",
"VALUE", NULL);
}
@@ -1388,8 +1390,8 @@ TtyParseMode(
stopPtr, &end);
if ((i != 4) || (mode[end] != '\0')) {
if (interp != NULL) {
- Tcl_AppendResult(interp, bad, ": should be baud,parity,data,stop",
- NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "%s: should be baud,parity,data,stop", bad));
Tcl_SetErrorCode(interp, "TCL", "VALUE", "SERIALMODE", NULL);
}
return TCL_ERROR;
@@ -1412,13 +1414,14 @@ TtyParseMode(
#endif /* PAREXT|USE_TERMIO */
== NULL) {
if (interp != NULL) {
- Tcl_AppendResult(interp, bad, " parity: should be ",
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "%s parity: should be %s", bad,
#if defined(PAREXT) || defined(USE_TERMIO)
- "n, o, e, m, or s",
+ "n, o, e, m, or s"
#else
- "n, o, or e",
+ "n, o, or e"
#endif /* PAREXT|USE_TERMIO */
- NULL);
+ ));
Tcl_SetErrorCode(interp, "TCL", "VALUE", "SERIALMODE", NULL);
}
return TCL_ERROR;
@@ -1426,15 +1429,16 @@ TtyParseMode(
*parityPtr = parity;
if ((*dataPtr < 5) || (*dataPtr > 8)) {
if (interp != NULL) {
- Tcl_AppendResult(interp, bad, " data: should be 5, 6, 7, or 8",
- NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "%s data: should be 5, 6, 7, or 8", bad));
Tcl_SetErrorCode(interp, "TCL", "VALUE", "SERIALMODE", NULL);
}
return TCL_ERROR;
}
if ((*stopPtr < 0) || (*stopPtr > 2)) {
if (interp != NULL) {
- Tcl_AppendResult(interp, bad, " stop: should be 1 or 2", NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "%s stop: should be 1 or 2", bad));
Tcl_SetErrorCode(interp, "TCL", "VALUE", "SERIALMODE", NULL);
}
return TCL_ERROR;
@@ -1583,8 +1587,9 @@ TclpOpenFileChannel(
if (fd < 0) {
if (interp != NULL) {
- Tcl_AppendResult(interp, "couldn't open \"", TclGetString(pathPtr),
- "\": ", Tcl_PosixError(interp), NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "couldn't open \"%s\": %s",
+ TclGetString(pathPtr), Tcl_PosixError(interp)));
}
return NULL;
}
@@ -1842,15 +1847,15 @@ Tcl_GetOpenFile(
if (chan == NULL) {
return TCL_ERROR;
}
- if ((forWriting) && ((chanMode & TCL_WRITABLE) == 0)) {
- Tcl_AppendResult(interp, "\"", chanID, "\" wasn't opened for writing",
- NULL);
+ if (forWriting && !(chanMode & TCL_WRITABLE)) {
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "\"%s\" wasn't opened for writing", chanID));
Tcl_SetErrorCode(interp, "TCL", "VALUE", "CHANNEL", "NOT_WRITABLE",
NULL);
return TCL_ERROR;
- } else if ((!forWriting) && ((chanMode & TCL_READABLE) == 0)) {
- Tcl_AppendResult(interp, "\"", chanID, "\" wasn't opened for reading",
- NULL);
+ } else if (!forWriting && !(chanMode & TCL_READABLE)) {
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "\"%s\" wasn't opened for reading", chanID));
Tcl_SetErrorCode(interp, "TCL", "VALUE", "CHANNEL", "NOT_READABLE",
NULL);
return TCL_ERROR;
@@ -1881,8 +1886,8 @@ Tcl_GetOpenFile(
f = fdopen(fd, (forWriting ? "w" : "r"));
if (f == NULL) {
- Tcl_AppendResult(interp, "cannot get a FILE * for \"", chanID,
- "\"", NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "cannot get a FILE * for \"%s\"", chanID));
Tcl_SetErrorCode(interp, "TCL", "VALUE", "CHANNEL",
"FILE_FAILURE", NULL);
return TCL_ERROR;
@@ -1892,8 +1897,8 @@ Tcl_GetOpenFile(
}
}
- Tcl_AppendResult(interp, "\"", chanID,
- "\" cannot be used to get a FILE *", NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "\"%s\" cannot be used to get a FILE *", chanID));
Tcl_SetErrorCode(interp, "TCL", "VALUE", "CHANNEL", "NO_DESCRIPTOR",
NULL);
return TCL_ERROR;
diff --git a/unix/tclUnixFCmd.c b/unix/tclUnixFCmd.c
index a695e9c..d3cc6bf 100644
--- a/unix/tclUnixFCmd.c
+++ b/unix/tclUnixFCmd.c
@@ -1320,9 +1320,9 @@ GetGroupAttribute(
if (result != 0) {
if (interp != NULL) {
- Tcl_AppendResult(interp, "could not read \"",
- TclGetString(fileName), "\": ",
- Tcl_PosixError(interp), NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "could not read \"%s\": %s",
+ TclGetString(fileName), Tcl_PosixError(interp)));
}
return TCL_ERROR;
}
@@ -1374,9 +1374,9 @@ GetOwnerAttribute(
if (result != 0) {
if (interp != NULL) {
- Tcl_AppendResult(interp, "could not read \"",
- TclGetString(fileName), "\": ",
- Tcl_PosixError(interp), NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "could not read \"%s\": %s",
+ TclGetString(fileName), Tcl_PosixError(interp)));
}
return TCL_ERROR;
}
@@ -1425,9 +1425,9 @@ GetPermissionsAttribute(
if (result != 0) {
if (interp != NULL) {
- Tcl_AppendResult(interp, "could not read \"",
- TclGetString(fileName), "\": ",
- Tcl_PosixError(interp), NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "could not read \"%s\": %s",
+ TclGetString(fileName), Tcl_PosixError(interp)));
}
return TCL_ERROR;
}
@@ -1478,9 +1478,10 @@ SetGroupAttribute(
if (groupPtr == NULL) {
if (interp != NULL) {
- Tcl_AppendResult(interp, "could not set group for file \"",
- TclGetString(fileName), "\": group \"", string,
- "\" does not exist", NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "could not set group for file \"%s\":"
+ " group \"%s\" does not exist",
+ TclGetString(fileName), string));
Tcl_SetErrorCode(interp, "TCL", "OPERATION", "SETGRP",
"NO_GROUP", NULL);
}
@@ -1494,9 +1495,9 @@ SetGroupAttribute(
if (result != 0) {
if (interp != NULL) {
- Tcl_AppendResult(interp, "could not set group for file \"",
- TclGetString(fileName), "\": ", Tcl_PosixError(interp),
- NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "could not set group for file \"%s\": %s",
+ TclGetString(fileName), Tcl_PosixError(interp)));
}
return TCL_ERROR;
}
@@ -1544,9 +1545,10 @@ SetOwnerAttribute(
if (pwPtr == NULL) {
if (interp != NULL) {
- Tcl_AppendResult(interp, "could not set owner for file \"",
- TclGetString(fileName), "\": user \"", string,
- "\" does not exist", NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "could not set owner for file \"%s\":"
+ " user \"%s\" does not exist",
+ TclGetString(fileName), string));
Tcl_SetErrorCode(interp, "TCL", "OPERATION", "SETOWN",
"NO_USER", NULL);
}
@@ -1560,9 +1562,9 @@ SetOwnerAttribute(
if (result != 0) {
if (interp != NULL) {
- Tcl_AppendResult(interp, "could not set owner for file \"",
- TclGetString(fileName), "\": ", Tcl_PosixError(interp),
- NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "could not set owner for file \"%s\": %s",
+ TclGetString(fileName), Tcl_PosixError(interp)));
}
return TCL_ERROR;
}
@@ -1630,9 +1632,9 @@ SetPermissionsAttribute(
result = TclpObjStat(fileName, &buf);
if (result != 0) {
if (interp != NULL) {
- Tcl_AppendResult(interp, "could not read \"",
- TclGetString(fileName), "\": ",
- Tcl_PosixError(interp), NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "could not read \"%s\": %s",
+ TclGetString(fileName), Tcl_PosixError(interp)));
}
return TCL_ERROR;
}
@@ -1640,8 +1642,9 @@ SetPermissionsAttribute(
if (GetModeFromPermString(NULL, modeStringPtr, &newMode) != TCL_OK) {
if (interp != NULL) {
- Tcl_AppendResult(interp, "unknown permission string format \"",
- modeStringPtr, "\"", NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "unknown permission string format \"%s\"",
+ modeStringPtr));
Tcl_SetErrorCode(interp, "TCL", "VALUE", "PERMISSION", NULL);
}
return TCL_ERROR;
@@ -1652,9 +1655,9 @@ SetPermissionsAttribute(
result = chmod(native, newMode); /* INTL: Native. */
if (result != 0) {
if (interp != NULL) {
- Tcl_AppendResult(interp, "could not set permissions for file \"",
- TclGetString(fileName), "\": ",
- Tcl_PosixError(interp), NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "could not set permissions for file \"%s\": %s",
+ TclGetString(fileName), Tcl_PosixError(interp)));
}
return TCL_ERROR;
}
@@ -2239,14 +2242,14 @@ GetReadOnlyAttribute(
if (result != 0) {
if (interp != NULL) {
- Tcl_AppendResult(interp, "could not read \"",
- TclGetString(fileName), "\": ", Tcl_PosixError(interp),
- NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "could not read \"%s\": %s",
+ TclGetString(fileName), Tcl_PosixError(interp)));
}
return TCL_ERROR;
}
- *attributePtrPtr = Tcl_NewBooleanObj((statBuf.st_flags&UF_IMMUTABLE) != 0);
+ *attributePtrPtr = Tcl_NewBooleanObj(statBuf.st_flags&UF_IMMUTABLE);
return TCL_OK;
}
@@ -2286,9 +2289,9 @@ SetReadOnlyAttribute(
if (result != 0) {
if (interp != NULL) {
- Tcl_AppendResult(interp, "could not read \"",
- TclGetString(fileName), "\": ", Tcl_PosixError(interp),
- NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "could not read \"%s\": %s",
+ TclGetString(fileName), Tcl_PosixError(interp)));
}
return TCL_ERROR;
}
@@ -2303,9 +2306,9 @@ SetReadOnlyAttribute(
result = chflags(native, statBuf.st_flags); /* INTL: Native. */
if (result != 0) {
if (interp != NULL) {
- Tcl_AppendResult(interp, "could not set flags for file \"",
- TclGetString(fileName), "\": ", Tcl_PosixError(interp),
- NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "could not set flags for file \"%s\": %s",
+ TclGetString(fileName), Tcl_PosixError(interp)));
}
return TCL_ERROR;
}
diff --git a/unix/tclUnixFile.c b/unix/tclUnixFile.c
index c213050..01fc6fe 100644
--- a/unix/tclUnixFile.c
+++ b/unix/tclUnixFile.c
@@ -310,10 +310,9 @@ TclpMatchInDirectory(
if (d == NULL) {
Tcl_DStringFree(&ds);
if (interp != NULL) {
- Tcl_ResetResult(interp);
- Tcl_AppendResult(interp, "couldn't read directory \"",
- Tcl_DStringValue(&dsOrig), "\": ",
- Tcl_PosixError(interp), NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "couldn't read directory \"%s\": %s",
+ Tcl_DStringValue(&dsOrig), Tcl_PosixError(interp)));
}
Tcl_DStringFree(&dsOrig);
Tcl_DecrRefCount(fileNamePtr);
@@ -771,9 +770,9 @@ TclpGetCwd(
#endif
{
if (interp != NULL) {
- Tcl_AppendResult(interp,
- "error getting working directory name: ",
- Tcl_PosixError(interp), NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "error getting working directory name: %s",
+ Tcl_PosixError(interp)));
}
return NULL;
}
diff --git a/unix/tclUnixPipe.c b/unix/tclUnixPipe.c
index 377b84b..654c9d8 100644
--- a/unix/tclUnixPipe.c
+++ b/unix/tclUnixPipe.c
@@ -267,35 +267,34 @@ TclpTempFileName(void)
}
/*
- *-----------------------------------------------------------------------------
+ *----------------------------------------------------------------------------
*
* TclpTempFileNameForLibrary --
*
- * Constructs a file name in the native file system where a
- * dynamically loaded library may be placed.
+ * Constructs a file name in the native file system where a dynamically
+ * loaded library may be placed.
*
* Results:
- * Returns the constructed file name. If an error occurs,
- * returns NULL and leaves an error message in the interpreter
- * result.
+ * Returns the constructed file name. If an error occurs, returns NULL
+ * and leaves an error message in the interpreter result.
*
- * On Unix, it works to load a shared object from a file of any
- * name, so this function is merely a thin wrapper around
- * TclpTempFileName().
+ * On Unix, it works to load a shared object from a file of any name, so this
+ * function is merely a thin wrapper around TclpTempFileName().
*
- *-----------------------------------------------------------------------------
+ *----------------------------------------------------------------------------
*/
-Tcl_Obj*
-TclpTempFileNameForLibrary(Tcl_Interp* interp, /* Tcl interpreter */
- Tcl_Obj* path) /* Path name of the library
- * in the VFS */
+Tcl_Obj *
+TclpTempFileNameForLibrary(
+ Tcl_Interp *interp, /* Tcl interpreter. */
+ Tcl_Obj *path) /* Path name of the library in the VFS. */
{
- Tcl_Obj* retval;
- retval = TclpTempFileName();
+ Tcl_Obj *retval = TclpTempFileName();
+
if (retval == NULL) {
- Tcl_AppendResult(interp, "couldn't create temporary file: ",
- Tcl_PosixError(interp), NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "couldn't create temporary file: %s",
+ Tcl_PosixError(interp)));
}
return retval;
}
@@ -442,8 +441,8 @@ TclpCreateProcess(
*/
if (TclpCreatePipe(&errPipeIn, &errPipeOut) == 0) {
- Tcl_AppendResult(interp, "couldn't create pipe: ",
- Tcl_PosixError(interp), NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "couldn't create pipe: %s", Tcl_PosixError(interp)));
goto error;
}
@@ -463,8 +462,9 @@ TclpCreateProcess(
/*
* After vfork(), do not call code in the child that changes global state,
* because it is using the parent's memory space at that point and writes
- * might corrupt the parent: so ensure standard channels are initialized in
- * the parent, otherwise SetupStdFile() might initialize them in the child.
+ * might corrupt the parent: so ensure standard channels are initialized
+ * in the parent, otherwise SetupStdFile() might initialize them in the
+ * child.
*/
if (!inputFile) {
@@ -495,7 +495,7 @@ TclpCreateProcess(
|| (joinThisError &&
((dup2(1,2) == -1) || (fcntl(2, F_SETFD, 0) != 0)))) {
sprintf(errSpace,
- "%dforked process couldn't set up input/output: ", errno);
+ "%dforked process couldn't set up input/output", errno);
len = strlen(errSpace);
if (len != (size_t) write(fd, errSpace, len)) {
Tcl_Panic("TclpCreateProcess: unable to write to errPipeOut");
@@ -509,11 +509,11 @@ TclpCreateProcess(
RestoreSignals();
execvp(newArgv[0], newArgv); /* INTL: Native. */
- sprintf(errSpace, "%dcouldn't execute \"%.150s\": ", errno, argv[0]);
+ sprintf(errSpace, "%dcouldn't execute \"%.150s\"", errno, argv[0]);
len = strlen(errSpace);
- if (len != (size_t) write(fd, errSpace, len)) {
+ if (len != (size_t) write(fd, errSpace, len)) {
Tcl_Panic("TclpCreateProcess: unable to write to errPipeOut");
- }
+ }
_exit(1);
}
@@ -528,8 +528,8 @@ TclpCreateProcess(
TclStackFree(interp, dsArray);
if (pid == -1) {
- Tcl_AppendResult(interp, "couldn't fork child process: ",
- Tcl_PosixError(interp), NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "couldn't fork child process: %s", Tcl_PosixError(interp)));
goto error;
}
@@ -546,9 +546,11 @@ TclpCreateProcess(
count = read(fd, errSpace, (size_t) (sizeof(errSpace) - 1));
if (count > 0) {
char *end;
+
errSpace[count] = 0;
errno = strtol(errSpace, &end, 10);
- Tcl_AppendResult(interp, end, Tcl_PosixError(interp), NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf("%s: %s",
+ end, Tcl_PosixError(interp)));
goto error;
}
@@ -832,8 +834,8 @@ Tcl_CreatePipe(
int fileNums[2];
if (pipe(fileNums) < 0) {
- Tcl_AppendResult(interp, "pipe creation failed: ",
- Tcl_PosixError(interp), NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf("pipe creation failed: %s",
+ Tcl_PosixError(interp)));
return TCL_ERROR;
}
diff --git a/unix/tclUnixSock.c b/unix/tclUnixSock.c
index 1e9d4eb..102c620 100644
--- a/unix/tclUnixSock.c
+++ b/unix/tclUnixSock.c
@@ -21,10 +21,10 @@
#define CLEAR_BITS(var, bits) ((var) &= ~(bits))
/* "sock" + a pointer in hex + \0 */
-#define SOCK_CHAN_LENGTH 4 + sizeof(void*) * 2 + 1
-#define SOCK_TEMPLATE "sock%lx"
+#define SOCK_CHAN_LENGTH (4 + sizeof(void *) * 2 + 1)
+#define SOCK_TEMPLATE "sock%lx"
-#undef SOCKET /* Possible conflict with win32 SOCKET */
+#undef SOCKET /* Possible conflict with win32 SOCKET */
/*
* This is needed to comply with the strict aliasing rules of GCC, but it also
@@ -58,19 +58,23 @@ struct TcpState {
/*
* Only needed for server sockets
*/
- Tcl_TcpAcceptProc *acceptProc; /* Proc to call on accept. */
- ClientData acceptProcData; /* The data for the accept proc. */
+
+ Tcl_TcpAcceptProc *acceptProc;
+ /* Proc to call on accept. */
+ ClientData acceptProcData; /* The data for the accept proc. */
+
/*
* Only needed for client sockets
*/
- struct addrinfo *addrlist; /* addresses to connect to */
- struct addrinfo *addr; /* iterator over addrlist */
- struct addrinfo *myaddrlist; /* local address */
- struct addrinfo *myaddr; /* iterator over myaddrlist */
- int filehandlers; /* Caches FileHandlers that get set up while
- * an async socket is not yet connected */
- int status; /* Cache status of async socket */
- int cachedBlocking; /* Cache blocking mode of async socket */
+
+ struct addrinfo *addrlist; /* Addresses to connect to. */
+ struct addrinfo *addr; /* Iterator over addrlist. */
+ struct addrinfo *myaddrlist;/* Local address. */
+ struct addrinfo *myaddr; /* Iterator over myaddrlist. */
+ int filehandlers; /* Caches FileHandlers that get set up while
+ * an async socket is not yet connected. */
+ int status; /* Cache status of async socket. */
+ int cachedBlocking; /* Cache blocking mode of async socket. */
};
/*
@@ -90,9 +94,7 @@ struct TcpState {
#ifndef SOMAXCONN
# define SOMAXCONN 100
-#endif /* SOMAXCONN */
-
-#if (SOMAXCONN < 100)
+#elif (SOMAXCONN < 100)
# undef SOMAXCONN
# define SOMAXCONN 100
#endif /* SOMAXCONN < 100 */
@@ -217,7 +219,7 @@ InitializeHostName(
if (native == NULL) {
native = tclEmptyStringRep;
}
-#else
+#else /* !NO_UNAME */
/*
* Uname doesn't exist; try gethostname instead.
*
@@ -242,7 +244,7 @@ InitializeHostName(
if (gethostname(buffer, sizeof(buffer)) > -1) { /* INTL: Native. */
native = buffer;
}
-#endif
+#endif /* NO_UNAME */
*encodingPtr = Tcl_GetEncoding(NULL, NULL);
*lengthPtr = strlen(native);
@@ -344,7 +346,7 @@ TcpBlockModeProc(
* TCL_MODE_BLOCKING or
* TCL_MODE_NONBLOCKING. */
{
- TcpState *statePtr = (TcpState *) instanceData;
+ TcpState *statePtr = instanceData;
if (mode == TCL_MODE_BLOCKING) {
CLEAR_BITS(statePtr->flags, TCP_ASYNC_SOCKET);
@@ -443,7 +445,7 @@ TcpInputProc(
* buffer? */
int *errorCodePtr) /* Where to store error code. */
{
- TcpState *statePtr = (TcpState *) instanceData;
+ TcpState *statePtr = instanceData;
int bytesRead;
*errorCodePtr = 0;
@@ -493,7 +495,7 @@ TcpOutputProc(
int toWrite, /* How many bytes to write? */
int *errorCodePtr) /* Where to store error code. */
{
- TcpState *statePtr = (TcpState *) instanceData;
+ TcpState *statePtr = instanceData;
int written;
*errorCodePtr = 0;
@@ -532,7 +534,7 @@ TcpCloseProc(
ClientData instanceData, /* The socket to close. */
Tcl_Interp *interp) /* For error reporting - unused. */
{
- TcpState *statePtr = (TcpState *) instanceData;
+ TcpState *statePtr = instanceData;
int errorCode = 0;
TcpFdList *fds;
@@ -593,7 +595,7 @@ TcpClose2Proc(
Tcl_Interp *interp, /* For error reporting. */
int flags) /* Flags that indicate which side to close. */
{
- TcpState *statePtr = (TcpState *) instanceData;
+ TcpState *statePtr = instanceData;
int errorCode = 0;
int sd;
@@ -610,8 +612,8 @@ TcpClose2Proc(
break;
default:
if (interp) {
- Tcl_AppendResult(interp,
- "Socket close2proc called bidirectionally", NULL);
+ Tcl_SetObjResult(interp, Tcl_NewStringObj(
+ "socket close2proc called bidirectionally", -1));
}
return TCL_ERROR;
}
@@ -653,7 +655,7 @@ TcpGetOptionProc(
Tcl_DString *dsPtr) /* Where to store the computed value;
* initialized by caller. */
{
- TcpState *statePtr = (TcpState *) instanceData;
+ TcpState *statePtr = instanceData;
char host[NI_MAXHOST], port[NI_MAXSERV];
size_t len = 0;
int reverseDNS = 0;
@@ -670,7 +672,7 @@ TcpGetOptionProc(
if (statePtr->status == 0) {
ret = getsockopt(statePtr->fds.fd, SOL_SOCKET, SO_ERROR,
- (char *)&err, &optlen);
+ (char *) &err, &optlen);
if (ret < 0) {
err = errno;
}
@@ -688,9 +690,8 @@ TcpGetOptionProc(
reverseDNS = NI_NUMERICHOST;
}
- if ((len == 0) ||
- ((len > 1) && (optionName[1] == 'p') &&
- (strncmp(optionName, "-peername", len) == 0))) {
+ if ((len == 0) || ((len > 1) && (optionName[1] == 'p') &&
+ (strncmp(optionName, "-peername", len) == 0))) {
address peername;
socklen_t size = sizeof(peername);
@@ -721,16 +722,16 @@ TcpGetOptionProc(
if (len) {
if (interp) {
- Tcl_AppendResult(interp, "can't get peername: ",
- Tcl_PosixError(interp), NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "can't get peername: %s",
+ Tcl_PosixError(interp)));
}
return TCL_ERROR;
}
}
}
- if ((len == 0) ||
- ((len > 1) && (optionName[1] == 's') &&
+ if ((len == 0) || ((len > 1) && (optionName[1] == 's') &&
(strncmp(optionName, "-sockname", len) == 0))) {
TcpFdList *fds;
address sockname;
@@ -772,7 +773,7 @@ TcpGetOptionProc(
sockname.sa6.sin6_addr.s6_addr[15] == 0)) {
flags |= NI_NUMERICHOST;
}
-#endif
+#endif /* NEED_FAKE_RFC2553 */
}
getnameinfo(&sockname.sa, size, host, sizeof(host), port,
sizeof(port), flags);
@@ -787,8 +788,8 @@ TcpGetOptionProc(
Tcl_DStringEndSublist(dsPtr);
} else {
if (interp) {
- Tcl_AppendResult(interp, "can't get sockname: ",
- Tcl_PosixError(interp), NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "can't get sockname: %s", Tcl_PosixError(interp)));
}
return TCL_ERROR;
}
@@ -825,7 +826,7 @@ TcpWatchProc(
* TCL_READABLE, TCL_WRITABLE and
* TCL_EXCEPTION. */
{
- TcpState *statePtr = (TcpState *) instanceData;
+ TcpState *statePtr = instanceData;
if (statePtr->acceptProc != NULL) {
/*
@@ -842,8 +843,7 @@ TcpWatchProc(
statePtr->filehandlers = mask;
} else if (mask) {
Tcl_CreateFileHandler(statePtr->fds.fd, mask,
- (Tcl_FileProc *) Tcl_NotifyChannel,
- (ClientData) statePtr->channel);
+ (Tcl_FileProc *) Tcl_NotifyChannel, statePtr->channel);
} else {
Tcl_DeleteFileHandler(statePtr->fds.fd);
}
@@ -874,7 +874,7 @@ TcpGetHandleProc(
int direction, /* Not used. */
ClientData *handlePtr) /* Where to store the handle. */
{
- TcpState *statePtr = (TcpState *) instanceData;
+ TcpState *statePtr = instanceData;
*handlePtr = INT2PTR(statePtr->fds.fd);
return TCL_OK;
@@ -946,12 +946,11 @@ CreateClientSocket(
}
for (state->addr = state->addrlist; state->addr != NULL;
- state->addr = state->addr->ai_next) {
-
+ state->addr = state->addr->ai_next) {
status = -1;
for (state->myaddr = state->myaddrlist; state->myaddr != NULL;
- state->myaddr = state->myaddr->ai_next) {
+ state->myaddr = state->myaddr->ai_next) {
int reuseaddr;
/*
@@ -967,6 +966,7 @@ CreateClientSocket(
* Close the socket if it is still open from the last unsuccessful
* iteration.
*/
+
if (state->fds.fd >= 0) {
close(state->fds.fd);
state->fds.fd = -1;
@@ -991,7 +991,8 @@ CreateClientSocket(
TclSockMinimumBuffers(INT2PTR(state->fds.fd), SOCKET_BUFSIZE);
if (async) {
- status = TclUnixSetBlockingMode(state->fds.fd, TCL_MODE_NONBLOCKING);
+ status = TclUnixSetBlockingMode(state->fds.fd,
+ TCL_MODE_NONBLOCKING);
if (status < 0) {
continue;
}
@@ -1001,7 +1002,7 @@ CreateClientSocket(
(void) setsockopt(state->fds.fd, SOL_SOCKET, SO_REUSEADDR,
(char *) &reuseaddr, sizeof(reuseaddr));
status = bind(state->fds.fd, state->myaddr->ai_addr,
- state->myaddr->ai_addrlen);
+ state->myaddr->ai_addrlen);
if (status < 0) {
continue;
}
@@ -1014,24 +1015,25 @@ CreateClientSocket(
*/
status = connect(state->fds.fd, state->addr->ai_addr,
- state->addr->ai_addrlen);
+ state->addr->ai_addrlen);
if (status < 0 && errno == EINPROGRESS) {
Tcl_CreateFileHandler(state->fds.fd,
- TCL_WRITABLE | TCL_EXCEPTION,
- TcpAsyncCallback, state);
+ TCL_WRITABLE|TCL_EXCEPTION, TcpAsyncCallback, state);
return TCL_OK;
reenter:
Tcl_DeleteFileHandler(state->fds.fd);
+
/*
* Read the error state from the socket to see if the async
* connection has succeeded or failed. As this clears the
* error condition, we cache the status in the socket state
* struct for later retrieval by [fconfigure -error].
*/
+
optlen = sizeof(int);
getsockopt(state->fds.fd, SOL_SOCKET, SO_ERROR,
- (char *)&status, &optlen);
+ (char *) &status, &optlen);
state->status = status;
}
if (status == 0) {
@@ -1047,6 +1049,7 @@ out:
/*
* An asynchonous connection has finally succeeded or failed.
*/
+
TcpWatchProc(state, state->filehandlers);
TclUnixSetBlockingMode(state->fds.fd, state->cachedBlocking);
@@ -1058,17 +1061,18 @@ out:
* hurt that this is also called in the successful case and will save
* the event mechanism one roundtrip through select().
*/
- Tcl_NotifyChannel(state->channel, TCL_WRITABLE);
+ Tcl_NotifyChannel(state->channel, TCL_WRITABLE);
} else if (status != 0) {
/*
* Failure for either a synchronous connection, or an async one that
* failed before it could enter background mode, e.g. because an
* invalid -myaddr was given.
*/
+
if (interp != NULL) {
- Tcl_AppendResult(interp, "couldn't open socket: ",
- Tcl_PosixError(interp), NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "couldn't open socket: %s", Tcl_PosixError(interp)));
}
return TCL_ERROR;
}
@@ -1111,13 +1115,16 @@ Tcl_OpenTcpClient(
/*
* Do the name lookups for the local and remote addresses.
*/
- if (!TclCreateSocketAddress(interp, &addrlist, host, port, 0, &errorMsg) ||
- !TclCreateSocketAddress(interp, &myaddrlist, myaddr, myport, 1, &errorMsg)) {
+
+ if (!TclCreateSocketAddress(interp, &addrlist, host, port, 0, &errorMsg)
+ || !TclCreateSocketAddress(interp, &myaddrlist, myaddr, myport, 1,
+ &errorMsg)) {
if (addrlist != NULL) {
freeaddrinfo(addrlist);
}
if (interp != NULL) {
- Tcl_AppendResult(interp, "couldn't open socket: ", errorMsg, NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "couldn't open socket: %s", errorMsg));
}
return NULL;
}
@@ -1141,10 +1148,10 @@ Tcl_OpenTcpClient(
return NULL;
}
- sprintf(channelName, SOCK_TEMPLATE, (long)state);
+ sprintf(channelName, SOCK_TEMPLATE, (long) state);
- state->channel = Tcl_CreateChannel(&tcpChannelType, channelName,
- state, (TCL_READABLE | TCL_WRITABLE));
+ state->channel = Tcl_CreateChannel(&tcpChannelType, channelName, state,
+ (TCL_READABLE | TCL_WRITABLE));
if (Tcl_SetChannelOption(interp, state->channel, "-translation",
"auto crlf") == TCL_ERROR) {
Tcl_Close(NULL, state->channel);
@@ -1257,6 +1264,7 @@ Tcl_OpenTcpServer(
* Try to record and return the most meaningful error message, i.e. the
* one from the first socket that went the farthest before it failed.
*/
+
enum { LOOKUP, SOCKET, BIND, LISTEN } howfar = LOOKUP;
int my_errno = 0;
@@ -1267,7 +1275,7 @@ Tcl_OpenTcpServer(
for (addrPtr = addrlist; addrPtr != NULL; addrPtr = addrPtr->ai_next) {
sock = socket(addrPtr->ai_family, addrPtr->ai_socktype,
- addrPtr->ai_protocol);
+ addrPtr->ai_protocol);
if (sock == -1) {
if (howfar < SOCKET) {
howfar = SOCKET;
@@ -1318,7 +1326,7 @@ Tcl_OpenTcpServer(
(void) setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY,
&v6only, sizeof(v6only));
}
-#endif
+#endif /* IPV6_V6ONLY */
status = bind(sock, addrPtr->ai_addr, addrPtr->ai_addrlen);
if (status == -1) {
@@ -1360,7 +1368,7 @@ Tcl_OpenTcpServer(
memset(statePtr, 0, sizeof(TcpState));
statePtr->acceptProc = acceptProc;
statePtr->acceptProcData = acceptProcData;
- sprintf(channelName, SOCK_TEMPLATE, (long)statePtr);
+ sprintf(channelName, SOCK_TEMPLATE, (long) statePtr);
newfds = &statePtr->fds;
} else {
newfds = ckalloc(sizeof(TcpFdList));
@@ -1389,13 +1397,15 @@ Tcl_OpenTcpServer(
return statePtr->channel;
}
if (interp != NULL) {
- Tcl_AppendResult(interp, "couldn't open socket: ", NULL);
+ Tcl_Obj *errorObj = Tcl_NewStringObj("couldn't open socket: ", -1);
+
if (errorMsg == NULL) {
errno = my_errno;
- Tcl_AppendResult(interp, Tcl_PosixError(interp), NULL);
+ Tcl_AppendToObj(errorObj, Tcl_PosixError(interp), -1);
} else {
- Tcl_AppendResult(interp, errorMsg, NULL);
+ Tcl_AppendToObj(errorObj, errorMsg, -1);
}
+ Tcl_SetObjResult(interp, errorObj);
}
if (sock != -1) {
close(sock);
@@ -1434,7 +1444,7 @@ TcpAccept(
char host[NI_MAXHOST], port[NI_MAXSERV];
len = sizeof(addr);
- newsock = accept(fds->fd, &(addr.sa), &len);
+ newsock = accept(fds->fd, &addr.sa, &len);
if (newsock < 0) {
return;
}
@@ -1451,7 +1461,7 @@ TcpAccept(
newSockState->flags = 0;
newSockState->fds.fd = newsock;
- sprintf(channelName, SOCK_TEMPLATE, (long)newSockState);
+ sprintf(channelName, SOCK_TEMPLATE, (long) newSockState);
newSockState->channel = Tcl_CreateChannel(&tcpChannelType, channelName,
newSockState, (TCL_READABLE | TCL_WRITABLE));
@@ -1459,7 +1469,7 @@ TcpAccept(
"auto crlf");
if (fds->statePtr->acceptProc != NULL) {
- getnameinfo(&(addr.sa), len, host, sizeof(host), port, sizeof(port),
+ getnameinfo(&addr.sa, len, host, sizeof(host), port, sizeof(port),
NI_NUMERICHOST|NI_NUMERICSERV);
fds->statePtr->acceptProc(fds->statePtr->acceptProcData,
newSockState->channel, host, atoi(port));