Itcl - the [incr Tcl] extension

View Ticket
Login
Ticket Hash: c949e73d3e93bc940be8e32bf74c4a91dd2b7cd4
Title: itcl crashes in info command
Status: Closed Type: Code_Defect
Severity: Critical Priority: Immediate
Subsystem: Resolution: Fixed
Last Modified: 2018-02-27 19:36:03
Version Found In: 4.1.0
User Comments:
wiede added on 2018-01-01 16:30:07:
package require itcl 4.1.0

::itcl::extendedclass Pushbutton {
  constructor {args} {}
  option [list -borderwidth borderWidth BorderWidth] -default 2
}

::itcl::body Pushbutton::constructor {args} {
  set win [createhull frame $this -class [info class]]
puts stderr "win: $win"
  set val2a [info option -borderwidth -resource]
puts stderr "val2a: $val2a"
  set val2b [namespace eval ::Pushbutton info class]
puts stderr "val2b: $val2b"
  # the next one crashes in Itcl_BiInfoMethodCmd in generic/itclInfo.c in Tcl_FindHashEntry
  # as contextIlsPtr == NULL
  #
  # /*
  #  *  Return info for a specific command.
  #  */
  # if (cmdName) {
  #     ItclCmdLookup *clookup;
  #     objPtr = Tcl_NewStringObj(cmdName, -1);
  #     hPtr = Tcl_FindHashEntry(&contextIclsPtr->resolveCmds, (char *)objPtr);
  #
  # The reason is that  Itcl_GetContext can no longer detect the ioContext from infoPtr->contextStack
  # as contextStack is no longer available as it was in version 4.0.3 see code below
  #
  # callContextPtr = Itcl_PeekStack(&infoPtr->contextStack);
  # if ((callContextPtr != NULL) && (callContextPtr->imPtr != NULL)) {
  #     *iclsPtrPtr = callContextPtr->imPtr->iclsPtr;
  # } else {
  #     hPtr = Tcl_FindHashEntry(&infoPtr->namespaceClasses,
  #             (char *)activeNs);
  #     if (hPtr != NULL) {
  #         *iclsPtrPtr = (ItclClass *)Tcl_GetHashValue(hPtr);
  #     }
  # }
  #
  # In that version if Tcl_FindHashEntry returned hptr == NULL, then ioPtrPtr
  # was filled like so:
  # if ((*ioPtrPtr == NULL) && ((*iclsPtrPtr)->nsPtr != NULL)) {
  #     /* maybe we are in a constructor try currIoPtr */
  #     *ioPtrPtr = (*iclsPtrPtr)->infoPtr->currIoPtr;
  # }
  #
  set val2c [namespace eval ::Pushbutton info option -borderwidth -resource]
puts stderr "val2c: $val2c"
}

Pushbutton .pb
pack .pb

dgp added on 2018-02-21 20:15:29:
The crash could be remedied by putting in the protection code
in [info option] so that it can operate without crashing when it
is called in a context where no "current object" can be resolved.
As written, it assumes a current object can always be resolved
and that's false.

That won't take care of things though. Recent changes in the
TclOO foundations have broken the itcl::extendedclass outside
of that.  Try Itcl 4.0.6 with tip of core-8-6-branch and the demo
script here. You now get an error:

namespace "::Pushbutton" is not a class namespace
    while executing
"createhull frame $this -class [info class]"
    while constructing object "::.pb" in ::Pushbutton::constructor (body line 7)
    invoked from within
"::itcl::parser::handleClass Pushbutton ::Pushbutton .pb"
    invoked from within
"Pushbutton .pb"

itcl::extendedclass will have to get a maintainer to keep up
with other changes in TclOO and Itcl or it will have to die.
It is a new command in Itcl 4. I have no interest in it. The
codebase that implements it is an indecipherable mess I cannot
deal with any longer. No one migrating from Itcl 3 needs it. I've
wasted too much time on it now already.

dgp added on 2018-02-22 03:37:52:
opening this up again. I got extremely frustrated because I was trying
to do something impossible -- not understanding all the interwoven
dependencies at play here.

dgp added on 2018-02-22 03:41:29:
So, with the internals revisions to namespaces an TclOO that will be part
of Tcl 8.6.9+ and Tcl 8.7a3+ the earliest Itcl 4 that can possibly work
is Itcl 4.1.1 which contains the corresponding reforms.  All the work trying
to figure out precise why Itcl 4.0.6 would not work with Tcl 8.6.9 was
just a terrible waste of time. It doesn't work. Itcl 4 users have to keep up.

dgp added on 2018-02-22 19:22:09:
Just to demonstrate this is a pre-existing problem, and not
something new in Itcl 4.1.* ...

% package present Tcl
8.6.8
% package require -exact itcl 4.0.6
4.0.6
% ::itcl::extendedclass Pushbutton {
  constructor {args} {}
  option [list -borderwidth borderWidth BorderWidth] -default 2
}
% namespace eval Pushbutton info option -borderwidth
Segmentation fault

dgp added on 2018-02-27 19:18:01:
Committed protections so that missing object context reports
error instead of segfaulting.

dgp added on 2018-02-27 19:35:49:
Revised Itcl_GetContext() to make Itcl 4.1 acts like Itcl 4.0 on the submitted script.

No test suite failures.

Gonna take it on faith, since I don't understand it.