Changes On Branch bug-a8e4f76ce4-androwish
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Changes In Branch bug-a8e4f76ce4-androwish Excluding Merge-Ins

This is equivalent to a diff from 74c4656650 to 4ad8c29369

2024-11-26
14:34
tclWinLoad.c must always be compiled with -D_UNICODE check-in: 8efedbb737 user: jan.nijtmans tags: bug-a8e4f76ce4
13:44
Missing Tcl_InitHashTable() Closed-Leaf check-in: 4ad8c29369 user: jan.nijtmans tags: bug-a8e4f76ce4-androwish
13:28
Disable TCL_LOAD_FROM_MEMORY, for testing check-in: c8c35f0eb4 user: jan.nijtmans tags: bug-a8e4f76ce4-androwish
13:19
Take over TclpFinalizeLoad from androwish check-in: 9c24e7f216 user: jan.nijtmans tags: bug-a8e4f76ce4-androwish
10:16
Experiment with Tk done, undo hack check-in: 74c4656650 user: jan.nijtmans tags: bug-a8e4f76ce4
2024-11-25
15:29
Hack: Add a pkgIndex.tcl file and tcl9tk90.dll file to tcl90.dll. For test purposes. check-in: 142494f1f7 user: jan.nijtmans tags: bug-a8e4f76ce4

Changes to generic/tclInt.h.
3543
3544
3545
3546
3547
3548
3549

3550
3551

3552
3553
3554
3555
3556
3557
3558
MODULE_SCOPE void	TclpDeleteFileHandler(int fd);
MODULE_SCOPE void	TclpFinalizeCondition(Tcl_Condition *condPtr);
MODULE_SCOPE void	TclpFinalizeMutex(Tcl_Mutex *mutexPtr);
MODULE_SCOPE void	TclpFinalizeNotifier(void *clientData);
MODULE_SCOPE void	TclpFinalizePipes(void);
MODULE_SCOPE void	TclpFinalizeSockets(void);
#ifdef _WIN32

MODULE_SCOPE void	TclInitSockets(void);
#else

#define TclInitSockets() /* do nothing */
#endif
struct addrinfo; /* forward declaration, needed for TclCreateSocketAddress */
MODULE_SCOPE int	TclCreateSocketAddress(Tcl_Interp *interp,
			    struct addrinfo **addrlist,
			    const char *host, int port, int willBind,
			    const char **errorMsgPtr);







>


>







3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
MODULE_SCOPE void	TclpDeleteFileHandler(int fd);
MODULE_SCOPE void	TclpFinalizeCondition(Tcl_Condition *condPtr);
MODULE_SCOPE void	TclpFinalizeMutex(Tcl_Mutex *mutexPtr);
MODULE_SCOPE void	TclpFinalizeNotifier(void *clientData);
MODULE_SCOPE void	TclpFinalizePipes(void);
MODULE_SCOPE void	TclpFinalizeSockets(void);
#ifdef _WIN32
MODULE_SCOPE void	TclpFinalizeLoad(void);
MODULE_SCOPE void	TclInitSockets(void);
#else
#define TclpFinalizeLoad() /* do nothing */
#define TclInitSockets() /* do nothing */
#endif
struct addrinfo; /* forward declaration, needed for TclCreateSocketAddress */
MODULE_SCOPE int	TclCreateSocketAddress(Tcl_Interp *interp,
			    struct addrinfo **addrlist,
			    const char *host, int port, int willBind,
			    const char **errorMsgPtr);
Changes to generic/tclLoad.c.
1253
1254
1255
1256
1257
1258
1259

1260
1261
1262
1263
1264
1265
1266
	}
#endif

	Tcl_Free(libraryPtr->fileName);
	Tcl_Free(libraryPtr->prefix);
	Tcl_Free(libraryPtr);
    }

}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78







>







1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
	}
#endif

	Tcl_Free(libraryPtr->fileName);
	Tcl_Free(libraryPtr->prefix);
	Tcl_Free(libraryPtr);
    }
    TclpFinalizeLoad();
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
Changes to win/Makefile.in.
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
	zip.$(HOST_OBJEXT) \
	zutil.$(HOST_OBJEXT) \
	minizip.$(HOST_OBJEXT)

ZIP_INSTALL_OBJS =  @ZIP_INSTALL_OBJS@

