2001-12-17 14:31:42 +00:00
|
|
|
|
/** Implementation of NSInvocation for GNUStep
|
2003-04-04 10:59:11 +00:00
|
|
|
|
Copyright (C) 1998,2003 Free Software Foundation, Inc.
|
2005-02-22 11:22:44 +00:00
|
|
|
|
|
2003-04-04 10:59:11 +00:00
|
|
|
|
Author: Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
1998-08-13 20:45:32 +00:00
|
|
|
|
Date: August 1998
|
|
|
|
|
Based on code by: Andrew Kachites McCallum <mccallum@gnu.ai.mit.edu>
|
2005-02-22 11:22:44 +00:00
|
|
|
|
|
1996-05-12 00:56:10 +00:00
|
|
|
|
This file is part of the GNUstep Base Library.
|
1994-11-08 16:44:01 +00:00
|
|
|
|
|
1996-02-24 18:47:39 +00:00
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
2005-02-22 11:22:44 +00:00
|
|
|
|
|
1996-02-24 18:47:39 +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
|
|
|
|
|
Library General Public License for more details.
|
2005-02-22 11:22:44 +00:00
|
|
|
|
|
1996-02-24 18:47:39 +00:00
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
|
|
|
License along with this library; if not, write to the Free
|
1999-09-09 02:56:20 +00:00
|
|
|
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
2001-12-18 16:54:15 +00:00
|
|
|
|
|
|
|
|
|
<title>NSInvocation class reference</title>
|
|
|
|
|
$Date$ $Revision$
|
2005-02-22 11:22:44 +00:00
|
|
|
|
*/
|
1994-11-08 16:44:01 +00:00
|
|
|
|
|
2003-06-07 01:24:41 +00:00
|
|
|
|
#include "Foundation/NSException.h"
|
|
|
|
|
#include "Foundation/NSCoder.h"
|
|
|
|
|
#include "Foundation/NSInvocation.h"
|
2003-07-31 23:49:32 +00:00
|
|
|
|
#include "GSInvocation.h"
|
2003-06-07 01:24:41 +00:00
|
|
|
|
#include "config.h"
|
1998-12-14 06:17:12 +00:00
|
|
|
|
#include <mframe.h>
|
2000-12-08 19:06:00 +00:00
|
|
|
|
#if defined(USE_LIBFFI)
|
|
|
|
|
#include "cifframe.h"
|
|
|
|
|
#elif defined(USE_FFCALL)
|
|
|
|
|
#include "callframe.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
static Class NSInvocation_abstract_class;
|
|
|
|
|
static Class NSInvocation_concrete_class;
|
1994-11-08 16:44:01 +00:00
|
|
|
|
|
2003-04-04 10:03:08 +00:00
|
|
|
|
@interface GSInvocationProxy
|
|
|
|
|
{
|
|
|
|
|
@public
|
|
|
|
|
Class isa;
|
|
|
|
|
id target;
|
|
|
|
|
NSInvocation *invocation;
|
|
|
|
|
}
|
|
|
|
|
+ (id) _newWithTarget: (id)t;
|
|
|
|
|
- (NSInvocation*) _invocation;
|
|
|
|
|
- (void) forwardInvocation: (NSInvocation*)anInvocation;
|
2003-07-27 08:59:08 +00:00
|
|
|
|
- (NSMethodSignature*) methodSignatureForSelector: (SEL)aSelector;
|
2003-04-04 10:03:08 +00:00
|
|
|
|
@end
|
|
|
|
|
@interface GSMessageProxy : GSInvocationProxy
|
|
|
|
|
@end
|
|
|
|
|
|
2003-04-04 10:59:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2004-06-22 22:40:40 +00:00
|
|
|
|
* <p>The <code>NSInvocation</code> class implements a mechanism of constructing
|
|
|
|
|
* messages (as <code>NSInvocation</code> instances), sending these to other
|
2003-04-04 10:59:11 +00:00
|
|
|
|
* objects, and handling the returned values.
|
|
|
|
|
* </p>
|
2004-06-22 22:40:40 +00:00
|
|
|
|
* <p>An <code>NSInvocation</code> object may contain a target object to which a
|
2003-04-04 10:59:11 +00:00
|
|
|
|
* message can be sent, or may send the message to an arbitrary object.<br />
|
|
|
|
|
* Each message consists of a selector for that method and an argument
|
|
|
|
|
* list. Once the message has been sent, the invocation will contain
|
|
|
|
|
* a return value whose contents may be copied out of it.
|
|
|
|
|
* </p>
|
|
|
|
|
* <p>The target, selector, and arguments of an instance be constructed
|
|
|
|
|
* dynamically, providing a great deal of power/flexibility.
|
|
|
|
|
* </p>
|
|
|
|
|
* <p>The sending of the message to the target object (using the -invoke
|
|
|
|
|
* or -invokeWithTarget: method) can be done at any time, but a standard
|
|
|
|
|
* use of this is by the [NSObject-forwardInvocation:] method which is
|
|
|
|
|
* called whenever a method is not implemented by the class of the
|
|
|
|
|
* object to which it was sent.
|
|
|
|
|
* </p>
|
|
|
|
|
* <p>Related to the class are two convenience macros ... NS_MESSAGE()
|
2004-06-22 22:40:40 +00:00
|
|
|
|
* and NS_INVOCATION() ... to allow easy construction of invocations
|
|
|
|
|
* with all the arguments set up.
|
2003-04-04 10:59:11 +00:00
|
|
|
|
* </p>
|
|
|
|
|
*/
|
1996-02-24 18:47:39 +00:00
|
|
|
|
@implementation NSInvocation
|
1994-11-08 16:44:01 +00:00
|
|
|
|
|
2000-12-08 19:06:00 +00:00
|
|
|
|
#ifdef USE_LIBFFI
|
|
|
|
|
static inline void
|
|
|
|
|
_get_arg(NSInvocation *inv, int index, void *buffer)
|
|
|
|
|
{
|
2002-04-18 16:02:12 +00:00
|
|
|
|
cifframe_get_arg((cifframe_t *)inv->_cframe, index, buffer,
|
|
|
|
|
inv->_info[index+1].size);
|
2000-12-08 19:06:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
|
_set_arg(NSInvocation *inv, int index, void *buffer)
|
|
|
|
|
{
|
2002-04-18 16:02:12 +00:00
|
|
|
|
cifframe_set_arg((cifframe_t *)inv->_cframe, index, buffer,
|
|
|
|
|
inv->_info[index+1].size);
|
2000-12-08 19:06:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void *
|
|
|
|
|
_arg_addr(NSInvocation *inv, int index)
|
|
|
|
|
{
|
|
|
|
|
return cifframe_arg_addr((cifframe_t *)inv->_cframe, index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#elif defined(USE_FFCALL)
|
|
|
|
|
static inline void
|
|
|
|
|
_get_arg(NSInvocation *inv, int index, void *buffer)
|
|
|
|
|
{
|
|
|
|
|
callframe_get_arg((callframe_t *)inv->_cframe, index, buffer,
|
|
|
|
|
inv->_info[index+1].size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
|
_set_arg(NSInvocation *inv, int index, void *buffer)
|
|
|
|
|
{
|
|
|
|
|
callframe_set_arg((callframe_t *)inv->_cframe, index, buffer,
|
|
|
|
|
inv->_info[index+1].size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void *
|
|
|
|
|
_arg_addr(NSInvocation *inv, int index)
|
|
|
|
|
{
|
|
|
|
|
return callframe_arg_addr((callframe_t *)inv->_cframe, index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#else
|
2001-04-20 14:04:38 +00:00
|
|
|
|
static inline void
|
2000-12-08 19:06:00 +00:00
|
|
|
|
_get_arg(NSInvocation *inv, int index, void *buffer)
|
|
|
|
|
{
|
2002-02-20 05:08:46 +00:00
|
|
|
|
mframe_get_arg((arglist_t)inv->_cframe, &inv->_info[index+1], buffer);
|
2000-12-08 19:06:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
|
_set_arg(NSInvocation *inv, int index, void *buffer)
|
|
|
|
|
{
|
2002-02-20 05:08:46 +00:00
|
|
|
|
mframe_set_arg((arglist_t)inv->_cframe, &inv->_info[index+1], buffer);
|
2000-12-08 19:06:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void *
|
|
|
|
|
_arg_addr(NSInvocation *inv, int index)
|
|
|
|
|
{
|
2002-02-20 05:08:46 +00:00
|
|
|
|
return mframe_arg_addr((arglist_t)inv->_cframe, &inv->_info[index+1]);
|
2000-12-08 19:06:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
+ (id) allocWithZone: (NSZone*)aZone
|
|
|
|
|
{
|
|
|
|
|
if (self == NSInvocation_abstract_class)
|
|
|
|
|
{
|
|
|
|
|
return NSAllocateObject(NSInvocation_concrete_class, 0, aZone);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return NSAllocateObject(self, 0, aZone);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (void) initialize
|
|
|
|
|
{
|
|
|
|
|
if (self == [NSInvocation class])
|
|
|
|
|
{
|
|
|
|
|
NSInvocation_abstract_class = self;
|
|
|
|
|
#if defined(USE_LIBFFI)
|
|
|
|
|
NSInvocation_concrete_class = [GSFFIInvocation class];
|
|
|
|
|
#elif defined(USE_FFCALL)
|
|
|
|
|
NSInvocation_concrete_class = [GSFFCallInvocation class];
|
|
|
|
|
#else
|
|
|
|
|
NSInvocation_concrete_class = [GSFrameInvocation class];
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-04 10:03:08 +00:00
|
|
|
|
/**
|
|
|
|
|
* Returns an invocation instance which can be used to send messages to
|
|
|
|
|
* a target object using the described signature.<br />
|
2003-04-17 06:20:17 +00:00
|
|
|
|
* You must set the target and selector (using -setTarget: and -setSelector:)
|
|
|
|
|
* before you attempt to use the invocation.<br />
|
2003-04-04 10:03:08 +00:00
|
|
|
|
* Raises an NSInvalidArgumentException if the signature is nil.
|
|
|
|
|
*/
|
1999-09-16 07:21:34 +00:00
|
|
|
|
+ (NSInvocation*) invocationWithMethodSignature: (NSMethodSignature*)_signature
|
1994-11-08 16:44:01 +00:00
|
|
|
|
{
|
2000-12-08 19:06:00 +00:00
|
|
|
|
return AUTORELEASE([[NSInvocation_concrete_class alloc]
|
1999-09-16 07:21:34 +00:00
|
|
|
|
initWithMethodSignature: _signature]);
|
1994-11-08 16:44:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-08-13 20:45:32 +00:00
|
|
|
|
- (void) dealloc
|
1994-11-08 16:44:01 +00:00
|
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
|
if (_argsRetained)
|
1998-10-28 13:58:05 +00:00
|
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
|
RELEASE(_target);
|
|
|
|
|
_argsRetained = NO;
|
2002-02-20 05:08:46 +00:00
|
|
|
|
if (_cframe && _sig)
|
1998-10-28 13:58:05 +00:00
|
|
|
|
{
|
2003-01-03 20:14:47 +00:00
|
|
|
|
unsigned int i;
|
1998-10-28 13:58:05 +00:00
|
|
|
|
|
1999-09-16 07:21:34 +00:00
|
|
|
|
for (i = 3; i <= _numArgs; i++)
|
1998-10-28 13:58:05 +00:00
|
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
|
if (*_info[i].type == _C_CHARPTR)
|
1998-10-28 13:58:05 +00:00
|
|
|
|
{
|
|
|
|
|
char *str;
|
|
|
|
|
|
2000-12-08 19:06:00 +00:00
|
|
|
|
_get_arg(self, i-1, &str);
|
1999-09-28 11:10:34 +00:00
|
|
|
|
NSZoneFree(NSDefaultMallocZone(), str);
|
1998-08-13 20:45:32 +00:00
|
|
|
|
}
|
1999-09-16 07:21:34 +00:00
|
|
|
|
else if (*_info[i].type == _C_ID)
|
1998-10-28 13:58:05 +00:00
|
|
|
|
{
|
|
|
|
|
id obj;
|
1998-08-13 20:45:32 +00:00
|
|
|
|
|
2000-12-08 19:06:00 +00:00
|
|
|
|
_get_arg(self, i-1, &obj);
|
1999-07-03 19:59:44 +00:00
|
|
|
|
RELEASE(obj);
|
1998-08-13 20:45:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-02-04 18:18:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CLEAR_RETURN_VALUE_IF_OBJECT;
|
2005-02-22 11:22:44 +00:00
|
|
|
|
|
2002-02-20 05:08:46 +00:00
|
|
|
|
#if defined(USE_LIBFFI)
|
2000-12-08 19:06:00 +00:00
|
|
|
|
if (_cframe)
|
2002-02-20 05:08:46 +00:00
|
|
|
|
{
|
2002-04-18 16:02:12 +00:00
|
|
|
|
NSZoneFree(NSDefaultMallocZone(), _cframe);
|
2002-02-20 05:08:46 +00:00
|
|
|
|
_retval = 0; // Part of _cframe
|
|
|
|
|
}
|
|
|
|
|
#elif defined(USE_FFCALL)
|
2000-12-08 19:06:00 +00:00
|
|
|
|
if (_cframe)
|
2001-09-21 15:14:57 +00:00
|
|
|
|
{
|
|
|
|
|
NSZoneFree(NSDefaultMallocZone(), _cframe);
|
|
|
|
|
_retval = 0; // Part of _cframe
|
|
|
|
|
}
|
2002-02-20 05:08:46 +00:00
|
|
|
|
#else
|
|
|
|
|
if (_cframe)
|
1998-10-28 13:58:05 +00:00
|
|
|
|
{
|
2002-02-20 05:08:46 +00:00
|
|
|
|
mframe_destroy_argframe([_sig methodType], (arglist_t)_cframe);
|
1998-08-13 20:45:32 +00:00
|
|
|
|
}
|
1999-09-16 07:21:34 +00:00
|
|
|
|
if (_retval)
|
1998-10-28 13:58:05 +00:00
|
|
|
|
{
|
1999-09-28 11:10:34 +00:00
|
|
|
|
NSZoneFree(NSDefaultMallocZone(), _retval);
|
1998-08-13 20:45:32 +00:00
|
|
|
|
}
|
2002-02-20 05:08:46 +00:00
|
|
|
|
#endif
|
1999-09-16 07:21:34 +00:00
|
|
|
|
RELEASE(_sig);
|
1998-10-28 13:58:05 +00:00
|
|
|
|
[super dealloc];
|
1994-11-08 16:44:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-04-04 10:03:08 +00:00
|
|
|
|
/**
|
|
|
|
|
* Copies the argument identified by index into the memory location specified
|
|
|
|
|
* by the buffer argument.<br />
|
|
|
|
|
* An index of zero is the target object, an index of one is the selector,
|
|
|
|
|
* so the actual method arguments start at index 2.
|
1998-08-13 20:45:32 +00:00
|
|
|
|
*/
|
|
|
|
|
- (void) getArgument: (void*)buffer
|
|
|
|
|
atIndex: (int)index
|
1994-11-08 16:44:01 +00:00
|
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
|
if ((unsigned)index >= _numArgs)
|
1998-10-28 13:58:05 +00:00
|
|
|
|
{
|
|
|
|
|
[NSException raise: NSInvalidArgumentException
|
|
|
|
|
format: @"bad invocation argument index"];
|
1998-08-13 20:45:32 +00:00
|
|
|
|
}
|
1998-10-28 13:58:05 +00:00
|
|
|
|
if (index == 0)
|
|
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
|
*(id*)buffer = _target;
|
1998-08-13 20:45:32 +00:00
|
|
|
|
}
|
1998-10-28 13:58:05 +00:00
|
|
|
|
else if (index == 1)
|
|
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
|
*(SEL*)buffer = _selector;
|
1998-01-26 14:18:18 +00:00
|
|
|
|
}
|
1998-10-28 13:58:05 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2000-12-08 19:06:00 +00:00
|
|
|
|
_get_arg(self, index, buffer);
|
1998-08-13 20:45:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-04 10:59:11 +00:00
|
|
|
|
/**
|
|
|
|
|
* Copies the invocations return value to the location pointed to by buffer
|
|
|
|
|
* if a return value has been set (see the -setReturnValue: method).<br />
|
|
|
|
|
* If there isn't a return value then this method raises an exception.
|
|
|
|
|
*/
|
1998-08-13 20:45:32 +00:00
|
|
|
|
- (void) getReturnValue: (void*)buffer
|
|
|
|
|
{
|
1998-10-28 13:58:05 +00:00
|
|
|
|
const char *type;
|
|
|
|
|
|
1999-09-16 07:21:34 +00:00
|
|
|
|
if (_validReturn == NO)
|
1998-10-28 13:58:05 +00:00
|
|
|
|
{
|
|
|
|
|
[NSException raise: NSGenericException
|
|
|
|
|
format: @"getReturnValue with no value set"];
|
|
|
|
|
}
|
1998-08-13 20:45:32 +00:00
|
|
|
|
|
1999-09-16 07:21:34 +00:00
|
|
|
|
type = [_sig methodReturnType];
|
1998-08-13 20:45:32 +00:00
|
|
|
|
|
1999-09-16 07:21:34 +00:00
|
|
|
|
if (*_info[0].type != _C_VOID)
|
1998-10-28 13:58:05 +00:00
|
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
|
int length = _info[0].size;
|
1998-08-13 20:45:32 +00:00
|
|
|
|
#if WORDS_BIGENDIAN
|
1998-10-28 13:58:05 +00:00
|
|
|
|
if (length < sizeof(void*))
|
|
|
|
|
length = sizeof(void*);
|
1998-01-26 14:18:18 +00:00
|
|
|
|
#endif
|
1999-09-16 07:21:34 +00:00
|
|
|
|
memcpy(buffer, _retval, length);
|
1998-08-13 20:45:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-04 10:59:11 +00:00
|
|
|
|
/**
|
|
|
|
|
* Returns the selector of the invocation (the argument at index 1)
|
|
|
|
|
*/
|
1998-08-13 20:45:32 +00:00
|
|
|
|
- (SEL) selector
|
|
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
|
return _selector;
|
1998-08-13 20:45:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-04-04 10:59:11 +00:00
|
|
|
|
/**
|
|
|
|
|
* Sets the argument identified by index from the memory location specified
|
|
|
|
|
* by the buffer argument.<br />
|
|
|
|
|
* Using an index of 0 is equivalent to calling -setTarget: and using an
|
|
|
|
|
* argument of 1 is equivalent to -setSelector:<br />
|
|
|
|
|
* Proper arguments start at index 2.<br />
|
2003-04-12 05:13:54 +00:00
|
|
|
|
* NB. Unlike -setTarget: and -setSelector: the value of buffer must be
|
|
|
|
|
* <em>a pointer to</em> the argument to be set in the invocation.<br />
|
2003-04-04 10:59:11 +00:00
|
|
|
|
* If -retainArguments was called, then any object argument set in the
|
|
|
|
|
* receiver is retained by it.
|
|
|
|
|
*/
|
1998-08-13 20:45:32 +00:00
|
|
|
|
- (void) setArgument: (void*)buffer
|
|
|
|
|
atIndex: (int)index
|
|
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
|
if ((unsigned)index >= _numArgs)
|
1998-10-28 13:58:05 +00:00
|
|
|
|
{
|
|
|
|
|
[NSException raise: NSInvalidArgumentException
|
|
|
|
|
format: @"bad invocation argument index"];
|
1998-08-13 20:45:32 +00:00
|
|
|
|
}
|
1998-10-28 13:58:05 +00:00
|
|
|
|
if (index == 0)
|
|
|
|
|
{
|
|
|
|
|
[self setTarget: *(id*)buffer];
|
1998-08-13 20:45:32 +00:00
|
|
|
|
}
|
1998-10-28 13:58:05 +00:00
|
|
|
|
else if (index == 1)
|
|
|
|
|
{
|
|
|
|
|
[self setSelector: *(SEL*)buffer];
|
1998-08-13 20:45:32 +00:00
|
|
|
|
}
|
1998-10-28 13:58:05 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
|
int i = index+1; /* Allow for return type in '_info' */
|
|
|
|
|
const char *type = _info[i].type;
|
1998-10-28 13:58:05 +00:00
|
|
|
|
|
1999-09-16 07:21:34 +00:00
|
|
|
|
if (_argsRetained && (*type == _C_ID || *type == _C_CHARPTR))
|
1998-10-28 13:58:05 +00:00
|
|
|
|
{
|
|
|
|
|
if (*type == _C_ID)
|
|
|
|
|
{
|
|
|
|
|
id old;
|
|
|
|
|
|
2000-12-08 19:06:00 +00:00
|
|
|
|
_get_arg(self, index, &old);
|
|
|
|
|
_set_arg(self, index, buffer);
|
1999-09-28 19:35:09 +00:00
|
|
|
|
IF_NO_GC(RETAIN(*(id*)buffer));
|
1998-10-28 13:58:05 +00:00
|
|
|
|
if (old != nil)
|
|
|
|
|
{
|
1999-07-03 19:59:44 +00:00
|
|
|
|
RELEASE(old);
|
1998-08-13 20:45:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
1998-10-28 13:58:05 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
char *oldstr;
|
|
|
|
|
char *newstr = *(char**)buffer;
|
1998-08-13 20:45:32 +00:00
|
|
|
|
|
2000-12-08 19:06:00 +00:00
|
|
|
|
_get_arg(self, index, &oldstr);
|
1998-10-28 13:58:05 +00:00
|
|
|
|
if (newstr == 0)
|
|
|
|
|
{
|
2000-12-08 19:06:00 +00:00
|
|
|
|
_set_arg(self, index, buffer);
|
1998-08-13 20:45:32 +00:00
|
|
|
|
}
|
1998-10-28 13:58:05 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
1999-09-28 11:10:34 +00:00
|
|
|
|
char *tmp;
|
1998-08-13 20:45:32 +00:00
|
|
|
|
|
1999-09-28 11:10:34 +00:00
|
|
|
|
tmp = NSZoneMalloc(NSDefaultMallocZone(), strlen(newstr)+1);
|
1998-10-28 13:58:05 +00:00
|
|
|
|
strcpy(tmp, newstr);
|
2000-12-08 19:06:00 +00:00
|
|
|
|
_set_arg(self, index, tmp);
|
1998-08-13 20:45:32 +00:00
|
|
|
|
}
|
1998-10-28 13:58:05 +00:00
|
|
|
|
if (oldstr != 0)
|
|
|
|
|
{
|
1999-09-28 11:10:34 +00:00
|
|
|
|
NSZoneFree(NSDefaultMallocZone(), oldstr);
|
1998-08-13 20:45:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
1998-10-28 13:58:05 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2000-12-08 19:06:00 +00:00
|
|
|
|
_set_arg(self, index, buffer);
|
1998-08-13 20:45:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-04 10:59:11 +00:00
|
|
|
|
/**
|
|
|
|
|
* Sets the return value of the invocation to the item that buffer points to.
|
|
|
|
|
*/
|
1998-08-13 20:45:32 +00:00
|
|
|
|
- (void) setReturnValue: (void*)buffer
|
|
|
|
|
{
|
1998-10-28 13:58:05 +00:00
|
|
|
|
const char *type;
|
1998-08-13 20:45:32 +00:00
|
|
|
|
|
1999-09-16 07:21:34 +00:00
|
|
|
|
type = _info[0].type;
|
1998-08-13 20:45:32 +00:00
|
|
|
|
|
2003-02-04 18:18:47 +00:00
|
|
|
|
CLEAR_RETURN_VALUE_IF_OBJECT;
|
2005-02-22 11:22:44 +00:00
|
|
|
|
|
1998-10-28 13:58:05 +00:00
|
|
|
|
if (*type != _C_VOID)
|
|
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
|
int length = _info[0].size;
|
1998-08-13 20:45:32 +00:00
|
|
|
|
|
|
|
|
|
#if WORDS_BIGENDIAN
|
1998-10-28 13:58:05 +00:00
|
|
|
|
if (length < sizeof(void*))
|
|
|
|
|
length = sizeof(void*);
|
1998-08-13 20:45:32 +00:00
|
|
|
|
#endif
|
1999-09-16 07:21:34 +00:00
|
|
|
|
memcpy(_retval, buffer, length);
|
1998-08-13 20:45:32 +00:00
|
|
|
|
}
|
2003-02-04 18:18:47 +00:00
|
|
|
|
|
|
|
|
|
RETAIN_RETURN_VALUE;
|
1999-09-16 07:21:34 +00:00
|
|
|
|
_validReturn = YES;
|
1998-08-13 20:45:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-04-04 10:59:11 +00:00
|
|
|
|
/**
|
|
|
|
|
* Sets the selector for the invocation.
|
|
|
|
|
*/
|
1998-08-13 20:45:32 +00:00
|
|
|
|
- (void) setSelector: (SEL)aSelector
|
|
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
|
_selector = aSelector;
|
1998-08-13 20:45:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-04-04 10:59:11 +00:00
|
|
|
|
/**
|
|
|
|
|
* Sets the target object for the invocation.<br />
|
|
|
|
|
* If -retainArguments was called, then the target is retained.
|
|
|
|
|
*/
|
1998-08-13 20:45:32 +00:00
|
|
|
|
- (void) setTarget: (id)anObject
|
|
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
|
if (_argsRetained)
|
1998-10-28 13:58:05 +00:00
|
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
|
ASSIGN(_target, anObject);
|
1998-08-13 20:45:32 +00:00
|
|
|
|
}
|
1999-09-16 07:21:34 +00:00
|
|
|
|
_target = anObject;
|
1998-08-13 20:45:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-04-04 10:59:11 +00:00
|
|
|
|
/**
|
|
|
|
|
* Returns the target object of the invocation.
|
|
|
|
|
*/
|
1998-08-13 20:45:32 +00:00
|
|
|
|
- (id) target
|
|
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
|
return _target;
|
1998-08-13 20:45:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-04-04 10:59:11 +00:00
|
|
|
|
/**
|
|
|
|
|
* Returns a flag to indicate whether object arguments of the invocation
|
|
|
|
|
* (including its target) are retained by the invocation.
|
1998-08-13 20:45:32 +00:00
|
|
|
|
*/
|
|
|
|
|
- (BOOL) argumentsRetained
|
|
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
|
return _argsRetained;
|
1998-08-13 20:45:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-04-04 10:59:11 +00:00
|
|
|
|
/**
|
|
|
|
|
* Instructs the invocation to retain its object arguments (including the
|
|
|
|
|
* target). The default is not to retain them.
|
|
|
|
|
*/
|
1999-09-16 07:21:34 +00:00
|
|
|
|
- (void) retainArguments
|
1998-08-13 20:45:32 +00:00
|
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
|
if (_argsRetained)
|
1998-10-28 13:58:05 +00:00
|
|
|
|
{
|
|
|
|
|
return;
|
1998-08-13 20:45:32 +00:00
|
|
|
|
}
|
1998-10-28 13:58:05 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2003-01-03 20:14:47 +00:00
|
|
|
|
unsigned int i;
|
1998-10-28 13:58:05 +00:00
|
|
|
|
|
1999-09-16 07:21:34 +00:00
|
|
|
|
_argsRetained = YES;
|
1999-09-28 19:35:09 +00:00
|
|
|
|
IF_NO_GC(RETAIN(_target));
|
2002-02-20 05:08:46 +00:00
|
|
|
|
if (_cframe == 0)
|
1998-10-28 13:58:05 +00:00
|
|
|
|
{
|
|
|
|
|
return;
|
1998-08-13 20:45:32 +00:00
|
|
|
|
}
|
1999-09-16 07:21:34 +00:00
|
|
|
|
for (i = 3; i <= _numArgs; i++)
|
1998-10-28 13:58:05 +00:00
|
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
|
if (*_info[i].type == _C_ID || *_info[i].type == _C_CHARPTR)
|
1998-10-28 13:58:05 +00:00
|
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
|
if (*_info[i].type == _C_ID)
|
1998-10-28 13:58:05 +00:00
|
|
|
|
{
|
|
|
|
|
id old;
|
|
|
|
|
|
2000-12-08 19:06:00 +00:00
|
|
|
|
_get_arg(self, i-1, &old);
|
1998-10-28 13:58:05 +00:00
|
|
|
|
if (old != nil)
|
|
|
|
|
{
|
1999-09-28 19:35:09 +00:00
|
|
|
|
IF_NO_GC(RETAIN(old));
|
1998-08-13 20:45:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
1998-10-28 13:58:05 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
char *str;
|
1998-08-13 20:45:32 +00:00
|
|
|
|
|
2000-12-08 19:06:00 +00:00
|
|
|
|
_get_arg(self, i-1, &str);
|
1998-10-28 13:58:05 +00:00
|
|
|
|
if (str != 0)
|
|
|
|
|
{
|
1999-09-28 11:10:34 +00:00
|
|
|
|
char *tmp;
|
1998-08-13 20:45:32 +00:00
|
|
|
|
|
1999-09-28 11:10:34 +00:00
|
|
|
|
tmp = NSZoneMalloc(NSDefaultMallocZone(), strlen(str)+1);
|
1998-10-28 13:58:05 +00:00
|
|
|
|
strcpy(tmp, str);
|
2000-12-08 19:06:00 +00:00
|
|
|
|
_set_arg(self, i-1, &tmp);
|
1998-08-13 20:45:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-04 10:59:11 +00:00
|
|
|
|
/**
|
|
|
|
|
* Sends the message encapsulated in the invocation to its target.
|
1998-08-13 20:45:32 +00:00
|
|
|
|
*/
|
|
|
|
|
- (void) invoke
|
|
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
|
[self invokeWithTarget: _target];
|
1998-08-13 20:45:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-04-04 10:59:11 +00:00
|
|
|
|
/**
|
|
|
|
|
* Sends the message encapsulated in the invocation to anObject.
|
|
|
|
|
*/
|
1999-09-16 07:21:34 +00:00
|
|
|
|
- (void) invokeWithTarget: (id)anObject
|
1998-08-13 20:45:32 +00:00
|
|
|
|
{
|
1998-10-28 13:58:05 +00:00
|
|
|
|
id old_target;
|
|
|
|
|
retval_t returned;
|
|
|
|
|
IMP imp;
|
|
|
|
|
int stack_argsize;
|
|
|
|
|
|
2003-02-04 18:18:47 +00:00
|
|
|
|
|
|
|
|
|
CLEAR_RETURN_VALUE_IF_OBJECT;
|
|
|
|
|
_validReturn = NO;
|
|
|
|
|
|
1998-10-28 13:58:05 +00:00
|
|
|
|
/*
|
|
|
|
|
* A message to a nil object returns nil.
|
|
|
|
|
*/
|
|
|
|
|
if (anObject == nil)
|
|
|
|
|
{
|
2003-02-04 18:18:47 +00:00
|
|
|
|
_validReturn = YES;
|
1999-09-16 07:21:34 +00:00
|
|
|
|
memset(_retval, '\0', _info[0].size); /* Clear return value */
|
1998-10-28 13:58:05 +00:00
|
|
|
|
return;
|
1998-08-13 20:45:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-16 07:21:34 +00:00
|
|
|
|
NSAssert(_selector != 0, @"you must set the selector before invoking");
|
1998-08-13 20:45:32 +00:00
|
|
|
|
|
1998-10-28 13:58:05 +00:00
|
|
|
|
/*
|
|
|
|
|
* Temporarily set new target and copy it (and the selector) into the
|
2002-02-20 05:08:46 +00:00
|
|
|
|
* _cframe.
|
1998-10-28 13:58:05 +00:00
|
|
|
|
*/
|
1999-09-16 07:21:34 +00:00
|
|
|
|
old_target = RETAIN(_target);
|
1998-10-28 13:58:05 +00:00
|
|
|
|
[self setTarget: anObject];
|
1998-08-13 20:45:32 +00:00
|
|
|
|
|
2000-12-08 19:06:00 +00:00
|
|
|
|
_set_arg(self, 0, &_target);
|
|
|
|
|
_set_arg(self, 1, &_selector);
|
1998-08-13 20:45:32 +00:00
|
|
|
|
|
2001-05-15 17:11:10 +00:00
|
|
|
|
if (_sendToSuper == YES)
|
|
|
|
|
{
|
|
|
|
|
Super s;
|
|
|
|
|
|
2001-07-15 03:51:11 +00:00
|
|
|
|
#ifndef NeXT_RUNTIME
|
2001-05-15 17:11:10 +00:00
|
|
|
|
s.self = _target;
|
2001-07-15 03:51:11 +00:00
|
|
|
|
#else
|
|
|
|
|
s.receiver = _target;
|
|
|
|
|
#endif
|
2001-05-15 17:11:10 +00:00
|
|
|
|
if (GSObjCIsInstance(_target))
|
2003-08-24 23:07:41 +00:00
|
|
|
|
s.class = GSObjCSuper(GSObjCClass(_target));
|
2001-05-15 17:11:10 +00:00
|
|
|
|
else
|
2003-08-24 23:07:41 +00:00
|
|
|
|
s.class = GSObjCSuper((Class)_target);
|
2001-05-15 17:11:10 +00:00
|
|
|
|
imp = objc_msg_lookup_super(&s, _selector);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2004-08-20 17:53:16 +00:00
|
|
|
|
GSMethod method;
|
|
|
|
|
method = GSGetMethod((GSObjCIsInstance(_target)
|
|
|
|
|
? GSObjCClass(_target)
|
|
|
|
|
: _target),
|
|
|
|
|
_selector,
|
|
|
|
|
GSObjCIsInstance(_target),
|
|
|
|
|
YES);
|
|
|
|
|
imp = method_get_imp(method);
|
2001-05-15 17:11:10 +00:00
|
|
|
|
/*
|
|
|
|
|
* If fast lookup failed, we may be forwarding or something ...
|
|
|
|
|
*/
|
|
|
|
|
if (imp == 0)
|
|
|
|
|
imp = objc_msg_lookup(_target, _selector);
|
|
|
|
|
}
|
1998-10-28 13:58:05 +00:00
|
|
|
|
[self setTarget: old_target];
|
1999-07-03 19:59:44 +00:00
|
|
|
|
RELEASE(old_target);
|
1998-08-13 20:45:32 +00:00
|
|
|
|
|
1999-09-16 07:21:34 +00:00
|
|
|
|
stack_argsize = [_sig frameLength];
|
1998-08-13 20:45:32 +00:00
|
|
|
|
|
2002-02-20 05:08:46 +00:00
|
|
|
|
returned = __builtin_apply((void(*)(void))imp,
|
|
|
|
|
(arglist_t)_cframe, stack_argsize);
|
1999-09-16 07:21:34 +00:00
|
|
|
|
if (_info[0].size)
|
1998-10-28 13:58:05 +00:00
|
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
|
mframe_decode_return(_info[0].type, _retval, returned);
|
1998-08-13 20:45:32 +00:00
|
|
|
|
}
|
2003-02-04 18:18:47 +00:00
|
|
|
|
|
|
|
|
|
RETAIN_RETURN_VALUE;
|
1999-09-16 07:21:34 +00:00
|
|
|
|
_validReturn = YES;
|
1998-08-13 20:45:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-04-04 10:59:11 +00:00
|
|
|
|
/**
|
|
|
|
|
* Returns the method signature of the invocation.
|
1998-08-13 20:45:32 +00:00
|
|
|
|
*/
|
|
|
|
|
- (NSMethodSignature*) methodSignature
|
|
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
|
return _sig;
|
1998-08-13 20:45:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-09-16 07:21:34 +00:00
|
|
|
|
- (NSString*) description
|
1998-08-13 20:45:32 +00:00
|
|
|
|
{
|
1998-10-28 13:58:05 +00:00
|
|
|
|
/*
|
|
|
|
|
* Don't use -[NSString stringWithFormat:] method because it can cause
|
|
|
|
|
* infinite recursion.
|
|
|
|
|
*/
|
|
|
|
|
char buffer[1024];
|
1998-08-13 20:45:32 +00:00
|
|
|
|
|
2003-08-24 23:07:41 +00:00
|
|
|
|
snprintf (buffer, 1024, "<%s %p selector: %s target: %s>", \
|
|
|
|
|
GSClassNameFromObject(self), \
|
1998-08-13 20:45:32 +00:00
|
|
|
|
self, \
|
2003-08-24 23:07:41 +00:00
|
|
|
|
_selector ? GSNameFromSelector(_selector) : "nil", \
|
|
|
|
|
_target ? GSNameFromClass([_target class]) : "nil" \
|
2005-02-22 11:22:44 +00:00
|
|
|
|
);
|
1998-08-13 20:45:32 +00:00
|
|
|
|
|
2003-08-24 23:07:41 +00:00
|
|
|
|
return [NSString stringWithCString: buffer];
|
1998-08-13 20:45:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) encodeWithCoder: (NSCoder*)aCoder
|
|
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
|
const char *types = [_sig methodType];
|
2003-01-03 20:14:47 +00:00
|
|
|
|
unsigned int i;
|
1998-08-13 20:45:32 +00:00
|
|
|
|
|
1998-10-28 13:58:05 +00:00
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(char*)
|
|
|
|
|
at: &types];
|
1998-08-13 20:45:32 +00:00
|
|
|
|
|
1999-09-16 07:21:34 +00:00
|
|
|
|
[aCoder encodeObject: _target];
|
1998-08-13 20:45:32 +00:00
|
|
|
|
|
1999-09-16 07:21:34 +00:00
|
|
|
|
[aCoder encodeValueOfObjCType: _info[2].type
|
|
|
|
|
at: &_selector];
|
1998-08-13 20:45:32 +00:00
|
|
|
|
|
1999-09-16 07:21:34 +00:00
|
|
|
|
for (i = 3; i <= _numArgs; i++)
|
1998-10-28 13:58:05 +00:00
|
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
|
const char *type = _info[i].type;
|
1998-10-28 13:58:05 +00:00
|
|
|
|
void *datum;
|
1998-08-13 20:45:32 +00:00
|
|
|
|
|
2000-12-08 19:06:00 +00:00
|
|
|
|
datum = _arg_addr(self, i-1);
|
1998-08-13 20:45:32 +00:00
|
|
|
|
|
1998-10-28 13:58:05 +00:00
|
|
|
|
if (*type == _C_ID)
|
|
|
|
|
{
|
|
|
|
|
[aCoder encodeObject: *(id*)datum];
|
|
|
|
|
}
|
2000-12-08 19:06:00 +00:00
|
|
|
|
#if !defined(USE_LIBFFI) && !defined(USE_FFCALL)
|
1999-01-04 15:23:17 +00:00
|
|
|
|
#if MFRAME_STRUCT_BYREF
|
|
|
|
|
else if (*type == _C_STRUCT_B || *type == _C_UNION_B || *type == _C_ARY_B)
|
|
|
|
|
{
|
|
|
|
|
[aCoder encodeValueOfObjCType: type at: *(void**)datum];
|
|
|
|
|
}
|
2000-12-08 19:06:00 +00:00
|
|
|
|
#endif
|
1999-01-04 15:23:17 +00:00
|
|
|
|
#endif
|
1998-10-28 13:58:05 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
[aCoder encodeValueOfObjCType: type at: datum];
|
|
|
|
|
}
|
|
|
|
|
}
|
1999-09-16 07:21:34 +00:00
|
|
|
|
if (*_info[0].type != _C_VOID)
|
1998-10-28 13:58:05 +00:00
|
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &_validReturn];
|
|
|
|
|
if (_validReturn)
|
1998-10-28 13:58:05 +00:00
|
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
|
[aCoder encodeValueOfObjCType: _info[0].type at: _retval];
|
1998-10-28 13:58:05 +00:00
|
|
|
|
}
|
1998-08-13 20:45:32 +00:00
|
|
|
|
}
|
1994-11-08 16:44:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-08-13 20:45:32 +00:00
|
|
|
|
- (id) initWithCoder: (NSCoder*)aCoder
|
|
|
|
|
{
|
1998-10-28 13:58:05 +00:00
|
|
|
|
NSMethodSignature *newSig;
|
|
|
|
|
const char *types;
|
|
|
|
|
void *datum;
|
2003-01-03 20:14:47 +00:00
|
|
|
|
unsigned int i;
|
2005-02-22 11:22:44 +00:00
|
|
|
|
|
1998-10-28 13:58:05 +00:00
|
|
|
|
[aCoder decodeValueOfObjCType: @encode(char*) at: &types];
|
|
|
|
|
newSig = [NSMethodSignature signatureWithObjCTypes: types];
|
2000-07-02 18:57:05 +00:00
|
|
|
|
NSZoneFree(NSDefaultMallocZone(), (void*)types);
|
2000-12-08 19:06:00 +00:00
|
|
|
|
|
|
|
|
|
RELEASE(self);
|
|
|
|
|
self = [NSInvocation invocationWithMethodSignature: newSig];
|
|
|
|
|
RETAIN(self);
|
2005-02-22 11:22:44 +00:00
|
|
|
|
|
1999-09-16 07:21:34 +00:00
|
|
|
|
[aCoder decodeValueOfObjCType: @encode(id) at: &_target];
|
1998-08-13 20:45:32 +00:00
|
|
|
|
|
1999-09-16 07:21:34 +00:00
|
|
|
|
[aCoder decodeValueOfObjCType: @encode(SEL) at: &_selector];
|
1998-08-13 20:45:32 +00:00
|
|
|
|
|
1999-09-16 07:21:34 +00:00
|
|
|
|
for (i = 3; i <= _numArgs; i++)
|
1998-10-28 13:58:05 +00:00
|
|
|
|
{
|
2000-12-08 19:06:00 +00:00
|
|
|
|
datum = _arg_addr(self, i-1);
|
|
|
|
|
#if !defined(USE_LIBFFI) && !defined(USE_FFCALL)
|
1999-01-04 15:23:17 +00:00
|
|
|
|
#if MFRAME_STRUCT_BYREF
|
|
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
|
const char *t = _info[i].type;
|
1999-01-04 15:23:17 +00:00
|
|
|
|
if (*t == _C_STRUCT_B || *t == _C_UNION_B || *t == _C_ARY_B)
|
|
|
|
|
{
|
2003-03-02 07:47:18 +00:00
|
|
|
|
*(void**)datum = GSAutoreleasedBuffer(_info[i].size);
|
1999-01-04 16:04:14 +00:00
|
|
|
|
datum = *(void**)datum;
|
1999-01-04 15:23:17 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2000-12-08 19:06:00 +00:00
|
|
|
|
#endif
|
1999-01-04 15:23:17 +00:00
|
|
|
|
#endif
|
1999-09-16 07:21:34 +00:00
|
|
|
|
[aCoder decodeValueOfObjCType: _info[i].type at: datum];
|
1998-08-13 20:45:32 +00:00
|
|
|
|
}
|
1999-09-16 07:21:34 +00:00
|
|
|
|
_argsRetained = YES;
|
|
|
|
|
if (*_info[0].type != _C_VOID)
|
1998-10-28 13:58:05 +00:00
|
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
|
[aCoder decodeValueOfObjCType: @encode(BOOL) at: &_validReturn];
|
|
|
|
|
if (_validReturn)
|
2003-02-04 18:18:47 +00:00
|
|
|
|
{
|
|
|
|
|
[aCoder decodeValueOfObjCType: _info[0].type at: _retval];
|
|
|
|
|
}
|
1998-10-28 13:58:05 +00:00
|
|
|
|
}
|
|
|
|
|
return self;
|
1998-08-13 20:45:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
1994-11-08 16:44:01 +00:00
|
|
|
|
@end
|
1998-08-13 20:45:32 +00:00
|
|
|
|
|
2003-04-04 10:59:11 +00:00
|
|
|
|
/**
|
|
|
|
|
* Provides some minor extensions and some utility methods to aid
|
2004-06-22 22:40:40 +00:00
|
|
|
|
* integration of <code>NSInvocation</code> with the Objective-C runtime.
|
2003-04-04 10:59:11 +00:00
|
|
|
|
*/
|
1998-08-13 20:45:32 +00:00
|
|
|
|
@implementation NSInvocation (GNUstep)
|
|
|
|
|
|
2003-04-04 10:59:11 +00:00
|
|
|
|
/**
|
|
|
|
|
* Internal use.<br />
|
|
|
|
|
* Initialises the receiver with a known selector and argument list
|
|
|
|
|
* as supplied to the forward:: method by the ObjectiveC runtime
|
|
|
|
|
* when it is unable to locate an implementation for mthe selector
|
|
|
|
|
* in a class.
|
|
|
|
|
*/
|
1999-09-16 07:21:34 +00:00
|
|
|
|
- (id) initWithArgframe: (arglist_t)frame selector: (SEL)aSelector
|
1998-08-13 20:45:32 +00:00
|
|
|
|
{
|
2000-12-08 19:06:00 +00:00
|
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
|
return nil;
|
1998-08-13 20:45:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-04-04 10:03:08 +00:00
|
|
|
|
/** <init /><override-subclass />
|
|
|
|
|
* Initialised an invocation instance which can be used to send messages to
|
|
|
|
|
* a target object using aSignature.<br />
|
2003-04-17 06:20:17 +00:00
|
|
|
|
* You must set the target and selector (using -setTarget: and -setSelector:)
|
|
|
|
|
* before you attempt to use the invocation.<br />
|
2003-04-04 10:03:08 +00:00
|
|
|
|
* Raises an NSInvalidArgumentException if aSignature is nil.
|
1998-08-13 20:45:32 +00:00
|
|
|
|
*/
|
1999-09-16 07:21:34 +00:00
|
|
|
|
- (id) initWithMethodSignature: (NSMethodSignature*)aSignature
|
1998-08-13 20:45:32 +00:00
|
|
|
|
{
|
2000-12-08 19:06:00 +00:00
|
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
|
return nil;
|
1998-08-13 20:45:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-04-04 10:03:08 +00:00
|
|
|
|
/**
|
|
|
|
|
* Tries to produce a method signature based on aSelector and uses that to
|
|
|
|
|
* initialise self by calling the -initWithMethodSignature: method.<br />
|
|
|
|
|
* If the argument type of aSelector cannot be determined, this releases self
|
|
|
|
|
* and returns nil.
|
|
|
|
|
*/
|
1999-09-16 07:21:34 +00:00
|
|
|
|
- (id) initWithSelector: (SEL)aSelector
|
1998-08-13 20:45:32 +00:00
|
|
|
|
{
|
2002-07-29 19:37:40 +00:00
|
|
|
|
const char *types;
|
|
|
|
|
NSMethodSignature *newSig;
|
|
|
|
|
|
|
|
|
|
types = sel_get_type(aSelector);
|
|
|
|
|
if (types == 0)
|
|
|
|
|
{
|
2003-08-24 23:07:41 +00:00
|
|
|
|
types = sel_get_type(sel_get_any_typed_uid(GSNameFromSelector(aSelector)));
|
2002-07-29 19:37:40 +00:00
|
|
|
|
}
|
|
|
|
|
if (types == 0)
|
|
|
|
|
{
|
|
|
|
|
NSLog(@"Couldn't find encoding type for selector %s.",
|
2003-08-24 23:07:41 +00:00
|
|
|
|
GSNameFromSelector(aSelector));
|
2002-07-29 19:37:40 +00:00
|
|
|
|
RELEASE(self);
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
newSig = [NSMethodSignature signatureWithObjCTypes: types];
|
|
|
|
|
return [self initWithMethodSignature: newSig];
|
1998-08-13 20:45:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-04-04 10:59:11 +00:00
|
|
|
|
/**
|
|
|
|
|
* Initialises the reciever with the specified target, selector, and
|
|
|
|
|
* a variable number of arguments.
|
|
|
|
|
*/
|
1999-09-16 07:21:34 +00:00
|
|
|
|
- (id) initWithTarget: anObject selector: (SEL)aSelector, ...
|
1998-08-13 20:45:32 +00:00
|
|
|
|
{
|
2002-07-29 19:37:40 +00:00
|
|
|
|
va_list ap;
|
|
|
|
|
NSMethodSignature *newSig;
|
1998-08-13 20:45:32 +00:00
|
|
|
|
|
2002-07-29 19:37:40 +00:00
|
|
|
|
if (anObject)
|
|
|
|
|
{
|
|
|
|
|
newSig = [anObject methodSignatureForSelector: aSelector];
|
|
|
|
|
self = [self initWithMethodSignature: newSig];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
self = [self initWithSelector: aSelector];
|
|
|
|
|
}
|
1998-10-28 13:58:05 +00:00
|
|
|
|
if (self)
|
|
|
|
|
{
|
2003-01-03 20:14:47 +00:00
|
|
|
|
unsigned int i;
|
1998-08-13 20:45:32 +00:00
|
|
|
|
|
1998-10-28 13:58:05 +00:00
|
|
|
|
[self setTarget: anObject];
|
2002-07-29 19:37:40 +00:00
|
|
|
|
[self setSelector: aSelector];
|
1998-10-28 13:58:05 +00:00
|
|
|
|
va_start (ap, aSelector);
|
1999-09-16 07:21:34 +00:00
|
|
|
|
for (i = 3; i <= _numArgs; i++)
|
1998-10-28 13:58:05 +00:00
|
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
|
const char *type = _info[i].type;
|
|
|
|
|
unsigned size = _info[i].size;
|
1998-10-28 13:58:05 +00:00
|
|
|
|
void *datum;
|
1998-08-13 20:45:32 +00:00
|
|
|
|
|
2000-12-08 19:06:00 +00:00
|
|
|
|
datum = _arg_addr(self, i-1);
|
1998-08-13 20:45:32 +00:00
|
|
|
|
|
|
|
|
|
#define CASE_TYPE(_C,_T) case _C: *(_T*)datum = va_arg (ap, _T); break
|
1998-10-28 13:58:05 +00:00
|
|
|
|
switch (*type)
|
|
|
|
|
{
|
|
|
|
|
case _C_ID:
|
|
|
|
|
*(id*)datum = va_arg (ap, id);
|
1999-09-16 07:21:34 +00:00
|
|
|
|
if (_argsRetained)
|
1998-10-28 13:58:05 +00:00
|
|
|
|
{
|
1999-09-28 19:35:09 +00:00
|
|
|
|
IF_NO_GC(RETAIN(*(id*)datum));
|
1998-10-28 13:58:05 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case _C_CHARPTR:
|
|
|
|
|
*(char**)datum = va_arg (ap, char*);
|
1999-09-16 07:21:34 +00:00
|
|
|
|
if (_argsRetained)
|
1998-10-28 13:58:05 +00:00
|
|
|
|
{
|
|
|
|
|
char *old = *(char**)datum;
|
|
|
|
|
|
|
|
|
|
if (old != 0)
|
|
|
|
|
{
|
1999-09-28 11:10:34 +00:00
|
|
|
|
char *tmp;
|
1998-10-28 13:58:05 +00:00
|
|
|
|
|
1999-09-28 11:10:34 +00:00
|
|
|
|
tmp = NSZoneMalloc(NSDefaultMallocZone(),strlen(old)+1);
|
1998-10-28 13:58:05 +00:00
|
|
|
|
strcpy(tmp, old);
|
|
|
|
|
*(char**)datum = tmp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
CASE_TYPE(_C_CLASS, Class);
|
|
|
|
|
CASE_TYPE(_C_SEL, SEL);
|
|
|
|
|
CASE_TYPE(_C_LNG, long);
|
|
|
|
|
CASE_TYPE(_C_ULNG, unsigned long);
|
|
|
|
|
CASE_TYPE(_C_INT, int);
|
|
|
|
|
CASE_TYPE(_C_UINT, unsigned int);
|
1999-10-21 09:09:00 +00:00
|
|
|
|
case _C_SHT:
|
|
|
|
|
*(short*)datum = (short)va_arg(ap, int);
|
|
|
|
|
break;
|
|
|
|
|
case _C_USHT:
|
|
|
|
|
*(unsigned short*)datum = (unsigned short)va_arg(ap, int);
|
|
|
|
|
break;
|
|
|
|
|
case _C_CHR:
|
|
|
|
|
*(char*)datum = (char)va_arg(ap, int);
|
|
|
|
|
break;
|
|
|
|
|
case _C_UCHR:
|
|
|
|
|
*(unsigned char*)datum = (unsigned char)va_arg(ap, int);
|
|
|
|
|
break;
|
|
|
|
|
case _C_FLT:
|
|
|
|
|
*(float*)datum = (float)va_arg(ap, double);
|
|
|
|
|
break;
|
1998-10-28 13:58:05 +00:00
|
|
|
|
CASE_TYPE(_C_DBL, double);
|
|
|
|
|
CASE_TYPE(_C_PTR, void*);
|
1999-08-03 16:37:08 +00:00
|
|
|
|
case _C_STRUCT_B:
|
1999-10-31 05:38:30 +00:00
|
|
|
|
default:
|
2000-12-08 19:06:00 +00:00
|
|
|
|
#if !defined(USE_LIBFFI) && !defined(USE_FFCALL)
|
1999-09-09 02:56:20 +00:00
|
|
|
|
#if defined(sparc) || defined(powerpc)
|
1999-08-03 16:37:08 +00:00
|
|
|
|
/* FIXME: This only appears on sparc and ppc machines so far.
|
2005-02-22 11:22:44 +00:00
|
|
|
|
structures appear to be aligned on word boundaries.
|
1999-08-03 16:37:08 +00:00
|
|
|
|
Hopefully there is a more general way to figure this out */
|
|
|
|
|
size = (size<sizeof(int))?4:size;
|
2000-12-08 19:06:00 +00:00
|
|
|
|
#endif
|
1999-08-03 16:37:08 +00:00
|
|
|
|
#endif
|
1999-10-31 05:45:13 +00:00
|
|
|
|
NSLog(@"Unsafe handling of type of %d argument.", i-1);
|
|
|
|
|
{
|
|
|
|
|
struct {
|
|
|
|
|
char x[size];
|
|
|
|
|
} dummy;
|
|
|
|
|
dummy = va_arg(ap, typeof(dummy));
|
2001-03-08 03:58:07 +00:00
|
|
|
|
memcpy(datum, dummy.x, size);
|
1999-10-31 05:45:13 +00:00
|
|
|
|
}
|
1999-10-31 05:38:30 +00:00
|
|
|
|
break;
|
1998-08-13 20:45:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
1998-10-28 13:58:05 +00:00
|
|
|
|
return self;
|
1998-08-13 20:45:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-04-04 10:59:11 +00:00
|
|
|
|
/**
|
|
|
|
|
* Internal use.<br />
|
|
|
|
|
* Provides a return frame that the ObjectiveC runtime can use to
|
|
|
|
|
* return the result of an invocation to a calling function.
|
|
|
|
|
*/
|
1998-08-13 20:45:32 +00:00
|
|
|
|
- (void*) returnFrame: (arglist_t)argFrame
|
|
|
|
|
{
|
2000-12-08 19:06:00 +00:00
|
|
|
|
[self subclassResponsibility: _cmd];
|
|
|
|
|
return NULL;
|
1998-08-13 20:45:32 +00:00
|
|
|
|
}
|
2001-05-15 17:11:10 +00:00
|
|
|
|
|
2003-04-04 10:59:11 +00:00
|
|
|
|
/**
|
|
|
|
|
* Returns the status of the flag set by -setSendsToSuper:
|
|
|
|
|
*/
|
2001-05-15 17:11:10 +00:00
|
|
|
|
- (BOOL) sendsToSuper
|
|
|
|
|
{
|
|
|
|
|
return _sendToSuper;
|
|
|
|
|
}
|
|
|
|
|
|
2003-04-04 10:59:11 +00:00
|
|
|
|
/**
|
|
|
|
|
* Sets the flag to tell the invocation that it should actually invoke a
|
|
|
|
|
* method in the superclass of the target rather than the method of the
|
2004-06-22 22:40:40 +00:00
|
|
|
|
* target itself.<br />
|
2003-04-04 10:59:11 +00:00
|
|
|
|
* This extension permits an invocation to act like a regular method
|
|
|
|
|
* call sent to <em>super</em> in the method of a class.
|
|
|
|
|
*/
|
2001-05-15 17:11:10 +00:00
|
|
|
|
- (void) setSendsToSuper: (BOOL)flag
|
|
|
|
|
{
|
|
|
|
|
_sendToSuper = flag;
|
|
|
|
|
}
|
2003-04-04 10:59:11 +00:00
|
|
|
|
@end
|
2001-05-15 17:11:10 +00:00
|
|
|
|
|
2003-04-04 10:59:11 +00:00
|
|
|
|
/**
|
|
|
|
|
* These methods are for internal use only ... not public API<br />
|
|
|
|
|
* They are used by the NS_INVOCATION() and NS_MESSAGE() macros to help
|
|
|
|
|
* create invocations.
|
|
|
|
|
*/
|
|
|
|
|
@implementation NSInvocation (MacroSetup)
|
2003-04-04 10:03:08 +00:00
|
|
|
|
+ (id) _newProxyForInvocation: (id)target
|
|
|
|
|
{
|
|
|
|
|
return [GSInvocationProxy _newWithTarget: target];
|
|
|
|
|
}
|
|
|
|
|
+ (id) _newProxyForMessage: (id)target
|
|
|
|
|
{
|
|
|
|
|
return [GSMessageProxy _newWithTarget: target];
|
|
|
|
|
}
|
|
|
|
|
+ (NSInvocation*) _returnInvocationAndDestroyProxy: (id)proxy
|
|
|
|
|
{
|
|
|
|
|
NSInvocation *inv = [proxy _invocation];
|
|
|
|
|
NSDeallocateObject(proxy);
|
|
|
|
|
return inv;
|
|
|
|
|
}
|
1998-08-13 20:45:32 +00:00
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation NSInvocation (BackwardCompatibility)
|
|
|
|
|
|
|
|
|
|
- (void) invokeWithObject: (id)obj
|
|
|
|
|
{
|
1998-10-28 13:58:05 +00:00
|
|
|
|
[self invokeWithTarget: (id)obj];
|
1998-08-13 20:45:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
2000-12-08 19:06:00 +00:00
|
|
|
|
@implementation GSFrameInvocation
|
|
|
|
|
|
|
|
|
|
- (id) initWithArgframe: (arglist_t)frame selector: (SEL)aSelector
|
|
|
|
|
{
|
2002-07-29 19:37:40 +00:00
|
|
|
|
self = [self initWithSelector: aSelector];
|
2000-12-08 19:06:00 +00:00
|
|
|
|
if (self)
|
|
|
|
|
{
|
|
|
|
|
[self setSelector: aSelector];
|
|
|
|
|
/*
|
2002-02-20 05:08:46 +00:00
|
|
|
|
* Copy the _cframe we were given.
|
2000-12-08 19:06:00 +00:00
|
|
|
|
*/
|
|
|
|
|
if (frame)
|
|
|
|
|
{
|
2003-01-03 20:14:47 +00:00
|
|
|
|
unsigned int i;
|
2000-12-08 19:06:00 +00:00
|
|
|
|
|
|
|
|
|
mframe_get_arg(frame, &_info[1], &_target);
|
|
|
|
|
for (i = 1; i <= _numArgs; i++)
|
|
|
|
|
{
|
2002-02-20 05:08:46 +00:00
|
|
|
|
mframe_cpy_arg((arglist_t)_cframe, frame, &_info[i]);
|
2000-12-08 19:06:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This is the de_signated initialiser.
|
|
|
|
|
*/
|
|
|
|
|
- (id) initWithMethodSignature: (NSMethodSignature*)aSignature
|
|
|
|
|
{
|
2002-07-29 19:37:40 +00:00
|
|
|
|
if (aSignature == nil)
|
|
|
|
|
{
|
|
|
|
|
RELEASE(self);
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
2000-12-08 19:06:00 +00:00
|
|
|
|
_sig = RETAIN(aSignature);
|
|
|
|
|
_numArgs = [aSignature numberOfArguments];
|
|
|
|
|
_info = [aSignature methodInfo];
|
2002-02-20 05:08:46 +00:00
|
|
|
|
_cframe = mframe_create_argframe([_sig methodType], &_retval);
|
2000-12-08 19:06:00 +00:00
|
|
|
|
if (_retval == 0 && _info[0].size > 0)
|
|
|
|
|
{
|
|
|
|
|
_retval = NSZoneMalloc(NSDefaultMallocZone(), _info[0].size);
|
|
|
|
|
}
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void*) returnFrame: (arglist_t)argFrame
|
|
|
|
|
{
|
|
|
|
|
return mframe_handle_return(_info[0].type, _retval, argFrame);
|
|
|
|
|
}
|
|
|
|
|
@end
|
2003-04-04 10:03:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@implementation GSInvocationProxy
|
|
|
|
|
+ (id) _newWithTarget: (id)t
|
|
|
|
|
{
|
|
|
|
|
GSInvocationProxy *o;
|
|
|
|
|
o = (GSInvocationProxy*) NSAllocateObject(self, 0, NSDefaultMallocZone());
|
2003-07-27 08:59:08 +00:00
|
|
|
|
o->target = RETAIN(t);
|
2003-04-04 10:03:08 +00:00
|
|
|
|
return o;
|
|
|
|
|
}
|
|
|
|
|
- (NSInvocation*) _invocation
|
|
|
|
|
{
|
|
|
|
|
return invocation;
|
|
|
|
|
}
|
|
|
|
|
- (retval_t) forward: (SEL)aSel : (arglist_t)argFrame
|
|
|
|
|
{
|
|
|
|
|
NSInvocation *inv;
|
|
|
|
|
|
|
|
|
|
if (aSel == 0)
|
|
|
|
|
[NSException raise: NSInvalidArgumentException
|
|
|
|
|
format: @"%@ null selector given", NSStringFromSelector(_cmd)];
|
|
|
|
|
|
|
|
|
|
inv = AUTORELEASE([[NSInvocation alloc] initWithArgframe: argFrame
|
|
|
|
|
selector: aSel]);
|
|
|
|
|
[self forwardInvocation: inv];
|
|
|
|
|
return [inv returnFrame: argFrame];
|
|
|
|
|
}
|
|
|
|
|
- (void) forwardInvocation: (NSInvocation*)anInvocation
|
|
|
|
|
{
|
|
|
|
|
invocation = anInvocation;
|
|
|
|
|
}
|
2003-07-27 08:59:08 +00:00
|
|
|
|
- (NSMethodSignature*) methodSignatureForSelector: (SEL)aSelector
|
|
|
|
|
{
|
|
|
|
|
return [target methodSignatureForSelector: aSelector];
|
|
|
|
|
}
|
2003-04-04 10:03:08 +00:00
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation GSMessageProxy
|
|
|
|
|
- (NSInvocation*) _invocation
|
|
|
|
|
{
|
|
|
|
|
[invocation setTarget: target];
|
|
|
|
|
return invocation;
|
|
|
|
|
}
|
|
|
|
|
@end
|