2001-12-17 14:31:42 +00:00
|
|
|
/** Implementation of GSFFIInvocation for GNUStep
|
2000-12-08 19:06:00 +00:00
|
|
|
Copyright (C) 2000 Free Software Foundation, Inc.
|
2005-02-22 11:22:44 +00:00
|
|
|
|
2000-12-08 19:06:00 +00:00
|
|
|
Written: Adam Fedor <fedor@gnu.org>
|
2002-04-18 16:02:12 +00:00
|
|
|
Date: Apr 2002
|
2005-02-22 11:22:44 +00:00
|
|
|
|
2000-12-08 19:06:00 +00:00
|
|
|
This file is part of the GNUstep Base Library.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
2007-09-14 11:36:11 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
2000-12-08 19:06:00 +00:00
|
|
|
License as published by the Free Software Foundation; either
|
2008-06-08 10:38:33 +00:00
|
|
|
version 2 of the License, or (at your option) any later version.
|
2005-02-22 11:22:44 +00:00
|
|
|
|
2000-12-08 19:06:00 +00:00
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2019-12-09 23:36:00 +00:00
|
|
|
Lesser General Public License for more details.
|
2005-02-22 11:22:44 +00:00
|
|
|
|
2007-09-14 11:36:11 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2000-12-08 19:06:00 +00:00
|
|
|
License along with this library; if not, write to the Free
|
2024-11-07 13:37:59 +00:00
|
|
|
Software Foundation, Inc., 31 Milk Street #960789 Boston, MA 02196 USA.
|
2005-02-22 11:22:44 +00:00
|
|
|
*/
|
2010-02-14 10:48:10 +00:00
|
|
|
|
2010-02-19 08:12:46 +00:00
|
|
|
#import "common.h"
|
2011-05-19 08:19:24 +00:00
|
|
|
|
|
|
|
#if !defined (__GNU_LIBOBJC__)
|
|
|
|
# include <objc/encoding.h>
|
|
|
|
#endif
|
|
|
|
|
2010-02-24 10:23:47 +00:00
|
|
|
#define EXPOSE_NSInvocation_IVARS 1
|
2007-11-29 20:53:26 +00:00
|
|
|
#import "Foundation/NSException.h"
|
|
|
|
#import "Foundation/NSCoder.h"
|
|
|
|
#import "Foundation/NSDistantObject.h"
|
|
|
|
#import "Foundation/NSData.h"
|
|
|
|
#import "GSInvocation.h"
|
2021-07-28 14:17:47 +00:00
|
|
|
#import "GSPThread.h"
|
2010-02-22 10:13:20 +00:00
|
|
|
#import "GNUstepBase/GSObjCRuntime.h"
|
2007-11-29 20:53:26 +00:00
|
|
|
#import "cifframe.h"
|
2008-06-28 05:13:47 +00:00
|
|
|
#import "GSPrivate.h"
|
2010-12-23 02:23:05 +00:00
|
|
|
|
2010-07-16 18:00:45 +00:00
|
|
|
#ifdef __GNUSTEP_RUNTIME__
|
|
|
|
#include <objc/hooks.h>
|
|
|
|
#endif
|
2008-06-28 05:13:47 +00:00
|
|
|
|
2010-12-23 02:23:05 +00:00
|
|
|
#ifdef __GNU_LIBOBJC__
|
|
|
|
#include <objc/message.h>
|
|
|
|
#endif
|
|
|
|
|
2014-01-23 09:36:37 +00:00
|
|
|
#ifndef GS_STATIC_INLINE
|
|
|
|
#define GS_STATIC_INLINE static inline
|
2002-04-18 16:02:12 +00:00
|
|
|
#endif
|
2000-12-08 19:06:00 +00:00
|
|
|
|
2002-04-18 16:02:12 +00:00
|
|
|
/* Function that implements the actual forwarding */
|
|
|
|
typedef void (*ffi_closure_fun) (ffi_cif*,void*,void**,void*);
|
|
|
|
|
2003-03-23 07:06:27 +00:00
|
|
|
typedef void (*f_fun) ();
|
|
|
|
|
2006-10-16 09:30:18 +00:00
|
|
|
static void GSFFIInvocationCallback(ffi_cif*, void*, void **, void*);
|
2002-04-18 16:02:12 +00:00
|
|
|
|
2011-02-22 13:34:49 +00:00
|
|
|
/* This routine should return a typed selector corresponding to the
|
|
|
|
name of the specified selector. If there is only one type, then we
|
|
|
|
can safely return that typed selector. If not, then we can not be
|
|
|
|
certain which one is expected, and to prevent a crash if we return
|
|
|
|
the wrong type, we return NULL.
|
|
|
|
|
|
|
|
Older runtimes do not have facilities in the API to check for
|
|
|
|
conflicting types, hence would return a random selector in that
|
|
|
|
case. */
|
2014-01-23 09:36:37 +00:00
|
|
|
GS_STATIC_INLINE SEL
|
2011-02-21 11:05:33 +00:00
|
|
|
gs_find_best_typed_sel (SEL sel)
|
2011-02-22 13:34:49 +00:00
|
|
|
#ifdef __GNUSTEP_RUNTIME__
|
2011-02-21 11:05:33 +00:00
|
|
|
{
|
|
|
|
const char *selName = sel_getName(sel);
|
|
|
|
const char *types;
|
2011-02-22 13:34:49 +00:00
|
|
|
|
|
|
|
/* If there is not exactly one typed selector with this name
|
|
|
|
* registered with the runtime, then give up - we can't safely use
|
|
|
|
* this function. */
|
|
|
|
if (1 != sel_copyTypes_np (selName, NULL, 0))
|
|
|
|
return (SEL)0;
|
|
|
|
|
|
|
|
sel_copyTypes_np (selName, &types, 1);
|
2011-02-27 23:34:57 +00:00
|
|
|
return GSSelectorFromNameAndTypes(selName, types);
|
2011-02-22 13:34:49 +00:00
|
|
|
}
|
|
|
|
#elif defined (__GNU_LIBOBJC__)
|
|
|
|
{
|
2011-03-18 06:32:47 +00:00
|
|
|
/* The sel_getTypedSelector() function returns a typed selector if there
|
|
|
|
* is only one, nul if there are zero or more tha one.
|
|
|
|
*/
|
|
|
|
return sel_getTypedSelector(sel_getName(sel));
|
2011-02-21 11:05:33 +00:00
|
|
|
}
|
|
|
|
#elif defined(NeXTRUNTIME)
|
|
|
|
{
|
2011-02-22 13:34:49 +00:00
|
|
|
/* The NeXT runtime does not support typed selectors, so we simply
|
|
|
|
* return 0 here. */
|
2011-02-21 11:05:33 +00:00
|
|
|
return (SEL)0;
|
|
|
|
}
|
|
|
|
#else
|
2002-04-18 16:02:12 +00:00
|
|
|
{
|
2011-02-22 13:34:49 +00:00
|
|
|
/* We can't iterate over the selectors with the same name, but we
|
|
|
|
* can ask the runtime for a typed selector with a certain name.
|
|
|
|
* Usually this works, but it may produce unexpected results
|
|
|
|
* (including a crash) if more than one selector are registered with
|
|
|
|
* the same name but different types. */
|
2011-02-20 07:58:11 +00:00
|
|
|
if (!GSTypesFromSelector(sel))
|
2000-12-08 19:06:00 +00:00
|
|
|
{
|
2010-02-22 10:13:20 +00:00
|
|
|
const char *name = sel_getName(sel);
|
2002-04-18 16:02:12 +00:00
|
|
|
if (name)
|
2011-02-21 11:05:33 +00:00
|
|
|
{
|
|
|
|
SEL tmp_sel = sel_get_any_typed_uid(name);
|
|
|
|
if (GSTypesFromSelector(tmp_sel))
|
|
|
|
return tmp_sel;
|
|
|
|
}
|
2000-12-08 19:06:00 +00:00
|
|
|
}
|
2002-04-18 16:02:12 +00:00
|
|
|
return sel;
|
|
|
|
}
|
2011-02-21 11:05:33 +00:00
|
|
|
#endif
|
2002-04-18 16:02:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
@implementation GSFFIInvocation
|
|
|
|
|
2007-05-11 08:26:59 +00:00
|
|
|
static IMP gs_objc_msg_forward2 (id receiver, SEL sel)
|
2002-04-18 16:02:12 +00:00
|
|
|
{
|
2011-02-21 11:05:33 +00:00
|
|
|
NSMethodSignature *sig = nil;
|
2008-06-29 18:44:41 +00:00
|
|
|
GSCodeBuffer *memory;
|
2011-02-21 11:05:33 +00:00
|
|
|
const char *types;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we're called with a typed selector, then use this when deconstructing
|
|
|
|
* the stack frame. This deviates from OS X behaviour (where there are no
|
|
|
|
* typed selectors), but it always more reliable because the compiler will
|
|
|
|
* set the selector types to represent the layout of the call frame. This
|
|
|
|
* means that the invocation will always deconstruct the call frame
|
|
|
|
* correctly.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (NULL != (types = GSTypesFromSelector(sel)))
|
|
|
|
{
|
|
|
|
sig = [NSMethodSignature signatureWithObjCTypes: types];
|
|
|
|
}
|
2000-12-08 19:06:00 +00:00
|
|
|
|
2010-06-08 16:17:56 +00:00
|
|
|
/* Take care here ... the receiver may be nil (old runtimes) or may be
|
|
|
|
* a proxy which implements a method by forwarding it (so calling the
|
|
|
|
* method might cause recursion). However, any sane proxy ought to at
|
|
|
|
* least implement -methodSignatureForSelector: in such a way that it
|
|
|
|
* won't cause infinite recursion, so we check for that method being
|
|
|
|
* implemented and call it.
|
|
|
|
* NB. object_getClass() and class_respondsToSelector() should both
|
|
|
|
* return NULL when given NULL arguments, so they are safe to use.
|
|
|
|
*/
|
2011-02-21 11:05:33 +00:00
|
|
|
if (nil == sig)
|
2010-06-07 00:28:52 +00:00
|
|
|
{
|
2011-02-22 07:05:36 +00:00
|
|
|
Class c = object_getClass(receiver);
|
|
|
|
|
2011-02-21 11:05:33 +00:00
|
|
|
if (class_respondsToSelector(c, @selector(methodSignatureForSelector:)))
|
|
|
|
{
|
|
|
|
sig = [receiver methodSignatureForSelector: sel];
|
|
|
|
}
|
2011-02-22 07:05:36 +00:00
|
|
|
if (nil == sig
|
|
|
|
&& (NULL != (types = GSTypesFromSelector(gs_find_best_typed_sel(sel)))))
|
|
|
|
{
|
|
|
|
sig = [NSMethodSignature signatureWithObjCTypes: types];
|
|
|
|
}
|
|
|
|
if (nil == sig)
|
|
|
|
{
|
2012-07-09 15:31:12 +00:00
|
|
|
if (nil == receiver)
|
|
|
|
{
|
|
|
|
/* If we have a nil receiver, so the runtime is probably trying
|
|
|
|
* to check for forwarding ... return NULL to let it fall back
|
|
|
|
* on the standard forwarding mechanism.
|
|
|
|
*/
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-02-22 07:05:36 +00:00
|
|
|
[NSException raise: NSInvalidArgumentException
|
|
|
|
format: @"%c[%s %s]: unrecognized selector sent to instance %p",
|
|
|
|
(class_isMetaClass(c) ? '+' : '-'),
|
|
|
|
class_getName(c), sel_getName(sel), receiver];
|
|
|
|
}
|
2003-07-07 05:11:16 +00:00
|
|
|
}
|
2011-02-21 11:05:33 +00:00
|
|
|
|
2012-07-27 16:48:49 +00:00
|
|
|
memory = cifframe_closure(sig, GSFFIInvocationCallback);
|
2002-04-18 16:02:12 +00:00
|
|
|
|
2012-07-27 16:48:49 +00:00
|
|
|
return (IMP)[memory executable];
|
2002-04-18 16:02:12 +00:00
|
|
|
}
|
|
|
|
|
2008-11-17 13:45:32 +00:00
|
|
|
static __attribute__ ((__unused__))
|
|
|
|
IMP gs_objc_msg_forward (SEL sel)
|
2007-05-11 08:26:59 +00:00
|
|
|
{
|
|
|
|
return gs_objc_msg_forward2 (nil, sel);
|
|
|
|
}
|
2009-09-10 20:14:42 +00:00
|
|
|
#ifdef __GNUSTEP_RUNTIME__
|
2021-07-28 14:17:47 +00:00
|
|
|
gs_thread_key_t thread_slot_key;
|
2010-02-22 10:56:07 +00:00
|
|
|
static struct objc_slot *
|
2010-02-22 10:13:20 +00:00
|
|
|
gs_objc_msg_forward3(id receiver, SEL op)
|
2009-09-10 20:14:42 +00:00
|
|
|
{
|
|
|
|
/* The slot has its version set to 0, so it can not be cached. This makes it
|
|
|
|
* safe to free it when the thread exits. */
|
2021-07-28 14:17:47 +00:00
|
|
|
struct objc_slot *slot = GS_THREAD_KEY_GET(thread_slot_key);
|
2010-02-22 10:56:07 +00:00
|
|
|
|
2009-09-10 20:14:42 +00:00
|
|
|
if (NULL == slot)
|
|
|
|
{
|
|
|
|
slot = calloc(sizeof(struct objc_slot), 1);
|
2021-07-28 14:17:47 +00:00
|
|
|
GS_THREAD_KEY_SET(thread_slot_key, slot);
|
2009-09-10 20:14:42 +00:00
|
|
|
}
|
|
|
|
slot->method = gs_objc_msg_forward2(receiver, op);
|
|
|
|
return slot;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Hidden by legacy API define. Declare it locally */
|
2021-08-07 20:15:32 +00:00
|
|
|
GS_IMPORT BOOL class_isMetaClass(Class cls);
|
|
|
|
GS_IMPORT BOOL class_respondsToSelector(Class cls, SEL sel);
|
2009-09-10 20:14:42 +00:00
|
|
|
|
|
|
|
/**
|
2010-12-23 02:23:05 +00:00
|
|
|
* Runtime hook used to provide message redirections with libobjc2.
|
|
|
|
* If lookup fails but this function returns non-nil then the lookup
|
|
|
|
* will be retried with the returned value.
|
2009-09-10 20:14:42 +00:00
|
|
|
*
|
|
|
|
* Note: Every message sent by this function MUST be understood by the
|
|
|
|
* receiver. If this is not the case then there is a potential for infinite
|
|
|
|
* recursion.
|
|
|
|
*/
|
|
|
|
static id gs_objc_proxy_lookup(id receiver, SEL op)
|
|
|
|
{
|
2010-10-27 22:19:18 +00:00
|
|
|
id cls = object_getClass(receiver);
|
2010-02-22 10:13:20 +00:00
|
|
|
BOOL resolved = NO;
|
|
|
|
|
2010-12-23 02:23:05 +00:00
|
|
|
/* Note that __GNU_LIBOBJC__ implements +resolveClassMethod: and
|
|
|
|
+resolveInstanceMethod: directly in the runtime instead. */
|
|
|
|
|
2010-02-22 10:13:20 +00:00
|
|
|
/* Let the class try to add a method for this thing. */
|
|
|
|
if (class_isMetaClass(cls))
|
|
|
|
{
|
|
|
|
if (class_respondsToSelector(cls, @selector(resolveClassMethod:)))
|
|
|
|
{
|
|
|
|
resolved = [receiver resolveClassMethod: op];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-02-20 12:28:12 +00:00
|
|
|
if (class_respondsToSelector(object_getClass(cls),
|
2010-02-22 10:56:07 +00:00
|
|
|
@selector(resolveInstanceMethod:)))
|
2010-02-22 10:13:20 +00:00
|
|
|
{
|
|
|
|
resolved = [cls resolveInstanceMethod: op];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (resolved)
|
|
|
|
{
|
|
|
|
return receiver;
|
|
|
|
}
|
|
|
|
if (class_respondsToSelector(cls, @selector(forwardingTargetForSelector:)))
|
|
|
|
{
|
2010-02-22 10:56:07 +00:00
|
|
|
return [receiver forwardingTargetForSelector: op];
|
2010-02-22 10:13:20 +00:00
|
|
|
}
|
|
|
|
return nil;
|
2009-09-10 20:14:42 +00:00
|
|
|
}
|
|
|
|
#endif
|
2007-05-11 08:26:59 +00:00
|
|
|
|
2021-08-07 20:19:09 +00:00
|
|
|
#ifdef __GNUSTEP_RUNTIME__
|
|
|
|
static void GS_WINAPI
|
|
|
|
exitedThread(void *slot)
|
|
|
|
{
|
|
|
|
free(slot);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-04-18 16:02:12 +00:00
|
|
|
+ (void) load
|
|
|
|
{
|
2010-07-15 09:59:01 +00:00
|
|
|
#ifdef __GNUSTEP_RUNTIME__
|
2021-08-07 20:19:09 +00:00
|
|
|
GS_THREAD_KEY_INIT(thread_slot_key, exitedThread);
|
2010-07-16 18:00:45 +00:00
|
|
|
__objc_msg_forward3 = gs_objc_msg_forward3;
|
|
|
|
__objc_msg_forward2 = gs_objc_msg_forward2;
|
2010-07-15 09:59:01 +00:00
|
|
|
objc_proxy_lookup = gs_objc_proxy_lookup;
|
|
|
|
#else
|
2007-05-11 08:26:59 +00:00
|
|
|
#if HAVE_FORWARD2
|
|
|
|
__objc_msg_forward2 = gs_objc_msg_forward2;
|
|
|
|
#else
|
2002-04-18 16:02:12 +00:00
|
|
|
__objc_msg_forward = gs_objc_msg_forward;
|
2007-05-11 08:26:59 +00:00
|
|
|
#endif
|
2009-09-10 20:14:42 +00:00
|
|
|
#endif
|
2002-04-18 16:02:12 +00:00
|
|
|
}
|
|
|
|
|
2000-12-08 19:06:00 +00:00
|
|
|
|
|
|
|
/*
|
2002-04-18 16:02:12 +00:00
|
|
|
* This is the designated initialiser.
|
2000-12-08 19:06:00 +00:00
|
|
|
*/
|
|
|
|
- (id) initWithMethodSignature: (NSMethodSignature*)aSignature
|
|
|
|
{
|
2009-10-05 16:00:28 +00:00
|
|
|
int i;
|
|
|
|
|
2002-07-29 19:37:40 +00:00
|
|
|
if (aSignature == nil)
|
|
|
|
{
|
2010-02-25 18:49:31 +00:00
|
|
|
DESTROY(self);
|
2002-07-29 19:37:40 +00:00
|
|
|
return nil;
|
|
|
|
}
|
2000-12-08 19:06:00 +00:00
|
|
|
_sig = RETAIN(aSignature);
|
|
|
|
_numArgs = [aSignature numberOfArguments];
|
|
|
|
_info = [aSignature methodInfo];
|
2024-11-15 15:43:47 +00:00
|
|
|
[self setupFrameFFI: _sig];
|
2010-06-07 20:38:19 +00:00
|
|
|
_cframe = [_frame mutableBytes];
|
2009-10-03 18:34:44 +00:00
|
|
|
|
|
|
|
/* Make sure we have somewhere to store the return value if needed.
|
|
|
|
*/
|
|
|
|
_retval = _retptr = 0;
|
2009-10-05 16:00:28 +00:00
|
|
|
i = objc_sizeof_type (objc_skip_type_qualifiers ([_sig methodReturnType]));
|
|
|
|
if (i > 0)
|
2009-10-03 18:34:44 +00:00
|
|
|
{
|
2009-10-05 16:00:28 +00:00
|
|
|
if (i <= sizeof(_retbuf))
|
2009-10-03 18:34:44 +00:00
|
|
|
{
|
|
|
|
_retval = _retbuf;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-10-05 16:00:28 +00:00
|
|
|
_retptr = NSAllocateCollectable(i, NSScannedOption);
|
2009-10-03 18:34:44 +00:00
|
|
|
_retval = _retptr;
|
|
|
|
}
|
|
|
|
}
|
2002-04-18 16:02:12 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initializer used when we get a callback. uses the data provided by
|
|
|
|
the callback. The cifframe was allocated by the forwarding function,
|
|
|
|
but we own it now so we can free it */
|
2005-02-22 11:22:44 +00:00
|
|
|
- (id) initWithCallback: (ffi_cif *)cif
|
2002-04-18 16:02:12 +00:00
|
|
|
values: (void **)vals
|
2010-06-07 20:38:19 +00:00
|
|
|
frame: (void *)frame
|
2002-04-18 16:02:12 +00:00
|
|
|
signature: (NSMethodSignature*)aSignature
|
|
|
|
{
|
2009-11-24 20:39:31 +00:00
|
|
|
cifframe_t *f;
|
2008-06-30 05:29:19 +00:00
|
|
|
int i;
|
|
|
|
|
2002-04-18 16:02:12 +00:00
|
|
|
_sig = RETAIN(aSignature);
|
|
|
|
_numArgs = [aSignature numberOfArguments];
|
|
|
|
_info = [aSignature methodInfo];
|
2010-06-07 20:38:19 +00:00
|
|
|
_frame = (NSMutableData*)frame;
|
|
|
|
[_frame retain];
|
|
|
|
_cframe = [_frame mutableBytes];
|
2009-11-24 20:39:31 +00:00
|
|
|
f = (cifframe_t *)_cframe;
|
|
|
|
f->cif = *cif;
|
2002-04-18 16:02:12 +00:00
|
|
|
|
2008-06-30 05:29:19 +00:00
|
|
|
/* Copy the arguments into our frame so that they are preserved
|
|
|
|
* in the NSInvocation if the stack is changed before the
|
|
|
|
* invocation is used.
|
|
|
|
*/
|
2009-11-24 20:39:31 +00:00
|
|
|
for (i = 0; i < f->nargs; i++)
|
2008-06-30 05:29:19 +00:00
|
|
|
{
|
2009-11-24 20:39:31 +00:00
|
|
|
memcpy(f->values[i], vals[i], f->arg_types[i]->size);
|
2008-06-30 05:29:19 +00:00
|
|
|
}
|
2000-12-08 19:06:00 +00:00
|
|
|
|
2009-10-03 18:34:44 +00:00
|
|
|
/* Make sure we have somewhere to store the return value if needed.
|
|
|
|
*/
|
|
|
|
_retval = _retptr = 0;
|
2009-10-05 16:00:28 +00:00
|
|
|
i = objc_sizeof_type (objc_skip_type_qualifiers ([_sig methodReturnType]));
|
|
|
|
if (i > 0)
|
2009-10-03 18:34:44 +00:00
|
|
|
{
|
2009-10-05 16:00:28 +00:00
|
|
|
if (i <= sizeof(_retbuf))
|
2009-10-03 18:34:44 +00:00
|
|
|
{
|
|
|
|
_retval = _retbuf;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-10-05 16:00:28 +00:00
|
|
|
_retptr = NSAllocateCollectable(i, NSScannedOption);
|
2009-10-03 18:34:44 +00:00
|
|
|
_retval = _retptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return self;
|
2008-06-30 05:29:19 +00:00
|
|
|
}
|
|
|
|
|
2002-04-18 16:02:12 +00:00
|
|
|
/*
|
|
|
|
* This is implemented as a function so it can be used by other
|
|
|
|
* routines (like the DO forwarding)
|
|
|
|
*/
|
|
|
|
void
|
2010-02-24 10:23:47 +00:00
|
|
|
GSFFIInvokeWithTargetAndImp(NSInvocation *inv, id anObject, IMP imp)
|
2002-04-18 16:02:12 +00:00
|
|
|
{
|
|
|
|
/* Do it */
|
2005-02-22 11:22:44 +00:00
|
|
|
ffi_call(inv->_cframe, (f_fun)imp, (inv->_retval),
|
2002-04-18 16:02:12 +00:00
|
|
|
((cifframe_t *)inv->_cframe)->values);
|
|
|
|
|
2002-04-24 03:12:55 +00:00
|
|
|
/* Don't decode the return value here (?) */
|
2002-04-18 16:02:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) invokeWithTarget: (id)anObject
|
|
|
|
{
|
|
|
|
id old_target;
|
2009-10-05 16:00:28 +00:00
|
|
|
const char *type;
|
2002-04-18 16:02:12 +00:00
|
|
|
IMP imp;
|
|
|
|
|
2003-02-04 18:18:47 +00:00
|
|
|
CLEAR_RETURN_VALUE_IF_OBJECT;
|
|
|
|
_validReturn = NO;
|
2009-10-05 16:00:28 +00:00
|
|
|
type = objc_skip_type_qualifiers([_sig methodReturnType]);
|
|
|
|
|
2002-04-18 16:02:12 +00:00
|
|
|
/*
|
|
|
|
* A message to a nil object returns nil.
|
|
|
|
*/
|
|
|
|
if (anObject == nil)
|
|
|
|
{
|
|
|
|
if (_retval)
|
2009-10-05 16:00:28 +00:00
|
|
|
{
|
|
|
|
memset(_retval, '\0', objc_sizeof_type (type));
|
|
|
|
}
|
2005-02-22 11:22:44 +00:00
|
|
|
_validReturn = YES;
|
2002-04-18 16:02:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-09-07 09:42:50 +00:00
|
|
|
/* Make sure we have a typed selector for forwarding.
|
|
|
|
*/
|
2002-04-18 16:02:12 +00:00
|
|
|
NSAssert(_selector != 0, @"you must set the selector before invoking");
|
2011-09-07 09:42:50 +00:00
|
|
|
if (0 == GSTypesFromSelector(_selector))
|
|
|
|
{
|
|
|
|
_selector = GSSelectorFromNameAndTypes(sel_getName(_selector),
|
|
|
|
[_sig methodType]);
|
|
|
|
}
|
2002-04-18 16:02:12 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Temporarily set new target and copy it (and the selector) into the
|
|
|
|
* _cframe.
|
|
|
|
*/
|
|
|
|
old_target = RETAIN(_target);
|
|
|
|
[self setTarget: anObject];
|
|
|
|
|
2009-10-05 16:00:28 +00:00
|
|
|
cifframe_set_arg((cifframe_t *)_cframe, 0, &_target, sizeof(id));
|
|
|
|
cifframe_set_arg((cifframe_t *)_cframe, 1, &_selector, sizeof(SEL));
|
2002-04-18 16:02:12 +00:00
|
|
|
|
|
|
|
if (_sendToSuper == YES)
|
|
|
|
{
|
A huge blob of changes to make -base build with libobjc2, without using the old libobjc2 headers.
Most of these changes involve simply removing direct manipulation of any runtime structures and replacing them with runtime function calls. For example class->name becomes class_getName(class) and so on.
libobjc2, like the Apple runtime, the NeXT runtime, and every version of the Objective-C spec, calls the class pointer in id isa. A few files now have #define class_pointer isa at the top. This line replaces class_pointer in the old GNU libobjc headers with isa so either class_pointer or isa can be used for accessing the class of an object. Note: object_getClass() should be used in most cases because, in some future version of the runtime, this will skip things like lock classes and other hidden classes (e.g. KVO classes).
All of the old forwarding stuff has been removed. Most of this stuff followed convoluted code paths that ended with an exception. A few simply broke in exciting ways. Hopefully no one has used them for the last ten years or so, but we can bring them back with some #ifndef stuff if they're really needed by anyone.
There is currently a bug in configure, which prevents dladdr() from being detected, so you need to manually tweak config.h to build - I have not fixed the fall-back code in objc-load.m to work with libobjc2, I just added a new version that uses the loader's functionality directly.
Although -base now builds, it builds with a lot of warnings. <string.h> is missing from a lot of files, so memcpy() and strlen() generate implicit function declaration warnings.
Additionally, libobjc2 does still provide the sel_{get,register}_*() functions, but they're wrappers around the newer API ones. These are deprecated and are not exposed in the headers. Although they work, we should be replacing them with the libobjc2 versions as soon as possible.
This incorporates a patch by Eric.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@31265 72102866-910b-0410-8b05-ffd578937521
2010-09-09 15:06:09 +00:00
|
|
|
Class cls;
|
2002-04-18 16:02:12 +00:00
|
|
|
if (GSObjCIsInstance(_target))
|
A huge blob of changes to make -base build with libobjc2, without using the old libobjc2 headers.
Most of these changes involve simply removing direct manipulation of any runtime structures and replacing them with runtime function calls. For example class->name becomes class_getName(class) and so on.
libobjc2, like the Apple runtime, the NeXT runtime, and every version of the Objective-C spec, calls the class pointer in id isa. A few files now have #define class_pointer isa at the top. This line replaces class_pointer in the old GNU libobjc headers with isa so either class_pointer or isa can be used for accessing the class of an object. Note: object_getClass() should be used in most cases because, in some future version of the runtime, this will skip things like lock classes and other hidden classes (e.g. KVO classes).
All of the old forwarding stuff has been removed. Most of this stuff followed convoluted code paths that ended with an exception. A few simply broke in exciting ways. Hopefully no one has used them for the last ten years or so, but we can bring them back with some #ifndef stuff if they're really needed by anyone.
There is currently a bug in configure, which prevents dladdr() from being detected, so you need to manually tweak config.h to build - I have not fixed the fall-back code in objc-load.m to work with libobjc2, I just added a new version that uses the loader's functionality directly.
Although -base now builds, it builds with a lot of warnings. <string.h> is missing from a lot of files, so memcpy() and strlen() generate implicit function declaration warnings.
Additionally, libobjc2 does still provide the sel_{get,register}_*() functions, but they're wrappers around the newer API ones. These are deprecated and are not exposed in the headers. Although they work, we should be replacing them with the libobjc2 versions as soon as possible.
This incorporates a patch by Eric.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@31265 72102866-910b-0410-8b05-ffd578937521
2010-09-09 15:06:09 +00:00
|
|
|
cls = class_getSuperclass(object_getClass(_target));
|
2002-04-18 16:02:12 +00:00
|
|
|
else
|
A huge blob of changes to make -base build with libobjc2, without using the old libobjc2 headers.
Most of these changes involve simply removing direct manipulation of any runtime structures and replacing them with runtime function calls. For example class->name becomes class_getName(class) and so on.
libobjc2, like the Apple runtime, the NeXT runtime, and every version of the Objective-C spec, calls the class pointer in id isa. A few files now have #define class_pointer isa at the top. This line replaces class_pointer in the old GNU libobjc headers with isa so either class_pointer or isa can be used for accessing the class of an object. Note: object_getClass() should be used in most cases because, in some future version of the runtime, this will skip things like lock classes and other hidden classes (e.g. KVO classes).
All of the old forwarding stuff has been removed. Most of this stuff followed convoluted code paths that ended with an exception. A few simply broke in exciting ways. Hopefully no one has used them for the last ten years or so, but we can bring them back with some #ifndef stuff if they're really needed by anyone.
There is currently a bug in configure, which prevents dladdr() from being detected, so you need to manually tweak config.h to build - I have not fixed the fall-back code in objc-load.m to work with libobjc2, I just added a new version that uses the loader's functionality directly.
Although -base now builds, it builds with a lot of warnings. <string.h> is missing from a lot of files, so memcpy() and strlen() generate implicit function declaration warnings.
Additionally, libobjc2 does still provide the sel_{get,register}_*() functions, but they're wrappers around the newer API ones. These are deprecated and are not exposed in the headers. Although they work, we should be replacing them with the libobjc2 versions as soon as possible.
This incorporates a patch by Eric.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@31265 72102866-910b-0410-8b05-ffd578937521
2010-09-09 15:06:09 +00:00
|
|
|
cls = class_getSuperclass((Class)_target);
|
|
|
|
{
|
|
|
|
struct objc_super s = {_target, cls};
|
|
|
|
imp = objc_msg_lookup_super(&s, _selector);
|
|
|
|
}
|
2002-04-18 16:02:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-08-20 17:53:16 +00:00
|
|
|
GSMethod method;
|
|
|
|
method = GSGetMethod((GSObjCIsInstance(_target)
|
2010-02-22 10:13:20 +00:00
|
|
|
? (Class)object_getClass(_target)
|
2006-07-04 20:27:04 +00:00
|
|
|
: (Class)_target),
|
2004-08-20 17:53:16 +00:00
|
|
|
_selector,
|
|
|
|
GSObjCIsInstance(_target),
|
|
|
|
YES);
|
A huge blob of changes to make -base build with libobjc2, without using the old libobjc2 headers.
Most of these changes involve simply removing direct manipulation of any runtime structures and replacing them with runtime function calls. For example class->name becomes class_getName(class) and so on.
libobjc2, like the Apple runtime, the NeXT runtime, and every version of the Objective-C spec, calls the class pointer in id isa. A few files now have #define class_pointer isa at the top. This line replaces class_pointer in the old GNU libobjc headers with isa so either class_pointer or isa can be used for accessing the class of an object. Note: object_getClass() should be used in most cases because, in some future version of the runtime, this will skip things like lock classes and other hidden classes (e.g. KVO classes).
All of the old forwarding stuff has been removed. Most of this stuff followed convoluted code paths that ended with an exception. A few simply broke in exciting ways. Hopefully no one has used them for the last ten years or so, but we can bring them back with some #ifndef stuff if they're really needed by anyone.
There is currently a bug in configure, which prevents dladdr() from being detected, so you need to manually tweak config.h to build - I have not fixed the fall-back code in objc-load.m to work with libobjc2, I just added a new version that uses the loader's functionality directly.
Although -base now builds, it builds with a lot of warnings. <string.h> is missing from a lot of files, so memcpy() and strlen() generate implicit function declaration warnings.
Additionally, libobjc2 does still provide the sel_{get,register}_*() functions, but they're wrappers around the newer API ones. These are deprecated and are not exposed in the headers. Although they work, we should be replacing them with the libobjc2 versions as soon as possible.
This incorporates a patch by Eric.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@31265 72102866-910b-0410-8b05-ffd578937521
2010-09-09 15:06:09 +00:00
|
|
|
imp = method_getImplementation(method);
|
2002-04-18 16:02:12 +00:00
|
|
|
/*
|
|
|
|
* If fast lookup failed, we may be forwarding or something ...
|
|
|
|
*/
|
|
|
|
if (imp == 0)
|
|
|
|
{
|
|
|
|
imp = objc_msg_lookup(_target, _selector);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[self setTarget: old_target];
|
|
|
|
RELEASE(old_target);
|
2005-02-22 11:22:44 +00:00
|
|
|
|
2002-04-18 16:02:12 +00:00
|
|
|
GSFFIInvokeWithTargetAndImp(self, anObject, imp);
|
|
|
|
|
|
|
|
/* Decode the return value */
|
2009-10-05 16:00:28 +00:00
|
|
|
if (*type != _C_VOID)
|
|
|
|
{
|
|
|
|
cifframe_decode_arg(type, _retval);
|
|
|
|
}
|
2003-02-04 18:18:47 +00:00
|
|
|
|
2005-02-22 11:22:44 +00:00
|
|
|
RETAIN_RETURN_VALUE;
|
2002-04-18 16:02:12 +00:00
|
|
|
_validReturn = YES;
|
|
|
|
}
|
2000-12-08 19:06:00 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
2003-07-04 15:11:15 +00:00
|
|
|
/*
|
|
|
|
* Return YES if the selector contains protocol qualifiers.
|
|
|
|
*/
|
|
|
|
static BOOL
|
|
|
|
gs_protocol_selector(const char *types)
|
|
|
|
{
|
|
|
|
if (types == 0)
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
while (*types != '\0')
|
|
|
|
{
|
2010-03-01 10:34:35 +00:00
|
|
|
if (*types == '+' || *types == '-')
|
2004-09-02 16:35:44 +00:00
|
|
|
{
|
|
|
|
types++;
|
|
|
|
}
|
2012-01-01 07:38:53 +00:00
|
|
|
while (isdigit(*types))
|
2003-07-04 15:11:15 +00:00
|
|
|
{
|
2010-03-01 10:34:35 +00:00
|
|
|
types++;
|
2003-07-04 15:11:15 +00:00
|
|
|
}
|
|
|
|
while (*types == _C_CONST || *types == _C_GCINVISIBLE)
|
|
|
|
{
|
|
|
|
types++;
|
|
|
|
}
|
|
|
|
if (*types == _C_IN
|
|
|
|
|| *types == _C_INOUT
|
|
|
|
|| *types == _C_OUT
|
|
|
|
|| *types == _C_BYCOPY
|
|
|
|
|| *types == _C_BYREF
|
|
|
|
|| *types == _C_ONEWAY)
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
if (*types == '\0')
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
types = objc_skip_typespec(types);
|
|
|
|
}
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2006-10-16 09:30:18 +00:00
|
|
|
static void
|
2002-04-18 16:02:12 +00:00
|
|
|
GSFFIInvocationCallback(ffi_cif *cif, void *retp, void **args, void *user)
|
|
|
|
{
|
|
|
|
id obj;
|
|
|
|
SEL selector;
|
|
|
|
GSFFIInvocation *invocation;
|
|
|
|
NSMethodSignature *sig;
|
2005-02-22 11:22:44 +00:00
|
|
|
|
2002-04-24 03:12:55 +00:00
|
|
|
obj = *(id *)args[0];
|
|
|
|
selector = *(SEL *)args[1];
|
2002-04-18 16:02:12 +00:00
|
|
|
|
2011-02-20 12:28:12 +00:00
|
|
|
if (!class_respondsToSelector(object_getClass(obj),
|
2010-06-07 20:38:19 +00:00
|
|
|
@selector(forwardInvocation:)))
|
2002-04-18 16:02:12 +00:00
|
|
|
{
|
2003-08-24 23:07:41 +00:00
|
|
|
[NSException raise: NSInvalidArgumentException
|
|
|
|
format: @"GSFFIInvocation: Class '%s'(%s) does not respond"
|
|
|
|
@" to forwardInvocation: for '%s'",
|
|
|
|
GSClassNameFromObject(obj),
|
|
|
|
GSObjCIsInstance(obj) ? "instance" : "class",
|
2010-02-22 10:13:20 +00:00
|
|
|
selector ? sel_getName(selector) : "(null)"];
|
2002-04-18 16:02:12 +00:00
|
|
|
}
|
2005-02-22 11:22:44 +00:00
|
|
|
|
2003-07-04 15:11:15 +00:00
|
|
|
sig = nil;
|
2011-02-20 07:58:11 +00:00
|
|
|
if (gs_protocol_selector(GSTypesFromSelector(selector)) == YES)
|
2003-07-04 15:11:15 +00:00
|
|
|
{
|
2011-09-07 09:42:50 +00:00
|
|
|
sig = [NSMethodSignature signatureWithObjCTypes:
|
|
|
|
GSTypesFromSelector(selector)];
|
2003-07-04 15:11:15 +00:00
|
|
|
}
|
|
|
|
if (sig == nil)
|
|
|
|
{
|
|
|
|
sig = [obj methodSignatureForSelector: selector];
|
|
|
|
}
|
2003-07-04 09:33:53 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we got a method signature from the receiving object,
|
|
|
|
* ensure that the selector we are using matches the types.
|
|
|
|
*/
|
|
|
|
if (sig != nil)
|
|
|
|
{
|
|
|
|
const char *receiverTypes = [sig methodType];
|
2011-02-20 07:58:11 +00:00
|
|
|
const char *runtimeTypes = GSTypesFromSelector(selector);
|
2003-07-04 09:33:53 +00:00
|
|
|
|
2012-01-19 10:12:03 +00:00
|
|
|
if (NO == GSSelectorTypesMatch(receiverTypes, runtimeTypes))
|
2003-07-04 09:33:53 +00:00
|
|
|
{
|
2010-02-22 10:13:20 +00:00
|
|
|
const char *runtimeName = sel_getName(selector);
|
2003-07-04 09:33:53 +00:00
|
|
|
|
2011-02-20 07:58:11 +00:00
|
|
|
selector = GSSelectorFromNameAndTypes(runtimeName, receiverTypes);
|
2003-07-04 10:52:56 +00:00
|
|
|
if (runtimeTypes != 0)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* FIXME ... if we have a typed selector, it probably came
|
|
|
|
* from the compiler, and the types of the proxied method
|
|
|
|
* MUST match those that the compiler supplied on the stack
|
|
|
|
* and the type it expects to retrieve from the stack.
|
|
|
|
* We should therefore discriminate between signatures where
|
|
|
|
* type qalifiers and sizes differ, and those where the
|
|
|
|
* actual types differ.
|
|
|
|
*/
|
2004-08-19 16:19:48 +00:00
|
|
|
NSDebugFLog(@"Changed type signature '%s' to '%s' for '%s'",
|
2003-07-04 10:52:56 +00:00
|
|
|
runtimeTypes, receiverTypes, runtimeName);
|
|
|
|
}
|
2003-07-04 09:33:53 +00:00
|
|
|
}
|
|
|
|
}
|
2005-02-22 11:22:44 +00:00
|
|
|
|
2004-04-26 07:51:35 +00:00
|
|
|
if (sig == nil)
|
|
|
|
{
|
2012-11-05 15:16:30 +00:00
|
|
|
/* NB Don't overwrite selector prematurely, so we can show the untyped
|
|
|
|
* selector in the error message below if there is no best selector. */
|
|
|
|
SEL typed_sel = gs_find_best_typed_sel (selector);
|
2004-04-26 07:51:35 +00:00
|
|
|
|
2012-11-05 15:16:30 +00:00
|
|
|
if (typed_sel != 0)
|
2010-12-23 02:23:05 +00:00
|
|
|
{
|
2012-11-05 15:16:30 +00:00
|
|
|
selector = typed_sel;
|
|
|
|
if (GSTypesFromSelector(selector) != 0)
|
|
|
|
{
|
|
|
|
sig = [NSMethodSignature signatureWithObjCTypes:
|
|
|
|
GSTypesFromSelector(selector)];
|
|
|
|
}
|
2010-12-23 02:23:05 +00:00
|
|
|
}
|
2004-04-26 07:51:35 +00:00
|
|
|
}
|
2002-04-18 16:02:12 +00:00
|
|
|
|
2003-07-28 10:53:18 +00:00
|
|
|
if (sig == nil)
|
|
|
|
{
|
|
|
|
[NSException raise: NSInvalidArgumentException
|
2004-04-26 07:51:35 +00:00
|
|
|
format: @"Can not determine type information for %s[%s %s]",
|
|
|
|
GSObjCIsInstance(obj) ? "-" : "+",
|
2003-08-24 23:07:41 +00:00
|
|
|
GSClassNameFromObject(obj),
|
2010-02-22 10:13:20 +00:00
|
|
|
selector ? sel_getName(selector) : "(null)"];
|
2003-07-28 10:53:18 +00:00
|
|
|
}
|
2005-02-22 11:22:44 +00:00
|
|
|
|
2002-04-18 16:02:12 +00:00
|
|
|
invocation = [[GSFFIInvocation alloc] initWithCallback: cif
|
|
|
|
values: args
|
|
|
|
frame: user
|
|
|
|
signature: sig];
|
2022-02-17 10:08:18 +00:00
|
|
|
IF_NO_ARC([invocation autorelease];)
|
2002-04-18 16:02:12 +00:00
|
|
|
[invocation setTarget: obj];
|
|
|
|
[invocation setSelector: selector];
|
|
|
|
|
2010-06-01 19:35:26 +00:00
|
|
|
[obj forwardInvocation: invocation];
|
2002-04-18 16:02:12 +00:00
|
|
|
|
2009-10-03 18:34:44 +00:00
|
|
|
/* If we are returning a value, we must copy it from the invocation
|
|
|
|
* to the memory indicated by 'retp'.
|
|
|
|
*/
|
2010-02-24 10:23:47 +00:00
|
|
|
if (retp != 0 && invocation->_validReturn == YES)
|
2003-02-17 05:06:02 +00:00
|
|
|
{
|
2009-10-03 18:34:44 +00:00
|
|
|
[invocation getReturnValue: retp];
|
2003-02-17 05:06:02 +00:00
|
|
|
}
|
|
|
|
|
2002-04-18 16:02:12 +00:00
|
|
|
/* We need to (re)encode the return type for it's trip back. */
|
|
|
|
if (retp)
|
|
|
|
cifframe_encode_arg([sig methodReturnType], retp);
|
|
|
|
}
|
|
|
|
|
|
|
|
@implementation NSInvocation (DistantCoding)
|
|
|
|
|
|
|
|
/* An internal method used to help NSConnections code invocations
|
|
|
|
to send over the wire */
|
|
|
|
- (BOOL) encodeWithDistantCoder: (NSCoder*)coder passPointers: (BOOL)passp
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
BOOL out_parameters = NO;
|
|
|
|
const char *type = [_sig methodType];
|
|
|
|
|
|
|
|
[coder encodeValueOfObjCType: @encode(char*) at: &type];
|
|
|
|
|
|
|
|
for (i = 0; i < _numArgs; i++)
|
|
|
|
{
|
2009-10-05 16:00:28 +00:00
|
|
|
int flags = _inf[i+1].qual;
|
|
|
|
const char *type = _inf[i+1].type;
|
2002-04-18 16:02:12 +00:00
|
|
|
void *datum;
|
2005-02-22 11:22:44 +00:00
|
|
|
|
2002-04-18 16:02:12 +00:00
|
|
|
if (i == 0)
|
|
|
|
{
|
|
|
|
datum = &_target;
|
|
|
|
}
|
|
|
|
else if (i == 1)
|
|
|
|
{
|
|
|
|
datum = &_selector;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
datum = cifframe_arg_addr((cifframe_t *)_cframe, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Decide how, (or whether or not), to encode the argument
|
|
|
|
* depending on its FLAGS and TYPE. Only the first two cases
|
|
|
|
* involve parameters that may potentially be passed by
|
|
|
|
* reference, and thus only the first two may change the value
|
|
|
|
* of OUT_PARAMETERS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
switch (*type)
|
|
|
|
{
|
2005-02-22 11:22:44 +00:00
|
|
|
case _C_ID:
|
2002-04-18 16:02:12 +00:00
|
|
|
if (flags & _F_BYCOPY)
|
|
|
|
{
|
|
|
|
[coder encodeBycopyObject: *(id*)datum];
|
|
|
|
}
|
|
|
|
#ifdef _F_BYREF
|
|
|
|
else if (flags & _F_BYREF)
|
|
|
|
{
|
|
|
|
[coder encodeByrefObject: *(id*)datum];
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[coder encodeObject: *(id*)datum];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case _C_CHARPTR:
|
|
|
|
/*
|
|
|
|
* Handle a (char*) argument.
|
|
|
|
* If the char* is qualified as an OUT parameter, or if it
|
|
|
|
* not explicitly qualified as an IN parameter, then we will
|
|
|
|
* have to get this char* again after the method is run,
|
|
|
|
* because the method may have changed it. Set
|
|
|
|
* OUT_PARAMETERS accordingly.
|
|
|
|
*/
|
|
|
|
if ((flags & _F_OUT) || !(flags & _F_IN))
|
|
|
|
{
|
|
|
|
out_parameters = YES;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* If the char* is qualified as an IN parameter, or not
|
|
|
|
* explicity qualified as an OUT parameter, then encode
|
|
|
|
* it.
|
|
|
|
*/
|
|
|
|
if ((flags & _F_IN) || !(flags & _F_OUT))
|
|
|
|
{
|
|
|
|
[coder encodeValueOfObjCType: type at: datum];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_PTR:
|
|
|
|
/*
|
|
|
|
* If the pointer's value is qualified as an OUT parameter,
|
|
|
|
* or if it not explicitly qualified as an IN parameter,
|
|
|
|
* then we will have to get the value pointed to again after
|
|
|
|
* the method is run, because the method may have changed
|
|
|
|
* it. Set OUT_PARAMETERS accordingly.
|
|
|
|
*/
|
|
|
|
if ((flags & _F_OUT) || !(flags & _F_IN))
|
|
|
|
{
|
|
|
|
out_parameters = YES;
|
|
|
|
}
|
2005-02-22 11:22:44 +00:00
|
|
|
if (passp)
|
2002-04-18 16:02:12 +00:00
|
|
|
{
|
|
|
|
if ((flags & _F_IN) || !(flags & _F_OUT))
|
|
|
|
{
|
|
|
|
[coder encodeValueOfObjCType: type at: datum];
|
|
|
|
}
|
|
|
|
}
|
2005-02-22 11:22:44 +00:00
|
|
|
else
|
2002-04-18 16:02:12 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Handle an argument that is a pointer to a non-char. But
|
|
|
|
* (void*) and (anything**) is not allowed.
|
|
|
|
* The argument is a pointer to something; increment TYPE
|
|
|
|
* so we can see what it is a pointer to.
|
|
|
|
*/
|
|
|
|
type++;
|
|
|
|
/*
|
|
|
|
* If the pointer's value is qualified as an IN parameter,
|
|
|
|
* or not explicity qualified as an OUT parameter, then
|
|
|
|
* encode it.
|
|
|
|
*/
|
|
|
|
if ((flags & _F_IN) || !(flags & _F_OUT))
|
|
|
|
{
|
|
|
|
[coder encodeValueOfObjCType: type at: *(void**)datum];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case _C_STRUCT_B:
|
|
|
|
case _C_UNION_B:
|
|
|
|
case _C_ARY_B:
|
|
|
|
/*
|
|
|
|
* Handle struct and array arguments.
|
|
|
|
* Whether DATUM points to the data, or points to a pointer
|
|
|
|
* that points to the data, depends on the value of
|
|
|
|
* CALLFRAME_STRUCT_BYREF. Do the right thing
|
|
|
|
* so that ENCODER gets a pointer to directly to the data.
|
|
|
|
*/
|
|
|
|
[coder encodeValueOfObjCType: type at: datum];
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* Handle arguments of all other types. */
|
|
|
|
[coder encodeValueOfObjCType: type at: datum];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return a BOOL indicating whether or not there are parameters that
|
|
|
|
* were passed by reference; we will need to get those values again
|
|
|
|
* after the method has finished executing because the execution of
|
|
|
|
* the method may have changed them.
|
|
|
|
*/
|
|
|
|
return out_parameters;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|