a useful check

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

a useful check

Eliot Miranda-2
Hi All,

    I just stumbled across a bug of mine which is a rare but easy-to-make slip, that of an unused block,  e.g. expr ifTrue: [[something that doesn't get done]].  Here's a check for it (I'll check it in as a SysdtemNavigation method and perhaps the RB includes it in its lint tests).  There's one method in Squeak trunk that falls foul of this.

"Scan for the byte following each block creation being the pop bytecode."
SystemNavigation new browseAllSelect:
[:m| | is |
is := InstructionStream on: m.
is scanFor: [:b| b = 143 and: [(m at: is thirdByte * 256 + is fourthByte + is pc + 4) = 135]]]

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: a useful check

Stéphane Ducasse
What is the way to fix that?


> SystemNavigation new browseAllSelect:
> [:m| | is |
> is := InstructionStream on: m.
> is scanFor: [:b| b = 143 and: [(m at: is thirdByte * 256 + is fourthByte + is pc + 4) = 135]]]


lookForCode: code ifDifferent: handleBlock
        "We are expecting a certain numeric code next.  
        However, in the FTP protocol, multiple lines are allowed.  
        If the response is multi-line, the fourth character of the first line is a  
        $- and the last line repeats the numeric code but the code is followed by
        a space. So it's possible that there are more lines left of the last response that
        we need to throw away. We use peekForAll: so that we don't discard the
        next response that is not a continuation line."

       
        "check for multi-line response"
        (self lastResponse size > 3
                        and: [(self lastResponse at: 4) = $-])
                ifTrue: ["Discard continuation lines."
                        [ | headToDiscard |
                        headToDiscard := self lastResponse first: 4.
                        [[self stream peekForAll: headToDiscard]
                                whileTrue: [self stream nextLine]]
                                on: Exception
                                do: [:ex | ^handleBlock value: nil]]].
        ^ super lookForCode: code ifDifferent: handleBlock
_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: a useful check

Igor Stasenko
On 23 October 2010 14:36, Stéphane Ducasse <[hidden email]> wrote:
> What is the way to fix that?
>

something ifTrue: [ [ code which never runs ] ]  -->>
something ifTrue: [ code which now can run ]

unless, of course it is used like:

block := something ifTrue: [ [block1 ] ] ifFalse: [ [block2]].

>
>> SystemNavigation new browseAllSelect:
>>       [:m| | is |
>>       is := InstructionStream on: m.
>>       is scanFor: [:b| b = 143 and: [(m at: is thirdByte * 256 + is fourthByte + is pc + 4) = 135]]]
>
>
> lookForCode: code ifDifferent: handleBlock
>        "We are expecting a certain numeric code next.
>        However, in the FTP protocol, multiple lines are allowed.
>        If the response is multi-line, the fourth character of the first line is a
>        $- and the last line repeats the numeric code but the code is followed by
>        a space. So it's possible that there are more lines left of the last response that
>        we need to throw away. We use peekForAll: so that we don't discard the
>        next response that is not a continuation line."
>
>
>        "check for multi-line response"
>        (self lastResponse size > 3
>                        and: [(self lastResponse at: 4) = $-])
>                ifTrue: ["Discard continuation lines."
>                        [ | headToDiscard |
>                        headToDiscard := self lastResponse first: 4.
>                        [[self stream peekForAll: headToDiscard]
>                                whileTrue: [self stream nextLine]]
>                                on: Exception
>                                do: [:ex | ^handleBlock value: nil]]].
>        ^ super lookForCode: code ifDifferent: handleBlock
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>



--
Best regards,
Igor Stasenko AKA sig.

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project