Itcl - the [incr Tcl] extension

View Ticket
Login
Ticket Hash: 19fa152b36781ed9394611a47badda7384a03625
Title: class with self-nullifying proc - cycling instances segfaults
Status: Closed Type: Code_Defect
Severity: Critical Priority: Immediate
Subsystem: Resolution: Fixed
Last Modified: 2017-06-28 13:18:14
Version Found In: 4.0.6
User Comments:
dgp added on 2017-06-27 16:49:49:
itcl::class C {
  proc cheshire {} {
    itcl::body ::C::cheshire {} {}
  }
  constructor {args} {
    cheshire
  }
}
while 1 {
  itcl::delete object [C #auto]
}

dgp added on 2017-06-27 18:30:29:
This started segfaulting with checkin

http://core.tcl.tk/itcl/ci/a4b7fff898598267?sbs=1

Before that it just failed, which was also wrong:

Itcl 4.0.4
member function "::C::cheshire" is not defined and cannot be autoloaded
    while executing
"cheshire"
    while constructing object "::c1" in ::C::constructor (body line 3)
    invoked from within
"::itcl::parser::handleClass C ::C #auto"
    invoked from within
"C #auto"
    ("while" body line 2)
    invoked from within
"while 1 {
  itcl::delete object [C #auto]
}"
    (file "/home/dgp/cheshire.tcl" line 12)

dgp added on 2017-06-28 12:45:32:
At least part of the problem here is that
imPtr->codePtr gets a new value in the
middle of the evaluation of imPtr.  This
causes the Release in the After to be on
a different pointer than the Preserve
in the CheckCall.  Things get out of balance,
and that leads to crashes and memory trouble.

dgp added on 2017-06-28 13:18:14:
Removed the Preserve/Release pairs that were going wrong.

The reference in the ItclMemberFunc ought to be enough.