ExternalLong.st
changeset 4669 7c74cd2b4737
parent 4303 dc9dd4174b6e
child 5207 9c132367790a
equal deleted inserted replaced
4668:46a47d71f826 4669:7c74cd2b4737
       
     1 "{ Encoding: utf8 }"
       
     2 
     1 "
     3 "
     2  COPYRIGHT (c) 1998 by eXept Software AG
     4  COPYRIGHT (c) 1998 by eXept Software AG
     3 	      All Rights Reserved
     5 	      All Rights Reserved
     4 
     6 
     5  This software is furnished under a license and may be used
     7  This software is furnished under a license and may be used
    60      which expect strings simply keep a ref to the passed string - for those,
    62      which expect strings simply keep a ref to the passed string - for those,
    61      an ST/X string-pointer is not the right thing to pass, since ST/X objects
    63      an ST/X string-pointer is not the right thing to pass, since ST/X objects
    62      may change their address.
    64      may change their address.
    63 
    65 
    64      DANGER ALERT: the memory is NOT automatically freed until it is either
    66      DANGER ALERT: the memory is NOT automatically freed until it is either
    65 		   MANUALLY freed (see #free) or the returned externalBytes object
    67                    MANUALLY freed (see #free) or the returned externalBytes object
    66 		   is unprotected or the classes releaseAllMemory method is called."
    68                    is unprotected or the classes releaseAllMemory method is called."
    67 
    69 
    68     ^ super new:(ExternalAddress pointerSize)
    70     ^ super new:(ExternalBytes sizeofPointer)
    69 
    71 
    70     "
    72     "
    71      ExternalLong new
    73      ExternalLong new
    72     "
    74     "
    73 
    75 
    78     "allocate some memory usable for data;
    80     "allocate some memory usable for data;
    79      the memory is under the control of the garbage collector.
    81      the memory is under the control of the garbage collector.
    80      Return a corresponding ExternalBytes object or raise MallocFailure (if malloc fails).
    82      Return a corresponding ExternalBytes object or raise MallocFailure (if malloc fails).
    81 
    83 
    82      DANGER ALERT: the memory block as allocated will be automatically freed
    84      DANGER ALERT: the memory block as allocated will be automatically freed
    83 		   as soon as the reference to the returned externalBytes object
    85                    as soon as the reference to the returned externalBytes object
    84 		   is gone (by the next garbage collect).
    86                    is gone (by the next garbage collect).
    85 		   If the memory has been passed to a C-function which
    87                    If the memory has been passed to a C-function which
    86 		   remembers this pointer, bad things may happen ...."
    88                    remembers this pointer, bad things may happen ...."
    87 
    89 
    88     ^ super unprotectedNew:(ExternalAddress pointerSize)
    90     ^ super unprotectedNew:(ExternalBytes sizeofPointer)
    89 
    91 
    90     "
    92     "
    91      ExternalLong new
    93      ExternalLong new
    92     "
    94     "
    93 
    95 
   113 
   115 
   114 asInteger
   116 asInteger
   115     "warning: retrieves a signed integer with the size of the native machine's
   117     "warning: retrieves a signed integer with the size of the native machine's
   116      pointer (i.e. either 32 or 64bit)"
   118      pointer (i.e. either 32 or 64bit)"
   117 
   119 
   118     ExternalAddress pointerSize == 8 ifTrue:[
   120     ExternalBytes sizeofPointer == 8 ifTrue:[
   119         ^ self signedInt64At:1 MSB:IsBigEndian
   121         ^ self signedInt64At:1 MSB:IsBigEndian
   120     ] ifFalse:[
   122     ] ifFalse:[
   121         ^ self signedInt32At:1 MSB:IsBigEndian
   123         ^ self signedInt32At:1 MSB:IsBigEndian
   122     ]
   124     ]
   123 
   125 
   154 
   156 
   155 asUnsignedInteger
   157 asUnsignedInteger
   156     "warning: retrieves an integer with the size of the native machine's
   158     "warning: retrieves an integer with the size of the native machine's
   157      pointer (i.e. either 32 or 64bit)"
   159      pointer (i.e. either 32 or 64bit)"
   158 
   160 
   159     ExternalAddress pointerSize == 8 ifTrue:[
   161     ExternalBytes sizeofPointer == 8 ifTrue:[
   160         ^ self unsignedInt64At:1 MSB:IsBigEndian
   162         ^ self unsignedInt64At:1 MSB:IsBigEndian
   161     ] ifFalse:[
   163     ] ifFalse:[
   162         ^ self unsignedInt32At:1 MSB:IsBigEndian
   164         ^ self unsignedInt32At:1 MSB:IsBigEndian
   163     ]
   165     ]
   164 
   166