The Inbox: Collections-jar.924.mcz

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

The Inbox: Collections-jar.924.mcz

commits-2
A new version of Collections was added to project The Inbox:
http://source.squeak.org/inbox/Collections-jar.924.mcz

==================== Summary ====================

Name: Collections-jar.924
Author: jar
Time: 7 February 2021, 9:42:07.649004 am
UUID: 073b26bc-8e5e-ba41-9aac-9d424bbe6848
Ancestors: Collections-dtl.923

Fixes SharedQueue >> nextOrNilSuchThat bug to pass the existing test

=============== Diff against Collections-dtl.923 ===============

Item was changed:
  ----- Method: SharedQueue>>nextOrNilSuchThat: (in category 'accessing') -----
  nextOrNilSuchThat: aBlock
  "Answer the next object that satisfies aBlock, skipping any intermediate objects.
  If no object has been sent, answer <nil> and leave me intact.
  NOTA BENE:  aBlock MUST NOT contain a non-local return (^)."
 
  ^accessProtect critical: [
  | value readPos |
  value := nil.
  readPos := readPosition.
  [ readPos < writePosition and: [ value isNil ] ] whileTrue: [
  value := contentsArray at: readPos.
  readPos := readPos + 1.
  (aBlock value: value)
  ifFalse: [ value := nil ]
  ifTrue: [
  readSynch waitIfLocked: [ ^nil ]. "We found the value, but someone else booked it."
+ readPos-1 to: readPosition+1 by: -1 do: [ :j | contentsArray at: j put: (contentsArray at: j-1) ].
+ contentsArray at: readPosition put: nil.
+ readPosition := readPosition+1 ] ].
- readPosition to: readPos - 1 do: [ :j | contentsArray at: j put: nil ].
- readPosition := readPos ] ].
  value ].
  "===
  q := SharedQueue new.
  1 to: 10 do: [ :i | q nextPut: i].
  c := OrderedCollection new.
  [
  v := q nextOrNilSuchThat: [ :e | e odd].
  v notNil
  ] whileTrue: [
  c add: {v. q size}
  ].
  {c. q} explore
  ==="!


Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Collections-jar.924.mcz

David T. Lewis
This looks good to me, and it fixes the failing test.

Note that none of the historical versions of SharedQueue>>nextOrNilSuchThat:
pass the test, but the issue became visible after CollectionsTests-eem.342
last September when the existing test for SharedQueue2 was applied to
SharedQueue as well.

It would be good if Levente or Nicolas can review this, but +1 from me.

Thanks Jaromir for putting this in the inbox :-)

Dave


On Sun, Feb 07, 2021 at 08:42:11AM +0000, [hidden email] wrote:

> A new version of Collections was added to project The Inbox:
> http://source.squeak.org/inbox/Collections-jar.924.mcz
>
> ==================== Summary ====================
>
> Name: Collections-jar.924
> Author: jar
> Time: 7 February 2021, 9:42:07.649004 am
> UUID: 073b26bc-8e5e-ba41-9aac-9d424bbe6848
> Ancestors: Collections-dtl.923
>
> Fixes SharedQueue >> nextOrNilSuchThat bug to pass the existing test
>
> =============== Diff against Collections-dtl.923 ===============
>
> Item was changed:
>   ----- Method: SharedQueue>>nextOrNilSuchThat: (in category 'accessing') -----
>   nextOrNilSuchThat: aBlock
>   "Answer the next object that satisfies aBlock, skipping any intermediate objects.
>   If no object has been sent, answer <nil> and leave me intact.
>   NOTA BENE:  aBlock MUST NOT contain a non-local return (^)."
>  
>   ^accessProtect critical: [
>   | value readPos |
>   value := nil.
>   readPos := readPosition.
>   [ readPos < writePosition and: [ value isNil ] ] whileTrue: [
>   value := contentsArray at: readPos.
>   readPos := readPos + 1.
>   (aBlock value: value)
>   ifFalse: [ value := nil ]
>   ifTrue: [
>   readSynch waitIfLocked: [ ^nil ]. "We found the value, but someone else booked it."
> + readPos-1 to: readPosition+1 by: -1 do: [ :j | contentsArray at: j put: (contentsArray at: j-1) ].
> + contentsArray at: readPosition put: nil.
> + readPosition := readPosition+1 ] ].
> - readPosition to: readPos - 1 do: [ :j | contentsArray at: j put: nil ].
> - readPosition := readPos ] ].
>   value ].
>   "===
>   q := SharedQueue new.
>   1 to: 10 do: [ :i | q nextPut: i].
>   c := OrderedCollection new.
>   [
>   v := q nextOrNilSuchThat: [ :e | e odd].
>   v notNil
>   ] whileTrue: [
>   c add: {v. q size}
>   ].
>   {c. q} explore
>   ==="!
>
>

Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Collections-jar.924.mcz

