# HG changeset patch # User Stefan Vogel # Date 1015368326 -3600 # Node ID 45d1c43350a126453f6d3b59b97304e88a17171d # Parent 04becccdbd702b109da2c04ff89b646d49483921 *** empty log message *** diff -r 04becccdbd70 -r 45d1c43350a1 ExternalBytes.st --- a/ExternalBytes.st Tue Mar 05 23:26:17 2002 +0100 +++ b/ExternalBytes.st Tue Mar 05 23:45:26 2002 +0100 @@ -408,8 +408,8 @@ may change their address. DANGER ALERT: the memory is NOT automatically freed until it is either - MANUALLY freed (see #free) or the returned externalBytes object - is unprotected or the classes releaseAllMemory method is called." + MANUALLY freed (see #free) or the returned externalBytes object + is unprotected or the classes releaseAllMemory method is called." |newInst| @@ -433,10 +433,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| @@ -698,33 +698,33 @@ OBJ sz; if (__isSmallInteger(value)) { - val = __smallIntegerVal(value); + val = __smallIntegerVal(value); } else if (__isCharacter(value)) { - val = __smallIntegerVal(_characterVal(value)); + val = __smallIntegerVal(_characterVal(value)); } else - goto badArg; + goto badArg; if (cp && __isSmallInteger(index)) { - idx = __intVal(index); - if (idx > 0) { - if (((sz = __INST(size)) == nil) - || (__intVal(sz) >= idx)) { - if ((val & ~0xFF) == 0) /* i.e. (val >= 0) && (val <= 255) */ { - cp[idx-1] = val; - RETURN ( value ); - } - } - } + idx = __intVal(index); + if (idx > 0) { + if (((sz = __INST(size)) == nil) + || (__intVal(sz) >= idx)) { + if ((val & ~0xFF) == 0) /* i.e. (val >= 0) && (val <= 255) */ { + cp[idx-1] = val; + RETURN ( value ); + } + } + } } badArg: ; %}. (size notNil and:[self address notNil]) ifTrue:[ - (index between:1 and:size) ifTrue:[ - ^ ElementOutOfBoundsSignal raise - ]. - ^ self subscriptBoundsError:index + (index between:1 and:size) ifTrue:[ + ^ ElementOutOfBoundsSignal raise + ]. + ^ self subscriptBoundsError:index ]. " invalid index, invalid value or unallocated @@ -779,7 +779,7 @@ mem = (char *)(__INST(address_)); if (mem) { - __stx_free(mem); + __stx_free(mem); } __INST(address_) = __INST(size) = nil; %} @@ -794,8 +794,8 @@ "at least, we check for double freeing the same chunk" self address isNil ifTrue:[ - self error:'freeing memory twice'. - ^ self + self error:'freeing memory twice'. + ^ self ]. Lobby unregister:self. self finalize. "/ does what we need here .. @@ -816,13 +816,13 @@ int __start, __stop; if (__bothSmallInteger(start, stop) && __INST(address_) != nil) { - __start = __smallIntegerVal(start); - __stop = __smallIntegerVal(stop); - if (__start > 0 && __start <= __stop && __stop <= __smallIntegerVal(__INST(size))) { - addr = (void *)__INST(address_) + (__start - 1); - size = __stop - __start + 1; - RETURN(__MKEXTERNALBYTES_N(addr, size)) - } + __start = __smallIntegerVal(start); + __stop = __smallIntegerVal(stop); + if (__start > 0 && __start <= __stop && __stop <= __smallIntegerVal(__INST(size))) { + addr = (void *)__INST(address_) + (__start - 1); + size = __stop - __start + 1; + RETURN(__MKEXTERNALBYTES_N(addr, size)) + } } %}. ^ self primitiveFailed @@ -852,19 +852,19 @@ %{ /* NOCONTEXT */ if (__INST(address_) == nil) { - if (aNumber == nil) { - __INST(address_) = nil; - } else { - if (__isSmallInteger(aNumber)) { - __INST(address_) = (OBJ) __intVal(aNumber); - } else if(__isInteger(aNumber)) { - __INST(address_) = (OBJ) __unsignedLongIntVal(aNumber); - } else if(__isExternalAddress(aNumber)) { - __INST(address_) = __externalAddressVal(aNumber); - } - } - __INST(size) = sz; - RETURN (self); + if (aNumber == nil) { + __INST(address_) = nil; + } else { + if (__isSmallInteger(aNumber)) { + __INST(address_) = (OBJ) __intVal(aNumber); + } else if(__isInteger(aNumber)) { + __INST(address_) = (OBJ) __unsignedLongIntVal(aNumber); + } else if(__isExternalAddress(aNumber)) { + __INST(address_) = __externalAddressVal(aNumber); + } + } + __INST(size) = sz; + RETURN (self); } %}. ^ self error:'cannot change address' @@ -889,23 +889,23 @@ */ if (__INST(address_) == nil && __isSmallInteger(numberOfBytes)) { - nBytes = __smallIntegerVal(numberOfBytes); - if (nBytes > 0) { - space = __stx_malloc(nBytes); - if (space) { - __INST(address_) = space; - __INST(size) = numberOfBytes; - RETURN(self); - } else { - mallocFailure = true; - } - } + nBytes = __smallIntegerVal(numberOfBytes); + if (nBytes > 0) { + space = __stx_malloc(nBytes); + if (space) { + __INST(address_) = (OBJ)space; + __INST(size) = numberOfBytes; + RETURN(self); + } else { + mallocFailure = true; + } + } } %}. mallocFailure == true ifTrue:[ - ^ ObjectMemory mallocFailureSignal raiseRequest + ^ ObjectMemory mallocFailureSignal raiseRequest ] ifFalse:[ - self primitiveFailed. + self primitiveFailed. ]. ! ! @@ -955,6 +955,6 @@ !ExternalBytes class methodsFor:'documentation'! version - ^ '$Header: /cvs/stx/stx/libbasic/ExternalBytes.st,v 1.37 2002-03-05 22:26:17 stefan Exp $' + ^ '$Header: /cvs/stx/stx/libbasic/ExternalBytes.st,v 1.38 2002-03-05 22:45:26 stefan Exp $' ! ! ExternalBytes initialize!