UninterpretedBytes.st
changeset 6492 61c212c8b3fb
parent 4782 04a2ea1ad3a5
child 6885 ee7f2ed913a1
equal deleted inserted replaced
6491:6976d9b69e01 6492:61c212c8b3fb
     7  inclusion of the above copyright notice.   This software may not
     7  inclusion of the above copyright notice.   This software may not
     8  be provided or otherwise made available to, or used by, any
     8  be provided or otherwise made available to, or used by, any
     9  other person.  No title to or ownership of the software is
     9  other person.  No title to or ownership of the software is
    10  hereby transferred.
    10  hereby transferred.
    11 "
    11 "
       
    12 
       
    13 "{ Package: 'stx:libbasic' }"
    12 
    14 
    13 ArrayedCollection subclass:#UninterpretedBytes
    15 ArrayedCollection subclass:#UninterpretedBytes
    14 	instanceVariableNames:''
    16 	instanceVariableNames:''
    15 	classVariableNames:'IsBigEndian'
    17 	classVariableNames:'IsBigEndian'
    16 	poolDictionaries:''
    18 	poolDictionaries:''
  1266 
  1268 
  1267     "Created: / 9.5.1998 / 01:10:24 / cg"
  1269     "Created: / 9.5.1998 / 01:10:24 / cg"
  1268     "Modified: / 9.5.1998 / 01:13:34 / cg"
  1270     "Modified: / 9.5.1998 / 01:13:34 / cg"
  1269 !
  1271 !
  1270 
  1272 
       
  1273 pointerAt:index put:value
       
  1274     "set the pointer starting at index from the signed Integer value.
       
  1275      The index is a smalltalk index (i.e. 1-based). 
       
  1276      Only aligned accesses are allowed.
       
  1277      The value is either an ExternalAddress or ExternalBytes"
       
  1278 
       
  1279 %{
       
  1280     OBJ *pointer;
       
  1281 
       
  1282     if (__isExternalAddress(value)) {
       
  1283         pointer = __externalAddressVal(value);
       
  1284     } else if (__isExternalBytes(value)) {
       
  1285         pointer = __externalBytesVal(value);
       
  1286         if (pointer == nil)
       
  1287             pointer = 0;
       
  1288     } else goto bad;
       
  1289 
       
  1290     if (__isSmallInteger(index)) {
       
  1291         unsigned char *cp;
       
  1292         int sz;
       
  1293 
       
  1294         __fetchBytePointerAndSize__(self, &cp, &sz);
       
  1295         if (cp) {
       
  1296             unsigned INT idx = ((unsigned INT)__smallIntegerVal(index)) - 1;
       
  1297 
       
  1298             if ((idx+(sizeof(pointer)-1)) < sz) {
       
  1299                 cp += idx;
       
  1300                 /*
       
  1301                  * aligned
       
  1302                  */
       
  1303                 if (((INT)cp & (sizeof(pointer)-1)) == 0) {
       
  1304                     ((char **)cp)[0] = (char *) pointer;
       
  1305                     RETURN (value);
       
  1306                 }
       
  1307             }
       
  1308         }
       
  1309     }
       
  1310 bad:;
       
  1311 %}.
       
  1312 
       
  1313     self primitiveFailed.
       
  1314 
       
  1315     "
       
  1316      |b|
       
  1317      b := ByteArray new:ExternalAddress pointerSize.
       
  1318      b pointerAt:1 put:(ExternalAddress newAddress:16r12345678). 
       
  1319      (b unsignedLongAt:1) printStringRadix:16   
       
  1320     "
       
  1321 
       
  1322     "Modified: / 1.7.1996 / 21:11:39 / cg"
       
  1323     "Created: / 5.3.1998 / 10:57:18 / stefan"
       
  1324 !
       
  1325 
  1271 signedDoubleWordAt:index
  1326 signedDoubleWordAt:index
  1272     "return the 4-bytes starting at index as a signed Integer.
  1327     "return the 4-bytes starting at index as a signed Integer.
  1273      The index is a smalltalk index (i.e. 1-based).
  1328      The index is a smalltalk index (i.e. 1-based).
  1274      The value is retrieved in the machines natural byte order.
  1329      The value is retrieved in the machines natural byte order.
  1275      This may be worth a primitive."
  1330      This may be worth a primitive."
  2071 ! !
  2126 ! !
  2072 
  2127 
  2073 !UninterpretedBytes class methodsFor:'documentation'!
  2128 !UninterpretedBytes class methodsFor:'documentation'!
  2074 
  2129 
  2075 version
  2130 version
  2076     ^ '$Header: /cvs/stx/stx/libbasic/UninterpretedBytes.st,v 1.40 1999-09-21 00:23:30 cg Exp $'
  2131     ^ '$Header: /cvs/stx/stx/libbasic/UninterpretedBytes.st,v 1.41 2002-04-09 19:00:21 stefan Exp $'
  2077 ! !
  2132 ! !