Diff
Not logged in

Differences From Artifact [7619fd76e1]:

To Artifact [32d76f3acb]:


259
260
261
262
263
264
265
266

267
268

269
270
271
272
273
274
275
259
260
261
262
263
264
265

266
267

268
269
270
271
272
273
274
275







-
+

-
+







	    defaultPtr = libraryPtr;
	}
	if (filesMatch && !namesMatch && (fullFileName[0] != 0)) {
	    /*
	     * Can't have two different libraries loaded from the same file.
	     */

	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	    TclPrintfResult(interp,
		    "file \"%s\" is already loaded for prefix \"%s\"",
		    fullFileName, libraryPtr->prefix));
		    fullFileName, libraryPtr->prefix);
	    Tcl_SetErrorCode(interp, "TCL", "OPERATION", "LOAD",
		    "SPLITPERSONALITY", (char *)NULL);
	    code = TCL_ERROR;
	    Tcl_MutexUnlock(&libraryMutex);
	    goto done;
	}
    }
297
298
299
300
301
302
303
304
305


306
307
308
309
310
311
312
297
298
299
300
301
302
303


304
305
306
307
308
309
310
311
312







-
-
+
+







    if (libraryPtr == NULL) {
	/*
	 * The desired file isn't currently loaded, so load it. It's an error
	 * if the desired library is a static one.
	 */

	if (fullFileName[0] == 0) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "no library with prefix \"%s\" is loaded statically", prefix));
	    TclPrintfResult(interp,
		    "no library with prefix \"%s\" is loaded statically", prefix);
	    Tcl_SetErrorCode(interp, "TCL", "OPERATION", "LOAD", "NOTSTATIC",
		    (char *)NULL);
	    code = TCL_ERROR;
	    goto done;
	}

	/*
358
359
360
361
362
363
364
365
366
367


368
369
370
371
372
373
374
358
359
360
361
362
363
364



365
366
367
368
369
370
371
372
373







-
-
-
+
+







		if (!Tcl_UniCharIsWordChar(UCHAR(ch))
			|| Tcl_UniCharIsDigit(UCHAR(ch))) {
		    break;
		}
	    }
	    if (p == pkgGuess) {
		Tcl_DecrRefCount(splitPtr);
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"cannot figure out prefix for %s",
			fullFileName));
		TclPrintfResult(interp, "cannot figure out prefix for %s",
			fullFileName);
		Tcl_SetErrorCode(interp, "TCL", "OPERATION", "LOAD",
			"WHATLIBRARY", (char *)NULL);
		code = TCL_ERROR;
		goto done;
	    }
	    Tcl_DStringAppend(&pfx, pkgGuess, p - pkgGuess);
	    Tcl_DecrRefCount(splitPtr);
455
456
457
458
459
460
461
462

463
464

465
466
467
468
469
470
471
472
473

474
475

476
477
478
479
480
481
482
454
455
456
457
458
459
460

461
462

463
464
465
466
467
468
469
470
471

472
473

474
475
476
477
478
479
480
481







-
+

-
+








-
+

-
+







    /*
     * Invoke the library's initialization function (either the normal one or
     * the safe one, depending on whether or not the interpreter is safe).
     */

    if (Tcl_IsSafe(target)) {
	if (libraryPtr->safeInitProc == NULL) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	    TclPrintfResult(interp,
		    "cannot use library in a safe interpreter: no"
		    " %s_SafeInit procedure", libraryPtr->prefix));
		    " %s_SafeInit procedure", libraryPtr->prefix);
	    Tcl_SetErrorCode(interp, "TCL", "OPERATION", "LOAD", "UNSAFE",
		    (char *)NULL);
	    code = TCL_ERROR;
	    goto done;
	}
	code = libraryPtr->safeInitProc(target);
    } else {
	if (libraryPtr->initProc == NULL) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	    TclPrintfResult(interp,
		    "cannot attach library to interpreter: no %s_Init procedure",
		    libraryPtr->prefix));
		    libraryPtr->prefix);
	    Tcl_SetErrorCode(interp, "TCL", "OPERATION", "LOAD", "ENTRYPOINT",
		    (char *)NULL);
	    code = TCL_ERROR;
	    goto done;
	}
	code = libraryPtr->initProc(target);
    }
695
696
697
698
699
700
701
702

703
704

