Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problem casting CFMessagePortRef->CFMessagePortContext->info back to an object



Hi

I'm trying to write a Cocoa wrapper class for CFMessagePortRef and have run into a problem with the CFMessagePortRef- >CFMessagePortContext->info field. What I'm doing is storing the "self" variable of the wrapper class in the CFMessagePortContext- >info field and trying to cast it inside the "CFMessagePortCallBack" function so I can use it's methods.

I know about NSMessagePort but it's not "toll free bridged" and won't work with the pure Carbon App I'm writing an extension for.

Back to the problem, some parts of the self object seem survive the cast but others are corrupted and execution drops into the debugger when I try to use any methods, even "respondsToSelector" so it seems like it's no longer an object.

Here's the definition of the CFMessagePortContext struct:
struct CFMessagePortContext {
   CFIndex version;
   void *info;
   CFAllocatorRetainCallBack retain;
   CFAllocatorReleaseCallBack release;
   CFAllocatorCopyDescriptionCallBack copyDescription;
};


// Here's where I put "self" into the CFMessagePortContext : context.version = 0; context.info = self;


// Here's where I create a local CFMessagePort: receivingPort = CFMessagePortCreateLocal ( kCFAllocatorDefault, (CFStringRef) localName, (CFMessagePortCallBack) KCFCocoaMessagePortHandleMessage, &context, NULL );

// Here's the "CFMessagePortCallBack" function:
NSData* KCFCocoaMessagePortHandleMessage(CFMessagePortRef inPort, SInt32 inMessageID, CFDataRef inData, void *inInfo)
{
CFMessagePortContext *context = (CFMessagePortContext *) inInfo;
KCFCocoaMessagePort *messagePort = (KCFCocoaMessagePort *) &context- >info;


// Note: I also the following this but "messagePort" was even more corrupted
// KCFCocoaMessagePort *messagePort = (KCFCocoaMessagePort *) &context->info;

// Check to see if messagePort responds the "broadcastMessageToListeners:" method and that's all she wrote...
if ([messagePort respondsToSelector:@selector (broadcastMessageToListeners:)]) <- jumps into the debugger on this line
[messagePort broadcastMessageToListeners: (NSData *) inData];

return nil;
}


// Here's the call stack in the debugger
#0 0x909bf120 in objc_msgSend
#1 0x00222aa8 in KCFCocoaMessagePortHandleMessage at KCFCocoaMessagePort.m:188
#2 0x907a4590 in __CFMessagePortPerform
#3 0x9076acd0 in __CFRunLoopDoSource1
#4 0x9075d3e8 in __CFRunLoopRun
#5 0x9075ca18 in CFRunLoopRunSpecific
#6 0x9318f1e0 in RunCurrentEventLoopInMode
#7 0x9318e7ec in ReceiveNextEventCommon
#8 0x9318e6e0 in BlockUntilNextEventMatchingListInMode
#9 0x9368d104 in _DPSNextEvent


// And finally, here's the assembly view in the debugger
0x909bf108 <+0008> cmplwi cr1,r11,61440
0x909bf10c <+0012> beq- 0x909bf160 <objc_msgSend+96>
0x909bf110 <+0016> lwz r12,0(r3)
0x909bf114 <+0020> beqlr cr1
0x909bf118 <+0024> lwz r2,32(r12)
0x909bf11c <+0028> stw r9,48(r1)
0x909bf120 <+0032> lwz r11,0(r2) <- This is the line the debugger highlights
0x909bf124 <+0036> addi r0,r2,8
0x909bf128 <+0040> rlwinm r11,r11,2,0,29
0x909bf12c <+0044> and r9,r4,r11
0x909bf130 <+0048> lwzx r2,r9,r0
0x909bf134 <+0052> addi r9,r9,4
0x909bf138 <+0056> cmplwi r2,0



Anyone see where I'm going wrong here?

Thanks in advance,

Ken

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Carbon-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/carbon-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.