#at:put: with uint shape does not accept all uint

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

#at:put: with uint shape does not accept all uint

Mathieu Suen-2
Hi,

I have a class with a uint as shape:

Object subclass: Foo
[
        <shape:#uint>
        Foo class >> new [
                ^(self new:1)
                        at: 1 put: 16r80000000
        ]
]

Eval [
   
    Foo new.
   
]

This snippet above raise an error:
"Object: Foo new: 1 <0x101327230> error:
     Invalid argument 2147483648: argument must be between 0 and 4294967295"

I don't know if that make sense but I have fixed it with the following patch:
rev:
7ccfb10 https://github.com/mathk/smalltalk/commit/7ccfb10

I also have fixed the #at:put: for #int shape in a 32bit arch were it was possible to do:
aIntShape at: 1 put: 16r80000000 "Should raise an error"

Since I haven't an 32arch right now I didn't test it.

You can also fetch the test:
rev:
7756fd2 https://github.com/mathk/smalltalk/commit/7756fd2
bf36e41 https://github.com/mathk/smalltalk/commit/bf36e41
4807b3f https://github.com/mathk/smalltalk/commit/4807b3f

HTH

        Mth




__________________________________________________
Do You Yahoo!?
En finir avec le spam? Yahoo! Mail vous offre la meilleure protection possible contre les messages non sollicités
http://mail.yahoo.fr Yahoo! Mail

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: #at:put: with uint shape does not accept all uint

Paolo Bonzini-2
On 01/09/2011 11:17 PM, Mathieu Suen wrote:

> On Jan 9, 2011, at 10:50 PM, Paolo Bonzini wrote:
>
>> On Sun, Jan 9, 2011 at 19:38, Mathieu Suen<[hidden email]>  wrote:
>>> Hi,
>>>
>>> I have a class with a uint as shape:
>>>
>>> Object subclass: Foo
>>> [
>>>         <shape:#uint>
>>>         Foo class>>  new [
>>>                 ^(self new:1)
>>>                         at: 1 put: 16r80000000
>>>         ]
>>> ]
>>>
>>> Eval [
>>>
>>>     Foo new.
>>>
>>> ]
>>>
>>> This snippet above raise an error:
>>> "Object: Foo new: 1<0x101327230>  error:
>>>      Invalid argument 2147483648: argument must be between 0 and 4294967295"
>>>
>>> I don't know if that make sense but I have fixed it with the following patch:
>>> rev:
>>> 7ccfb10 https://github.com/mathk/smalltalk/commit/7ccfb10
>>
>> Yes, that's fine.
>>
>>> I also have fixed the #at:put: for #int shape in a 32bit arch were it was possible to do:
>>> aIntShape at: 1 put: 16r80000000 "Should raise an error"
>>
>> Your change doesn't change anything: :)
>>
>> -    return (ba->bytes[4] == 0);
>> +    return (ba->bytes[4] == 0)&&  (ba->bytes[4]&80) == 0;
>>
>> since it tests bytes[4] twice.  You probably meant ba->bytes[3]&  0x80.
>
> Yes of course :)
> Fixed in
> 1bfa206 https://github.com/mathk/smalltalk/commit/1bfa206

The following is also enough:

diff --git a/libgst/dict.inl b/libgst/dict.inl
index 702de10..c7b6bbc 100644
--- a/libgst/dict.inl
+++ b/libgst/dict.inl
@@ -1321,20 +1321,10 @@ is_c_int_32 (OOP oop)
 #endif
 
   ba = (gst_byte_array) OOP_TO_OBJ (oop);
-  if (ba->objClass == _gst_large_negative_integer_class)
+  if (COMMON (ba->objClass == _gst_large_positive_integer_class)
+      || ba->objClass == _gst_large_negative_integer_class)
     return (NUM_INDEXABLE_FIELDS (oop) == 4);
 
-  else if COMMON (ba->objClass == _gst_large_positive_integer_class)
-    {
-      switch (NUM_INDEXABLE_FIELDS (oop))
- {
- case 4:
-  return (true);
- case 5:
-  return (ba->bytes[4] == 0);
- }
-    }
-
   return (false);
 }
 
Paolo

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk