#REFACTORING by cg
class: ExternalAddress
added:
#newAddressFromBytes:
#sizeOfPointer
comment/format in:
#isBuiltInClass
#newAddress:
#pointerSize
changed: #setAddress:
--- a/ExternalAddress.st Tue Nov 15 16:37:32 2016 +0100
+++ b/ExternalAddress.st Tue Nov 15 16:43:29 2016 +0100
@@ -105,7 +105,29 @@
!ExternalAddress class methodsFor:'instance creation'!
newAddress:addr
+ "return a new externalAddress (pointer), pointing to addr."
+
^ self new setAddress:addr
+
+ "Modified (comment): / 15-11-2016 / 11:57:34 / cg"
+!
+
+newAddressFromBytes:bytesContainingAddress
+ "return a new externalAddress (pointer), pointing to the addr contained in the argument.
+ The argument must be a byteArray-like object, whose first pointerSize bytes are extracted"
+
+ ^ (bytesContainingAddress pointerAt:1)
+
+ "
+ |bytes ptr|
+
+ bytes := ByteArray new:(ExternalAddress pointerSize).
+ bytes pointerAt:1 put:16r12345678.
+ ptr := ExternalAddress newAddressFromBytes:bytes.
+ self assert:(ptr address = 16r12345678).
+ "
+
+ "Created: / 15-11-2016 / 12:53:21 / cg"
! !
!ExternalAddress class methodsFor:'Compatibility-V''Age'!
@@ -126,18 +148,21 @@
isBuiltInClass
"return true if this class is known by the run-time-system.
- Here, true is returned."
+ Here, true is returned (but not for subclasses)."
^ self == ExternalAddress
- "Modified: / 11.6.1998 / 17:12:40 / cg"
+ "Modified: / 11-06-1998 / 17:12:40 / cg"
+ "Modified (comment): / 15-11-2016 / 11:56:55 / cg"
!
pointerSize
"answer the size in bytes of a pointer.
Notice: this is inlined by the compiler(s) as a constant,
- therefore, a query like 'ExternalAddress pointerSize == 8'
- costs nothing; it is compiled in as a constant."
+ therefore, queries like
+ 'ExternalAddress pointerSize == 8'
+ cost nothing; they are compiled in as a constant
+ (and even conditionals are eliminated)."
%{ /* NOCONTEXT */
RETURN(__mkSmallInteger(sizeof(void *)));
@@ -146,8 +171,30 @@
"
self pointerSize
"
+
+ "Modified (comment): / 15-11-2016 / 11:56:38 / cg"
+!
+
+sizeOfPointer
+ "answer the size in bytes of a pointer.
+ Notice: this is inlined by the compiler(s) as a constant,
+ therefore, queries like
+ 'ExternalAddress pointerSize == 8'
+ cost nothing; they are compiled in as a constant
+ (and even conditionals are eliminated)."
+
+%{ /* NOCONTEXT */
+ RETURN(__mkSmallInteger(sizeof(void *)));
+%}.
+
+ "
+ self sizeOfPointer
+ "
+
+ "Created: / 15-11-2016 / 11:40:52 / cg"
! !
+
!ExternalAddress methodsFor:'Compatibility-Squeak'!
beNull
@@ -308,9 +355,14 @@
addr = __intVal(anInteger);
} else {
addr = __unsignedLongIntVal(anInteger);
+ if (addr == 0) {
+ console_printf("invalid address argument in ExternalAddress>>setAddress\n");
+ }
}
__INST(address_) = (OBJ)addr;
%}
+
+ "Modified: / 15-11-2016 / 11:59:24 / cg"
!
setAddressFromBytes:aByteArray