[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Changes in base
From: |
David Chisnall |
Subject: |
Re: Changes in base |
Date: |
Sat, 13 Mar 2010 18:22:45 +0000 |
Hi Stef,
I believe you are missing something important here. Although some
CoreFoundation types are not toll-free bridged with specific Objective-C
classes, they are all __attribute__((NSObject)) and all implement (at least
some of) the NSObject protocol. You can send -retain / -release to all of
them, including things like CFSocket that are not toll-free bridged:
$ cat cf.m
#import <Cocoa/Cocoa.h>
#import <CoreFoundation/CoreFoundation.h>
int main(void)
{
CFSocketRef s = CFSocketCreate(NULL, 0, 0, 0, 0, 0, 0);
printf("%d\n", (int)CFGetRetainCount(s));
[(id)s retain];
printf("%d\n", (int)CFGetRetainCount(s));
printf("%d\n", (int)[(id)s retainCount]);
NSLog(@"%@", s);
NSLog(@"%@", [(id)s class]);
return 0;
}
Liberator:tmp theraven$ gcc -framework Cocoa cf.m && ./a.out
2
3
3
2010-03-13 18:20:07.933 a.out[44021:903] <CFSocket 0x100111290
[0x7fff704fbf20]>{valid = Yes, type = 1, socket = 3, socket set count = 0,
callback types = 0x0, callout = ??? (0x0), source = 0x0,
run loops = <CFArray 0x100111360 [0x7fff704fbf20]>{type = mutable-small,
count = 0, values = ()},
context = <CFSocket context 0x0>}
2010-03-13 18:20:07.978 a.out[44021:903] __NSCFType
As you can see, the object responds to -retainCount, -retain, -description and
-class. It will also respond to things like -hash - you can store all
CoreFoundation types in Objective-C collection classes (they are also Core
Foundation collection types) transparently, for example.
David
On 13 Mar 2010, at 18:07, Stef Bidi wrote:
> I'm working on implementing the CFRuntime in corebase and would like to use
> as much out of base as possible.
>
> This first change is trivial, really. Some CF objects aren't toll-free
> bridged, so calling methods on them is a big no-no. This patch just works
> around the only instance I could find of a method called on anObject in the
> reference count functions in NSObject.m.
>
> I have a few more changes coming as I get to them. I'll need to add a (void
> *) at the beginning and one at end of NSZone, which I was going to propose
> after the next release but figured it'd be easier to just do it now, rather
> than later.
>
> Stefan
> <avoid_retainCount_method.diff>_______________________________________________
> Gnustep-dev mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/gnustep-dev
-- Sent from my Difference Engine
- Changes in base, Stef Bidi, 2010/03/13
- Re: Changes in base,
David Chisnall <=