Re: Is SmallInteger a really too dangerous class?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: Is SmallInteger a really too dangerous class?

Mariano Martinez Peck
 
sorry, it should be

SmallInteger class >> initialize
    self addInstVarName: 'Zaraza'.

Notice I want to add a class variable to SmallIneteger, not instVar.

Cheers

mariano

On Mon, Dec 13, 2010 at 9:16 PM, Mariano Martinez Peck <[hidden email]> wrote:
Hi folks. Sorry for the cross-post, I am not sure if it is image or vm problem.

If I implement this:

SmallInteger >> initialize
    self addInstVarName: 'Zaraza'.

I have the error: 'SmallInteger cannot be changed'

This is because SmallInteger is in the ClassBuilder >> tooDangerousClasses
and the error is in ClassBuilder >> name: className inEnvironment: env subclassOf: newSuper type: type instanceVariableNames: instVarString classVariableNames: classVarString poolDictionaries: poolString category: category unsafe: unsafe

Now....since this is Smalltalk, I can just comment something, continue, or any other kind of hack so that I can add class variables to SmallInetger.
For my CompiledMethod proxies stuff, I am using SmallIntegers and I have some crashes (one is due to a corrupt heap and Eliot said something about sizes)...I wonder if this is related to this...So the question is:  is really SMallInteger a too dangerous class so that it cannot be changed? not even adding a class variable???  does the VM assume that the class SmallInetger has a fixed size?  if true, where?

Thanks in advance

Mariano

Reply | Threaded
Open this post in threaded view
|

Re: Is SmallInteger a really too dangerous class?

Bert Freudenberg
 

On 13.12.2010, at 13:06, Mariano Martinez Peck wrote:

sorry, it should be

SmallInteger class >> initialize
    self addInstVarName: 'Zaraza'.

Notice I want to add a class variable to SmallIneteger, not instVar.


This is not really a VM question. Class variables are held in a dictionary. The VM knows nothing about this.

You add class variables simply by adding them to the class pool:

SmallInteger ensureClassPool.
SmallInteger classPool at: #Zaraza put: 42.

- Bert -

Reply | Threaded
Open this post in threaded view
|

Re: Is SmallInteger a really too dangerous class?

Andreas.Raab
 
On 12/13/2010 2:48 PM, Bert Freudenberg wrote:

> On 13.12.2010, at 13:06, Mariano Martinez Peck wrote:
>
>> sorry, it should be
>>
>> SmallInteger class >> initialize
>> self addInstVarName: 'Zaraza'.
>>
>> Notice I want to add a class variable to SmallIneteger, not instVar.
>
> This is not really a VM question. Class variables are held in a
> dictionary. The VM knows nothing about this.

And of course class vars are added by using #addClassVarName: not
#addInstVarName:.

Cheers,
   - Andreas
Reply | Threaded
Open this post in threaded view
|

Re: Is SmallInteger a really too dangerous class?

Igor Stasenko

On 14 December 2010 00:13, Andreas Raab <[hidden email]> wrote:

>
> On 12/13/2010 2:48 PM, Bert Freudenberg wrote:
>>
>> On 13.12.2010, at 13:06, Mariano Martinez Peck wrote:
>>
>>> sorry, it should be
>>>
>>> SmallInteger class >> initialize
>>> self addInstVarName: 'Zaraza'.
>>>

'Zaraza' in russian means 'infection'.
It also used for swearing, when something goes not what expected to be :)

>>> Notice I want to add a class variable to SmallIneteger, not instVar.
>>
>> This is not really a VM question. Class variables are held in a
>> dictionary. The VM knows nothing about this.
>
> And of course class vars are added by using #addClassVarName: not
> #addInstVarName:.
>

class inst var should be ok too. Not sure what the correct message for
adding it programmatically.

> Cheers,
>  - Andreas
>



--
Best regards,
Igor Stasenko AKA sig.
Reply | Threaded
Open this post in threaded view
|

Re: Is SmallInteger a really too dangerous class?

Andreas.Raab
 
On 12/14/2010 1:09 AM, Igor Stasenko wrote:

>>>> Notice I want to add a class variable to SmallIneteger, not instVar.
>>>
>>> This is not really a VM question. Class variables are held in a
>>> dictionary. The VM knows nothing about this.
>>
>> And of course class vars are added by using #addClassVarName: not
>> #addInstVarName:.
>>
>
> class inst var should be ok too. Not sure what the correct message for
> adding it programmatically.

Obviously that would be "self ->class<- addInstVarName:
'classInstVarName'".

BTW, you do realize that you can try all of this right in the browser,
no? All you need is to go to class SmallInteger and edit the class
definition. Then you can see whether it is possible to add instance
variables (it's not), class variables (works fine), or class instance
variables (works fine, too). And once you've tried this it should be
pretty obvious that your code is broken and not the VM and/or ClassBuilder.

Cheers,
   - Andreas
Reply | Threaded
Open this post in threaded view
|

Re: Is SmallInteger a really too dangerous class?

Mariano Martinez Peck
 


On Tue, Dec 14, 2010 at 10:18 AM, Andreas Raab <[hidden email]> wrote:

On 12/14/2010 1:09 AM, Igor Stasenko wrote:
Notice I want to add a class variable to SmallIneteger, not instVar.

This is not really a VM question. Class variables are held in a
dictionary. The VM knows nothing about this.

And of course class vars are added by using #addClassVarName: not
#addInstVarName:.


class inst var should be ok too. Not sure what the correct message for
adding it programmatically.

Obviously that would be "self ->class<- addInstVarName: 'classInstVarName'".


Yep....sorry.

Conclusion:  do not program while building the christmas tree with your wife ;)
 
BTW, you do realize that you can try all of this right in the browser, no? All you need is to go to class SmallInteger and edit the class definition. Then you can see whether it is possible to add instance variables (it's not), class variables (works fine), or class instance variables (works fine, too). And once you've tried this it should be pretty obvious that your code is broken and not the VM and/or ClassBuilder.

yes, that a good tip. Thanks
 

Cheers,
 - Andreas

Reply | Threaded
Open this post in threaded view
|

Re: Is SmallInteger a really too dangerous class?

Mariano Martinez Peck
In reply to this post by Bert Freudenberg
 


On Mon, Dec 13, 2010 at 11:48 PM, Bert Freudenberg <[hidden email]> wrote:
 

On 13.12.2010, at 13:06, Mariano Martinez Peck wrote:

sorry, it should be

SmallInteger class >> initialize
    self addInstVarName: 'Zaraza'.

Notice I want to add a class variable to SmallIneteger, not instVar.


This is not really a VM question. Class variables are held in a dictionary. The VM knows nothing about this.


Ok, perfect. I asked because once I was doing some proxies for Classes and I realized that the VM automatically access the offset of the Class instVar like methodDict, etc.
I thought that maybe at some place the same could happen with SmallInteger class.

Thanks

Mariano
 
You add class variables simply by adding them to the class pool:

SmallInteger ensureClassPool.
SmallInteger classPool at: #Zaraza put: 42.

- Bert -