# HG changeset patch # User Stefan Vogel # Date 1392209694 -3600 # Node ID 824d113634fce7c646636d60a27e4ebabd6c9ec5 # Parent c096b155b7047866a8976a87c6aef350dbc46ce9 class: SHA1Stream changed: #nextPutBytes:from:startingAt: Do double and longlong alignment if configured diff -r c096b155b704 -r 824d113634fc 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 $' ! !