Adding new instance variables to Behavior...

Alan Lovejoy sourcery at pacbell.net
Thu Jun 24 05:03:44 UTC 1999


"Kevin R. Powell" wrote:

>  I was working on a quick and dirty namespace implementation for squeak and
>  discovered a small problem.  If I add a new instance variable called
>  namespace to Behavior I get an error when the Dictionary class is being
>  recompiled (looks like the Dictionary class's instance variable offsets are
>  one off with respect to Behaviors new added inst. var.)
>
>  I had to redefine Behavior>>superclass: aClass to the following to get this
>  kind of change to proceed at all:
>
>  superclass: aClass
>   "Change the receiver's superclass to be aClass."
>   (aClass == nil
>    or: [(aClass isKindOf: Behavior)
>      or: [(aClass isKindOf: Metaclass)
>        or: [aClass == Metaclass]]])
>    ifTrue: [superclass _ aClass]
>    ifFalse: [self error: 'superclass must be a class-describing object']
>
>  I am doing this on Windows/NT using 2.4c with all updates applied, however
>  this looks like something that should blow up on any OS type.
>
>  Kevin

The problem is simply that, in this case, "Behavior ~~ Behavior".  When you
redefine a class, a new class object is created.  There will temporarily be
two class objects with the same name in the image.  Before the old one is
replaced with the new one as the value of the Association in the
SystemDictionary whose key is the name of the class, the new class must
be properly initialized.  As part of its initialization, it must be 
told what its
superclass is.

One way to avoid this problem is to redefine ClassDescription instead of
Behavior.  The other, perhaps more general, solution would be to define
the method #isBehavior in both Object and Behavior (with the former
answering false, and the latter answering true).  Then the #superclass: aClass
method could perform its validity test by sending the message #isBehavior,
instead of using #isKindOf: (which unfortunately depends on the identity of
class objects).

--Alan


Content-Type: text/x-vcard; charset=us-ascii;
  name="sourcery.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Alan Lovejoy
Content-Disposition: attachment;
  filename="sourcery.vcf"

Attachment converted: Anon:sourcery.vcf 2 (TEXT/R*ch) (0000AD08)
Content-Type: application/x-pkcs7-signature; name="smime.p7s"
Content-Disposition: attachment; filename="smime.p7s"
Content-Description: S/MIME Cryptographic Signature

Attachment converted: Anon:smime.p7s 3 (????/----) (0000AD09)





More information about the Squeak-dev mailing list