--- a/AbstractTime.st Tue Mar 22 08:03:27 2016 +0000
+++ b/AbstractTime.st Wed Mar 23 07:50:28 2016 +0000
@@ -512,6 +512,7 @@
"
! !
+
!AbstractTime methodsFor:'abstract'!
hours
@@ -990,7 +991,10 @@
!
asSeconds
- "return the number of seconds elapsed since midnight"
+ "get the seconds since some point of time in the past.
+ For Time instances, this is the number of seconds elapsed since midnight;
+ For TimeDurations, that is the duration in seconds;
+ For TimeStamps, that is the number of seconds since the epoch"
^ self getSeconds
--- a/ByteArray.st Tue Mar 22 08:03:27 2016 +0000
+++ b/ByteArray.st Wed Mar 23 07:50:28 2016 +0000
@@ -1,5 +1,3 @@
-"{ Encoding: utf8 }"
-
"
COPYRIGHT (c) 1989 by Claus Gittinger
All Rights Reserved
@@ -166,7 +164,6 @@
! !
-
!ByteArray class methodsFor:'queries'!
elementByteSize
@@ -187,7 +184,6 @@
"Modified: 23.4.1996 / 15:56:25 / cg"
! !
-
!ByteArray methodsFor:'Compatibility-Squeak'!
bitXor:aByteArray
@@ -1063,20 +1059,20 @@
!
asInteger
- "convert myself to an integer - the first byte is most significant.
+ "convert myself to an unsigned integer - the first byte is most significant.
This is also in Squeak."
^ self asIntegerMSB:true
"
- #[ 2 ] asInteger hexPrintString
- #[ 16r1 16r2 ] asInteger hexPrintString
- #[4 0 0 0 0 0 0 0] asInteger hexPrintString
+ #[ 2 ] asInteger hexPrintString
+ #[ 16r1 16r2 ] asInteger hexPrintString
+ #[4 0 0 0 0 0 0 0] asInteger hexPrintString
"
!
asIntegerMSB:isMSBFirst
- "convert myself to an integer - the first byte is most significant.
+ "convert myself to an unsigned integer - the first byte is most significant.
This is also in Squeak."
^ (LargeInteger digitBytes:self MSB:isMSBFirst) compressed
@@ -2983,6 +2979,7 @@
"
! !
+
!ByteArray methodsFor:'searching'!
indexOf:aByte startingAt:start
--- a/ExternalBytes.st Tue Mar 22 08:03:27 2016 +0000
+++ b/ExternalBytes.st Wed Mar 23 07:50:28 2016 +0000
@@ -26,7 +26,14 @@
%{
#include <stdlib.h>
#include <stdio.h>
- #include <malloc.h>
+// cg: not needed
+#if 0
+# ifdef __osx__
+# include <sys/malloc.h>
+# else
+# include <malloc.h>
+# endif
+#endif
extern char *__stx_malloc(size_t);
extern char *__stx_calloc(size_t, size_t);
--- a/ExternalStream.st Tue Mar 22 08:03:27 2016 +0000
+++ b/ExternalStream.st Wed Mar 23 07:50:28 2016 +0000
@@ -3934,69 +3934,66 @@
|| (__INST(handleType) == @symbol(socketFilePointer))
|| (__INST(handleType) == @symbol(socketHandle))
|| (__INST(handleType) == @symbol(pipeFilePointer))) {
- if (((fp = __INST(handle)) != nil)
- && (__INST(mode) != @symbol(writeonly))
- ) {
- FILEPOINTER f;
- int ret, _buffered;
- int value;
- union {
- unsigned char buffer[4];
- int intVal;
- } u;
-
- f = __FILEVal(fp);
- _buffered = (__INST(buffered) == true);
- if (_buffered) {
- __READING__(f)
- }
- __READBYTES__(ret, f, u.buffer, 4, _buffered, __INST(handleType));
-
- if (ret == 4) {
- if (__isSmallInteger(__INST(position))) {
- INT np = __intVal(__INST(position)) + 4;
- OBJ t;
-
- t = __MKINT(np); __INST(position) = t; __STORE(self, t);
- } else {
- __INST(position) = nil; /* i.e. do not know */
- }
- if (msbFlag == true) {
+ if (((fp = __INST(handle)) != nil)
+ && (__INST(mode) != @symbol(writeonly))
+ ) {
+ FILEPOINTER f;
+ int ret, _buffered;
+ int value;
+ union {
+ unsigned char buffer[4];
+ int intVal;
+ } u;
+
+ f = __FILEVal(fp);
+ _buffered = (__INST(buffered) == true);
+ if (_buffered) {
+ __READING__(f)
+ }
+ __READBYTES__(ret, f, u.buffer, 4, _buffered, __INST(handleType));
+
+ if (ret == 4) {
+ if (__isSmallInteger(__INST(position))) {
+ INT np = __intVal(__INST(position)) + 4;
+ OBJ t;
+
+ t = __MKINT(np); __INST(position) = t; __STORE(self, t);
+ } else {
+ __INST(position) = nil; /* i.e. do not know */
+ }
+ if (msbFlag == true) {
#if defined(__MSBFIRST__)
- value = u.intVal;
+ value = u.intVal;
#else
- value = (u.buffer[0] & 0xFF);
- value = (value << 8) | (u.buffer[1] & 0xFF);
- value = (value << 8) | (u.buffer[2] & 0xFF);
- value = (value << 8) | (u.buffer[3] & 0xFF);
+ value = (u.buffer[0] & 0xFF);
+ value = (value << 8) | (u.buffer[1] & 0xFF);
+ value = (value << 8) | (u.buffer[2] & 0xFF);
+ value = (value << 8) | (u.buffer[3] & 0xFF);
#endif
- } else {
+ } else {
#if defined(__LSBFIRST__)
- value = u.intVal;
+ value = u.intVal;
#else
- value = (u.buffer[3] & 0xFF);
- value = (value << 8) | (u.buffer[2] & 0xFF);
- value = (value << 8) | (u.buffer[1] & 0xFF);
- value = (value << 8) | (u.buffer[0] & 0xFF);
+ value = (u.buffer[3] & 0xFF);
+ value = (value << 8) | (u.buffer[2] & 0xFF);
+ value = (value << 8) | (u.buffer[1] & 0xFF);
+ value = (value << 8) | (u.buffer[0] & 0xFF);
#endif
- }
+ }
#if __POINTER_SIZE__ == 8
- RETURN ( __mkSmallInteger(value));
+ RETURN ( __mkSmallInteger(value));
#else
- if ((value >= _MIN_INT) && (value <= _MAX_INT)) {
- RETURN ( __mkSmallInteger(value));
- }
- RETURN ( __MKLARGEINT(value) );
+ RETURN ( __MKINT(value) );
#endif
- }
-
- if (ret < 0) {
- __INST(position) = nil;
- error = __mkSmallInteger(__threadErrno);
- } else /* ret == 0 */ {
- __INST(hitEOF) = true;
- }
- }
+ }
+
+ if (ret < 0) {
+ __INST(position) = nil;
+ error = __mkSmallInteger(__threadErrno);
+ } else /* ret == 0 */ {
+ __INST(hitEOF) = true;
+ }
+ }
}
%}.
hitEOF ifTrue:[^ self pastEndRead].
--- a/HashStream.st Tue Mar 22 08:03:27 2016 +0000
+++ b/HashStream.st Wed Mar 23 07:50:28 2016 +0000
@@ -398,8 +398,8 @@
].
anObject isCharacter ifTrue:[
- "/ only ascii allowed !!
- self nextPutBytes:(ByteArray with:anObject codePoint).
+ "/ only 8bit chars are allowed !!
+ self nextPutBytes:1 from:(ByteArray with:anObject codePoint) startingAt:1.
^ self.
].
--- a/Integer.st Tue Mar 22 08:03:27 2016 +0000
+++ b/Integer.st Wed Mar 23 07:50:28 2016 +0000
@@ -1,5 +1,3 @@
-"{ Encoding: utf8 }"
-
"
COPYRIGHT (c) 1988 by Claus Gittinger
All Rights Reserved
@@ -756,6 +754,8 @@
"Modified: / 15.11.1999 / 20:35:20 / cg"
! !
+
+
!Integer class methodsFor:'class initialization'!
initialize
@@ -801,6 +801,7 @@
"Modified: 18.7.1996 / 12:26:38 / cg"
! !
+
!Integer class methodsFor:'prime numbers'!
flushPrimeCache
@@ -1176,6 +1177,7 @@
^ self == Integer
! !
+
!Integer methodsFor:'*Roe'!
acceptRoeVisitor: aVisitor
@@ -3482,7 +3484,7 @@
^ fibUsingDict value:self
"the running time is mostly dictated by the LargeInteger multiplication performance...
- (therefore, we get O(n²) execution times, even for a linear number of multiplications)
+ (therefore, we get O(n) execution times, even for a linear number of multiplications)
Time millisecondsToRun:[50000 fib_iterative] 312 (DUO 1.7Ghz CPU)
Time millisecondsToRun:[50000 fib_helper] 109
@@ -4860,6 +4862,7 @@
"Created: / 09-01-2012 / 17:18:06 / cg"
! !
+
!Integer methodsFor:'special modulo arithmetic'!
add_32:anInteger
@@ -5593,6 +5596,12 @@
!Integer::ModuloNumber methodsFor:'converting'!
+asInteger
+ "return the modulus"
+
+ ^ modulus
+!
+
asModuloNumber
^ self
--- a/PositionableStream.st Tue Mar 22 08:03:27 2016 +0000
+++ b/PositionableStream.st Wed Mar 23 07:50:28 2016 +0000
@@ -124,7 +124,6 @@
! !
-
!PositionableStream methodsFor:'Compatibility-Dolphin'!
endChunk
@@ -276,11 +275,10 @@
!PositionableStream methodsFor:'misc functions'!
-copyToEndInto:aWriteStream bufferSize:bufferSize
+copyToEndInto:aWriteStream
"read from the receiver, and write all data up to the end to another stream.
Return the number of bytes which have been transferred.
- Redefined here to avoid intermediate buffers/garbage.
- bufferSize does not matter here."
+ Redefined here to avoid intermediate buffers/garbage."
|cnt|
@@ -290,6 +288,28 @@
position := readLimit.
^ cnt.
].
+ ^ super copyToEndInto:aWriteStream.
+
+ "
+ |rs ws cnt|
+
+ ws := #() writeStream.
+ rs := #( 1 2 3 4 a nil true) readWriteStream.
+ rs next.
+ cnt := rs copyToEndInto:ws bufferSize:0.
+ Transcript show:cnt; show:' '; showCR:ws contents.
+ "
+!
+
+copyToEndInto:aWriteStream bufferSize:bufferSize
+ "read from the receiver, and write all data up to the end to another stream.
+ Return the number of bytes which have been transferred.
+ Redefined here to avoid intermediate buffers/garbage.
+ bufferSize does not matter here."
+
+ collection notNil ifTrue:[
+ ^ self copyToEndInto:aWriteStream.
+ ].
^ super copyToEndInto:aWriteStream bufferSize:bufferSize.
"
@@ -903,11 +923,11 @@
!PositionableStream class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/PositionableStream.st,v 1.171 2015-03-12 19:24:30 stefan Exp $'
+ ^ '$Header$'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libbasic/PositionableStream.st,v 1.171 2015-03-12 19:24:30 stefan Exp $'
+ ^ '$Header$'
!
version_HG
--- a/SHA1Stream.st Tue Mar 22 08:03:27 2016 +0000
+++ b/SHA1Stream.st Wed Mar 23 07:50:28 2016 +0000
@@ -550,6 +550,26 @@
!SHA1Stream methodsFor:'writing'!
+nextPutByte:anInteger
+ "update the hash value with anInteger <= 255."
+
+%{
+ if (__isSmallInteger(anInteger) && __intVal(anInteger) <= 255
+ && __isByteArray(__INST(hashContext))
+ && __byteArraySize(__INST(hashContext)) == sizeof(SHA1_CTX)
+ ) {
+ SHA1_CTX *ctx = (SHA1_CTX *)__ByteArrayInstPtr(__INST(hashContext))->ba_element;
+ unsigned char value = __intVal(anInteger);
+
+ SHA1Update(ctx, &value, 1);
+ RETURN(self);
+ }
+bad: ;
+%}.
+
+ ^ self primitiveFailed
+!
+
nextPutBytes:count from:anObject startingAt:start
"update the hash value with count bytes from an object starting at index start.
The object must have non-pointer indexed instvars
--- a/SequenceableCollection.st Tue Mar 22 08:03:27 2016 +0000
+++ b/SequenceableCollection.st Wed Mar 23 07:50:28 2016 +0000
@@ -399,7 +399,6 @@
! !
-
!SequenceableCollection methodsFor:'Compatibility-Squeak'!
allButFirst
@@ -2195,8 +2194,8 @@
#(1 2 3 4 5 6) hash
(1 to:6) hash
- #(1 2 3 4 5.0) asOrderedCollection hash
- #(1 2 3 4 5) hash
+ #(1 2 3 4 5 6.0) asOrderedCollection hash
+ #[1 2 3 4 5 6] hash
"
"Modified: / 27.3.1998 / 17:33:49 / cg"
--- a/Stream.st Tue Mar 22 08:03:27 2016 +0000
+++ b/Stream.st Wed Mar 23 07:50:28 2016 +0000
@@ -1080,6 +1080,36 @@
"Created: 10.1.1996 / 19:49:41 / cg"
!
+nextInt24MSB:msbFlag
+ "return a signed 3 byte integer from the stream.
+ The receiver must support reading of binary bytes.
+
+ The msbFlag argument controls if the integer is to be read with
+ most-significant-byte-first (true) or least-first (false).
+ This interface is provided to allow talking to external programs,
+ where it's known that the byte order is some definite one.
+ If you don't care (i.e. talk to other smalltalks) or you can control the
+ order, please use the corresponding xxxNet methods, which use a standard
+ network byte order."
+
+ |uval "{ Class: SmallInteger }"|
+
+ uval := self nextUnsignedInt24MSB:msbFlag.
+ "change from unsigned 0..FFFFFF to signed -800000..7FFFFF"
+ uval >= 16r800000 ifTrue:[
+ ^ uval - 16r1000000
+ ].
+ ^ uval
+
+ "
+ ((ReadStream on:#[16r10 16r20 16rFF]) nextInt24MSB:true) hexPrintString
+ ((ReadStream on:#[16rFF 16r20 16r30]) nextInt24MSB:false) hexPrintString
+
+ ((ReadStream on:#[16rFF 16r20 16r30]) nextInt24MSB:true) hexPrintString
+ ((ReadStream on:#[16r10 16r20 16rFF]) nextInt24MSB:false) hexPrintString
+ "
+!
+
nextInt32MSB:msbFlag
"return a signed long (4 bytes) from the stream.
The receiver must support reading of binary bytes.
@@ -1259,15 +1289,14 @@
^ self nextUnsignedInt16MSB:msbFlag
].
numBytes == 3 ifTrue:[
- val := self nextUnsignedInt16MSB:msbFlag.
- msbFlag ifTrue:[
- ^ (val bitShift:8) + self nextByte
- ].
- ^ val + (self nextByte bitShift:16)
+ ^ self nextUnsignedInt24MSB:msbFlag.
].
numBytes == 4 ifTrue:[
^ self nextUnsignedInt32MSB:msbFlag
].
+ numBytes == 8 ifTrue:[
+ ^ self nextUnsignedInt64MSB:msbFlag
+ ].
val := 0.
msbFlag ifTrue:[
@@ -1351,15 +1380,24 @@
order, please use the corresponding xxxNet methods, which use a standard
network byte order."
- |b1 b2|
+ |b1 b2 bH bL|
b1 := self nextByte.
b2 := self nextByte.
msbFlag ifTrue:[
- ^ (b1 bitShift:8) bitOr:b2
- ].
- ^ (b2 bitShift:8) bitOr:b1
+ bH := b1.
+ bL := b2.
+ ] ifFalse:[
+ bL := b1.
+ bH := b2.
+ ].
+ ^ (bH bitShift:8) bitOr:bL
+
+ "
+ ((ReadStream on:#[16r10 16r20 16r30]) nextUnsignedInt16MSB:true) hexPrintString
+ ((ReadStream on:#[16r10 16r20 16r30]) nextUnsignedInt16MSB:false) hexPrintString
+ "
"Modified: 11.7.1996 / 10:07:20 / cg"
!
@@ -1374,6 +1412,41 @@
"Created: 10.1.1996 / 19:50:02 / cg"
!
+nextUnsignedInt24MSB:msbFlag
+ "return an unsigned 3 byte integer from the stream.
+ The receiver must support reading of binary bytes.
+
+ The msbFlag argument controls if the integer is to be read with
+ most-significant-byte-first (true) or least-first (false).
+ This interface is provided to allow talking to external programs,
+ where its known that the byte order is some definite one.
+ If you dont care (i.e. talk to other smalltalks) or you can control the
+ order, please use the corresponding xxxNet methods, which use a standard
+ network byte order."
+
+ |b1 b2 b3 bL bM bH|
+
+ b1 := self nextByte.
+ b2 := self nextByte.
+ b3 := self nextByte.
+
+ msbFlag ifTrue:[
+ bH := b1.
+ bM := b2.
+ bL := b3.
+ ] ifFalse:[
+ bH := b3.
+ bM := b2.
+ bL := b1.
+ ].
+ ^ (((bH bitShift:8) bitOr:bM) bitShift:8) bitOr:bL
+
+ "
+ ((ReadStream on:#[16r10 16r20 16r30]) nextUnsignedInt24MSB:true) hexPrintString
+ ((ReadStream on:#[16r10 16r20 16r30]) nextUnsignedInt24MSB:false) hexPrintString
+ "
+!
+
nextUnsignedInt32MSB:msbFlag
"return an unsigned long (4 bytes) from the stream.
The receiver must support reading of binary bytes.
@@ -3351,7 +3424,8 @@
nextDecimalInteger:numChars
"read and return the next integer of numChars size from the receiver stream.
Does NOT skip separators.
- Leaves the stream positioned after the digits"
+ Leaves the stream positioned after the digits.
+ Raises an error, if the characters cannot be converted to an integer"
|chars|
@@ -3384,7 +3458,8 @@
nextDecimalNumber:numChars
"read and return the next number of numChars size from the receiver stream.
Does NOT skip separators.
- Leaves the stream positioned after the digits"
+ Leaves the stream positioned after the digits.
+ Raises an error, if the characters cannot be converted to a number"
|chars|
--- a/UninterpretedBytes.st Tue Mar 22 08:03:27 2016 +0000
+++ b/UninterpretedBytes.st Wed Mar 23 07:50:28 2016 +0000
@@ -14,10 +14,10 @@
"{ NameSpace: Smalltalk }"
ArrayedCollection subclass:#UninterpretedBytes
- instanceVariableNames:''
- classVariableNames:'IsBigEndian'
- poolDictionaries:''
- category:'Collections-Abstract'
+ instanceVariableNames:''
+ classVariableNames:'IsBigEndian'
+ poolDictionaries:''
+ category:'Collections-Abstract'
!
!UninterpretedBytes primitiveDefinitions!
@@ -467,7 +467,6 @@
"Modified: / 5.3.1998 / 14:56:22 / stefan"
! !
-
!UninterpretedBytes methodsFor:'Compatibility'!
doubleWordAt:index
@@ -1522,7 +1521,7 @@
}
}
%}.
- ExternalAddress pointerSize == 8 ifTrue:[
+ SmallInteger maxBytes == 8 ifTrue:[
^ self signedInt64At:index
].
^ self signedInt32At:index
@@ -1575,7 +1574,7 @@
}
}
%}.
- ExternalAddress pointerSize == 8 ifTrue:[
+ SmallInteger maxBytes == 8 ifTrue:[
^ self signedInt64At:index put:value MSB:IsBigEndian
].
^ self signedInt32At:index put:value MSB:IsBigEndian
@@ -1588,28 +1587,33 @@
"
!
-signedIntegerAt:index length:n bigEndian:bigEndian
+signedIntegerAt:index length:len bigEndian:bigEndian
"return the n-byte signed integer starting at index.
With n=1, this returns the single signed byte's value,
n=2, a signed short, n=4 a signed int etc.
Useful to extract arbitrary long integers"
- |val highByte|
+ |val highByte
+ iIndex "{ Class:SmallInteger }"
+ last "{ Class:SmallInteger }"|
+
+ iIndex := index.
+ last := iIndex + len - 1.
val := 0.
bigEndian ifTrue:[
- highByte := (self at:index).
- index to:index+n-1 do:[:i |
+ highByte := self at:iIndex.
+ iIndex to:last do:[:i |
val := (val<<8) + (self byteAt:i)
]
] ifFalse:[
- highByte := (self at:index+n-1).
- index+n-1 to:index by:-1 do:[:i |
+ highByte := self at:last.
+ last to:iIndex by:-1 do:[:i |
val := (val<<8) + (self byteAt:i)
]
].
(highByte bitTest:16r80) ifTrue:[
- ^ val - (1 bitShift:(n*8))
+ ^ val - (1 bitShift:(len*8))
].
^ val
@@ -1644,21 +1648,26 @@
"
!
-unsignedIntegerAt:index length:n bigEndian:bigEndian
+unsignedIntegerAt:index length:len bigEndian:bigEndian
"return the n-byte unsigned integer starting at index.
With n=1, this returns the single byte's value,
n=2, an unsigned short, n=4 an unsigned int etc.
Useful to extract arbitrary long integers"
- |val|
+ |val
+ iIndex "{ Class:SmallInteger }"
+ last "{ Class:SmallInteger }"|
+
+ iIndex := index.
+ last := iIndex + len - 1.
val := 0.
bigEndian ifTrue:[
- index to:index+n-1 do:[:i |
+ iIndex to:last do:[:i |
val := (val<<8) + (self byteAt:i)
]
] ifFalse:[
- index+n-1 to:index by:-1 do:[:i |
+ last to:iIndex by:-1 do:[:i |
val := (val<<8) + (self byteAt:i)
]
].
@@ -1672,22 +1681,27 @@
"
!
-unsignedIntegerAt:index put:newValue length:n bigEndian:bigEndian
+unsignedIntegerAt:index put:newValue length:len bigEndian:bigEndian
"store the n-byte unsigned integer starting at index.
With n=1, this stores a single byte's value,
n=2, an unsigned short, n=4 an unsigned int etc.
Useful to replace arbitrary long integers"
- |val|
+ |val
+ iIndex "{ Class:SmallInteger }"
+ last "{ Class:SmallInteger }"|
+
+ iIndex := index.
+ last := iIndex + len - 1.
val := newValue.
bigEndian ifTrue:[
- index to:index+n-1 do:[:i |
+ iIndex to:last do:[:i |
self byteAt:i put:(val bitAnd:16rFF).
val := val bitShift:-8.
]
] ifFalse:[
- index+n-1 to:index by:-1 do:[:i |
+ last to:iIndex by:-1 do:[:i |
self byteAt:i put:(val bitAnd:16rFF).
val := val bitShift:-8.
]
@@ -3393,7 +3407,7 @@
INT sz;
__fetchBytePointerAndSize__(self, &cp, &sz);
-printf("cp=%"_lx_"\n", (INT)cp);
+ // printf("cp=%"_lx_"\n", (INT)cp);
if (cp) {
unsigned INT idx = ((unsigned INT)__intVal(byteIndex)) - 1;