Skip to content

Commit

Permalink
Add dummy TclpLoadMemoryGetBuffer/TclpLoadMemory for Windows and UNIX…
Browse files Browse the repository at this point in the history
…, so compiling with TCL_LOAD_FROM_MEMORY succeeds (but fallbacks normally at runtime)
  • Loading branch information
jan.nijtmans committed Jan 16, 2025
2 parents 2fe2533 + 1345a76 commit eb701e1
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 4 deletions.
36 changes: 33 additions & 3 deletions unix/tclLoadDl.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ TclpDlopen(
*/

Tcl_DString ds;
const char *fileName = Tcl_GetString(pathPtr);
const char *fileName = TclGetString(pathPtr);

native = Tcl_UtfToExternalDString(NULL, fileName, TCL_INDEX_NONE, &ds);
/*
Expand All @@ -127,7 +127,7 @@ TclpDlopen(
if (interp) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"couldn't load file \"%s\": %s",
Tcl_GetString(pathPtr), errorStr));
TclGetString(pathPtr), errorStr));
}
return TCL_ERROR;
}
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -259,6 +259,36 @@ UnloadFile(
ckfree(loadHandle);
}

/*
* 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(
TCL_UNUSED(size_t))
{
return NULL;
}

MODULE_SCOPE int
TclpLoadMemory(
TCL_UNUSED(void *),
TCL_UNUSED(size_t),
TCL_UNUSED(Tcl_Size),
TCL_UNUSED(const char *),
TCL_UNUSED(Tcl_LoadHandle *),
TCL_UNUSED(Tcl_FSUnloadFileProc **),
TCL_UNUSED(int))
{
return TCL_ERROR;
}

#endif /* TCL_LOAD_FROM_MEMORY */

/*
* Local Variables:
* mode: c
Expand Down
31 changes: 30 additions & 1 deletion win/tclWinLoad.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ TclpDlopen(
*/

handlePtr = (Tcl_LoadHandle)ckalloc(sizeof(struct Tcl_LoadHandle_));
handlePtr->clientData = (void *) hInstance;
handlePtr->clientData = (void *)hInstance;
handlePtr->findSymbolProcPtr = &FindSymbol;
handlePtr->unloadFileProcPtr = &UnloadFile;
*loadHandle = handlePtr;
Expand Down Expand Up @@ -395,6 +395,35 @@ InitDLLDirectoryName(void)
return TCL_OK;
}

/*
* 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(
TCL_UNUSED(size_t))
{
return NULL;
}

MODULE_SCOPE int
TclpLoadMemory(
TCL_UNUSED(void *),
TCL_UNUSED(size_t),
TCL_UNUSED(Tcl_Size),
TCL_UNUSED(const char *),
TCL_UNUSED(Tcl_LoadHandle *),
TCL_UNUSED(Tcl_FSUnloadFileProc **),
TCL_UNUSED(int))
{
return TCL_ERROR;
}

#endif /* TCL_LOAD_FROM_MEMORY */
/*
* Local Variables:
* mode: c
Expand Down

0 comments on commit eb701e1

Please sign in to comment.