705
706
707
708
709
710
711
712
713
714
715
716


717
718
719
720
721
722
723
694
695
696
697
698
699
700

701
702

703
704
705
706
707
708
709
710
711
712
713


714
715
716
717
718
719
720
721
722







-
+

-
+










-
-
+
+







    }
    Tcl_MutexUnlock(&libraryMutex);
    if (fullFileName[0] == 0) {
	/*
	 * It's an error to try unload a static library.
	 */

	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	TclPrintfResult(interp,
		"library with prefix \"%s\" is loaded statically and cannot be unloaded",
		prefix));
		prefix);
	Tcl_SetErrorCode(interp, "TCL", "OPERATION", "UNLOAD", "STATIC",
		(char *)NULL);
	code = TCL_ERROR;
	goto done;
    }
    if (libraryPtr == NULL) {
	/*
	 * The DLL pointed by the provided filename has never been loaded.
	 */

	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"file \"%s\" has never been loaded", fullFileName));
	TclPrintfResult(interp, "file \"%s\" has never been loaded",
		fullFileName);
	Tcl_SetErrorCode(interp, "TCL", "OPERATION", "UNLOAD", "NEVERLOADED",
		(char *)NULL);
	code = TCL_ERROR;
	goto done;
    }

    /*
737
738
739
740
741
742
743
744

745
746

747
748
749
750
751
752
753
736
737
738
739
740
741
742

743
744

745
746
747
748
749
750
751
752







-
+

-
+







	}
    }
    if (code != TCL_OK) {
	/*
	 * The library has not been loaded in this interpreter.
	 */

	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	TclPrintfResult(interp,
		"file \"%s\" has never been loaded in this interpreter",
		fullFileName));
		fullFileName);
	Tcl_SetErrorCode(interp, "TCL", "OPERATION", "UNLOAD", "NEVERLOADED",
		(char *)NULL);
	code = TCL_ERROR;
	goto done;
    }

    code = UnloadLibrary(interp, target, libraryPtr, keepLibrary, fullFileName, 0);
798
799
800
801
802
803
804
805

806
807

808
809
810
811
812
813
814
815
816
817
818

819
820

821
822
823
824
825
826
827
797
798
799
800
801
802
803

804
805

806
807
808
809
810
811
812
813
814
815
816

817
818

819
820
821
822
823
824
825
826







-
+

-
+










-
+

-
+







     * libraryPtr->unloadProc must not be NULL for the DLL to be unloadable. If
     * the interpreter is a safe one, libraryPtr->safeUnloadProc must be non-NULL.
     */

    if (Tcl_IsSafe(target)) {
	if (libraryPtr->safeUnloadProc == NULL) {
	    if (!interpExiting) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		TclPrintfResult(interp,
			"file \"%s\" cannot be unloaded under a safe interpreter",
			fullFileName));
			fullFileName);
		Tcl_SetErrorCode(interp, "TCL", "OPERATION", "UNLOAD", "CANNOT",
			(char *)NULL);
		code = TCL_ERROR;
		goto done;
	    }
	}
	unloadProc = libraryPtr->safeUnloadProc;
    } else {
	if (libraryPtr->unloadProc == NULL) {
	    if (!interpExiting) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		TclPrintfResult(interp,
			"file \"%s\" cannot be unloaded under a trusted interpreter",
			fullFileName));
			fullFileName);
		Tcl_SetErrorCode(interp, "TCL", "OPERATION", "UNLOAD", "CANNOT",
			(char *)NULL);
		code = TCL_ERROR;
		goto done;
	    }
	}
	unloadProc = libraryPtr->unloadProc;
965
966
967
968
969
970
971
972

973
974

975
976
977
978
979
980
981
964
965
966
967
968
969
970

971
972

973
974
975
976
977
978
979
980







-
+

-
+







		Tcl_Free(iterLibraryPtr);
		Tcl_MutexUnlock(&libraryMutex);
	    } else {
		code = TCL_ERROR;
	    }
	}
#else
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	TclPrintfResult(interp,
		"file \"%s\" cannot be unloaded: unloading disabled",
		fullFileName));
		fullFileName);
	Tcl_SetErrorCode(interp, "TCL", "OPERATION", "UNLOAD", "DISABLED",
		NULL);
	code = TCL_ERROR;
#endif
    }

  done: