DependentsArray size and subscript is out of bounds

nicolas cellier ncellier at ifrance.com
Thu Jul 20 17:05:56 UTC 2006


OK, so this is not a bug of SmaCC, this is one of the many bugs in 
DependentsArray...

(see http://bugs.impara.de/view.php?id=2701)

As long as #at: and #size messages are not defined consistently 
(possibility to use an index greater than size) DependentsArray cannot 
inherit safely from SequenceableCollection.

It would be better to place it in a different hierarchy, maybe under 
Collection...

Nicolas

Andrew Tween a écrit :
> Hi,
> I think that the problem occurs iff a garbage collect/finalization occurs during
> the DependentsArray>>copyWith: .
>
> This code exhibits the problem that you describe...
>
>      d := (DependentsArray new: 1).
>      1 to: 50 do:[:i |
>         d := d copyWith: Object new ].
>
> whereas this code runs without error....
>
>     d := (DependentsArray new: 1).
>     1 to: 50 do:[:i |
>           Smalltalk garbageCollect.
>           d := d copyWith: Object new ].
>
> I have also seen this problem when using Smacc, but didn't solve the root cause
> of the problem. I just did a garbage collect before generating the
> parser/scanner and the problem went away.
>
> Hope this helps.
> Cheers,
> Andy
>
>
>
> ----- Original Message ----- 
> From: "mathieu" <mathk.sue at gmail.com>
> To: <ncellier at ifrance.com>; "The general-purpose Squeak developers list"
> <squeak-dev at lists.squeakfoundation.org>
> Sent: Thursday, July 20, 2006 6:49 AM
> Subject: Re: DependentsArray size and subscript is out of bounds
>
>
>   
>> nicolas cellier a écrit :
>>     
>>> Le Jeudi 20 Juillet 2006 00:38, mathieu a écrit :
>>>       
>>>> Hi,
>>>>
>>>> It is normal that:
>>>>
>>>> (DependentsArray new: 100) size
>>>>
>>>> return 0?
>>>>         
>>> Yes
>>>
>>>       
>>>> If yes so why?
>>>>         
>>> DependentsArray count only non nil elements
>>>
>>>       
>>>> And if I do:
>>>> | o |
>>>>
>>>> o := WriteStream on: (DependentsArray new: 100).
>>>> 1 to: 24 do: [:each | o nextPut: Object new]. "do it sevral time"
>>>>
>>>> it raise an error 'subscript is out of bounds: 22' from time to time
>>>> why?
>>>>         
>>> You cannot do that with DependentsArray.
>>>
>>> DependentsArray are weak array: that mean that storing an object into a
>>> DependentsArray does not prevent it from being garbageCollected.
>>>
>>> When an element is garbage collected, corresponding index in DependentsArray
>>> is replaced by nil.
>>>
>>> All is occuring in pastEndPut:
>>> Since initial size (non nil elements) is zero, then the array is grown to
>>> size: oldSize + ((oldSize max: 20) min: 1000000)
>>>
>>> When no garbageCollection occurs, that works fine (except a new
>>> DependentsArray is created each time you add an Object).
>>>
>>> When a garbage collect occurs, all unreferenced (Object new) are removed
>>>       
> from
>   
>>> the DependentsArray, except one (I do not know who is referencing it, maybe
>>> the BlockContext...).
>>>
>>> Thus you allocate a DependentsArray of size 21 and fail when storing element
>>> number 22...
>>>
>>>       
>>>> Thx
>>>> Math
>>>>         
>>> What do you need DependentsArray for?
>>>
>>> Nicolas
>>>       
>> ok thx :)
>>
>> In fact this is "used" in SmaCC and raise this error:
>>
>> ======================================================
>> DependentsArray(Object)>>error:
>> Receiver: a DependentsArray(<keyword> ")" "]" <binarySymbol> "}" ";"
>> <period> ">" <name> E O F)
>> Arguments and temporary variables:
>> aString: *'subscript is out of bounds: 23'*
>> Receiver's instance variables:
>> a DependentsArray(<keyword> ")" "]" <binarySymbol> "}" ";" <period> ">"
>> <name> E O F)
>>
>> DependentsArray(Object)>>errorSubscriptBounds:
>> Receiver: a DependentsArray(<keyword> ")" "]" <binarySymbol> "}" ";"
>> <period> ">" <name> E O F)
>> Arguments and temporary variables:
>> index: 23
>> Receiver's instance variables:
>> a DependentsArray(<keyword> ")" "]" <binarySymbol> "}" ";" <period> ">"
>> <name> E O F)
>>
>> DependentsArray(Object)>>at:put:
>> Receiver: a DependentsArray(<keyword> ")" "]" <binarySymbol> "}" ";"
>> <period> ">" <name> E O F)
>> Arguments and temporary variables:
>> index: 23
>> value:
>> Receiver's instance variables:
>> a DependentsArray(<keyword> ")" "]" <binarySymbol> "}" ";" <period> ">"
>> <name> E O F)
>>
>> WriteStream>>pastEndPut:
>> Receiver: <<error during printing>>
>> Arguments and temporary variables:
>> anObject:
>> oldSize: 2
>> grownCollection: a DependentsArray(<keyword> ")" "]" <binarySymbol>
>> "}" ";" <pe...etc...
>> Receiver's instance variables:
>> collection: a DependentsArray(<keyword> ")" "]" <binarySymbol> "}"
>> ";" <period>...etc...
>> position: 23
>> readLimit: 23
>> writeLimit: 1
>>
>>
>> --- The full stack ---
>> DependentsArray(Object)>>error:
>> DependentsArray(Object)>>errorSubscriptBounds:
>> DependentsArray(Object)>>at:put:
>> WriteStream>>pastEndPut:
>>  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
>> WriteStream>>nextPut:
>> [] in DependentsArray>>copyWith: {[:s |  self   do: [:item | s nextPut:
>> item].  s nextPut: newElement]}
>> DependentsArray class(SequenceableCollection class)>>streamContents:
>> DependentsArray>>copyWith:
>> DependentsArray(Array)>>copyWithDependent:
>> SmaCCSymbolSet(Object)>>addDependent:
>> SmaCCSymbolSet>>addComponent:
>> SmaCCSymbolSet>>baseOn:
>> SmaCCSymbolSet class>>basedOn:
>> SmaCCLR1Item>>moveNext
>> [] in SmaCCItemSet>>moveOn: {[:each | each nextSymbol == aGrammarSymbol
>>   ifTrue: [anItemSet add: each mo...]}
>> SmaCCItemSet(Set)>>do:
>> SmaCCItemSet>>moveOn:
>> [] in SmaCCGrammarCompiler>>createItemSets {[:each |  newState :=
>> itemSet moveOn: each.  newState notEmpty   ifTrue: [sh...]}
>> SortedCollection(OrderedCollection)>>do:
>> SmaCCGrammarCompiler>>createItemSets
>> SmaCCGrammarCompiler>>transitionTable
>> SmaCCGrammarCompiler>>compileTransitionTable
>> SmaCCGrammarCompiler>>compileParser
>> SmaCCGrammarCompiler>>createChanges
>> ======================================================
>>
>>
>>
>>
>>     
>
>
>   




More information about the Squeak-dev mailing list