Merge pull request #216 from madsmtm/fix-nsgetsizeandalignment

Fix `NSGetSizeAndAlignment` usage
This commit is contained in:
Fred Kiefer 2021-11-05 20:05:13 +01:00 committed by GitHub
commit 824fcb8e65
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 37 additions and 9 deletions

View file

@ -1862,7 +1862,7 @@ GSObjCSetVal(NSObject *self, const char *key, id val, SEL sel,
{
NSUInteger size;
NSGetSizeAndAlignment(type, &size, 0);
NSGetSizeAndAlignment(type, &size, NULL);
if (sel == 0)
{
[val getValue: ((char *)self + offset)];

View file

@ -113,7 +113,7 @@
format: @"Cannot copy value into NULL buffer"];
/* NOT REACHED */
}
NSGetSizeAndAlignment([self objCType], 0, &size);
NSGetSizeAndAlignment([self objCType], &size, NULL);
memcpy(value, &data, size);
}

View file

@ -73,7 +73,7 @@ typeSize(const char* type)
{
NSUInteger size;
NSGetSizeAndAlignment(type, &size, 0);
NSGetSizeAndAlignment(type, &size, NULL);
return (int)size;
}
case _C_VOID: return 0;
@ -265,7 +265,7 @@ typeSize(const char* type)
size = strlen(objctype)+1;
[coder encodeValueOfObjCType: @encode(unsigned) at: &size];
[coder encodeArrayOfObjCType: @encode(signed char) count: size at: objctype];
NSGetSizeAndAlignment(objctype, 0, &tsize);
NSGetSizeAndAlignment(objctype, &tsize, NULL);
size = tsize;
d = [NSMutableData new];
[d serializeDataAt: data ofObjCType: objctype context: nil];

View file

@ -427,7 +427,7 @@ static NSMapTable *globalClassMap = 0;
format: @"[%@ +%@]: count mismatch for %@",
NSStringFromClass([self class]), NSStringFromSelector(_cmd), o];
}
NSGetSizeAndAlignment(type, 0, &size);
NSGetSizeAndAlignment(type, &size, NULL);
memcpy(buf, [o bytes], expected * size);
}

View file

@ -611,7 +611,7 @@ static NSUInteger urlAlign;
{
if (clientsLock == nil)
{
NSGetSizeAndAlignment(@encode(parsedURL), &urlAlign, 0);
NSGetSizeAndAlignment(@encode(parsedURL), NULL, &urlAlign);
clientsLock = [NSLock new];
[[NSObject leakAt: &clientsLock] release];
ASSIGN(fileCharSet, [NSCharacterSet characterSetWithCharactersInString:

View file

@ -440,7 +440,7 @@ static NSLock *placeholderLock;
return;
}
NSGetSizeAndAlignment(objctype, 0, &tsize);
NSGetSizeAndAlignment(objctype, &tsize, NULL);
data = (void *)NSZoneMalloc([self zone], tsize);
[self getValue: (void*)data];
d = [NSMutableData new];
@ -583,7 +583,7 @@ static NSLock *placeholderLock;
* For performance, decode small values directly onto the stack,
* For larger values we allocate and deallocate heap space.
*/
NSGetSizeAndAlignment(objctype, 0, &tsize);
NSGetSizeAndAlignment(objctype, &tsize, NULL);
if (tsize <= 64)
{
unsigned char data[tsize];
@ -625,7 +625,7 @@ static NSLock *placeholderLock;
* For performance, decode small values directly onto the stack,
* For larger values we allocate and deallocate heap space.
*/
NSGetSizeAndAlignment(objctype, 0, &tsize);
NSGetSizeAndAlignment(objctype, &tsize, NULL);
if (tsize <= 64)
{
unsigned char data[tsize];

View 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;
}