Index: src/OFValue.m ================================================================== --- src/OFValue.m +++ src/OFValue.m @@ -14,14 +14,15 @@ * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFValue.h" +#import "OFMethodSignature.h" +#import "OFString.h" #import "OFValue_bytes.h" #import "OFValue_nonretainedObject.h" #import "OFValue_pointer.h" -#import "OFMethodSignature.h" #import "OFInvalidFormatException.h" #import "OFOutOfMemoryException.h" static struct { @@ -101,11 +102,11 @@ - (bool)isEqual: (id)object { const char *objCType; size_t size; - void *buffer, *otherBuffer; + void *value, *otherValue; if (![object isKindOfClass: [OFValue class]]) return false; objCType = [self objCType]; @@ -113,55 +114,55 @@ if (strcmp([object objCType], objCType) != 0) return false; size = of_sizeof_type_encoding(objCType); - if ((buffer = malloc(size)) == NULL) + if ((value = malloc(size)) == NULL) @throw [OFOutOfMemoryException exceptionWithRequestedSize: size]; - if ((otherBuffer = malloc(size)) == NULL) + if ((otherValue = malloc(size)) == NULL) { + free(value); @throw [OFOutOfMemoryException exceptionWithRequestedSize: size]; + } @try { - [self getValue: buffer + [self getValue: value size: size]; - [object getValue: otherBuffer + [object getValue: otherValue size: size]; - return (memcmp(buffer, otherBuffer, size) == 0); + return (memcmp(value, otherValue, size) == 0); } @finally { - free(buffer); - free(otherBuffer); + free(value); + free(otherValue); } } - (uint32_t)hash { + size_t size = of_sizeof_type_encoding([self objCType]); + unsigned char *value; uint32_t hash; - size_t size; - char *buffer; - size = of_sizeof_type_encoding([self objCType]); - - if ((buffer = malloc(size)) == NULL) + if ((value = malloc(size)) == NULL) @throw [OFOutOfMemoryException exceptionWithRequestedSize: size]; - [self getValue: buffer - size: size]; - @try { + [self getValue: value + size: size]; + OF_HASH_INIT(hash); for (size_t i = 0; i < size; i++) - OF_HASH_ADD(hash, buffer[i]); + OF_HASH_ADD(hash, value[i]); OF_HASH_FINALIZE(hash); } @finally { - free(buffer); + free(value); } return hash; } @@ -198,6 +199,37 @@ [self getValue: &ret size: sizeof(ret)]; return ret; } + +- (OFString *)description +{ + OFMutableString *ret = + [OFMutableString stringWithString: @" 0) + [ret appendString: @" "]; + + [ret appendFormat: @"%02x", value[i]]; + } + } @finally { + free(value); + } + + [ret appendString: @">"]; + + [ret makeImmutable]; + return ret; +} @end