mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Use type encoding helpers to detect known structs in KVC
This commit is contained in:
parent
71beb1ae5e
commit
2ebbb02918
3 changed files with 33 additions and 21 deletions
|
@ -48,6 +48,7 @@
|
|||
|
||||
#import "../GSPrivate.h"
|
||||
#import "../GSPThread.h"
|
||||
#import "../typeEncodingHelper.h"
|
||||
|
||||
#include <objc/Protocol.h>
|
||||
|
||||
|
@ -1317,7 +1318,8 @@ GSObjCGetVal(NSObject *self, const char *key, SEL sel,
|
|||
break;
|
||||
|
||||
case _C_STRUCT_B:
|
||||
if (strncmp(@encode(NSPoint), type, strlen(@encode(NSPoint))) == 0)
|
||||
{
|
||||
if (IS_CGPOINT_ENCODING(type))
|
||||
{
|
||||
NSPoint v;
|
||||
|
||||
|
@ -1334,7 +1336,7 @@ GSObjCGetVal(NSObject *self, const char *key, SEL sel,
|
|||
}
|
||||
val = [NSValue valueWithPoint: v];
|
||||
}
|
||||
else if (strncmp(@encode(NSRange), type, strlen(@encode(NSRange))) == 0)
|
||||
else if (IS_NSRANGE_ENCODING(type))
|
||||
{
|
||||
NSRange v;
|
||||
|
||||
|
@ -1351,7 +1353,7 @@ GSObjCGetVal(NSObject *self, const char *key, SEL sel,
|
|||
}
|
||||
val = [NSValue valueWithRange: v];
|
||||
}
|
||||
else if (strncmp(@encode(NSRect), type, strlen(@encode(NSRect))) == 0)
|
||||
else if (IS_CGRECT_ENCODING(type))
|
||||
{
|
||||
NSRect v;
|
||||
|
||||
|
@ -1368,7 +1370,7 @@ GSObjCGetVal(NSObject *self, const char *key, SEL sel,
|
|||
}
|
||||
val = [NSValue valueWithRect: v];
|
||||
}
|
||||
else if (strncmp(@encode(NSSize), type, strlen(@encode(NSSize))) == 0)
|
||||
else if (IS_CGSIZE_ENCODING(type))
|
||||
{
|
||||
NSSize v;
|
||||
|
||||
|
@ -1410,6 +1412,7 @@ GSObjCGetVal(NSObject *self, const char *key, SEL sel,
|
|||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
#ifdef __GNUSTEP_RUNTIME__
|
||||
|
|
|
@ -22,14 +22,13 @@
|
|||
Boston, MA 02110 USA.
|
||||
*/
|
||||
|
||||
#include "Foundation/NSMethodSignature.h"
|
||||
#include "Foundation/NSZone.h"
|
||||
#include "GNUstepBase/GSObjCRuntime.h"
|
||||
#import <objc/runtime.h>
|
||||
#import <objc/slot.h>
|
||||
|
||||
#import "common.h" // for likely and unlikely
|
||||
#import "typeEncodingHelper.h"
|
||||
#import "Foundation/NSKeyValueCoding.h"
|
||||
#import "Foundation/NSMethodSignature.h"
|
||||
#import "Foundation/NSValue.h"
|
||||
#import "Foundation/NSInvocation.h"
|
||||
#import "NSKeyValueCoding+Caching.h"
|
||||
|
@ -282,25 +281,22 @@ _getBoxedBlockForIVar(NSString *key, Ivar ivar)
|
|||
return slot;
|
||||
}
|
||||
case '{': {
|
||||
if (strncmp(@encode(NSRange), encoding, strlen(@encode(NSRange))) == 0)
|
||||
if (IS_NSRANGE_ENCODING(encoding))
|
||||
{
|
||||
slot.get = _getBoxedNSRangeForIvar;
|
||||
return slot;
|
||||
}
|
||||
else if (strncmp(@encode(NSRect), encoding, strlen(@encode(NSRect)))
|
||||
== 0)
|
||||
else if (IS_CGRECT_ENCODING(encoding))
|
||||
{
|
||||
slot.get = _getBoxedNSRectForIvar;
|
||||
return slot;
|
||||
}
|
||||
else if (strncmp(@encode(NSPoint), encoding, strlen(@encode(NSPoint)))
|
||||
== 0)
|
||||
else if (IS_CGPOINT_ENCODING(encoding))
|
||||
{
|
||||
slot.get = _getBoxedNSPointForIvar;
|
||||
return slot;
|
||||
}
|
||||
else if (strncmp(@encode(NSSize), encoding, strlen(@encode(NSSize)))
|
||||
== 0)
|
||||
else if (IS_CGSIZE_ENCODING(encoding))
|
||||
{
|
||||
slot.get = _getBoxedNSSizeForIvar;
|
||||
return slot;
|
||||
|
@ -396,25 +392,22 @@ _getBoxedBlockForMethod(NSString *key, Method method, SEL sel, uint64_t version)
|
|||
return slot;
|
||||
}
|
||||
case '{': {
|
||||
if (strncmp(@encode(NSRange), encoding, strlen(@encode(NSRange))) == 0)
|
||||
if (IS_NSRANGE_ENCODING(encoding))
|
||||
{
|
||||
slot.get = _getBoxedNSRange;
|
||||
return slot;
|
||||
}
|
||||
else if (strncmp(@encode(NSRect), encoding, strlen(@encode(NSRect)))
|
||||
== 0)
|
||||
else if (IS_CGRECT_ENCODING(encoding))
|
||||
{
|
||||
slot.get = _getBoxedNSRect;
|
||||
return slot;
|
||||
}
|
||||
else if (strncmp(@encode(NSPoint), encoding, strlen(@encode(NSPoint)))
|
||||
== 0)
|
||||
else if (IS_CGPOINT_ENCODING(encoding))
|
||||
{
|
||||
slot.get = _getBoxedNSPoint;
|
||||
return slot;
|
||||
}
|
||||
else if (strncmp(@encode(NSSize), encoding, strlen(@encode(NSSize)))
|
||||
== 0)
|
||||
else if (IS_CGSIZE_ENCODING(encoding))
|
||||
{
|
||||
slot.get = _getBoxedNSSize;
|
||||
return slot;
|
||||
|
|
16
Tests/base/KVC/type_encoding.m
Normal file
16
Tests/base/KVC/type_encoding.m
Normal file
|
@ -0,0 +1,16 @@
|
|||
#import <Foundation/NSGeometry.h>
|
||||
|
||||
#import "Testing.h"
|
||||
#import "../../../Source/typeEncodingHelper.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
START_SET("Known Struct Type Encodings")
|
||||
|
||||
PASS(strncmp(@encode(NSPoint), CGPOINT_ENCODING_PREFIX, strlen(CGPOINT_ENCODING_PREFIX)) == 0, "CGPoint encoding");
|
||||
PASS(strncmp(@encode(NSSize), CGSIZE_ENCODING_PREFIX, strlen(CGSIZE_ENCODING_PREFIX)) == 0, "CGSize encoding");
|
||||
PASS(strncmp(@encode(NSRect), CGRECT_ENCODING_PREFIX, strlen(CGRECT_ENCODING_PREFIX)) == 0, "CGRect encoding");
|
||||
PASS(strncmp(@encode(NSRange), NSRANGE_ENCODING_PREFIX, strlen(NSRANGE_ENCODING_PREFIX)) == 0, "NSRange encoding");
|
||||
|
||||
END_SET("Known Struct Type Encodings")
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue