Posted to tcl by davygrvy at Fri May 15 19:33:30 GMT 2020view pretty

    unsigned RunTclLoop (void)
    {
	EXCEPTION_RECORD exceptRec;
	char buffer[578];
	
	exceptRec.ExceptionCode = 0;

	// enter Tcl's notifier and don't fall-out until the thread is
	// told to quit.

	// If a fatal exception happens, catch it.
	//
	__try {
	    __try {
		while (!done) {
		    // *ALL* of Tcl runs from this loop.
		    Tcl_DoOneEvent(TCL_ALL_EVENTS);
		}
		Tcl_AsyncDelete(*token);
		Tcl_Finalize();
	    }
	    __finally {
		// Be careful..  Tcl's DllMain() can lock-up.
		// Leave this here anyways as Tcl _should_ be OK.
		// Go fix the DllMain() bug instead!
		FreeLibrary(hTclMod);
		// Be explicit and reset the Stubs library just
		// cause we should.
		tclStubsPtr = nullptr;
		// Reset the async token, too.  Renders QueueJob()
		// non-functional.
		*token = nullptr;
	    }
	} __except (
	    exceptRec = *(GetExceptionInformation())->ExceptionRecord,
	    EXCEPTION_EXECUTE_HANDLER)
	{
	    if (exceptRec.ExceptionCode != TES_PANIC_UNWIND) {
		// Something from Tcl's execution tossed a big one.
		wsprintf(buffer,
			"Tcl has crashed with exception [0x%X] (%s) "
			"at address 0x%X", exceptRec.ExceptionCode,
			GetExceptionString(exceptRec.ExceptionCode),
			exceptRec.ExceptionAddress);
		// We don't need RaiseException() for this call.  We're
		// already unwound.
		nfatal(buffer);
	    }
	}
	return exceptRec.ExceptionCode;
    }