Diff
Not logged in

Differences From Artifact [8fa8adb11d]:

To Artifact [3578877861]:


194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
	prefix = TclGetString(objv[2]);
	if (prefix[0] == '\0') {
	    prefix = NULL;
	}
    }
    if ((fullFileName[0] == 0) && (prefix == NULL)) {
	TclPrintfResult(interp, "must specify either file name or prefix");
	Tcl_SetErrorCode(interp, "TCL", "OPERATION", "LOAD", "NOLIBRARY",
		(char *)NULL);
	code = TCL_ERROR;
	goto done;
    }

    /*
     * Figure out which interpreter we're going to load the library into.
     */







|
<







194
195
196
197
198
199
200
201

202
203
204
205
206
207
208
	prefix = TclGetString(objv[2]);
	if (prefix[0] == '\0') {
	    prefix = NULL;
	}
    }
    if ((fullFileName[0] == 0) && (prefix == NULL)) {
	TclPrintfResult(interp, "must specify either file name or prefix");
	TclSetErrorCode(interp, "TCL", "OPERATION", "LOAD", "NOLIBRARY");

	code = TCL_ERROR;
	goto done;
    }

    /*
     * Figure out which interpreter we're going to load the library into.
     */
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
	    /*
	     * Can't have two different libraries loaded from the same file.
	     */

	    TclPrintfResult(interp,
		    "file \"%s\" is already loaded for prefix \"%s\"",
		    fullFileName, libraryPtr->prefix);
	    Tcl_SetErrorCode(interp, "TCL", "OPERATION", "LOAD",
		    "SPLITPERSONALITY", (char *)NULL);
	    code = TCL_ERROR;
	    Tcl_MutexUnlock(&libraryMutex);
	    goto done;
	}
    }
    Tcl_MutexUnlock(&libraryMutex);
    if (libraryPtr == NULL) {







|
|







259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
	    /*
	     * Can't have two different libraries loaded from the same file.
	     */

	    TclPrintfResult(interp,
		    "file \"%s\" is already loaded for prefix \"%s\"",
		    fullFileName, libraryPtr->prefix);
	    TclSetErrorCode(interp, "TCL", "OPERATION", "LOAD",
		    "SPLITPERSONALITY");
	    code = TCL_ERROR;
	    Tcl_MutexUnlock(&libraryMutex);
	    goto done;
	}
    }
    Tcl_MutexUnlock(&libraryMutex);
    if (libraryPtr == NULL) {
296
297
298
299
300
301
302
303

304
305
306
307
308
309
310
311
312
	/*
	 * 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) {
	    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;
	}

	/*
	 * Figure out the prefix if it wasn't provided explicitly.
	 */







|
>
|
<







295
296
297
298
299
300
301
302
303
304

305
306
307
308
309
310
311
	/*
	 * 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) {
	    TclPrintfResult(interp,
		    "no library with prefix \"%s\" is loaded statically",
		    prefix);
	    TclSetErrorCode(interp, "TCL", "OPERATION", "LOAD", "NOTSTATIC");

	    code = TCL_ERROR;
	    goto done;
	}

	/*
	 * Figure out the prefix if it wasn't provided explicitly.
	 */
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
		if (!Tcl_UniCharIsWordChar(UCHAR(ch))
			|| Tcl_UniCharIsDigit(UCHAR(ch))) {
		    break;
		}
	    }
	    if (p == pkgGuess) {
		Tcl_DecrRefCount(splitPtr);
		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);

	    /*







|
<

|
|







355
356
357
358
359
360
361
362

363
364
365
366
367
368
369
370
371
372
		if (!Tcl_UniCharIsWordChar(UCHAR(ch))
			|| Tcl_UniCharIsDigit(UCHAR(ch))) {
		    break;
		}
	    }
	    if (p == pkgGuess) {
		Tcl_DecrRefCount(splitPtr);
		TclPrintfResult(interp, "cannot figure out prefix for %s",

			fullFileName);
		TclSetErrorCode(interp, "TCL", "OPERATION", "LOAD",
			"WHATLIBRARY");
		code = TCL_ERROR;
		goto done;
	    }
	    Tcl_DStringAppend(&pfx, pkgGuess, p - pkgGuess);
	    Tcl_DecrRefCount(splitPtr);

	    /*
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
483
484
     */

    if (Tcl_IsSafe(target)) {
	if (libraryPtr->safeInitProc == NULL) {
	    TclPrintfResult(interp,
		    "cannot use library in a safe interpreter: no"
		    " %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) {
	    TclPrintfResult(interp,
		    "cannot attach library to interpreter: no %s_Init procedure",
		    libraryPtr->prefix);
	    Tcl_SetErrorCode(interp, "TCL", "OPERATION", "LOAD", "ENTRYPOINT",
		    (char *)NULL);
	    code = TCL_ERROR;
	    goto done;
	}
	code = libraryPtr->initProc(target);
    }

    /*







|
<









|
<







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
     */

    if (Tcl_IsSafe(target)) {
	if (libraryPtr->safeInitProc == NULL) {
	    TclPrintfResult(interp,
		    "cannot use library in a safe interpreter: no"
		    " %s_SafeInit procedure", libraryPtr->prefix);
	    TclSetErrorCode(interp, "TCL", "OPERATION", "LOAD", "UNSAFE");

	    code = TCL_ERROR;
	    goto done;
	}
	code = libraryPtr->safeInitProc(target);
    } else {
	if (libraryPtr->initProc == NULL) {
	    TclPrintfResult(interp,
		    "cannot attach library to interpreter: no %s_Init procedure",
		    libraryPtr->prefix);
	    TclSetErrorCode(interp, "TCL", "OPERATION", "LOAD", "ENTRYPOINT");

	    code = TCL_ERROR;
	    goto done;
	}
	code = libraryPtr->initProc(target);
    }

    /*
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
	prefix = TclGetString(objv[i+1]);
	if (prefix[0] == '\0') {
	    prefix = NULL;
	}
    }
    if ((fullFileName[0] == 0) && (prefix == NULL)) {
	TclPrintfResult(interp, "must specify either file name or prefix");
	Tcl_SetErrorCode(interp, "TCL", "OPERATION", "UNLOAD", "NOLIBRARY",
		(char *)NULL);
	code = TCL_ERROR;
	goto done;
    }

    /*
     * Figure out which interpreter we're going to load the library into.
     */







|
<







625
626
627
628
629
630
631
632

633
634
635
636
637
638
639
	prefix = TclGetString(objv[i+1]);
	if (prefix[0] == '\0') {
	    prefix = NULL;
	}
    }
    if ((fullFileName[0] == 0) && (prefix == NULL)) {
	TclPrintfResult(interp, "must specify either file name or prefix");
	TclSetErrorCode(interp, "TCL", "OPERATION", "UNLOAD", "NOLIBRARY");

	code = TCL_ERROR;
	goto done;
    }

    /*
     * Figure out which interpreter we're going to load the library into.
     */
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
724
	/*
	 * It's an error to try unload a static library.
	 */

	TclPrintfResult(interp,
		"library with prefix \"%s\" is loaded statically and cannot be unloaded",
		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.
	 */

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

    /*
     * Scan through the list of libraries already loaded in the target
     * interpreter. If the library we want is already loaded there, then we







|
<








|
|
|
<







692
693
694
695
696
697
698
699

700
701
702
703
704
705
706
707
708
709
710

711
712
713
714
715
716
717
	/*
	 * It's an error to try unload a static library.
	 */

	TclPrintfResult(interp,
		"library with prefix \"%s\" is loaded statically and cannot be unloaded",
		prefix);
	TclSetErrorCode(interp, "TCL", "OPERATION", "UNLOAD", "STATIC");

	code = TCL_ERROR;
	goto done;
    }
    if (libraryPtr == NULL) {
	/*
	 * The DLL pointed by the provided filename has never been loaded.
	 */

	TclPrintfResult(interp, "file \"%s\" has never been loaded",
		fullFileName);
	TclSetErrorCode(interp, "TCL", "OPERATION", "UNLOAD", "NEVERLOADED");

	code = TCL_ERROR;
	goto done;
    }

    /*
     * Scan through the list of libraries already loaded in the target
     * interpreter. If the library we want is already loaded there, then we
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
	/*
	 * The library has not been loaded in this interpreter.
	 */

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

    code = UnloadLibrary(interp, target, libraryPtr, keepLibrary, fullFileName, 0);

  done:







