*** empty log message ***
authorsr
Fri, 14 Aug 2009 18:44:33 +0200
changeset 11854 7fefd527563d
parent 11853 7c3265d8931e
child 11855 8e32bf8bc50e
*** empty log message ***
ExternalBytes.st
--- a/ExternalBytes.st	Thu Aug 13 17:54:45 2009 +0200
+++ b/ExternalBytes.st	Fri Aug 14 18:44:33 2009 +0200
@@ -385,7 +385,7 @@
 
 initialize
     Lobby isNil ifTrue:[
-        Lobby := Registry new.
+	Lobby := Registry new.
     ]
 ! !
 
@@ -450,10 +450,10 @@
 !
 
 newNullTerminatedFromString:aString
-    ^ ((self new:aString size+1) 
-        replaceBytesFrom:1 to:aString size with:aString startingAt:1)
-        at:aString size+1 put:0;
-        yourself
+    ^ ((self new:aString size+1)
+	replaceBytesFrom:1 to:aString size with:aString startingAt:1)
+	at:aString size+1 put:0;
+	yourself
 !
 
 unprotectedNew:numberOfBytes
@@ -462,10 +462,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 ...."
 
     |newInst|
 
@@ -661,10 +661,10 @@
 %{  /* NOCONTEXT */
 
     if (__INST(address_) != nil) {
-        unsigned INT addr;
+	unsigned INT addr;
 
-        addr = (unsigned INT)__INST(address_);
-        RETURN ( __MKUINT(addr));
+	addr = (unsigned INT)__INST(address_);
+	RETURN ( __MKUINT(addr));
     }
 %}.
     ^ nil
@@ -783,7 +783,7 @@
 
     s := String new:(self indexOf:0)-1.
     1 to:s size do:[:idx |
-        s at:idx put:(Character value:(self at:idx))
+	s at:idx put:(Character value:(self at:idx))
     ].
     ^ s.
 ! !
@@ -1088,14 +1088,14 @@
     |addr addrString|
 
     (addr := self address) isNil ifTrue:[
-        addrString := '[free]'
+	addrString := '[free]'
     ] ifFalse:[
-        size notNil ifTrue:[
-            addrString := '[sz:', size printString, ' '
-        ] ifFalse:[
-            addrString := '['
-        ].
-        addrString := addrString , 'at:' , (addr printStringRadix:16), ']'
+	size notNil ifTrue:[
+	    addrString := '[sz:', size printString, ' '
+	] ifFalse:[
+	    addrString := '['
+	].
+	addrString := addrString , 'at:' , (addr printStringRadix:16), ']'
     ].
     ^ self class name , addrString
 
@@ -1145,7 +1145,15 @@
 !ExternalBytes methodsFor:'private-allocation'!
 
 allocateBytes:numberOfBytes
-    "allocate (malloc) numberOfBytes.
+    "allocate (malloc) numberOfBytes; if doClear is true, the allocated memory is cleared.
+     Fail if already allocated.
+     Raise MallocFailure if malloc fails to allocate enough memory"
+
+    ^ self allocateBytes:numberOfBytes clear:true
+!
+
+allocateBytes:numberOfBytes clear:doClear
+    "allocate (malloc) numberOfBytes; if doClear is true, the allocated memory is cleared.
      Fail if already allocated.
      Raise MallocFailure if malloc fails to allocate enough memory"
 
@@ -1159,12 +1167,14 @@
     /*
      * Fail if already allocated
      */
-
     if (__INST(address_) == nil && __isSmallInteger(numberOfBytes)) {
 	nBytes = __smallIntegerVal(numberOfBytes);
 	if (nBytes > 0) {
 	    space = __stx_malloc(nBytes);
 	    if (space) {
+		if (doClear == true) {
+		    bzero(space, nBytes);
+		}
 		__INST(address_) = (OBJ)space;
 		__INST(size) = numberOfBytes;
 		RETURN(self);
@@ -1214,15 +1224,15 @@
     |wasBlocked|
 
 
-    "using a Semaphore can cause a deadlock, since unprotectFromGC may be called by 
+    "using a Semaphore can cause a deadlock, since unprotectFromGC may be called by
      a finalization method"
 
     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].
 !
@@ -1240,8 +1250,8 @@
 
     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].
@@ -1293,7 +1303,7 @@
 !ExternalBytes class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/ExternalBytes.st,v 1.73 2009-06-01 21:07:16 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/ExternalBytes.st,v 1.74 2009-08-14 16:44:33 sr Exp $'
 ! !
 
 ExternalBytes initialize!