CC_SWITCHES = -I"${BUILD_DIR}" -I"${GENERIC_DIR_NATIVE}" -I"${TOMMATH_DIR_NATIVE}" \
-I"${ZLIB_DIR_NATIVE}" -I"${WIN_DIR_NATIVE}" -DTCL_LOAD_FROM_MEMORY \
${CFLAGS} ${CFLAGS_WARNING} ${SHLIB_CFLAGS} -DMP_PREC=4 \
${AC_FLAGS} ${COMPILE_DEBUG_FLAGS} ${NO_DEPRECATED_FLAGS}

CC_OBJNAME = @CC_OBJNAME@
CC_EXENAME = @CC_EXENAME@

STUB_CC_SWITCHES = -I"${GENERIC_DIR_NATIVE}" -I"${TOMMATH_DIR_NATIVE}" \







|







261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
	zip.$(HOST_OBJEXT) \
	zutil.$(HOST_OBJEXT) \
	minizip.$(HOST_OBJEXT)

ZIP_INSTALL_OBJS =  @ZIP_INSTALL_OBJS@

CC_SWITCHES = -I"${BUILD_DIR}" -I"${GENERIC_DIR_NATIVE}" -I"${TOMMATH_DIR_NATIVE}" \
-I"${ZLIB_DIR_NATIVE}" -I"${WIN_DIR_NATIVE}" \
${CFLAGS} ${CFLAGS_WARNING} ${SHLIB_CFLAGS} -DMP_PREC=4 \
${AC_FLAGS} ${COMPILE_DEBUG_FLAGS} ${NO_DEPRECATED_FLAGS}

CC_OBJNAME = @CC_OBJNAME@
CC_EXENAME = @CC_EXENAME@

STUB_CC_SWITCHES = -I"${GENERIC_DIR_NATIVE}" -I"${TOMMATH_DIR_NATIVE}" \
Changes to win/makefile.vc.
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483

LIBTCLVFSSUBDIR = libtcl.vfs
LIBTCLVFS = $(OUT_DIR)\$(LIBTCLVFSSUBDIR)

# Additional include and C macro definitions for the implicit rules
# defined in rules.vc
PRJ_INCLUDES	= -I"$(TOMMATHDIR)"
PRJ_DEFINES	= /DMP_PREC=4 /Dinline=__inline /D_CRT_SECURE_NO_DEPRECATE /D_CRT_NONSTDC_NO_DEPRECATE /DMP_FIXED_CUTOFFS /DTCL_LOAD_FROM_MEMORY

!if $(STATIC_BUILD)
PRJ_DEFINES = $(PRJ_DEFINES) /DTCL_WITH_INTERNAL_ZLIB
!endif

# Additional Link libraries needed beyond those in rules.vc
PRJ_LIBS   = netapi32.lib user32.lib userenv.lib ws2_32.lib







|







469
470
471
472
473
474
475
476
477
478
479
480
481
482
483

LIBTCLVFSSUBDIR = libtcl.vfs
LIBTCLVFS = $(OUT_DIR)\$(LIBTCLVFSSUBDIR)

# Additional include and C macro definitions for the implicit rules
# defined in rules.vc
PRJ_INCLUDES	= -I"$(TOMMATHDIR)"
PRJ_DEFINES	= /DMP_PREC=4 /Dinline=__inline /D_CRT_SECURE_NO_DEPRECATE /D_CRT_NONSTDC_NO_DEPRECATE /DMP_FIXED_CUTOFFS

!if $(STATIC_BUILD)
PRJ_DEFINES = $(PRJ_DEFINES) /DTCL_WITH_INTERNAL_ZLIB
!endif

# Additional Link libraries needed beyond those in rules.vc
PRJ_LIBS   = netapi32.lib user32.lib userenv.lib ws2_32.lib
Changes to win/tclWinLoad.c.
10
11
12
13
14
15
16

17

18
19
20
21
22
23
24
25
26
27
28
29
30

31
32
33
34
35
36
37
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tclWinInt.h"
#ifdef TCL_LOAD_FROM_MEMORY
#undef  UNICODE

#define UNICODE

#include "MemoryModule.h"
#endif

/*
 * Native name of the directory in the native filesystem where DLLs used in
 * this process are copied prior to loading, and mutex used to protect its
 * allocation.
 */

static WCHAR *dllDirectoryName = NULL;
#if TCL_THREADS
static Tcl_Mutex dllDirectoryNameMutex;
#endif


/*
 * Static functions defined within this file.
 */

static void *		FindSymbol(Tcl_Interp *interp,
			    Tcl_LoadHandle loadHandle, const char *symbol);