Levente Uzonyi
Hi David,

On Sun, 7 Feb 2021, David T. Lewis wrote:

> This looks good to me, and it fixes the failing test.
>
> Note that none of the historical versions of SharedQueue>>nextOrNilSuchThat:
> pass the test, but the issue became visible after CollectionsTests-eem.342
> last September when the existing test for SharedQueue2 was applied to
> SharedQueue as well.
>
> It would be good if Levente or Nicolas can review this, but +1 from me.

The fix looks right in the sense that it does what the test case requires.
But it may affect the way events are processed.
The only sender of this method is EventSensor which may rely on the
current behavior.
So, I would like someone who understands how EventSensor works confirm
that the change is okay before pushing it to the Trunk.


Levente

>
> Thanks Jaromir for putting this in the inbox :-)
>
> Dave
>
>
> On Sun, Feb 07, 2021 at 08:42:11AM +0000, [hidden email] wrote:
>> A new version of Collections was added to project The Inbox:
>> http://source.squeak.org/inbox/Collections-jar.924.mcz
>>
>> ==================== Summary ====================
>>
>> Name: Collections-jar.924
>> Author: jar
>> Time: 7 February 2021, 9:42:07.649004 am
>> UUID: 073b26bc-8e5e-ba41-9aac-9d424bbe6848
>> Ancestors: Collections-dtl.923
>>
>> Fixes SharedQueue >> nextOrNilSuchThat bug to pass the existing test
>>
>> =============== Diff against Collections-dtl.923 ===============
>>
>> Item was changed:
>>   ----- Method: SharedQueue>>nextOrNilSuchThat: (in category 'accessing') -----
>>   nextOrNilSuchThat: aBlock
>>   "Answer the next object that satisfies aBlock, skipping any intermediate objects.
>>   If no object has been sent, answer <nil> and leave me intact.
>>   NOTA BENE:  aBlock MUST NOT contain a non-local return (^)."
>>
>>   ^accessProtect critical: [
>>   | value readPos |
>>   value := nil.
>>   readPos := readPosition.
>>   [ readPos < writePosition and: [ value isNil ] ] whileTrue: [
>>   value := contentsArray at: readPos.
>>   readPos := readPos + 1.
>>   (aBlock value: value)
>>   ifFalse: [ value := nil ]
>>   ifTrue: [
>>   readSynch waitIfLocked: [ ^nil ]. "We found the value, but someone else booked it."
>> + readPos-1 to: readPosition+1 by: -1 do: [ :j | contentsArray at: j put: (contentsArray at: j-1) ].
>> + contentsArray at: readPosition put: nil.
>> + readPosition := readPosition+1 ] ].
>> - readPosition to: readPos - 1 do: [ :j | contentsArray at: j put: nil ].
>> - readPosition := readPos ] ].
>>   value ].
>>   "===
>>   q := SharedQueue new.
>>   1 to: 10 do: [ :i | q nextPut: i].
>>   c := OrderedCollection new.
>>   [
>>   v := q nextOrNilSuchThat: [ :e | e odd].
>>   v notNil
>>   ] whileTrue: [
>>   c add: {v. q size}
>>   ].
>>   {c. q} explore
>>   ==="!
>>
>>

Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Collections-jar.924.mcz

David T. Lewis
On Tue, Feb 09, 2021 at 01:54:33PM +0100, Levente Uzonyi wrote:

> Hi David,
>
> On Sun, 7 Feb 2021, David T. Lewis wrote:
>
> >This looks good to me, and it fixes the failing test.
> >
> >Note that none of the historical versions of
> >SharedQueue>>nextOrNilSuchThat:
> >pass the test, but the issue became visible after CollectionsTests-eem.342
> >last September when the existing test for SharedQueue2 was applied to
> >SharedQueue as well.
> >
> >It would be good if Levente or Nicolas can review this, but +1 from me.
>
> The fix looks right in the sense that it does what the test case requires.
> But it may affect the way events are processed.
> The only sender of this method is EventSensor which may rely on the
> current behavior.
> So, I would like someone who understands how EventSensor works confirm
> that the change is okay before pushing it to the Trunk.
>

Agreed, although I would say that if no further comments show up after
a couple of days, we should move it to trunk anyway.

The reason I say this is that the only sender is part of the Etoys package,
that that sender is part of SugarLauncher. That means that nobody is
actually using it in Squeak today. The unit test shows an actual error
condition (not a failed test expectation).

Earlier method versions show a test failure (not error) so indeed there
has been some change to the behavior over time. So indeed additional
review would be welcome.

Let's wait a few days and if no objections move it to trunk.

Dave