64bit fix
authorClaus Gittinger <cg@exept.de>
Tue, 02 Apr 2013 11:10:35 +0200
changeset 2964 ae1be6343dda
parent 2963 76da9963f31e
child 2965 a93f50f1c830
64bit fix
ExternalLong.st
--- a/ExternalLong.st	Tue Apr 02 11:10:14 2013 +0200
+++ b/ExternalLong.st	Tue Apr 02 11:10:35 2013 +0200
@@ -1,6 +1,6 @@
 "
  COPYRIGHT (c) 1998 by eXept Software AG
-              All Rights Reserved
+	      All Rights Reserved
 
  This software is furnished under a license and may be used
  only in accordance with the terms of that license and with the
@@ -23,7 +23,7 @@
 copyright
 "
  COPYRIGHT (c) 1998 by eXept Software AG
-              All Rights Reserved
+	      All Rights Reserved
 
  This software is furnished under a license and may be used
  only in accordance with the terms of that license and with the
@@ -58,8 +58,8 @@
      may change their address.
 
      DANGER ALERT: the memory is NOT automatically freed until it is either
-                   MANUALLY freed (see #free) or the returned externalBytes object
-                   is unprotected or the classes releaseAllMemory method is called."
+		   MANUALLY freed (see #free) or the returned externalBytes object
+		   is unprotected or the classes releaseAllMemory method is called."
 
     ^ super new:(ExternalAddress pointerSize)
 
@@ -76,10 +76,10 @@
      Return a corresponding ExternalBytes object or raise MallocFailure (if malloc fails).
 
      DANGER ALERT: the memory block as allocated will be automatically freed
-                   as soon as the reference to the returned externalBytes object
-                   is gone (by the next garbage collect).
-                   If the memory has been passed to a C-function which
-                   remembers this pointer, bad things may happen ...."
+		   as soon as the reference to the returned externalBytes object
+		   is gone (by the next garbage collect).
+		   If the memory has been passed to a C-function which
+		   remembers this pointer, bad things may happen ...."
 
     ^ super unprotectedNew:(ExternalAddress pointerSize)
 
@@ -97,7 +97,7 @@
 
     result := self byteAt:1.
     result = 0 ifTrue:[
-        ^ false.
+	^ false.
     ].
     ^ true.
 !
@@ -106,15 +106,20 @@
     ^ ExternalBytes address:(self value)
 
     "
-     (ExternalLong new value:10) asExternalBytes   
-     (ExternalLong new value:0) asExternalBytes   
+     (ExternalLong new value:10) asExternalBytes
+     (ExternalLong new value:0) asExternalBytes
     "
 !
 
 asInteger
-    "warning: only returns a 32bit integer"
+    "warning: retrieves an integer with the size of the native machine's
+     pointer (i.e. either 32 or 64bit)"
 
-    ^ self signedDoubleWordAt:1 MSB:false
+    ExternalAddress pointerSize == 8 ifTrue:[
+	^ self lonhLongAt:1 MSB:(UninterpretedBytes isBigEndian)
+    ] ifFalse:[
+	^ self signedDoubleWordAt:1 MSB:(UninterpretedBytes isBigEndian)
+    ]
 
     "
      ExternalLong new value:10
@@ -125,6 +130,8 @@
 !
 
 asNullStatus
+    "cg: whoever added this here should move it to the sql package"
+
     |result|
 
     result := self wordAt:1 MSB:false.
@@ -134,7 +141,7 @@
 !
 
 asPointer
-    "fetch my cell's pointer value 
+    "fetch my cell's pointer value
      (use this if you passed me to a C function as out parameter, to fetch the returned value)"
 
     "/ ^ ExternalAddress new setAddress:(self value address)
@@ -148,10 +155,17 @@
 asUnsignedInteger
     "warning: only returns a 32bit integer"
 
-    ^ self doubleWordAt:1 MSB:false
+    "warning: retrieves an integer with the size of the native machine's
+     pointer (i.e. either 32 or 64bit)"
+
+    ExternalAddress pointerSize == 8 ifTrue:[
+	^ self unsignedLongLongAt:1 MSB:(UninterpretedBytes isBigEndian)
+    ] ifFalse:[
+	^ self doubleWordAt:1 MSB:false
+    ]
 
     "
-     (ExternalLong new value:10) asUnsignedInteger 
+     (ExternalLong new value:10) asUnsignedInteger
     "
 
     "Created: / 22-12-2010 / 18:31:03 / cg"
@@ -174,7 +188,7 @@
 
 value:anInteger
     "/ self doubleWordAt:1 put:anInteger
-    self pointerAt:1 put:(ExternalAddress newAddress:anInteger)
+    self pointerAt:1 put:anInteger
 ! !
 
 !ExternalLong methodsFor:'printing & storing'!
@@ -188,10 +202,9 @@
 !ExternalLong class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/ExternalLong.st,v 1.12 2013-03-29 14:42:07 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/ExternalLong.st,v 1.13 2013-04-02 09:10:35 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic2/ExternalLong.st,v 1.12 2013-03-29 14:42:07 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/ExternalLong.st,v 1.13 2013-04-02 09:10:35 cg Exp $'
 ! !
-