Skip to content
Tcl Source Code View Ticket
Login

View Ticket

TclOO - mixing an object

Closed / Fixed3c32a3f8bd054837124c84f1725003e5a3eec028Created 9 years agoUpdated 9 years ago
Descriptionwiki2017-11-01 20:48:42
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 {}
pooryorickwiki2017-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.

pooryorickwiki2017-11-17 23:06:36

Fixed in commit [5f178e7f03].

pooryorick Ticket [3c32a3f8bd]: 4 changes [History diff]2017-11-18 00:14:37
Log in (anonymous is fine) to add a comment.