--- a/ExternalBytes.st Wed Apr 03 12:39:02 2019 +0200
+++ b/ExternalBytes.st Wed Apr 03 13:57:19 2019 +0200
@@ -116,7 +116,7 @@
char *ptr = malloc(nBytes);
if (@global(TraceMalloc) == true) {
- console_printf("ExternalBytes [info]: allocated %d bytes at: %016"_lx_"\n", nBytes, (INT)ptr);
+ console_printf("ExternalBytes [info]: allocated %ld bytes at: %p\n", (long)nBytes, ptr);
}
addToMallocList(ptr, nBytes);
@@ -142,7 +142,7 @@
addToMallocList(newPtr, nBytes);
if (@global(TraceMalloc) == true) {
- console_printf("ExternalBytes [info]: realloc %d bytes for %"_lx_" at: %"_lx_"\n", nBytes, (INT)ptr, (INT)newPtr);
+ console_printf("ExternalBytes [info]: realloc %ld bytes for %p at: %p\n", (long)nBytes, ptr, newPtr);
}
return newPtr;
}
@@ -410,13 +410,13 @@
The size is known, which allows byte accesses to be checked for valid index.
Use this, if you get a pointer to a structure from some external source
(such as a C-callBack function) and you have to extract things from that.
- The pointer is protected from GC
+ The pointer is protected from GC
(i.e. I will not free the heap memory,
once the returned reference is no longer in use).
Be careful to avoid memory leaks, when getting malloc'd memory from an external function.
-
+
DANGER ALERT: this method allows very bad things to be done to the
- system - use with GREAT care (better: do not use it)"
+ system - use with GREAT care (better: do not use it)"
^ self basicNew setAddress:anAddressInteger size:size
@@ -436,8 +436,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."
"/ ^ self protectedNew:numberOfBytes.
^ self unprotectedNew:numberOfBytes.
@@ -499,8 +499,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."
|newInst|
@@ -564,7 +564,7 @@
struct mallocList *entry;
for (entry = mallocList; entry; entry=entry->next) {
- console_printf(" %"_lx_" (%d)\n", (INT)(entry->chunk), entry->size);
+ console_printf(" %p (%ld)\n", (entry->chunk), (long)(entry->size));
}
%}
"
@@ -590,7 +590,7 @@
while ((entry = mallocList) != (struct mallocList *)0) {
if (@global(TraceMalloc) == true ) {
- console_printf("ExternalBytes [info]: **** forced free of %"_lx_" (%d)\n", (INT)entry->chunk, entry->size);
+ console_printf("ExternalBytes [info]: **** forced free of %p (%ld)\n", entry->chunk, (long)(entry->size));
}
__stx_free(entry->chunk);
}
@@ -693,8 +693,8 @@
%{ /* NOCONTEXT */
struct {
- char c;
- void* p;
+ char c;
+ void* p;
} dummy;
RETURN (__mkSmallInteger( (char *)&dummy.p - (char *)&dummy.c ));
%}
@@ -807,9 +807,9 @@
sizeofPointer
"return the number of bytes used by the machine's native 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
+ therefore, queries like
+ 'ExternalAddress pointerSize == 8'
+ cost nothing; they are compiled in as a constant
(and even conditionals are eliminated)."
%{ /* NOCONTEXT */
@@ -937,8 +937,8 @@
idx := 1.
s := WriteStream on:''.
[(byte := self at:idx) ~~ 0] whileTrue:[
- s nextPut:(Character value:byte).
- idx := idx + 1.
+ s nextPut:(Character value:byte).
+ idx := idx + 1.
].
^ s contents
!
@@ -987,8 +987,8 @@
|size|
self class == ExternalBytes ifTrue:[
- size := self size.
- ^ (String uninitializedNew:size) replaceBytesFrom:1 to:size with:self startingAt:1.
+ size := self size.
+ ^ (String uninitializedNew:size) replaceBytesFrom:1 to:size with:self startingAt:1.
].
^ super asString.
@@ -1292,29 +1292,29 @@
"/ what a kludge - Dolphin and Squeak mean: printOn: a stream;
"/ old ST80 means: draw-yourself on a GC.
(aGCOrStream isStream) ifFalse:[
- ^ super displayOn:aGCOrStream
+ ^ super displayOn:aGCOrStream
].
aGCOrStream nextPutAll:self className.
addr := self address.
addr isNil ifTrue:[
- aGCOrStream nextPutAll:'[free]'.
+ aGCOrStream nextPutAll:'[free]'.
] ifFalse:[
- size notNil ifTrue:[
- aGCOrStream nextPutAll:'[sz:'.
- size printOn:aGCOrStream.
- aGCOrStream space.
- ] ifFalse:[
- aGCOrStream nextPut:$[.
- ].
- aGCOrStream nextPutAll:'@'.
- addr printOn:aGCOrStream base:16.
- aGCOrStream nextPut:$].
+ size notNil ifTrue:[
+ aGCOrStream nextPutAll:'[sz:'.
+ size printOn:aGCOrStream.
+ aGCOrStream space.
+ ] ifFalse:[
+ aGCOrStream nextPut:$[.
+ ].
+ aGCOrStream nextPutAll:'@'.
+ addr printOn:aGCOrStream base:16.
+ aGCOrStream nextPut:$].
].
"
- self new printString
- (self new:5) displayString
+ self new printString
+ (self new:5) displayString
"
"Modified: / 24-02-2000 / 19:02:19 / cg"
@@ -1337,19 +1337,19 @@
%{ /* NOCONTEXT */
if (__INST(address_) == nil) {
- if (aNumberOrExternalAddress == nil) {
- __INST(address_) = nil;
- } else {
- if (__isSmallInteger(aNumberOrExternalAddress)) {
- __INST(address_) = (OBJ) __intVal(aNumberOrExternalAddress);
- } else if(__isInteger(aNumberOrExternalAddress)) {
- __INST(address_) = (OBJ) __unsignedLongIntVal(aNumberOrExternalAddress);
- } else if(__isExternalAddressLike(aNumberOrExternalAddress)) {
- __INST(address_) = __externalAddressVal(aNumberOrExternalAddress);
- }
- }
- __INST(size) = sz;
- RETURN (self);
+ if (aNumberOrExternalAddress == nil) {
+ __INST(address_) = nil;
+ } else {
+ if (__isSmallInteger(aNumberOrExternalAddress)) {
+ __INST(address_) = (OBJ) __intVal(aNumberOrExternalAddress);
+ } else if(__isInteger(aNumberOrExternalAddress)) {
+ __INST(address_) = (OBJ) __unsignedLongIntVal(aNumberOrExternalAddress);
+ } else if(__isExternalAddressLike(aNumberOrExternalAddress)) {
+ __INST(address_) = __externalAddressVal(aNumberOrExternalAddress);
+ }
+ }
+ __INST(size) = sz;
+ RETURN (self);
}
%}.
^ self error:'cannot change address'
@@ -1485,10 +1485,10 @@
"forget the underlying memory - i.e. it will NOT be freed by me,
and actually no reference to the underlying memory is kept.
Warning:
- Unless freed by someone else (typically a C-program/client),
- this leads to a memory leak.
- Use this only, if memory which was allocated by me
- is given to a C-program which frees the memory."
+ Unless freed by someone else (typically a C-program/client),
+ this leads to a memory leak.
+ Use this only, if memory which was allocated by me
+ is given to a C-program which frees the memory."
Lobby unregister:self. "/ prevents finalization
self unprotectFromGC. "/ no longer remembered
@@ -1511,10 +1511,10 @@
wasBlocked := OperatingSystem blockInterrupts.
"/ AccessLock critical:[
- AllocatedInstances isNil ifTrue:[
- AllocatedInstances := IdentitySet new
- ].
- AllocatedInstances add:self.
+ AllocatedInstances isNil ifTrue:[
+ AllocatedInstances := IdentitySet new
+ ].
+ AllocatedInstances add:self.
"/ ]
wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
@@ -1535,9 +1535,9 @@
wasBlocked := OperatingSystem blockInterrupts.
"/ AccessLock critical:[
- AllocatedInstances notNil ifTrue:[
- AllocatedInstances remove:self ifAbsent:nil.
- ].
+ AllocatedInstances notNil ifTrue:[
+ AllocatedInstances remove:self ifAbsent:nil.
+ ].
"/ ]
wasBlocked ifFalse:[OperatingSystem unblockInterrupts].