Leopard problem: can't pass NSPredicate in a distributed object message

  • Hi, all,
    I'm updating an application to Leopard, and some existing functionality got
    broken:

    I use distributed objects to communicate between my main thread and a
    background thread that manages Spotlight metadata queries; the method used
    to initiate a query is:

    - (void)initiateQueryForID:(NSString *)recID
    withPredicate:(NSPredicate*)pred andScopes:(
    NSArray *)scopes;

    This worked fine under Tiger, but the background thread hangs when it tries
    to use the NSPredicate value.  Inspecting the object from within the called
    routine isn't telling me much.  It appears to be an NSProxy, which I expect,
    but I can't print the description or the className of the object.  The
    member variable "_remoteClass" of the proxy is nil, which doesn't feel
    right...

    I've tried changing the protocol and method declarations to:

    - (void)initiateQueryForID:(bycopy NSString *)recID withPredicate:(bycopy
    NSPredicate *)pred andScopes:(bycopy NSArray *)scopes;

    Oddly, I still seem to be receiving a broken proxy object in the called
    routine.

    Again, these problems are new to Leopard.

    TIA,

    Doug Knowles
  • Hi, David,
    I tried permutations of your suggestion; when I used "bycopy", I got an
    error message I hadn't seen before:

    *NSPredicates and NSExpressions cannot be encoded by non-keyed archivers*

    This prompted me to try manually archiving the NSPredicate with an
    NSKeyedArchiver for bycopy, and (of course) unarchiving it on the other side
    of the call, and I'm back in business again.  I'd rather not have to jump
    through this hoop, but it's good to get past this blockage.

    Thanks for the suggestion; besides leading me to the right answer, it
    expanded my Cocoa knowledge, which is always a good thing!

    Best regard,
    Doug Knowles

    On 10/28/07, David Spooner <dave...> wrote:
    >
    > Doug,
    >
    > As a workaround, you might try adding the following in a category on
    > NSPredicate...
    >
    > - (id) replacementObjectForPortCoder:(NSPortCoder *)coder
    > { return [coder isBycopy] == NO ? [NSDistantObject
    > proxyWithLocal:self connection:[coder connection]] : self; }
    >
    > dave
    >
    > On 28-Oct-07, at 12:23 PM, Doug Knowles wrote:
    >
    >> Hi, all,
    >> I'm updating an application to Leopard, and some existing
    >> functionality got
    >> broken:
    >>
    >> I use distributed objects to communicate between my main thread and a
    >> background thread that manages Spotlight metadata queries; the
    >> method used
    >> to initiate a query is:
    >>
    >> - (void)initiateQueryForID:(NSString *)recID
    >> withPredicate:(NSPredicate*)pred andScopes:(
    >> NSArray *)scopes;
    >>
    >> This worked fine under Tiger, but the background thread hangs when
    >> it tries
    >> to use the NSPredicate value.  Inspecting the object from within the
    >> called
    >> routine isn't telling me much.  It appears to be an NSProxy, which I
    >> expect,
    >> but I can't print the description or the className of the object.  The
    >> member variable "_remoteClass" of the proxy is nil, which doesn't feel
    >> right...
    >>
    >> I've tried changing the protocol and method declarations to:
    >>
    >> - (void)initiateQueryForID:(bycopy NSString *)recID withPredicate:
    >> (bycopy
    >> NSPredicate *)pred andScopes:(bycopy NSArray *)scopes;
    >>
    >> Oddly, I still seem to be receiving a broken proxy object in the
    >> called
    >> routine.
    >>
    >> Again, these problems are new to Leopard.
    >>
    >> TIA,
    >>
    >> Doug Knowles
    >> _______________________________________________
    >
    >
  • On Oct 28, 2007, at 7:57 PM, Doug Knowles wrote:

    > Hi, David,
    > I tried permutations of your suggestion; when I used "bycopy", I got
    > an
    > error message I hadn't seen before:
    >
    > *NSPredicates and NSExpressions cannot be encoded by non-keyed
    > archivers*
    >
    > This prompted me to try manually archiving the NSPredicate with an
    > NSKeyedArchiver for bycopy, and (of course) unarchiving it on the
    > other side
    > of the call, and I'm back in business again.  I'd rather not have to
    > jump
    > through this hoop, but it's good to get past this blockage.

    You can avoid the proxy-fication by casting the arguments to
    "uintptr_t" types:

    - (void)initiateQueryForID:(uintptr_t)recID withPredicate:
    (uintptr_t)pred andScopes:(uintptr_t)scopes;

    Note that you're working with the same object in both threads now, so
    be careful about all those fun multithreading issues.

    -D
previous month october 2007 next month
MTWTFSS
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Go to today