--- a/UninterpretedBytes.st Thu Mar 28 12:21:50 2013 +0000
+++ b/UninterpretedBytes.st Mon Apr 01 13:42:45 2013 +0100
@@ -36,12 +36,13 @@
if (__isByteArrayLike(o)) { \
*(pPtr) = (unsigned char *)__ByteArrayInstPtr(o)->ba_element; \
*(pSize) = __byteArraySize(o); \
- } else if (__qClass(o) == ExternalBytes) { \
+ } else if (__qIsExternalBytesLike(o)) { \
OBJ __sz__ = __externalBytesSize(o); \
if (__isSmallInteger(__sz__)) { \
*(pSize) = __intVal(__sz__); \
*(pPtr) = (unsigned char *)(__externalBytesAddress(o)); \
} else { \
+ *(pSize) = 0; \
*(pPtr) = (unsigned char *)0; \
} \
} else { \
@@ -50,6 +51,7 @@
*(pSize) = __qSize(self) - *(pSize) /* nInstBytes */; \
} \
} else { \
+ *(pSize) = 0; \
*(pPtr) = (unsigned char *)0; \
} \
}
@@ -133,9 +135,9 @@
bytes := self new: sz // 2.
s := aString readStream.
1 to: sz // 2 do: [ :idx |
- hi := s next digitValue.
- lo := s next digitValue.
- bytes at:idx put: ((hi bitShift:4) bitOr: lo)
+ hi := s next digitValue.
+ lo := s next digitValue.
+ bytes at:idx put: ((hi bitShift:4) bitOr: lo)
].
^ bytes
@@ -150,7 +152,7 @@
"
"
Time millisecondsToRun:[
- 1000000 timesRepeat:[ ByteArray fromHexString:'1234FEFF1234FEFF1234FEFF1234FEFF' ]
+ 1000000 timesRepeat:[ ByteArray fromHexString:'1234FEFF1234FEFF1234FEFF1234FEFF' ]
].
"
!
@@ -397,8 +399,8 @@
^ (self byteAt:index) decodeFromBCD
"
- #[ 16r55 ] bcdByteAt:1
- #[ 16r99] bcdByteAt:1
+ #[ 16r55 ] bcdByteAt:1
+ #[ 16r99] bcdByteAt:1
#[ 16rAA] bcdByteAt:1
"
@@ -411,7 +413,7 @@
(i.e. the value n is encoded as: ((n // 10) * 16) + (n \\ 10)"
(aNumber between:0 and:99) ifFalse:[
- self error:'invalid value for BCD encoding'
+ self error:'invalid value for BCD encoding'
].
^ self byteAt:index put:aNumber encodeAsBCD
@@ -453,9 +455,9 @@
|b "{ Class: SmallInteger }"|
aSignedByteValue >= 0 ifTrue:[
- b := aSignedByteValue
+ b := aSignedByteValue
] ifFalse:[
- b := 16r100 + aSignedByteValue
+ b := 16r100 + aSignedByteValue
].
self at:index put:b.
^ aSignedByteValue
@@ -489,7 +491,7 @@
*/
if (__isSmallInteger(index)) {
unsigned char *cp;
- int sz;
+ INT sz;
__fetchBytePointerAndSize__(self, &cp, &sz);
if (cp) {
@@ -569,7 +571,7 @@
*/
if (__isSmallInteger(index) && __isFloat(flt)) {
unsigned char *cp;
- int sz;
+ INT sz;
__fetchBytePointerAndSize__(self, &cp, &sz);
if (cp) {
@@ -638,7 +640,7 @@
*/
if (__isSmallInteger(index)) {
unsigned char *cp;
- int sz;
+ INT sz;
__fetchBytePointerAndSize__(self, &cp, &sz);
if (cp) {
@@ -712,7 +714,7 @@
*/
if (__isSmallInteger(index) && __isShortFloat(sflt)) {
unsigned char *cp;
- int sz;
+ INT sz;
__fetchBytePointerAndSize__(self, &cp, &sz);
if (cp) {
@@ -1118,7 +1120,7 @@
*/
if (__isSmallInteger(index)) {
unsigned char *cp;
- int sz;
+ INT sz;
__fetchBytePointerAndSize__(self, &cp, &sz);
if (cp) {
@@ -1331,7 +1333,7 @@
*/
if (__isSmallInteger(index)) {
unsigned char *cp;
- int sz;
+ INT sz;
__fetchBytePointerAndSize__(self, &cp, &sz);
if (cp) {
@@ -1425,7 +1427,7 @@
*/
if (__isSmallInteger(index)) {
unsigned char *cp;
- int sz;
+ INT sz;
__fetchBytePointerAndSize__(self, &cp, &sz);
if (cp) {
@@ -1497,7 +1499,7 @@
%{
if (__isSmallInteger(index)) {
unsigned char *cp;
- int sz;
+ INT sz;
__fetchBytePointerAndSize__(self, &cp, &sz);
if (cp) {
@@ -1512,9 +1514,26 @@
if (((INT)cp & (sizeof(pointer)-1)) == 0) {
pointer = ((char **)cp)[0];
RETURN (__MKEXTERNALADDRESS(pointer));
+ } else {
+#if 0
+ printf("cp UNALIGNED (%"_lx_")\n", (INT)cp);
+#endif
}
+ } else {
+#if 0
+ printf("idx(%"_ld_")+(sizeof(pointer)-1) (%d) >= sz (%"_ld_")\n",
+ idx, (int)(sizeof(pointer)-1), sz);
+#endif
}
+ } else {
+#if 0
+ printf("cp is NULL\n");
+#endif
}
+ } else {
+#if 0
+ printf("bad index\n");
+#endif
}
bad:;
%}.
@@ -1531,7 +1550,7 @@
!
pointerAt:index put:value
- "set the pointer starting at index from the signed Integer value.
+ "set the pointer starting at index from the integer or externalAddress value.
The index is a smalltalk index (i.e. 1-based).
Only aligned accesses are allowed.
The value is either an ExternalAddress or ExternalBytes"
@@ -1547,11 +1566,17 @@
pointer = 0;
} else if (value == nil) {
pointer = 0;
- } else goto bad;
+ } else if (__isSmallInteger(value)) {
+ pointer = (OBJ *)__intVal(value);
+ } else {
+ if ((pointer = (OBJ *)__unsignedLongIntVal(value)) == 0) {
+ goto bad;
+ }
+ }
if (__isSmallInteger(index)) {
unsigned char *cp;
- int sz;
+ INT sz;
__fetchBytePointerAndSize__(self, &cp, &sz);
if (cp) {
@@ -1630,7 +1655,7 @@
*/
if (__isSmallInteger(index)) {
unsigned char *cp;
- int sz;
+ INT sz;
__fetchBytePointerAndSize__(self, &cp, &sz);
if (cp) {
@@ -2512,142 +2537,142 @@
&& (__isBytes(self) || __isWords(self))
&& __bothSmallInteger(start, stop)
&& __isSmallInteger(repStart)) {
- startIndex = __intVal(start) - 1;
- if (startIndex >= 0) {
- dst = (__ByteArrayInstPtr(self)->ba_element) + startIndex;
- nIndex = __byteArraySize(self);
-
- if ((cls = __qClass(self)) != @global(ByteArray)) {
- int nInst;
-
- nInst = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
- dst += nInst;
- nIndex -= nInst;
- }
-
- stopIndex = __intVal(stop) - 1;
- count = stopIndex - startIndex + 1;
- if (count == 0) {
- RETURN ( self );
- }
-
- if ((count > 0) && (stopIndex < nIndex)) {
- repStartIndex = __intVal(repStart) - 1;
- if (repStartIndex >= 0) {
- if (__isExternalBytesLike(aCollection)) {
- OBJ sz;
-
- src = __externalAddressVal(aCollection);
- if (src == 0) goto fallBack;
-
- sz = __externalBytesSize(aCollection);
- if (__isSmallInteger(sz)) {
- repNIndex = __smallIntegerVal(sz);
- } else {
- repNIndex = repStopIndex+1; /* always enough */
- }
- src = src + repStartIndex;
- } else {
- if (__isStringLike(aCollection)) {
- repNIndex = __stringSize(aCollection);
- } else {
- repNIndex = __qSize(aCollection) - OHDR_SIZE;
- }
- src = (__ByteArrayInstPtr(aCollection)->ba_element) + repStartIndex;
- if ((cls = __qClass(aCollection)) != @global(ByteArray)) {
- int nInst;
-
- nInst = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
- src += nInst;
- repNIndex -= nInst;
- }
- }
- repStopIndex = repStartIndex + (stopIndex - startIndex);
- if (repStopIndex < repNIndex) {
- if (aCollection == self) {
- /* take care of overlapping copy */
- if (src < dst) {
- /* must do a reverse copy */
- src += count;
- dst += count;
- while (count-- > 0) {
- *--dst = *--src;
- }
- RETURN ( self );
- }
- }
+ startIndex = __intVal(start) - 1;
+ if (startIndex >= 0) {
+ dst = (__ByteArrayInstPtr(self)->ba_element) + startIndex;
+ nIndex = __byteArraySize(self);
+
+ if ((cls = __qClass(self)) != @global(ByteArray)) {
+ int nInst;
+
+ nInst = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+ dst += nInst;
+ nIndex -= nInst;
+ }
+
+ stopIndex = __intVal(stop) - 1;
+ count = stopIndex - startIndex + 1;
+ if (count == 0) {
+ RETURN ( self );
+ }
+
+ if ((count > 0) && (stopIndex < nIndex)) {
+ repStartIndex = __intVal(repStart) - 1;
+ if (repStartIndex >= 0) {
+ if (__isExternalBytesLike(aCollection)) {
+ OBJ sz;
+
+ src = __externalAddressVal(aCollection);
+ if (src == 0) goto fallBack;
+
+ sz = __externalBytesSize(aCollection);
+ if (__isSmallInteger(sz)) {
+ repNIndex = __smallIntegerVal(sz);
+ } else {
+ repNIndex = repStopIndex+1; /* always enough */
+ }
+ src = src + repStartIndex;
+ } else {
+ if (__isStringLike(aCollection)) {
+ repNIndex = __stringSize(aCollection);
+ } else {
+ repNIndex = __qSize(aCollection) - OHDR_SIZE;
+ }
+ src = (__ByteArrayInstPtr(aCollection)->ba_element) + repStartIndex;
+ if ((cls = __qClass(aCollection)) != @global(ByteArray)) {
+ int nInst;
+
+ nInst = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+ src += nInst;
+ repNIndex -= nInst;
+ }
+ }
+ repStopIndex = repStartIndex + (stopIndex - startIndex);
+ if (repStopIndex < repNIndex) {
+ if (aCollection == self) {
+ /* take care of overlapping copy */
+ if (src < dst) {
+ /* must do a reverse copy */
+ src += count;
+ dst += count;
+ while (count-- > 0) {
+ *--dst = *--src;
+ }
+ RETURN ( self );
+ }
+ }
# ifdef bcopy4
- if (((unsigned INT)src & 3) == ((unsigned INT)dst & 3)) {
- int nW;
-
- /* copy unaligned part */
- while (count && ((unsigned INT)src & 3)) {
- *dst++ = *src++;
- count--;
- }
-
- if (count > 0) {
- /* copy aligned part */
- nW = count >> 2;
- bcopy4(src, dst, nW);
- if ((count = count & 3) != 0) {
- /* copy any remaining part */
- src += (nW<<2);
- dst += (nW<<2);
- while (count--) {
- *dst++ = *src++;
- }
- }
- }
- RETURN ( self );
- }
+ if (((unsigned INT)src & 3) == ((unsigned INT)dst & 3)) {
+ int nW;
+
+ /* copy unaligned part */
+ while (count && ((unsigned INT)src & 3)) {
+ *dst++ = *src++;
+ count--;
+ }
+
+ if (count > 0) {
+ /* copy aligned part */
+ nW = count >> 2;
+ bcopy4(src, dst, nW);
+ if ((count = count & 3) != 0) {
+ /* copy any remaining part */
+ src += (nW<<2);
+ dst += (nW<<2);
+ while (count--) {
+ *dst++ = *src++;
+ }
+ }
+ }
+ RETURN ( self );
+ }
# else
# if __POINTER_SIZE__ == 8
- if (((unsigned INT)src & 7) == ((unsigned INT)dst & 7)) {
- /* copy unaligned part */
- while (count && ((unsigned INT)src & 7)) {
- *dst++ = *src++;
- count--;
- }
-
- /* copy aligned part */
- while (count >= 8) {
- ((unsigned INT *)dst)[0] = ((unsigned INT *)src)[0];
- dst += 8;
- src += 8;
- count -= 8;
- }
- while (count--) {
- *dst++ = *src++;
- }
- RETURN ( self );
- }
+ if (((unsigned INT)src & 7) == ((unsigned INT)dst & 7)) {
+ /* copy unaligned part */
+ while (count && ((unsigned INT)src & 7)) {
+ *dst++ = *src++;
+ count--;
+ }
+
+ /* copy aligned part */
+ while (count >= 8) {
+ ((unsigned INT *)dst)[0] = ((unsigned INT *)src)[0];
+ dst += 8;
+ src += 8;
+ count -= 8;
+ }
+ while (count--) {
+ *dst++ = *src++;
+ }
+ RETURN ( self );
+ }
# endif /* 64bit */
# endif /* bcopy4 */
# ifdef FAST_MEMCPY
- bcopy(src, dst, count);
+ bcopy(src, dst, count);
# else
# ifdef __UNROLL_LOOPS__
- while (count >= 8) {
- dst[0] = src[0]; dst[1] = src[1];
- dst[2] = src[2]; dst[3] = src[3];
- dst[4] = src[4]; dst[5] = src[5];
- dst[6] = src[6]; dst[7] = src[7];
- dst += 8; src += 8;
- count -= 8;
- }
+ while (count >= 8) {
+ dst[0] = src[0]; dst[1] = src[1];
+ dst[2] = src[2]; dst[3] = src[3];
+ dst[4] = src[4]; dst[5] = src[5];
+ dst[6] = src[6]; dst[7] = src[7];
+ dst += 8; src += 8;
+ count -= 8;
+ }
# endif /* __UNROLL_LOOPS__ */
- while (count-- > 0) {
- *dst++ = *src++;
- }
+ while (count-- > 0) {
+ *dst++ = *src++;
+ }
# endif
- RETURN ( self );
- }
- }
- }
- }
+ RETURN ( self );
+ }
+ }
+ }
+ }
}
fallBack: ;
#endif
@@ -2660,34 +2685,34 @@
"
#[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16]
- copy
- replaceFrom:1 to:8
- with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160]
- startingAt:1
+ copy
+ replaceFrom:1 to:8
+ with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160]
+ startingAt:1
#[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16]
- copy
- replaceFrom:3 to:10
- with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160]
- startingAt:1
+ copy
+ replaceFrom:3 to:10
+ with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160]
+ startingAt:1
#[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16]
- copy
- replaceFrom:3 to:4
- with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160]
- startingAt:1
+ copy
+ replaceFrom:3 to:4
+ with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160]
+ startingAt:1
#[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16]
- copy
- replaceFrom:0 to:9
- with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160]
- startingAt:1
+ copy
+ replaceFrom:0 to:9
+ with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160]
+ startingAt:1
#[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16]
- copy
- replaceFrom:1 to:10
- with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160]
- startingAt:0
+ copy
+ replaceFrom:1 to:10
+ with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160]
+ startingAt:0
"
!
@@ -2724,14 +2749,14 @@
therefore the change may affect all others referencing the receiver."
^ self
- replaceBytesFrom:1
- to:(replacementCollection size min:self size)
- with:replacementCollection
- startingAt:1
+ replaceBytesFrom:1
+ to:(replacementCollection size min:self size)
+ with:replacementCollection
+ startingAt:1
"
- (ByteArray new:10) replaceBytesWith:'hello'
- (ByteArray new:10) replaceBytesWith:'hello world bla bla bla'
+ (ByteArray new:10) replaceBytesWith:'hello'
+ (ByteArray new:10) replaceBytesWith:'hello world bla bla bla'
"
"Created: / 09-01-2012 / 16:18:10 / cg"
@@ -2746,18 +2771,18 @@
therefore the change may affect all others referencing the receiver."
self class isBytes ifTrue:[
- ((aCollection class == self class)
- or:[aCollection isByteCollection]) ifTrue:[
- ^ self replaceBytesFrom:startIndex to:stopIndex with:aCollection startingAt:repStartIndex
- ].
+ ((aCollection class == self class)
+ or:[aCollection isByteCollection]) ifTrue:[
+ ^ self replaceBytesFrom:startIndex to:stopIndex with:aCollection startingAt:repStartIndex
+ ].
].
^ super replaceFrom:startIndex to:stopIndex with:aCollection startingAt:repStartIndex
"
args: startIndex : <integer>
- stopIndex : <integer>
- replacementCollection : <collection of <bytes> >
- repStartIndex : <integer>
+ stopIndex : <integer>
+ replacementCollection : <collection of <bytes> >
+ repStartIndex : <integer>
returns: self
"
@@ -2964,10 +2989,9 @@
!UninterpretedBytes class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/UninterpretedBytes.st,v 1.91 2013-03-26 17:02:41 stefan Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/UninterpretedBytes.st,v 1.92 2013-03-29 15:10:08 cg Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libbasic/UninterpretedBytes.st,v 1.91 2013-03-26 17:02:41 stefan Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/UninterpretedBytes.st,v 1.92 2013-03-29 15:10:08 cg Exp $'
! !
-