crude KVO setter for structs

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@35324 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2012-07-27 16:48:49 +00:00
parent 27a33dbedb
commit e6c15aef54
8 changed files with 156 additions and 45 deletions

View file

@ -44,6 +44,10 @@
#import "GNUstepBase/NSObject+GNUstepBase.h"
#import "GSInvocation.h"
#if defined(USE_LIBFFI)
#import "cifframe.h"
#endif
/*
* IMPLEMENTATION NOTES
*
@ -385,6 +389,38 @@ replacementForClass(Class c)
return r;
}
#if defined(USE_LIBFFI)
static void
cifframe_callback(ffi_cif *cif, void *retp, void **args, void *user)
{
id obj;
SEL sel;
NSString *key;
Class c;
void (*imp)(id,SEL,void*);
obj = *(id *)args[0];
sel = *(SEL *)args[1];
c = [obj class];
imp = (void (*)(id,SEL,void*))[c instanceMethodForSelector: sel];
key = newKey(sel);
if ([c automaticallyNotifiesObserversForKey: key] == YES)
{
// pre setting code here
[obj willChangeValueForKey: key];
ffi_call(cif, imp, retp, args);
// post setting code here
[obj didChangeValueForKey: key];
}
else
{
ffi_call(cif, imp, retp, args);
}
RELEASE(key);
}
#endif
@implementation GSKVOReplacement
- (void) dealloc
{
@ -557,7 +593,15 @@ replacementForClass(Class c)
}
else
{
#if defined(USE_LIBFFI)
GSCodeBuffer *b;
b = cifframe_closure(sig, cifframe_callback);
[b retain];
imp = [b executable];
#else
imp = 0;
#endif
}
break;
default: