Discussion:
Toll-free bridging of NSObject?
Glen Low
2004-01-31 08:58:05 UTC
Permalink
According to
http://developer.apple.com/documentation/Cocoa/Conceptual/
CarbonCocoaDoc/cci_chap2/chapter_2_section_5.html#//apple_ref/doc/uid/
20001515/TPXREF144, some Core Foundation (ObjC) and Foundation (C)
types are toll-free bridged i.e. they can be intercast without
conversion.

I know the "root class" of Foundation objects is CFType (or CFTypeRef)
and that of Core Foundation is NSObject (NSObject*). Does this mean
that CFType is toll-free bridged with NSObject? -- or at the very least
can I perform the generic CFType functions like CFRelease, CFRetain on
an NSObject or derivative?


Cheers, Glen Low


---
pixelglow software | simply brilliant stuff
www.pixelglow.com
Chris Kane
2004-02-07 16:30:40 UTC
Permalink
Post by Glen Low
According to
http://developer.apple.com/documentation/Cocoa/Conceptual/
CarbonCocoaDoc/cci_chap2/chapter_2_section_5.html#//apple_ref/doc/uid/
20001515/TPXREF144, some Core Foundation (ObjC) and Foundation (C)
types are toll-free bridged i.e. they can be intercast without
conversion.
I know the "root class" of Foundation objects is CFType (or CFTypeRef)
and that of Core Foundation is NSObject (NSObject*).
Or vice versa.
Post by Glen Low
Does this mean that CFType is toll-free bridged with NSObject? -- or
at the very least can I perform the generic CFType functions like
CFRelease, CFRetain on an NSObject or derivative?
In effect they are toll-free bridged, and you can CFRelease() NSObjects
or -retain CF objects.


Chris Kane
Cocoa Frameworks, Apple
Shaun Wexler
2004-02-07 16:59:54 UTC
Permalink
Post by Chris Kane
In effect they are toll-free bridged, and you can CFRelease()
NSObjects or -retain CF objects.
If I were to replace the IMP of NSObject's retain/release methods to
use inline ref counting, what is the best way to do it? I have a
direct subclass which all my custom classes are based on. I can
swizzle any NSObject methods to use SKWObject IMP's, since it's not
feasible (or possible) to +poseAsClass: NSObject AFAIK. SKWObject
currently has an ivar for the refcount, so I don't have a problem
there. But to attach one to NSObject instances would require it to be
placed ahead of isa, and override allocation methods & functions to
maintain vec alignment, correct? Would it break any Foundation/AppKit
classes, to add an ivar after isa? And how does this affect CFType
objects?
--
Shaun Wexler
MacFOH
http://www.macfoh.com
Chris Kane
2004-02-08 03:41:22 UTC
Permalink
Post by Shaun Wexler
Post by Chris Kane
In effect they are toll-free bridged, and you can CFRelease()
NSObjects or -retain CF objects.
If I were to replace the IMP of NSObject's retain/release methods to
use inline ref counting, what is the best way to do it? I have a
direct subclass which all my custom classes are based on. I can
swizzle any NSObject methods to use SKWObject IMP's, since it's not
feasible (or possible) to +poseAsClass: NSObject AFAIK. SKWObject
currently has an ivar for the refcount, so I don't have a problem
there. But to attach one to NSObject instances would require it to be
placed ahead of isa, and override allocation methods & functions to
maintain vec alignment, correct? Would it break any Foundation/AppKit
classes, to add an ivar after isa? And how does this affect CFType
objects?
There's no way something like that could work and still be practical.
You can't add ivars after the isa. You should just not consider doing
anything like this to NSObject.

One can pose as NSObject, though you can't add ivars to the posing
class, so that is also out. And, you can't expect everything to funnel
up through NSObject's methods (or then, your class) for all classes.

You'd just be causing yourself a mess of mystery bugs to attempt
anything like what you're suggesting.


Chris Kane
Cocoa Frameworks, Apple
Jared McIntyre
2004-02-08 23:32:37 UTC
Permalink
I'm working on url handling code, and I can't get
the program not to crash when loading the scrpt
suite. The suite looks like this:

{
Name = "CotVNC";
AppleEventCode = "çVnÇ";

Commands = {
"GetURL" = {
CommandClass = "URLHandlerCommand";
AppleEventCode = "GURL";
AppleEventClassCode = "GURL";
};
};
}

The stack looks like this:

#0 0x901b5c20 in __CFCopyFormattingDescription
#1 0x9019eef8 in _CFStringAppendFormatAndArgumentsAux
#2 0x901a4c54 in _CFStringCreateWithFormatAndArgumentsAux
#3 0x90a5af38 in NSLogv
#4 0x90a75288 in NSLog
#5 0x90ae5c44 in _NSMacOSTypeFromString
#6 0x90ae2294 in -[NSScriptSuiteRegistry
loadSuiteWithDictionary:fromBundle:]
#7 0x90ae2ae4 in -[NSScriptSuiteRegistry loadSuitesFromBundle:]
#8 0x90ae13e0 in -[NSScriptSuiteRegistry _loadSuitesForLoadedBundles]
#9 0x90ae20cc in -[NSScriptSuiteRegistry init]
#10 0x90ae0fb8 in +[NSScriptSuiteRegistry sharedScriptSuiteRegistry]
#11 0x90a7c090 in +[NSScriptSuiteRegistry _loadScriptSuites]
#12 0x909f794c in _nsnote_callback
#13 0x901aa7d0 in __CFXNotificationPost
#14 0x901af1e0 in _CFXNotificationPostNotification
#15 0x909f5798 in -[NSNotificationCenter
postNotificationName:object:userInfo:]
#16 0x90a7bf24 in _NSAppleEventManagerPreDispatchHandler
#17 0x92ccea68 in AEPutParamDesc
#18 0x92cd18b0 in AECreateList
#19 0x92cceca8 in aeProcessAppleEvent
#20 0x928c4afc in AEProcessAppleEvent
#21 0x92dd2f84 in _DPSNextEvent
#22 0x92de9728 in -[NSApplication
nextEventMatchingMask:untilDate:inMode:dequeue:]
#23 0x92dfda90 in -[NSApplication run]
#24 0x92eb9e98 in NSApplicationMain
#25 0x0002ede8 in main at VNCViewer_main.m:17

The code isn't making it to the
performDefaultImplementation handler and the
stack makes it appear that it is still loading
the script definition file. Anyone have any idea
what could be causing such an issue? The demo
app I have works fine.
--
Jared McIntyre
Deep Fried Software
Deep Fried LLC
Owner/Engineer
http://www.dfsoftware.com
***@dfsoftware.com
Matt Watson
2004-02-08 23:58:37 UTC
Permalink
Post by Jared McIntyre
AppleEventCode = "çVnÇ";
There seems to be a bug in the code that tries to convert strings to
OSTypes when non-ASCII chars are used.

Try using only printable ASCII characters here...

matt.
Jared McIntyre
2004-02-09 00:54:21 UTC
Permalink
Post by Matt Watson
Post by Jared McIntyre
AppleEventCode = "çVnÇ";
There seems to be a bug in the code that tries
to convert strings to OSTypes when non-ASCII
chars are used.
Try using only printable ASCII characters here...
matt.
That did it, thanks.

Jared

Loading...