Re: Attributed Strings in Distributed Objects
Re: Attributed Strings in Distributed Objects
- Subject: Re: Attributed Strings in Distributed Objects
- From: "Gerriet M. Denkmann" <email@hidden>
- Date: Wed, 5 Sep 2007 16:33:50 +0200
On 5 Sep 2007, at 15:34, Gerriet M. Denkmann wrote:
On 5 Sep 2007, at 13:05, Alastair Houghton wrote:
On 5 Sep 2007, at 08:23, Gerriet M. Denkmann wrote:
I have an object, which responds to this message:
- (NSAttributedString *)dummyWithStyle: (BOOL)withStyle ;
{
NSString *s = withStyle ? @"with Style" : @"without Style";
NSMutableAttributedString *a = [ [ [ NSMutableAttributedString
alloc ] initWithString: s ] autorelease ];
if ( withStyle )
{
NSParagraphStyle *p = [ NSParagraphStyle defaultParagraphStyle ];
unsigned int length = [ a length];
NSRange all = NSMakeRange( 0, length );
[ a addAttribute: NSParagraphStyleAttributeName value: p
range: all ];
};
NSLog(@"%s will return %@", __FUNCTION__, a );
return a;
}
If the flag "withStyle" is NO, or if sender and reveiver live in
the same thread (i.e. [myObject isProxy ] = 0) then all is fine.
But when I do: [proxyForMyObject dummyWithStyle: YES ] (with
[proxyForMyObject isProxy] = 1) then the program will hang after
writing the log message immediately before the return.
I think (though I could be wrong) that some object is being
proxied in the main thread (possibly the attributed string itself,
though I would have thought that these were always copied... it
could be something to do with the attribute structure, or maybe
your NSParagraphStyle that's causing the problem).
The main thread has a method doButton: which contains:
NSLog(@"%s will do: [ %s dummyWithStyle: %s ] in main thread %p",
__FUNCTION__, [o isProxy] ? "proxy" : "real", style ? "YES" : "NO",
[NSThread currentThread]);
NSAttributedString *a = [o dummyWithStyle: style] ;
NSLog(@"%s got %s AttributedString = \"%@\"", __FUNCTION__, [a
isProxy] ? "proxy" : "real", [a string]);
This is the output:
... -[SWDocument doButton:] will do: [ proxy dummyWithStyle: NO ]
in main thread 0x306cf0
... -[SXLeaf dummyWithStyle:] will return "without Style" in thread
0x3a0300
... -[SWDocument doButton:] got real AttributedString = "without
Style"
no problem so far. But now with NSParagraphStyle added:
... -[SWDocument doButton:] will do: [ proxy dummyWithStyle: YES ]
in main thread 0x306cf0
... -[SXLeaf dummyWithStyle:] will return "with Style" in thread
0x3a0300
Now the app is not crashing at all, it just hangs.
When I run it under the debugger and hit the "Pause" button, then I
will see the stack as quoted.
Anyway, as a result, your thread needs to run a run loop in order
to process messages from the main thread. I'm guessing that your
thread has terminated or is doing something other than running a
run loop.
Well, the main thread obviously has a run loop; and the other
thread also has one. I followed the example in "Communicating With
Distributed Objects" in "Multithreading Programming Topics".
One possible way around this would be to subclass e.g.
NSParagraphStyle (or whatever is causing the problem) and override
-replacementObjectForPortCoder: to return self (assuming that it
doesn't already). As I say, I think NSAttributedStrings are
copied rather than proxied, and your backtrace seems to support
that, so I don't think it's the string itself that's the issue
(and if it was, you could just use "bycopy" in a declaration
somewhere).
Well, maybe it's NSParagraphStyle, maybe it's any kind of text
attachment, maybe any deep structure (what about an NSArray
containing objects, which again contain arrays, which again... -
how deep a copy is NSConnection prepared to make?) - I am just too
tired to find out.
Well - I did try after all:
It is not NSParagraphStyle - it seems to be any kind of attachment (I
tried an NSTextAttachment).
And NSArrays are returned as real arrays, containing the same stuff
(not proxies to the things in the original array) - it is a shallow
copy.
So NSAttributed strings seem to be just broken with DO.
Kind regards,
Gerriet.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden