Skip to content
Tcl Source Code History Of Ticket 1061224fffffffffffffffffffffffffffffffff
Login

History Of Ticket 1061224fffffffffffffffffffffffffffffffff

Artifacts Associated With Ticket 1061224fffffffffffffffffffffffffffffffff

  1. Ticket change [08f20683aa] (rid 89643) by davygrvy on 2004-11-05 22:32:45:

    1. assignee initialized to: "kennykb"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized to:
      Stack trace:
      KERNEL32! RaiseException
      MSVCRTD! _raise_exc
      MSVCRTD! _87except
      MSVCRTD! _startOneArgErrorHandling
      MSVCRTD! sqrt
      TclExecuteByteCode
      TclCompEvalObj
      Tcl_EvalObjEx
      NamespaceEvalCmd
      Tcl_NamespaceObjCmd
      TclEvalObjvInternal
      TclExecuteByteCode
      TclCompEvalObj
      Tcl_EvalObjEx
      Tcl_CatchObjCmd
      TclEvalObjvInterna
      TclExecuteByteCode
      Tcl_ExprObj
      Tcl_ExprBooleanObj
      Tcl_IfObjCmd
      TclEvalObjvInternal
      Tcl_EvalEx
      Tcl_Eva
      fake_Tcl_Eval
      
      The script I asked it to eval was "expr sqrt(-1)". 
      When my fake_Tcl_Eval() modifies the registers as you
      suggested, the app killing exception 0xC0000090 is avoided:
      
      int
      fake_Tcl_Eval (Tcl_Interp *interp, char *string)
      {
          Tcl_DString dst;
          int result;
      
          Tcl_DStringInit(&dst);
      
          // ensure no upper ascii character combos look like
          // UTF-8 start codes.
          //
          Tcl_ExternalToUtfDString(XiRCEncoding, string, -1,
      &dst);
      
          int mask = _controlfp( 0, 0 );
          // Some math functions need to be protected from
      raising
          // exceptions: /tcl expr sqrt(-1)
          _controlfp( _CW_DEFAULT, _MCW_EM );
      
          result = Tcl_Eval(interp, Tcl_DStringValue(&dst));
      
          _controlfp( mask, _MCW_EM );
          Tcl_DStringFree(&dst);
          return result;
      }
      
      Can Tcl assume the responsibility of protecting it's
      own math calls by this method rather than the client of
      the API?
      
      
    4. foundin initialized to: "obsolete: 8.5a2"
    5. priority initialized to: "5 Medium"
    6. resolution initialized to: "None"
    7. status initialized to: "Open"
    8. submitter initialized to: "davygrvy"
    9. subsystem initialized to: "50. Embedding Support"
    10. title initialized to:
      math functions can cause unwanted exceptions and termination
      
    11. type initialized to: "Bug"
  2. Ticket change [24dd5005a7] (rid 131180) by davygrvy on 2004-11-06 05:47:28:

    1. icomment:
      Logged In: YES 
      user_id=7549
      
      Wait!   That trick works with a msvcrtd.dll loaded, but not
      the release build.  I can't seem to trace it.  The exception
      appears to be raised _after_ the Tcl_Eval that invoked it.
      
      
    2. login: "davygrvy"
    3. mimetype: "text/plain"
    4. username: "davygrvy"
  3. Ticket change [56112219a0] (rid 94258) by davygrvy on 2004-11-06 06:08:12:

    1. icomment:
      Logged In: YES 
      user_id=7549
      
      Adding _clear87(); before resetting the mask solves this. 
      Good, but should this be the responsibility of Tcl itself,
      not for me as a client of the API?
      
      
    2. login: "davygrvy"
    3. mimetype: "text/plain"
    4. username: "davygrvy"
  4. Ticket change [9e7fd723f7] (rid 96477) by davygrvy on 2004-11-06 06:24:54:

    1. icomment:
      Logged In: YES 
      user_id=7549
      
      Personally, I don't think it should be my responsibility to
      handle the math errors that the core throws to me as a user
      of the API.
      
      
    2. login: "davygrvy"
    3. mimetype: "text/plain"
    4. username: "davygrvy"
  5. Ticket change [4316bc9630] (rid 116487) by davygrvy on 2004-11-06 06:55:49:

    1. icomment:
      
      
      File Added - 107767: patch.txt
      
      Logged In: YES 
      user_id=7549
      
      modified ExprUnaryFunc() in tclExecute.c to support
      saving/restoring and clearing math errors.
      
      Is this bad?  ExprBinaryFunc and the others would be next I
      guess.  What if they all called a common Save() and
      Restore/Clear() so the #ifdefs just sit one function?
      
      
    2. login: "davygrvy"
    3. mimetype: "text/plain"
    4. username: "davygrvy"
  6. Add attachment "patch.txt" [f6d91bebae] (rid 130382) by davygrvy on 2004-11-06 06:55:49.

  7. Ticket change [f4601af61b] (rid 129900) by davygrvy on 2004-11-06 07:30:48:

    1. icomment:
      Logged In: YES 
      user_id=7549
      
      Here's another, slightly cleaner patch.
      
      
    2. login: "davygrvy"
    3. mimetype: "text/plain"
    4. username: "davygrvy"
  8. Ticket change [4971ba628c] (rid 100052) by davygrvy on 2004-11-06 07:30:49:

    1. icomment:
      
      
      File Added - 107772: patch.txt
      
      
      
    2. login: "davygrvy"
    3. mimetype: "text/plain"
    4. username: "davygrvy"
  9. Add attachment "patch.txt" [c7e42617d3] (rid 122019) by davygrvy on 2004-11-06 07:30:49.

  10. Ticket change [e7b2ef3ec6] (rid 104514) by nobody on 2004-11-07 00:55:20:

    1. icomment:
      Logged In: NO 
      
      
      On Linux/Alpha, similar difficulties
      were long ago solved with a
      -mieee switch to gcc.  Isn't there
      something similar on your platform?
      
      
    2. login: "nobody"
    3. mimetype: "text/plain"
    4. username: "nobody"
  11. Ticket change [be5686b545] (rid 102057) by davygrvy on 2004-11-07 01:29:56:

    1. icomment:
      Logged In: YES 
      user_id=7549
      
      no
      
      
    2. login: "davygrvy"
    3. mimetype: "text/plain"
    4. username: "davygrvy"
  12. Ticket change [28e00fe60a] (rid 88777) by davygrvy on 2004-11-07 02:36:21:

    1. icomment:
      Logged In: YES 
      user_id=7549
      
      The problem here is that normally, hardware exceptions are
      caught by the C runtime (msvcrt) unless changed.  As Tcl is
      not specifically resetting the runtime's exception mask for
      each time a math function is called, the control mask
      follows the global settings.  As part of my application is
      not accible to me in source, I can not change the rest of
      the DLLs usage of the global control mask.  But if Tcl
      dis-associated itself to a global exception setting and was
      responsible just for its own calls, all is fixable.
      
      
    2. login: "davygrvy"
    3. mimetype: "text/plain"
    4. username: "davygrvy"
  13. Ticket change [6ed92a38b0] (rid 100212) by davygrvy on 2004-11-07 02:41:49:

    1. title changed to:
      "expr sqrt(-1)" crash with EXCEPTION_FLT_INVALID_OPERATION
      
  14. Ticket change [dcda856d7f] (rid 114557) by davygrvy on 2004-11-09 08:15:15:

    1. icomment:
      Logged In: YES 
      user_id=7549
      
      Having to create my own notifier to manage the non-parented
      calls is not "less difficult" as jenglish would have
      thought.  This will take me a couple days or so to get working.
      
      
    2. login: "davygrvy"
    3. mimetype: "text/plain"
    4. username: "davygrvy"
  15. Ticket change [edefae59f8] (rid 103996) by davygrvy on 2004-11-09 10:20:14:

    1. icomment:
      Logged In: YES 
      user_id=7549
      
      Initial call in my bridge:
      
      struct Tcl_NotifierProcs us = {
          Tcl_SetTimer,
          XiRCwaitForEventProc,
          0L,
          0L,
          Tcl_InitNotifier,
          Tcl_FinalizeNotifier,
          Tcl_AlertNotifier,
          Tcl_ServiceModeHook
      };
      originalW4EP = (Tcl_WaitForEventProc *)
      GetProcAddress(hTclMod, "Tcl_WaitForEvent");
      Tcl_SetNotifier(&us);  // Need to specify our own!
      
      
      Thunk stuff ended up being:
      struct ThunkData {
          int cwords;
      };
      
      void
      EnterToMsvcrt (ThunkData *data)
      {
          // See
      https://sourceforge.net/support/tracker.php?aid=1061224
          data->cwords = _controlfp(0, 0);
          _controlfp(CW_DEFAULT, 0xFFFF);
      }
      
      void
      LeaveFromMsvcrt (ThunkData *data)
      {
          _clearfp();
          _controlfp(data->cwords, 0xFFFF);
      }
      
      #define ENTER \
          ThunkData data; EnterToMsvcrt(&data)
      
      #define LEAVE \
          LeaveFromMsvcrt(&data)
      
      All the exports to the app are protected by ENTER and LEAVE:
      int
      fake_Tcl_EvalFile (Tcl_Interp *interp, char *fileName)
      {
          ENTER;
          int result = Tcl_EvalFile(interp, fileName);
          LEAVE;
          return result;
      }
      
      My Tcl_WaitForEvent got a bit tricky, though, to prevent an
      infinite loop:
      int
      XiRCwaitForEventProc (Tcl_Time *timePtr)
      {
          ENTER;
          int result;
          struct Tcl_NotifierProcs stuff = {
      Tcl_SetTimer,
      originalW4EP,
      0L,
      0L,
      Tcl_InitNotifier,
      Tcl_FinalizeNotifier,
      Tcl_AlertNotifier,
      Tcl_ServiceModeHook
          };
      
          Tcl_SetNotifier(&stuff);
          result = originalW4EP(timePtr);
          stuff.waitForEventProc = XiRCwaitForEventProc;
          Tcl_SetNotifier(&stuff);
          LEAVE;
          return result;
      }
      
      I'll make a note here if this passes the acid test I'll
      start working on now.  I think I've got XiRCwaitForEventProc
      upside down, but not sure yet.
      
      
    2. login: "davygrvy"
    3. mimetype: "text/plain"
    4. username: "davygrvy"
  16. Ticket change [3b324658d7] (rid 112692) by davygrvy on 2004-11-12 00:04:24:

    1. closedate changed to: "2004-11-11T17:04:24"
    2. closer changed to: "davygrvy"
    3. icomment:
      Logged In: YES 
      user_id=7549
      
      Ok, I give in.  This shouldn't be Tcl's responsibility.  I
      research more on this, and it's just a nasty behavior in a
      mixed Borland (exe) and MS compiled (dll) application just
      like you jenglish had explained it.
      
      
    4. login: "davygrvy"
    5. mimetype: "text/plain"
    6. resolution changed to: "Invalid"
    7. status changed to: "Closed"
    8. username: "davygrvy"