[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 19:15:27 +0000 |
On 13 Mar 2010, at 18:58, Stef Bidi wrote:
> I really was missing that point, most because I did not know that was the
> case! Let me make sure I got this right, are all non-toll-free bridged CF
> classes also a __NSCFType? If that's the case, it works for me.
Yup, there are two issues. All CoreFoundation types are (things that are not
but look and behave exactly like) Objective-C objects. They all inherit from
__NSCFType. A more interesting case is this:
NSLog(@"%@", [[(id)s class] superclass]);
Which produces...
2010-03-13 19:01:09.460 a.out[44586:903] NSObject
So, __NSCFType is a class, which inherits from NSObject. No, coincidentally,
one of the examples from my upcoming book is a program that dumps the ivar and
instance method names from all of the classes in the system. What does this
tell us:
NSCFType
Ivars:
NSCFType
Methods:
finalize
retainCount
release
retain
hash
isEqual:
These are largely irrelevant to us. CoreFoundation has to exist when
Foundation does not, so it uses its own reference counting mechanism. CoreBase
assumes the existence of base, so does not. This means that we don't really
need to bother with the __CFType class. We can make CF classes inherit
directly from NSObject.
For things that are not toll-free bridged, I suggest that you write them as
Objective-C classes and use make_c_interface to dump the CFType version
automatically.
David
> I guess that patch is invalid.
>
> Stefan
>
> On Sat, Mar 13, 2010 at 12:22 PM, David Chisnall <address@hidden> wrote:
> 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
> _______________________________________________
> Gnustep-dev mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/gnustep-dev
-- Sent from my IBM 1620