Tcl Source Code

View Ticket
Login
Ticket UUID: 3c32a3f8bd054837124c84f1725003e5a3eec028
Title: TclOO - mixing an object
Type: Bug Version: trunk
Submitter: pooryorick Created on: 2017-11-01 20:48:42
Subsystem: 35. TclOO Package Assigned To: nobody
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2017-11-18 00:14:37
Resolution: Fixed Closed By: pooryorick
    Closed on: 2017-11-18 00:14:37
Description:

The following script causes a segmentation fault

proc dying {_ args} {
	puts [list $_ is dying]
}

oo::define oo::class {export createWithNamespace}
oo::class createWithNamespace obj1 obj1
::oo::define obj1 {self mixin [self]}

::oo::copy obj1 obj2
::oo::objdefine obj2 {mixin [self]}

::oo::copy obj2 obj3
trace add command obj3 delete [list obj3 dying]
rename obj2 {}

User Comments: pooryorick added on 2017-11-17 23:06:36:

Fixed in commit [5f178e7f03].


pooryorick added on 2017-11-01 20:57:39:

The problem lies in TclOO.c/ReleaseClassContents(), in a section that seems to be about removing a class that has been mixed into one of its instances (an unusual use case, to say the least):

for(j=0 ; j<instancePtr->mixins.num ; j++) {
    Class *mixin = instancePtr->mixins.list[j];
    if (mixin == clsPtr) {
        instancePtr->mixins.list[j] = NULL;
    }
}

Leaving a NULL in the list breaks expectations. Instead, that particular item should be unstitched from the list.