>

>













>







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tclWinInt.h"
#ifdef TCL_LOAD_FROM_MEMORY
#undef  UNICODE
#undef  _UNICODE
#define UNICODE
#define _UNICODE
#include "MemoryModule.h"
#endif

/*
 * Native name of the directory in the native filesystem where DLLs used in
 * this process are copied prior to loading, and mutex used to protect its
 * allocation.
 */

static WCHAR *dllDirectoryName = NULL;
#if TCL_THREADS
static Tcl_Mutex dllDirectoryNameMutex;
#endif
static Tcl_HashTable tempDllTable;

/*
 * Static functions defined within this file.
 */

static void *		FindSymbol(Tcl_Interp *interp,
			    Tcl_LoadHandle loadHandle, const char *symbol);
181
182
183
184
185
186
187
















188
189
190
191
192
193
194

    handlePtr = (Tcl_LoadHandle)Tcl_Alloc(sizeof(struct Tcl_LoadHandle_));
    handlePtr->clientData = hInstance;
    handlePtr->findSymbolProcPtr = &FindSymbol;
    handlePtr->unloadFileProcPtr = &UnloadFile;
    *loadHandle = handlePtr;
    *unloadProcPtr = &UnloadFile;
















    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * FindSymbol --







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213

    handlePtr = (Tcl_LoadHandle)Tcl_Alloc(sizeof(struct Tcl_LoadHandle_));
    handlePtr->clientData = hInstance;
    handlePtr->findSymbolProcPtr = &FindSymbol;
    handlePtr->unloadFileProcPtr = &UnloadFile;
    *loadHandle = handlePtr;
    *unloadProcPtr = &UnloadFile;

    /*
     * Remember handle for process termination cleanup handler
     * if the DLL is a copy in temporary directory.
     */

    Tcl_MutexLock(&dllDirectoryNameMutex);
    if (dllDirectoryName != NULL) {
	int dummy, len = wcslen(dllDirectoryName);

	if ((len > 0) && (_wcsnicmp(nativeName, dllDirectoryName, len) == 0)) {
	    Tcl_CreateHashEntry(&tempDllTable, (ClientData) handlePtr, &dummy);
	}
    }
    Tcl_MutexUnlock(&dllDirectoryNameMutex);

    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * FindSymbol --
258
259
260
261
262
263
264

265
266
















267

268
269
270
271
272
273
274
static void
UnloadFile(
    Tcl_LoadHandle loadHandle)	/* loadHandle returned by a previous call to
				 * TclpDlopen(). The loadHandle is a token
				 * that represents the loaded file. */
{
    HINSTANCE hInstance = (HINSTANCE)loadHandle->clientData;


    FreeLibrary(hInstance);
















    Tcl_Free(loadHandle);

}

/*
 *----------------------------------------------------------------------
 *
 * TclpTempFileNameForLibrary --
 *







>

|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>







277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
static void
UnloadFile(
    Tcl_LoadHandle loadHandle)	/* loadHandle returned by a previous call to
				 * TclpDlopen(). The loadHandle is a token
				 * that represents the loaded file. */
{
    HINSTANCE hInstance = (HINSTANCE)loadHandle->clientData;
    BOOL success, keep = 0;

    success = FreeLibrary(hInstance);
    Tcl_MutexLock(&dllDirectoryNameMutex);
    if (dllDirectoryName != NULL) {
	Tcl_HashEntry *hPtr =
	    Tcl_FindHashEntry(&tempDllTable, (ClientData) loadHandle);

	if (hPtr != NULL) {
	    if (success) {
		Tcl_DeleteHashEntry(hPtr);
	    } else {
		/* FreeLibrary() will be retried in TclpFinalizeLoad() later */
		keep = 1;
	    }
	}
    }
    Tcl_MutexUnlock(&dllDirectoryNameMutex);
    if (!keep) {
	Tcl_Free(loadHandle);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TclpTempFileNameForLibrary --
 *
316
317
318
319
320
321
322

























































































323
324
325
326
327
328
329
	Tcl_DecrRefCount(fileName);
	return NULL;
    }
    Tcl_AppendToObj(fileName, "/", 1);
    Tcl_AppendObjToObj(fileName, tail);
    return fileName;
}


























































































