class: SHA1Stream
authorStefan Vogel <sv@exept.de>
Wed, 12 Feb 2014 13:54:54 +0100
changeset 15989 824d113634fc
parent 15988 c096b155b704
child 15990 358873f8b450
class: SHA1Stream changed: #nextPutBytes:from:startingAt: Do double and longlong alignment if configured
SHA1Stream.st
--- a/SHA1Stream.st	Wed Feb 12 13:54:43 2014 +0100
+++ b/SHA1Stream.st	Wed Feb 12 13:54:54 2014 +0100
@@ -521,57 +521,64 @@
 %{
     INT len, offs;
     INT objSize;
-    int nInstVars, nInstBytes;
+    int nInstBytes;
     char *extPtr;
 
    if (__isByteArray(__INST(hashContext))
        && __byteArraySize(__INST(hashContext)) == sizeof(SHA1_CTX)
        && __bothSmallInteger(count, start)
    ) {
-	SHA1_CTX *ctx = (SHA1_CTX *)__ByteArrayInstPtr(__INST(hashContext))->ba_element;
+        SHA1_CTX *ctx = (SHA1_CTX *)__ByteArrayInstPtr(__INST(hashContext))->ba_element;
 
-	len = __intVal(count);
-	offs = __intVal(start) - 1;
+        len = __intVal(count);
+        offs = __intVal(start) - 1;
 
-	if (__isExternalBytesLike(anObject)) {
-	    OBJ sz;
+        if (__isExternalBytesLike(anObject)) {
+            OBJ sz;
 
-	    nInstBytes = 0;
-	    extPtr = (char *)__externalBytesAddress(anObject);
-	    if (extPtr == NULL) goto bad;
-	    sz = __externalBytesSize(anObject);
-	    if (__isSmallInteger(sz)) {
-		objSize = __intVal(sz);
-	    } else {
-		objSize = 0; /* unknown */
-	    }
-	} else {
-	    OBJ oClass;
+            nInstBytes = 0;
+            extPtr = (char *)__externalBytesAddress(anObject);
+            if (extPtr == NULL) goto bad;
+            sz = __externalBytesSize(anObject);
+            if (__isSmallInteger(sz)) {
+                objSize = __intVal(sz);
+            } else {
+                objSize = 0; /* unknown */
+            }
+        } else {
+            OBJ oClass = __Class(anObject);
+            int nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
 
-	    oClass = __Class(anObject);
-	    switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
-		case BYTEARRAY:
-		case WORDARRAY:
-		case LONGARRAY:
-		case SWORDARRAY:
-		case SLONGARRAY:
-		case FLOATARRAY:
-		case DOUBLEARRAY:
-		    break;
-		default:
-		    goto bad;
-	    }
-	    nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
-	    nInstBytes = __OBJS2BYTES__(nInstVars);
-	    // nInstBytes is the number of bytes occupied by pointer instance variables
-	    // subtract from size and add to byte-pointer
-	    objSize = __Size(anObject) - OHDR_SIZE - nInstBytes;
-	    extPtr = (char *)__byteArrayVal(anObject)+nInstBytes;
-	}
-	if ((offs >= 0) && (len >= 0) && (objSize >= (len + offs))) {
-	    SHA1Update(ctx, extPtr+offs, (unsigned int)len);
-	    RETURN (count);
-	}
+            nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars);
+            switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
+                case BYTEARRAY:
+                case WORDARRAY:
+                case LONGARRAY:
+                case SWORDARRAY:
+                case SLONGARRAY:
+                case FLOATARRAY:
+                case DOUBLEARRAY:
+#ifdef __NEED_DOUBLE_ALIGN
+                    nInstBytes = (nInstBytes-1+__DOUBLE_ALIGN) &~ (__DOUBLE_ALIGN-1);
+#endif
+                    break;
+                case LONGLONGARRAY:
+                case SLONGLONGARRAY:
+#ifdef __NEED_LONGLONG_ALIGN
+                    nInstBytes = (nInstBytes-1+__LONGLONG_ALIGN) &~ (__LONGLONG_ALIGN-1);
+#endif
+                default:
+                    goto bad;
+            }
+            // nInstBytes is the number of bytes occupied by pointer instance variables
+            // subtract from size and add to byte-pointer
+            objSize = __Size(anObject) - OHDR_SIZE - nInstBytes;
+            extPtr = (char *)__byteArrayVal(anObject)+nInstBytes;
+        }
+        if ((offs >= 0) && (len >= 0) && (objSize >= (len + offs))) {
+            SHA1Update(ctx, extPtr+offs, (unsigned int)len);
+            RETURN (count);
+        }
     }
 bad: ;
 %}.
@@ -582,11 +589,11 @@
 !SHA1Stream class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/SHA1Stream.st,v 1.40 2014-01-25 00:31:18 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/SHA1Stream.st,v 1.41 2014-02-12 12:54:54 stefan Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/SHA1Stream.st,v 1.40 2014-01-25 00:31:18 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/SHA1Stream.st,v 1.41 2014-02-12 12:54:54 stefan Exp $'
 ! !