|
<







732
733
734
735
736
737
738
739

740
741
742
743
744
745
746
	/*
	 * The library has not been loaded in this interpreter.
	 */

	TclPrintfResult(interp,
		"file \"%s\" has never been loaded in this interpreter",
		fullFileName);
	TclSetErrorCode(interp, "TCL", "OPERATION", "UNLOAD", "NEVERLOADED");

	code = TCL_ERROR;
	goto done;
    }

    code = UnloadLibrary(interp, target, libraryPtr, keepLibrary, fullFileName, 0);

  done:
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
828

    if (Tcl_IsSafe(target)) {
	if (libraryPtr->safeUnloadProc == NULL) {
	    if (!interpExiting) {
		TclPrintfResult(interp,
			"file \"%s\" cannot be unloaded under a safe interpreter",
			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) {
		TclPrintfResult(interp,
			"file \"%s\" cannot be unloaded under a trusted interpreter",
			fullFileName);
		Tcl_SetErrorCode(interp, "TCL", "OPERATION", "UNLOAD", "CANNOT",
			(char *)NULL);
		code = TCL_ERROR;
		goto done;
	    }
	}
	unloadProc = libraryPtr->unloadProc;
    }








|
<











|
<







792
793
794
795
796
797
798
799

800
801
802
803
804
805
806
807
808
809
810
811

812
813
814
815
816
817
818

    if (Tcl_IsSafe(target)) {
	if (libraryPtr->safeUnloadProc == NULL) {
	    if (!interpExiting) {
		TclPrintfResult(interp,
			"file \"%s\" cannot be unloaded under a safe interpreter",
			fullFileName);
		TclSetErrorCode(interp, "TCL", "OPERATION", "UNLOAD", "CANNOT");

		code = TCL_ERROR;
		goto done;
	    }
	}
	unloadProc = libraryPtr->safeUnloadProc;
    } else {
	if (libraryPtr->unloadProc == NULL) {
	    if (!interpExiting) {
		TclPrintfResult(interp,
			"file \"%s\" cannot be unloaded under a trusted interpreter",
			fullFileName);
		TclSetErrorCode(interp, "TCL", "OPERATION", "UNLOAD", "CANNOT");

		code = TCL_ERROR;
		goto done;
	    }
	}
	unloadProc = libraryPtr->unloadProc;
    }

967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
		code = TCL_ERROR;
	    }
	}
#else
	TclPrintfResult(interp,
		"file \"%s\" cannot be unloaded: unloading disabled",
		fullFileName);
	Tcl_SetErrorCode(interp, "TCL", "OPERATION", "UNLOAD", "DISABLED",
		NULL);
	code = TCL_ERROR;
#endif
    }

  done:
    return code;
}







|
<







957
958
959
960
961
962
963
964

965
966
967
968
969
970
971
		code = TCL_ERROR;
	    }
	}
#else
	TclPrintfResult(interp,
		"file \"%s\" cannot be unloaded: unloading disabled",
		fullFileName);
	TclSetErrorCode(interp, "TCL", "OPERATION", "UNLOAD", "DISABLED");

	code = TCL_ERROR;
#endif
    }

  done:
    return code;
}