/*
 *----------------------------------------------------------------------
 *
 * InitDLLDirectoryName --
 *
 *	Helper for TclpTempFileNameForLibrary; builds a temporary directory







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
	Tcl_DecrRefCount(fileName);
	return NULL;
    }
    Tcl_AppendToObj(fileName, "/", 1);
    Tcl_AppendObjToObj(fileName, tail);
    return fileName;
}

/*
 *----------------------------------------------------------------------
 *
 * TclpFinalizeLoad --
 *
 *	On process termination, cleanup and finally remove the
 *	directory used for temporary copies of DLLs.
 *
 * Results:
 *	None.
 *
 * Side-effects:
 *	Delete files in temp directory.
 *	Remove temp directory.
 *
 *----------------------------------------------------------------------
 */

void
TclpFinalizeLoad(void)
{
    WCHAR *dllDir = NULL;
    int dllDirLen;
    Tcl_DString ds;
    Tcl_HashEntry *hPtr;
    Tcl_HashSearch search;
    HANDLE handle;
    WIN32_FIND_DATAW data;

    if (!TclFullFinalizationRequested()) {
	Tcl_MutexLock(&dllDirectoryNameMutex);
    }
    if (dllDirectoryName != NULL) {
	dllDir = dllDirectoryName;
	dllDirectoryName = NULL;
    }
    if (dllDir != NULL) {

	/*
	 * Try unloading left-over DLLs.
	 */

	hPtr = Tcl_FirstHashEntry(&tempDllTable, &search);
	while (hPtr != NULL) {
	    Tcl_LoadHandle loadHandle =
		(Tcl_LoadHandle) Tcl_GetHashKey(&tempDllTable, hPtr);

	    Tcl_DeleteHashEntry(hPtr);
	    hPtr = Tcl_NextHashEntry(&search);

	    /*
	     * Same cleanup steps as in UnloadFile(), but dangerous anyway.
	     */

	    FreeLibrary((HINSTANCE) loadHandle->clientData);
	    Tcl_Free(loadHandle);
	}
	Tcl_DeleteHashTable(&tempDllTable);

	/*
	 * Delete temporary copies of DLLs, then the temporary directory.
	 */

	Tcl_DStringInit(&ds);
	dllDirLen = wcslen(dllDir) * sizeof (WCHAR);
	Tcl_DStringAppend(&ds, (char *) dllDir, dllDirLen);
	Tcl_DStringAppend(&ds, (char *) L"\\*.dll\0",
		wcslen(L"\\*.dll\0") * sizeof (WCHAR));
	dllDirLen += sizeof (WCHAR);	/* include trailing backslash */
	handle = FindFirstFileW((WCHAR *) Tcl_DStringValue(&ds), &data);
	if (handle != INVALID_HANDLE_VALUE) {
	    do {
		Tcl_DStringSetLength(&ds, dllDirLen);
		Tcl_DStringAppend(&ds, (char *) data.cFileName,
			wcslen(data.cFileName) * sizeof (WCHAR));
		Tcl_DStringAppend(&ds, (char *) L"\0", sizeof (WCHAR));
		DeleteFileW((WCHAR *) Tcl_DStringValue(&ds));
	    } while (FindNextFileW(handle, &data) == TRUE);
	    FindClose(handle);
	}
	Tcl_DStringFree(&ds);
	RemoveDirectoryW(dllDir);
	Tcl_Free(dllDir);
    }
    if (!TclFullFinalizationRequested()) {
	Tcl_MutexUnlock(&dllDirectoryNameMutex);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * InitDLLDirectoryName --
 *
 *	Helper for TclpTempFileNameForLibrary; builds a temporary directory
393
394
395
396
397
398
399

400
401
402
403
404
405
406
    /*
     * Store our computed value in the global.
     */

  copyToGlobalBuffer:
    dllDirectoryName = (WCHAR *)Tcl_Alloc((nameLen+1) * sizeof(WCHAR));
    wcscpy(dllDirectoryName, name);

    return TCL_OK;
}

#ifdef TCL_LOAD_FROM_MEMORY

MODULE_SCOPE void *
TclpLoadMemoryGetBuffer(







>







519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
    /*
     * Store our computed value in the global.
     */

  copyToGlobalBuffer:
    dllDirectoryName = (WCHAR *)Tcl_Alloc((nameLen+1) * sizeof(WCHAR));
    wcscpy(dllDirectoryName, name);
    Tcl_InitHashTable(&tempDllTable, TCL_ONE_WORD_KEYS);
    return TCL_OK;
}

#ifdef TCL_LOAD_FROM_MEMORY

MODULE_SCOPE void *
TclpLoadMemoryGetBuffer(