From bef67008420c0d053694ff9c6e02e4b23950f102 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Mon, 13 Jan 2025 09:37:34 +0000 Subject: Re-enable Tcl_SavedResult testcases. They won't work if TCL_NO_DEPRECATED is set. --- generic/tclTest.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/generic/tclTest.c b/generic/tclTest.c index 8db9a7a..1e50106 100644 --- a/generic/tclTest.c +++ b/generic/tclTest.c @@ -24,7 +24,6 @@ #ifdef TCL_NO_DEPRECATED # define TCL_UTF_MAX 4 #else -# define TCL_NO_DEPRECATED # define TCL_UTF_MAX 3 #endif #define TCLBOOLWARNING(boolPtr) /* needed here because we compile with -Wc++-compat */ @@ -144,9 +143,9 @@ typedef struct { * was called for a result. */ -#if TCL_UTF_MAX < 4 +#ifdef TCL_NO_DEPRECATED static int freeCount; -#endif /* TCL_UTF_MAX */ +#endif /* TCL_NO_DEPRECATED */ /* * Boolean flag used by the "testsetmainloop" and "testexitmainloop" commands. @@ -297,10 +296,10 @@ static Tcl_ObjCmdProc TestregexpObjCmd; static Tcl_ObjCmdProc TestreturnObjCmd; static void TestregexpXflags(const char *string, size_t length, int *cflagsPtr, int *eflagsPtr); -#if TCL_UTF_MAX < 4 +#ifdef TCL_NO_DEPRECATED static Tcl_ObjCmdProc TestsaveresultCmd; static Tcl_FreeProc TestsaveresultFree; -#endif /* TCL_UTF_MAX */ +#endif /* TCL_NO_DEPRECATED */ static Tcl_CmdProc TestsetassocdataCmd; static Tcl_CmdProc TestsetCmd; static Tcl_CmdProc Testset2Cmd; @@ -690,10 +689,10 @@ Tcltest_Init( NULL, NULL); Tcl_CreateObjCommand(interp, "testreturn", TestreturnObjCmd, NULL, NULL); -#if TCL_UTF_MAX < 4 +#ifdef TCL_NO_DEPRECATED Tcl_CreateObjCommand(interp, "testsaveresult", TestsaveresultCmd, NULL, NULL); -#endif +#endif /* TCL_NO_DEPRECATED */ Tcl_CreateCommand(interp, "testservicemode", TestServiceModeCmd, NULL, NULL); Tcl_CreateCommand(interp, "testsetassocdata", TestsetassocdataCmd, @@ -5918,7 +5917,7 @@ Testset2Cmd( *---------------------------------------------------------------------- */ -#if TCL_UTF_MAX < 4 +#ifdef TCL_NO_DEPRECATED static int TestsaveresultCmd( TCL_UNUSED(void *), @@ -6036,7 +6035,7 @@ TestsaveresultFree( { freeCount++; } -#endif /* TCL_UTF_MAX */ +#endif /* TCL_NO_DEPRECATED */ /* *---------------------------------------------------------------------- -- cgit v0.12 From e7a7b152eedd5ad7da7ca920e62bfd7a2197cbaf Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Mon, 13 Jan 2025 10:23:33 +0000 Subject: #ifdef TCL_NO_DEPRECATED -> #ifndef TCL_NO_DEPRECATED --- generic/tclTest.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/generic/tclTest.c b/generic/tclTest.c index 1e50106..34d284a 100644 --- a/generic/tclTest.c +++ b/generic/tclTest.c @@ -143,7 +143,7 @@ typedef struct { * was called for a result. */ -#ifdef TCL_NO_DEPRECATED +#ifndef TCL_NO_DEPRECATED static int freeCount; #endif /* TCL_NO_DEPRECATED */ @@ -296,7 +296,7 @@ static Tcl_ObjCmdProc TestregexpObjCmd; static Tcl_ObjCmdProc TestreturnObjCmd; static void TestregexpXflags(const char *string, size_t length, int *cflagsPtr, int *eflagsPtr); -#ifdef TCL_NO_DEPRECATED +#ifndef TCL_NO_DEPRECATED static Tcl_ObjCmdProc TestsaveresultCmd; static Tcl_FreeProc TestsaveresultFree; #endif /* TCL_NO_DEPRECATED */ @@ -689,7 +689,7 @@ Tcltest_Init( NULL, NULL); Tcl_CreateObjCommand(interp, "testreturn", TestreturnObjCmd, NULL, NULL); -#ifdef TCL_NO_DEPRECATED +#ifndef TCL_NO_DEPRECATED Tcl_CreateObjCommand(interp, "testsaveresult", TestsaveresultCmd, NULL, NULL); #endif /* TCL_NO_DEPRECATED */ @@ -5917,7 +5917,7 @@ Testset2Cmd( *---------------------------------------------------------------------- */ -#ifdef TCL_NO_DEPRECATED +#ifndef TCL_NO_DEPRECATED static int TestsaveresultCmd( TCL_UNUSED(void *), -- cgit v0.12 From 74c0e694b2ccd97cb89fdc870e9c982a804bda21 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Tue, 14 Jan 2025 12:11:39 +0000 Subject: Undo previous commit, it didn't really help. Fix tests for Tcl_UtfNext/Tcl_UtfPrev, which were always expected in UTF-32 mode. Make Tcl_SetResult() usable with TCL_NO_DEPRECATED too, otherwise it leads to a test crash Always install header-files before documentation: If documentation copying takes too long it can be aborted. --- generic/tclDecls.h | 4 ++-- generic/tclTest.c | 28 +++++++++++++++++----------- unix/Makefile.in | 2 +- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/generic/tclDecls.h b/generic/tclDecls.h index 8f80023..dc573ec 100644 --- a/generic/tclDecls.h +++ b/generic/tclDecls.h @@ -4331,8 +4331,9 @@ extern const TclStubs *tclStubsPtr; #undef Tcl_SaveResult #undef Tcl_RestoreResult #undef Tcl_DiscardResult -#undef Tcl_SetResult #undef Tcl_MakeSafe +#endif /* TCL_NO_DEPRECATED */ +#undef Tcl_SetResult #define Tcl_SetResult(interp, result, freeProc) \ do { \ const char *__result = result; \ @@ -4346,7 +4347,6 @@ extern const TclStubs *tclStubsPtr; } \ } \ } while(0) -#endif /* TCL_NO_DEPRECATED */ #if defined(USE_TCL_STUBS) # if defined(_WIN32) && defined(_WIN64) diff --git a/generic/tclTest.c b/generic/tclTest.c index 34d284a..3cf0255 100644 --- a/generic/tclTest.c +++ b/generic/tclTest.c @@ -15,13 +15,14 @@ * this file, and for a DISCLAIMER OF ALL WARRANTIES. */ -#undef STATIC_BUILD #undef BUILD_tcl +#undef STATIC_BUILD #ifndef USE_TCL_STUBS # define USE_TCL_STUBS #endif #undef TCL_UTF_MAX #ifdef TCL_NO_DEPRECATED +# undef TCL_NO_DEPRECATED # define TCL_UTF_MAX 4 #else # define TCL_UTF_MAX 3 @@ -31,6 +32,11 @@ #include "tclOO.h" #include +/* We want to test the UTF-32 versions of the following 3 functions */ +#undef Tcl_UtfNext +#undef Tcl_UtfPrev +#define Tcl_UtfNext (tclStubsPtr->tcl_UtfNext) +#define Tcl_UtfPrev (tclStubsPtr->tcl_UtfPrev) /* * Required for Testregexp*Cmd */ @@ -143,9 +149,9 @@ typedef struct { * was called for a result. */ -#ifndef TCL_NO_DEPRECATED +#if TCL_UTF_MAX < 4 static int freeCount; -#endif /* TCL_NO_DEPRECATED */ +#endif /* TCL_UTF_MAX */ /* * Boolean flag used by the "testsetmainloop" and "testexitmainloop" commands. @@ -296,10 +302,10 @@ static Tcl_ObjCmdProc TestregexpObjCmd; static Tcl_ObjCmdProc TestreturnObjCmd; static void TestregexpXflags(const char *string, size_t length, int *cflagsPtr, int *eflagsPtr); -#ifndef TCL_NO_DEPRECATED +#if TCL_UTF_MAX < 4 static Tcl_ObjCmdProc TestsaveresultCmd; static Tcl_FreeProc TestsaveresultFree; -#endif /* TCL_NO_DEPRECATED */ +#endif /* TCL_UTF_MAX */ static Tcl_CmdProc TestsetassocdataCmd; static Tcl_CmdProc TestsetCmd; static Tcl_CmdProc Testset2Cmd; @@ -689,10 +695,10 @@ Tcltest_Init( NULL, NULL); Tcl_CreateObjCommand(interp, "testreturn", TestreturnObjCmd, NULL, NULL); -#ifndef TCL_NO_DEPRECATED +#if TCL_UTF_MAX < 4 Tcl_CreateObjCommand(interp, "testsaveresult", TestsaveresultCmd, NULL, NULL); -#endif /* TCL_NO_DEPRECATED */ +#endif Tcl_CreateCommand(interp, "testservicemode", TestServiceModeCmd, NULL, NULL); Tcl_CreateCommand(interp, "testsetassocdata", TestsetassocdataCmd, @@ -2167,7 +2173,7 @@ static int UtfExtWrapper( if (dstCharsVar == NULL || (valueObj = Tcl_ObjGetVar2(interp, dstCharsVar, NULL, 0)) == NULL ) { - Tcl_SetResult(interp, + Tcl_SetResult(interp, (char *) "dstCharsVar must be specified with integer value if " "TCL_ENCODING_CHAR_LIMIT set in flags.", TCL_STATIC); return TCL_ERROR; @@ -2190,7 +2196,7 @@ static int UtfExtWrapper( &dstWrote, dstCharsVar ? &dstChars : NULL); if (memcmp(bufPtr + bufLen - 4, "\xAB\xCD\xEF\xAB", 4)) { - Tcl_SetResult(interp, + Tcl_SetResult(interp, (char *) "Tcl_ExternalToUtf wrote past output buffer", TCL_STATIC); result = TCL_ERROR; @@ -5917,7 +5923,7 @@ Testset2Cmd( *---------------------------------------------------------------------- */ -#ifndef TCL_NO_DEPRECATED +#if TCL_UTF_MAX < 4 static int TestsaveresultCmd( TCL_UNUSED(void *), @@ -6035,7 +6041,7 @@ TestsaveresultFree( { freeCount++; } -#endif /* TCL_NO_DEPRECATED */ +#endif /* TCL_UTF_MAX */ /* *---------------------------------------------------------------------- diff --git a/unix/Makefile.in b/unix/Makefile.in index 1074a02..6185b71 100644 --- a/unix/Makefile.in +++ b/unix/Makefile.in @@ -994,7 +994,7 @@ INSTALL_DOC_TARGETS = install-doc INSTALL_PACKAGE_TARGETS = install-packages INSTALL_DEV_TARGETS = install-headers INSTALL_EXTRA_TARGETS = @EXTRA_INSTALL@ -INSTALL_TARGETS = $(INSTALL_BASE_TARGETS) $(INSTALL_DOC_TARGETS) $(INSTALL_DEV_TARGETS) \ +INSTALL_TARGETS = $(INSTALL_BASE_TARGETS) $(INSTALL_DEV_TARGETS) $(INSTALL_DOC_TARGETS) \ $(INSTALL_PACKAGE_TARGETS) $(INSTALL_EXTRA_TARGETS) install: $(INSTALL_TARGETS) -- cgit v0.12 From 2fe25338c3cb272a550045731f0b99ce21a36106 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Tue, 14 Jan 2025 14:16:54 +0000 Subject: Make Tcl_SetResult usable in tclTest.c, even if TCL_NO_DEPRECATED is defined --- generic/tclDecls.h | 2 +- generic/tclTest.c | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/generic/tclDecls.h b/generic/tclDecls.h index dc573ec..a02a70f 100644 --- a/generic/tclDecls.h +++ b/generic/tclDecls.h @@ -4332,7 +4332,6 @@ extern const TclStubs *tclStubsPtr; #undef Tcl_RestoreResult #undef Tcl_DiscardResult #undef Tcl_MakeSafe -#endif /* TCL_NO_DEPRECATED */ #undef Tcl_SetResult #define Tcl_SetResult(interp, result, freeProc) \ do { \ @@ -4347,6 +4346,7 @@ extern const TclStubs *tclStubsPtr; } \ } \ } while(0) +#endif /* TCL_NO_DEPRECATED */ #if defined(USE_TCL_STUBS) # if defined(_WIN32) && defined(_WIN64) diff --git a/generic/tclTest.c b/generic/tclTest.c index 3cf0255..99ae05f 100644 --- a/generic/tclTest.c +++ b/generic/tclTest.c @@ -32,6 +32,25 @@ #include "tclOO.h" #include +#if TCL_UTF_MAX > 3 +/* TCL_NO_DEPRECATED was specified, so the core doesn't have a Tcl_SetResult stub entry */ +#undef Tcl_SetResult +#define Tcl_SetResult(interp, result, freeProc) \ + do { \ + const char *__result = result; \ + Tcl_FreeProc *__freeProc = freeProc; \ + Tcl_SetObjResult(interp, Tcl_NewStringObj(__result, TCL_INDEX_NONE)); \ + if (__result != NULL && __freeProc != NULL && __freeProc != TCL_VOLATILE) { \ + if (__freeProc == TCL_DYNAMIC) { \ + ckfree(__result); \ + } else { \ + (*__freeProc)((char *)__result); \ + } \ + } \ + } while(0) +#endif /* TCL_UTF_MAX */ + + /* We want to test the UTF-32 versions of the following 3 functions */ #undef Tcl_UtfNext #undef Tcl_UtfPrev @@ -524,6 +543,9 @@ static const char version[] = TCL_PATCH_LEVEL "+" STRINGIFY(TCL_VERSION_UUID) #ifdef USE_NMAKE ".nmake" #endif +#if TCL_UTF_MAX > 3 + ".no-deprecate" +#endif #if !TCL_THREADS ".no-thread" #endif -- cgit v0.12 From 1345a76e91c7b805f4acb78ee9c151e5067b3850 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Wed, 15 Jan 2025 17:19:51 +0000 Subject: change (internal) TclpLoadMemory() signature, backported from 9.0. Install headers before documentation. If documentation copying (which is slow) is aborted, it doesn't affect development work --- generic/tclIOUtil.c | 28 ++++++++-------- generic/tclInt.h | 4 +-- generic/tclLoadNone.c | 8 ++--- unix/Makefile.in | 2 +- unix/tclLoadDl.c | 57 ++++++++++++++++++++++++-------- unix/tclLoadDyld.c | 16 ++------- win/tclWinLoad.c | 91 ++++++++++++++++++++++++++++++++++----------------- 7 files changed, 126 insertions(+), 80 deletions(-) diff --git a/generic/tclIOUtil.c b/generic/tclIOUtil.c index ae3c2bc..23d25b4 100644 --- a/generic/tclIOUtil.c +++ b/generic/tclIOUtil.c @@ -3262,10 +3262,11 @@ Tcl_LoadFile( } /* - * The filesystem doesn't support 'load', so we fall back on the following - * technique: - * - * First check if it is readable -- and exists! + * The filesystem doesn't support 'load'. Fall to the following: + */ + + /* + * Make sure the file is accessible. */ if (Tcl_FSAccess(pathPtr, R_OK) != 0) { @@ -3279,9 +3280,9 @@ Tcl_LoadFile( #ifdef TCL_LOAD_FROM_MEMORY /* - * The platform supports loading code from memory, so ask for a buffer of - * the appropriate size, read the file into it and load the code from the - * buffer: + * The platform supports loading a dynamic shared object from memory. + * Create a sufficiently large buffer, read the file into it, and then load + * the dynamic shared object from the buffer: */ { @@ -3298,7 +3299,7 @@ Tcl_LoadFile( size = statBuf.st_size; /* - * Tcl_Read takes an int: check that file size isn't wide. + * Tcl_Read takes an int: Determine whether the file size <= INT_MAX */ if (size > INT_MAX) { @@ -3306,6 +3307,9 @@ Tcl_LoadFile( } data = Tcl_FSOpenFileChannel(interp, pathPtr, "rb", 0666); if (!data) { + if (interp) { + Tcl_ResetResult(interp); + } goto mustCopyToTempAnyway; } buffer = TclpLoadMemoryGetBuffer(size); @@ -3315,7 +3319,7 @@ Tcl_LoadFile( } ret = Tcl_Read(data, buffer, size); Tcl_Close(interp, data); - ret = TclpLoadMemory(interp, buffer, size, ret, handlePtr, + ret = TclpLoadMemory(buffer, size, ret, TclGetString(pathPtr), handlePtr, &unloadProcPtr, flags); if (ret == TCL_OK && *handlePtr != NULL) { goto resolveSymbols; @@ -3323,14 +3327,10 @@ Tcl_LoadFile( } mustCopyToTempAnyway: - if (interp) { - Tcl_ResetResult(interp); - } #endif /* TCL_LOAD_FROM_MEMORY */ /* - * Get a temporary filename to use, first to copy the file into, and then - * to load. + * Get a temporary filename, first to copy the file into, and then to load. */ copyToPtr = TclpTempFileNameForLibrary(interp, pathPtr); diff --git a/generic/tclInt.h b/generic/tclInt.h index 987611b..24e8eb7 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -3196,8 +3196,8 @@ MODULE_SCOPE int TclpDlopen(Tcl_Interp *interp, Tcl_Obj *pathPtr, MODULE_SCOPE int TclpUtime(Tcl_Obj *pathPtr, struct utimbuf *tval); #ifdef TCL_LOAD_FROM_MEMORY MODULE_SCOPE void * TclpLoadMemoryGetBuffer(size_t size); -MODULE_SCOPE int TclpLoadMemory(Tcl_Interp *interp, void *buffer, - size_t size, int codeSize, Tcl_LoadHandle *loadHandle, +MODULE_SCOPE int TclpLoadMemory(void *buffer, size_t size, + int codeSize, const char *path, Tcl_LoadHandle *loadHandle, Tcl_FSUnloadFileProc **unloadProcPtr, int flags); #endif MODULE_SCOPE void TclInitThreadStorage(void); diff --git a/generic/tclLoadNone.c b/generic/tclLoadNone.c index 1af943a..8359664 100644 --- a/generic/tclLoadNone.c +++ b/generic/tclLoadNone.c @@ -93,27 +93,23 @@ TclGuessPackageName( MODULE_SCOPE void * TclpLoadMemoryGetBuffer( - int size) /* Dummy: unused by this implementation */ + size_t size) /* Dummy: unused by this implementation */ { return NULL; } MODULE_SCOPE int TclpLoadMemory( - Tcl_Interp *interp, /* Used for error reporting. */ void *buffer, /* Dummy: unused by this implementation */ size_t size, /* Dummy: unused by this implementation */ int codeSize, /* Dummy: unused by this implementation */ + const char *path, /* Dummy: unused by this implementation */ Tcl_LoadHandle *loadHandle, /* Dummy: unused by this implementation */ Tcl_FSUnloadFileProc **unloadProcPtr, /* Dummy: unused by this implementation */ int flags) /* Dummy: unused by this implementation */ { - if (interp) { - Tcl_SetObjResult(interp, Tcl_NewStringObj("dynamic loading from memory " - "is not available on this system", -1)); - } return TCL_ERROR; } diff --git a/unix/Makefile.in b/unix/Makefile.in index 1c34c72..18b943a 100644 --- a/unix/Makefile.in +++ b/unix/Makefile.in @@ -792,7 +792,7 @@ INSTALL_DOC_TARGETS = install-doc INSTALL_PACKAGE_TARGETS = install-packages INSTALL_DEV_TARGETS = install-headers INSTALL_EXTRA_TARGETS = @EXTRA_INSTALL@ -INSTALL_TARGETS = $(INSTALL_BASE_TARGETS) $(INSTALL_DOC_TARGETS) $(INSTALL_DEV_TARGETS) \ +INSTALL_TARGETS = $(INSTALL_BASE_TARGETS) $(INSTALL_DEV_TARGETS) $(INSTALL_DOC_TARGETS) \ $(INSTALL_PACKAGE_TARGETS) $(INSTALL_EXTRA_TARGETS) install: $(INSTALL_TARGETS) diff --git a/unix/tclLoadDl.c b/unix/tclLoadDl.c index 9ea88ff..27ed6ce 100644 --- a/unix/tclLoadDl.c +++ b/unix/tclLoadDl.c @@ -83,19 +83,19 @@ TclpDlopen( * relative path. */ - native = Tcl_FSGetNativePath(pathPtr); + native = (const char *)Tcl_FSGetNativePath(pathPtr); /* * Use (RTLD_NOW|RTLD_LOCAL) as default, see [Bug #3216070] */ if (flags & TCL_LOAD_GLOBAL) { - dlopenflags |= RTLD_GLOBAL; + dlopenflags |= RTLD_GLOBAL; } else { - dlopenflags |= RTLD_LOCAL; + dlopenflags |= RTLD_LOCAL; } if (flags & TCL_LOAD_LAZY) { - dlopenflags |= RTLD_LAZY; + dlopenflags |= RTLD_LAZY; } else { - dlopenflags |= RTLD_NOW; + dlopenflags |= RTLD_NOW; } handle = dlopen(native, dlopenflags); if (handle == NULL) { @@ -106,7 +106,7 @@ TclpDlopen( */ Tcl_DString ds; - const char *fileName = Tcl_GetString(pathPtr); + const char *fileName = TclGetString(pathPtr); native = Tcl_UtfToExternalDString(NULL, fileName, -1, &ds); /* @@ -127,11 +127,11 @@ TclpDlopen( if (interp) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "couldn't load file \"%s\": %s", - Tcl_GetString(pathPtr), errorStr)); + TclGetString(pathPtr), errorStr)); } return TCL_ERROR; } - newHandle = ckalloc(sizeof(*newHandle)); + newHandle = (Tcl_LoadHandle)ckalloc(sizeof(*newHandle)); newHandle->clientData = handle; newHandle->findSymbolProcPtr = &FindSymbol; newHandle->unloadFileProcPtr = &UnloadFile; @@ -168,7 +168,7 @@ FindSymbol( Tcl_DString newName, ds; /* Buffers for converting the name to * system encoding and prepending an * underscore*/ - void *handle = (void *) loadHandle->clientData; + void *handle = loadHandle->clientData; /* Native handle to the loaded library */ void *proc; /* Address corresponding to the resolved * symbol */ @@ -210,15 +210,14 @@ FindSymbol( * * UnloadFile -- * - * Unloads a dynamically loaded binary code file from memory. Code - * pointers in the formerly loaded file are no longer valid after calling - * this function. + * Unloads a dynamic shared object, after which all pointers to functions + * in the formerly-loaded object are no longer valid. * * Results: * None. * * Side effects: - * Code removed from memory. + * Memory for the loaded object is deallocated. * *---------------------------------------------------------------------- */ @@ -266,6 +265,38 @@ TclGuessPackageName( } /* + * These functions are fallbacks if we somehow determine that the platform can + * do loading from memory but the user wishes to disable it. They just report + * (gracefully) that they fail. + */ + +#ifdef TCL_LOAD_FROM_MEMORY + +MODULE_SCOPE void * +TclpLoadMemoryGetBuffer( + size_t size) /* Dummy: unused by this implementation */ +{ + return NULL; +} + +MODULE_SCOPE int +TclpLoadMemory( + void *buffer, /* Dummy: unused by this implementation */ + size_t size, /* Dummy: unused by this implementation */ + int codeSize, /* Dummy: unused by this implementation */ + const char *path, /* Dummy: unused by this implementation */ + Tcl_LoadHandle *loadHandle, /* Dummy: unused by this implementation */ + Tcl_FSUnloadFileProc **unloadProcPtr, + /* Dummy: unused by this implementation */ + int flags) + /* Dummy: unused by this implementation */ +{ + return TCL_ERROR; +} + +#endif /* TCL_LOAD_FROM_MEMORY */ + +/* * Local Variables: * mode: c * c-basic-offset: 4 diff --git a/unix/tclLoadDyld.c b/unix/tclLoadDyld.c index 6b4ceb7..bd1640e 100644 --- a/unix/tclLoadDyld.c +++ b/unix/tclLoadDyld.c @@ -562,13 +562,13 @@ TclpLoadMemoryGetBuffer( #ifdef TCL_LOAD_FROM_MEMORY MODULE_SCOPE int TclpLoadMemory( - Tcl_Interp *interp, /* Used for error reporting. */ void *buffer, /* Buffer containing the desired code * (allocated with TclpLoadMemoryGetBuffer). */ size_t size, /* Allocation size of buffer. */ int codeSize, /* Size of code data read into buffer or -1 if * an error occurred and the buffer should * just be freed. */ + const char *path, Tcl_LoadHandle *loadHandle, /* Filled with token for dynamically loaded * file which will be passed back to * (*unloadProcPtr)() to unload the file. */ @@ -583,7 +583,6 @@ TclpLoadMemory( NSObjectFileImage dyldObjFileImage = NULL; Tcl_DyldModuleHandle *modulePtr; NSModule module; - const char *objFileImageErrMsg = NULL; int nsflags = NSLINKMODULE_OPTION_RETURN_ON_ERROR; /* @@ -652,26 +651,16 @@ TclpLoadMemory( if (err == NSObjectFileImageSuccess) { err = NSCreateObjectFileImageFromMemory(buffer, codeSize, &dyldObjFileImage); - if (err != NSObjectFileImageSuccess) { - objFileImageErrMsg = DyldOFIErrorMsg(err); - } - } else { - objFileImageErrMsg = DyldOFIErrorMsg(err); } } /* * If it went wrong (or we were asked to just deallocate), get rid of the - * memory block and create an error message. + * memory block. */ if (dyldObjFileImage == NULL) { vm_deallocate(mach_task_self(), (vm_address_t) buffer, size); - if (objFileImageErrMsg != NULL) { - Tcl_SetObjResult(interp, Tcl_ObjPrintf( - "NSCreateObjectFileImageFromMemory() error: %s", - objFileImageErrMsg)); - } return TCL_ERROR; } @@ -693,7 +682,6 @@ TclpLoadMemory( const char *errorName, *errMsg; NSLinkEditError(&editError, &errorNumber, &errorName, &errMsg); - Tcl_SetObjResult(interp, Tcl_NewStringObj(errMsg, -1)); return TCL_ERROR; } diff --git a/win/tclWinLoad.c b/win/tclWinLoad.c index 9d2d87e..b62920b 100644 --- a/win/tclWinLoad.c +++ b/win/tclWinLoad.c @@ -89,11 +89,11 @@ TclpDlopen( Tcl_DString ds; - /* - * Remember the first error on load attempt to be used if the - * second load attempt below also fails. - */ - firstError = (nativeName == NULL) ? + /* + * Remember the first error on load attempt to be used if the + * second load attempt below also fails. + */ + firstError = (nativeName == NULL) ? ERROR_MOD_NOT_FOUND : GetLastError(); nativeName = (WCHAR *)Tcl_WinUtfToTChar(Tcl_GetString(pathPtr), -1, &ds); @@ -104,22 +104,22 @@ TclpDlopen( if (hInstance == NULL) { DWORD lastError; - Tcl_Obj *errMsg; - - /* - * We choose to only use the error from the second call if the first - * call failed due to the file not being found. Else stick to the - * first error for reporting purposes. - */ - if (firstError == ERROR_MOD_NOT_FOUND || - firstError == ERROR_DLL_NOT_FOUND) { - lastError = GetLastError(); - } else { - lastError = firstError; - } + Tcl_Obj *errMsg; + + /* + * We choose to only use the error from the second call if the first + * call failed due to the file not being found. Else stick to the + * first error for reporting purposes. + */ + if (firstError == ERROR_MOD_NOT_FOUND || + firstError == ERROR_DLL_NOT_FOUND) { + lastError = GetLastError(); + } else { + lastError = firstError; + } errMsg = Tcl_ObjPrintf("couldn't load library \"%s\": ", - Tcl_GetString(pathPtr)); + TclGetString(pathPtr)); /* * Check for possible DLL errors. This doesn't work quite right, @@ -131,35 +131,35 @@ TclpDlopen( if (interp) { switch (lastError) { case ERROR_MOD_NOT_FOUND: - Tcl_SetErrorCode(interp, "WIN_LOAD", "MOD_NOT_FOUND", NULL); + Tcl_SetErrorCode(interp, "WIN_LOAD", "MOD_NOT_FOUND", (char *)NULL); goto notFoundMsg; case ERROR_DLL_NOT_FOUND: - Tcl_SetErrorCode(interp, "WIN_LOAD", "DLL_NOT_FOUND", NULL); + Tcl_SetErrorCode(interp, "WIN_LOAD", "DLL_NOT_FOUND", (char *)NULL); notFoundMsg: Tcl_AppendToObj(errMsg, "this library or a dependent library" " could not be found in library path", -1); break; case ERROR_PROC_NOT_FOUND: - Tcl_SetErrorCode(interp, "WIN_LOAD", "PROC_NOT_FOUND", NULL); + Tcl_SetErrorCode(interp, "WIN_LOAD", "PROC_NOT_FOUND", (char *)NULL); Tcl_AppendToObj(errMsg, "A function specified in the import" " table could not be resolved by the system. Windows" " is not telling which one, I'm sorry.", -1); break; case ERROR_INVALID_DLL: - Tcl_SetErrorCode(interp, "WIN_LOAD", "INVALID_DLL", NULL); + Tcl_SetErrorCode(interp, "WIN_LOAD", "INVALID_DLL", (char *)NULL); Tcl_AppendToObj(errMsg, "this library or a dependent library" " is damaged", -1); break; case ERROR_DLL_INIT_FAILED: - Tcl_SetErrorCode(interp, "WIN_LOAD", "DLL_INIT_FAILED", NULL); + Tcl_SetErrorCode(interp, "WIN_LOAD", "DLL_INIT_FAILED", (char *)NULL); Tcl_AppendToObj(errMsg, "the library initialization" " routine failed", -1); break; - case ERROR_BAD_EXE_FORMAT: - Tcl_SetErrorCode(interp, "WIN_LOAD", "BAD_EXE_FORMAT", NULL); + case ERROR_BAD_EXE_FORMAT: + Tcl_SetErrorCode(interp, "WIN_LOAD", "BAD_EXE_FORMAT", (char *)NULL); Tcl_AppendToObj(errMsg, "Bad exe format. Possibly a 32/64-bit mismatch.", -1); - break; - default: + break; + default: TclWinConvertError(lastError); Tcl_AppendToObj(errMsg, Tcl_PosixError(interp), -1); } @@ -173,7 +173,7 @@ TclpDlopen( */ handlePtr = (Tcl_LoadHandle)ckalloc(sizeof(struct Tcl_LoadHandle_)); - handlePtr->clientData = (ClientData) hInstance; + handlePtr->clientData = hInstance; handlePtr->findSymbolProcPtr = &FindSymbol; handlePtr->unloadFileProcPtr = &UnloadFile; *loadHandle = handlePtr; @@ -225,7 +225,7 @@ FindSymbol( if (proc == NULL && interp != NULL) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "cannot find symbol \"%s\"", symbol)); - Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "LOAD_SYMBOL", symbol, NULL); + Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "LOAD_SYMBOL", symbol, (char *)NULL); } return proc; } @@ -427,6 +427,37 @@ InitDLLDirectoryName(void) } /* + * These functions are fallbacks if we somehow determine that the platform can + * do loading from memory but the user wishes to disable it. They just report + * (gracefully) that they fail. + */ + +#ifdef TCL_LOAD_FROM_MEMORY + +MODULE_SCOPE void * +TclpLoadMemoryGetBuffer( + size_t size) /* Dummy: unused by this implementation */ +{ + return NULL; +} + +MODULE_SCOPE int +TclpLoadMemory( + void *buffer, /* Dummy: unused by this implementation */ + size_t size, /* Dummy: unused by this implementation */ + int codeSize, /* Dummy: unused by this implementation */ + const char *path, /* Dummy: unused by this implementation */ + Tcl_LoadHandle *loadHandle, /* Dummy: unused by this implementation */ + Tcl_FSUnloadFileProc **unloadProcPtr, + /* Dummy: unused by this implementation */ + int flags) + /* Dummy: unused by this implementation */ +{ + return TCL_ERROR; +} + +#endif /* TCL_LOAD_FROM_MEMORY */ +/* * Local Variables: * mode: c * c-basic-offset: 4 -- cgit v0.12