<div dir="ltr">Usage of primitiveFail is on purpose here because this is the source code of the (misc) primitive.<div>So, it's an imperative style to make the primitive fail.</div><div><br></div><div>This is confusing if we run the primitive code as a fallback code</div><div>(we will run exact same code as primitive which is duplicating the work, if the primitive really exist, and will fail for same reasons).</div><div><br></div><div>I thought we got rid of those MiscprimitivePlugin.</div><div>We really should.<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le mar. 28 mai 2019 à 11:09, <<a href="mailto:commits@source.squeak.org">commits@source.squeak.org</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">A new version of Graphics was added to project The Inbox:<br>
<a href="http://source.squeak.org/inbox/Graphics-cmfcmf.407.mcz" rel="noreferrer" target="_blank">http://source.squeak.org/inbox/Graphics-cmfcmf.407.mcz</a><br>
<br>
==================== Summary ====================<br>
<br>
Name: Graphics-cmfcmf.407<br>
Author: cmfcmf<br>
Time: 28 May 2019, 11:08:38.38585 am<br>
UUID: 02f1c0df-d0cd-4c46-a8bc-c2cd77ab3ed3<br>
Ancestors: Graphics-mt.406<br>
<br>
Send correct message when primitive fails (>>primitiveFailed instead of >>primitiveFail)<br>
<br>
I found no other occurrences of >>primitiveFail in the image.<br>
<br>
=============== Diff against Graphics-mt.406 ===============<br>
<br>
Item was changed:<br>
  ----- Method: Bitmap>>decompress:fromByteArray:at: (in category 'filing') -----<br>
  decompress: bm fromByteArray: ba at: index<br>
        "Decompress the body of a byteArray encoded by compressToByteArray (qv)...<br>
        The format is simply a sequence of run-coded pairs, {N D}*.<br>
                N is a run-length * 4 + data code.<br>
                D, the data, depends on the data code...<br>
                        0       skip N words, D is absent<br>
                                (could be used to skip from one raster line to the next)<br>
                        1       N words with all 4 bytes = D (1 byte)<br>
                        2       N words all = D (4 bytes)<br>
                        3       N words follow in D (4N bytes)<br>
                S and N are encoded as follows (see decodeIntFrom:)...<br>
                        0-223   0-223<br>
                        224-254 (0-30)*256 + next byte (0-7935)<br>
                        255             next 4 bytes"   <br>
        "NOTE:  If fed with garbage, this routine could read past the end of ba, but it should fail before writing past the ned of bm."<br>
        | i code n anInt data end k pastEnd |<br>
        <primitive: 'primitiveDecompressFromByteArray' module: 'MiscPrimitivePlugin'><br>
        <var: #bm type: 'int *'><br>
        <var: #ba type: 'unsigned char *'><br>
        <var: #anInt type: 'unsigned int'> "Force the type, otherwise it is inferred as unsigned char because assigned from ba"<br>
        <var: #data type: 'unsigned int'><br>
        i := index.  "byteArray read index"<br>
        end := ba size.<br>
        k := 1.  "bitmap write index"<br>
        pastEnd := bm size + 1.<br>
        [i <= end] whileTrue:<br>
                ["Decode next run start N"<br>
                anInt := ba at: i.  i := i+1.<br>
                anInt <= 223 ifFalse:<br>
                        [anInt <= 254<br>
                                ifTrue: [anInt := (anInt-224)*256 + (ba at: i).  i := i+1]<br>
                                ifFalse: [anInt := 0.<br>
                                                1 to: 4 do: [:j | anInt := (anInt bitShift: 8) + (ba at: i).  i := i+1]]].<br>
                n := anInt >> 2.<br>
+               (k + n) > pastEnd ifTrue: [^ self primitiveFailed].<br>
-               (k + n) > pastEnd ifTrue: [^ self primitiveFail].<br>
                code := anInt bitAnd: 3.<br>
                code = 0 ifTrue: ["skip"].<br>
                code = 1 ifTrue: ["n consecutive words of 4 bytes = the following byte"<br>
                                                data := ba at: i.  i := i+1.<br>
                                                data := data bitOr: (data bitShift: 8).<br>
                                                data := data bitOr: (data bitShift: 16).<br>
                                                1 to: n do: [:j | bm at: k put: data.  k := k+1]].<br>
                code = 2 ifTrue: ["n consecutive words = 4 following bytes"<br>
                                                data := 0.<br>
                                                1 to: 4 do: [:j | data := (data bitShift: 8) bitOr: (ba at: i).  i := i+1].<br>
                                                1 to: n do: [:j | bm at: k put: data.  k := k+1]].<br>
                code = 3 ifTrue: ["n consecutive words from the data..."<br>
                                                1 to: n do:<br>
                                                        [:m | data := 0.<br>
                                                        1 to: 4 do: [:j | data := (data bitShift: 8) bitOr: (ba at: i).  i := i+1].<br>
                                                        bm at: k put: data.  k := k+1]]]!<br>
<br>
<br>
</blockquote></div>