mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 00:30:53 +00:00
Fix NSGetSizeAndAlignment usage
The argument order is (*sizep, *alignp), but it was often incorrectly used the other way around.
This commit is contained in:
parent
f958c37c15
commit
4033ee28a8
7 changed files with 37 additions and 9 deletions
|
@ -1862,7 +1862,7 @@ GSObjCSetVal(NSObject *self, const char *key, id val, SEL sel,
|
||||||
{
|
{
|
||||||
NSUInteger size;
|
NSUInteger size;
|
||||||
|
|
||||||
NSGetSizeAndAlignment(type, &size, 0);
|
NSGetSizeAndAlignment(type, &size, NULL);
|
||||||
if (sel == 0)
|
if (sel == 0)
|
||||||
{
|
{
|
||||||
[val getValue: ((char *)self + offset)];
|
[val getValue: ((char *)self + offset)];
|
||||||
|
|
|
@ -113,7 +113,7 @@
|
||||||
format: @"Cannot copy value into NULL buffer"];
|
format: @"Cannot copy value into NULL buffer"];
|
||||||
/* NOT REACHED */
|
/* NOT REACHED */
|
||||||
}
|
}
|
||||||
NSGetSizeAndAlignment([self objCType], 0, &size);
|
NSGetSizeAndAlignment([self objCType], &size, NULL);
|
||||||
memcpy(value, &data, size);
|
memcpy(value, &data, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,7 @@ typeSize(const char* type)
|
||||||
{
|
{
|
||||||
NSUInteger size;
|
NSUInteger size;
|
||||||
|
|
||||||
NSGetSizeAndAlignment(type, &size, 0);
|
NSGetSizeAndAlignment(type, &size, NULL);
|
||||||
return (int)size;
|
return (int)size;
|
||||||
}
|
}
|
||||||
case _C_VOID: return 0;
|
case _C_VOID: return 0;
|
||||||
|
@ -265,7 +265,7 @@ typeSize(const char* type)
|
||||||
size = strlen(objctype)+1;
|
size = strlen(objctype)+1;
|
||||||
[coder encodeValueOfObjCType: @encode(unsigned) at: &size];
|
[coder encodeValueOfObjCType: @encode(unsigned) at: &size];
|
||||||
[coder encodeArrayOfObjCType: @encode(signed char) count: size at: objctype];
|
[coder encodeArrayOfObjCType: @encode(signed char) count: size at: objctype];
|
||||||
NSGetSizeAndAlignment(objctype, 0, &tsize);
|
NSGetSizeAndAlignment(objctype, &tsize, NULL);
|
||||||
size = tsize;
|
size = tsize;
|
||||||
d = [NSMutableData new];
|
d = [NSMutableData new];
|
||||||
[d serializeDataAt: data ofObjCType: objctype context: nil];
|
[d serializeDataAt: data ofObjCType: objctype context: nil];
|
||||||
|
|
|
@ -427,7 +427,7 @@ static NSMapTable *globalClassMap = 0;
|
||||||
format: @"[%@ +%@]: count mismatch for %@",
|
format: @"[%@ +%@]: count mismatch for %@",
|
||||||
NSStringFromClass([self class]), NSStringFromSelector(_cmd), o];
|
NSStringFromClass([self class]), NSStringFromSelector(_cmd), o];
|
||||||
}
|
}
|
||||||
NSGetSizeAndAlignment(type, 0, &size);
|
NSGetSizeAndAlignment(type, &size, NULL);
|
||||||
memcpy(buf, [o bytes], expected * size);
|
memcpy(buf, [o bytes], expected * size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -611,7 +611,7 @@ static NSUInteger urlAlign;
|
||||||
{
|
{
|
||||||
if (clientsLock == nil)
|
if (clientsLock == nil)
|
||||||
{
|
{
|
||||||
NSGetSizeAndAlignment(@encode(parsedURL), &urlAlign, 0);
|
NSGetSizeAndAlignment(@encode(parsedURL), NULL, &urlAlign);
|
||||||
clientsLock = [NSLock new];
|
clientsLock = [NSLock new];
|
||||||
[[NSObject leakAt: &clientsLock] release];
|
[[NSObject leakAt: &clientsLock] release];
|
||||||
ASSIGN(fileCharSet, [NSCharacterSet characterSetWithCharactersInString:
|
ASSIGN(fileCharSet, [NSCharacterSet characterSetWithCharactersInString:
|
||||||
|
|
|
@ -440,7 +440,7 @@ static NSLock *placeholderLock;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NSGetSizeAndAlignment(objctype, 0, &tsize);
|
NSGetSizeAndAlignment(objctype, &tsize, NULL);
|
||||||
data = (void *)NSZoneMalloc([self zone], tsize);
|
data = (void *)NSZoneMalloc([self zone], tsize);
|
||||||
[self getValue: (void*)data];
|
[self getValue: (void*)data];
|
||||||
d = [NSMutableData new];
|
d = [NSMutableData new];
|
||||||
|
@ -583,7 +583,7 @@ static NSLock *placeholderLock;
|
||||||
* For performance, decode small values directly onto the stack,
|
* For performance, decode small values directly onto the stack,
|
||||||
* For larger values we allocate and deallocate heap space.
|
* For larger values we allocate and deallocate heap space.
|
||||||
*/
|
*/
|
||||||
NSGetSizeAndAlignment(objctype, 0, &tsize);
|
NSGetSizeAndAlignment(objctype, &tsize, NULL);
|
||||||
if (tsize <= 64)
|
if (tsize <= 64)
|
||||||
{
|
{
|
||||||
unsigned char data[tsize];
|
unsigned char data[tsize];
|
||||||
|
@ -625,7 +625,7 @@ static NSLock *placeholderLock;
|
||||||
* For performance, decode small values directly onto the stack,
|
* For performance, decode small values directly onto the stack,
|
||||||
* For larger values we allocate and deallocate heap space.
|
* For larger values we allocate and deallocate heap space.
|
||||||
*/
|
*/
|
||||||
NSGetSizeAndAlignment(objctype, 0, &tsize);
|
NSGetSizeAndAlignment(objctype, &tsize, NULL);
|
||||||
if (tsize <= 64)
|
if (tsize <= 64)
|
||||||
{
|
{
|
||||||
unsigned char data[tsize];
|
unsigned char data[tsize];
|
||||||
|
|
28
Tests/base/NSValue/basic.m
Normal file
28
Tests/base/NSValue/basic.m
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
#import "Testing.h"
|
||||||
|
#import "ObjectTesting.h"
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||||
|
NSValue *testObj;
|
||||||
|
|
||||||
|
test_alloc_only(@"NSValue");
|
||||||
|
|
||||||
|
int val = 5;
|
||||||
|
int out;
|
||||||
|
testObj = [NSValue valueWithBytes: &val objCType: @encode(int)];
|
||||||
|
[testObj getValue: &out];
|
||||||
|
PASS_EQUAL(val, out, "NSValue -getValue returned the same integer");
|
||||||
|
|
||||||
|
NSRange range_val = NSMakeRange(1, 1);
|
||||||
|
NSRange range_out;
|
||||||
|
testObj = [NSValue valueWithBytes: &range_val objCType: @encode(NSRange)];
|
||||||
|
[testObj getValue: &range_out];
|
||||||
|
PASS(NSEqualRanges(range_val, range_out), "NSValue -getValue returned the same NSRange");
|
||||||
|
range_out = [testObj rangeValue];
|
||||||
|
PASS(NSEqualRanges(range_val, range_out), "NSValue -rangeValue returned the same NSRange");
|
||||||
|
|
||||||
|
[arp release]; arp = nil;
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue