help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-smalltalk] [PATCH 1/2] kernel: Make >>#new/>>#new: go through


From: Paolo Bonzini
Subject: Re: [Help-smalltalk] [PATCH 1/2] kernel: Make >>#new/>>#new: go through >>#initialize
Date: Thu, 24 Jul 2014 20:26:29 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0

Il 24/07/2014 20:16, Holger Hans Peter Freyther ha scritto:
> In Pharo it is common that new/new: will already go through an
> initialize call. When porting code from and to Pharo one needs
> to make sure that initialize is called and only called once or
> idempotent. Align the code with Pharo.

I resisted doing this for several years, but I guess we should follow
Pharo's leadership now.

However, I think you should squash the two patches.

Thanks!

Paolo


> ---
>  kernel/Builtins.st           | 34 +++++++++++++++-------------------
>  kernel/Metaclass.st          |  5 +++++
>  packages/debug/debugtests.st |  2 +-
>  3 files changed, 21 insertions(+), 20 deletions(-)
> 
> diff --git a/kernel/Builtins.st b/kernel/Builtins.st
> index 666db54..eb5fa3b 100644
> --- a/kernel/Builtins.st
> +++ b/kernel/Builtins.st
> @@ -43,6 +43,11 @@ Behavior extend [
>  ]
>  
>  Object extend [
> +    initialize [
> +        "Subclasses should redefine this method to perform initializations on
> +        instance creation"
> +    ]
> +
>      class [
>          "Answer the class to which the receiver belongs"
>          <primitive: VMpr_Object_class>
> @@ -53,15 +58,19 @@ Object extend [
>          
>  
>  Behavior extend [
> -    
> +
>      new [
>          "Create a new instance of a class with no indexed instance variables"
> -        <primitive: VMpr_Behavior_basicNew>
> -        <category: 'builtin'>
> -        self isFixed ifFalse: [ ^self new: 0 ].
> -        ^self primitiveFailed
> +        ^self basicNew initialize
>      ]
> -    
> +
> +    new: numInstanceVariables [
> +        "Create a new instance of a class with indexed instance variables. 
> The
> +         instance has numInstanceVariables indexed instance variables."
> +        ^(self basicNew: numInstanceVariables) initialize
> +    ]
> +
> +
>      basicNew [
>          "Create a new instance of a class with no indexed instance variables;
>           this method must not be overridden."
> @@ -71,19 +80,6 @@ Behavior extend [
>          ^self primitiveFailed
>      ]
>      
> -    new: numInstanceVariables [
> -        "Create a new instance of a class with indexed instance variables. 
> The
> -         instance has numInstanceVariables indexed instance variables."
> -        <primitive: VMpr_Behavior_basicNewColon>
> -        <category: 'builtin'>
> -        self isFixed ifTrue: [
> -     SystemExceptions.WrongMessageSent signalOn: #new: useInstead: #new
> -        ].
> -        numInstanceVariables isSmallInteger ifTrue: [ ^self primitiveFailed 
> ].
> -    
> -        ^SystemExceptions.WrongClass signalOn: numInstanceVariables mustBe: 
> SmallInteger
> -    ]
> -    
>      basicNew: numInstanceVariables [
>          "Create a new instance of a class with indexed instance variables. 
> The
>           instance has numInstanceVariables indexed instance variables;
> diff --git a/kernel/Metaclass.st b/kernel/Metaclass.st
> index 8b320cd..7fd8178 100644
> --- a/kernel/Metaclass.st
> +++ b/kernel/Metaclass.st
> @@ -55,6 +55,11 @@ it should be...the Smalltalk metaclass system is strange 
> and complex.'>
>       ^newMeta
>      ]
>  
> +    new [
> +        "Do not call >>#initialize on the classes"
> +        ^self basicNew
> +    ]
> +
>      addClassVarName: aString [
>       "Add a class variable with the given name to the class pool dictionary"
>  
> diff --git a/packages/debug/debugtests.st b/packages/debug/debugtests.st
> index eaa62f0..16f4c5d 100644
> --- a/packages/debug/debugtests.st
> +++ b/packages/debug/debugtests.st
> @@ -256,7 +256,7 @@ TestCase subclass: DebuggerTest [
>  
>       <category: 'test'>
>       | debugger reached notReached |
> -     debugger := self debuggerOn: [reached := Object new].
> +     debugger := self debuggerOn: [reached := Object basicNew].
>       debugger step.
>       self assert: reached notNil
>      ]
> 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]