mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Correct FFI value setting
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@13532 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
591ce7b3de
commit
3a327f1177
6 changed files with 51 additions and 28 deletions
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
|||
2002-04-23 Adam Fedor <fedor@gnu.org>
|
||||
|
||||
* Source/GSFFIInvocation.m
|
||||
(-initWithCallback:returnp:values:frame:signature:): Simplify
|
||||
setting values. Structs passed by ref when MFRAME_STRUCT_BYREF.
|
||||
(GSFFIInvokeWithTargetAndImp): Encoding values unneedded now.
|
||||
|
||||
* Source/mframe/powerpc/generic: Fix offset for structs.
|
||||
* Source/mframe/powerpc/linux-gnu: Idem.
|
||||
* Source/mframe/powerpc/darwin: Idem.
|
||||
|
||||
2002-04-22 Adam Fedor <fedor@gnu.org>
|
||||
|
||||
* Tools/gdomap.c (gdomap_log): For LOG_INFO, write to 1, not 0.
|
||||
|
|
|
@ -27,17 +27,12 @@
|
|||
#include <config.h>
|
||||
#include <objc/objc-api.h>
|
||||
#include "cifframe.h"
|
||||
#include "mframe.h"
|
||||
|
||||
#ifndef INLINE
|
||||
#define INLINE inline
|
||||
#endif
|
||||
|
||||
#if defined(ALPHA) || (defined(MIPS) && (_MIPS_SIM == _ABIN32))
|
||||
typedef long long smallret_t;
|
||||
#else
|
||||
typedef int smallret_t;
|
||||
#endif
|
||||
|
||||
typedef struct _NSInvocation_t {
|
||||
@defs(NSInvocation)
|
||||
} NSInvocation_t;
|
||||
|
@ -224,24 +219,34 @@ static IMP gs_objc_msg_forward (SEL sel)
|
|||
frame: (cifframe_t *)frame
|
||||
signature: (NSMethodSignature*)aSignature
|
||||
{
|
||||
int i, offset;
|
||||
int i;
|
||||
_sig = RETAIN(aSignature);
|
||||
_numArgs = [aSignature numberOfArguments];
|
||||
_info = [aSignature methodInfo];
|
||||
_cframe = frame;
|
||||
((cifframe_t *)_cframe)->cif = *cif;
|
||||
((cifframe_t *)_cframe)->values = vals;
|
||||
|
||||
/* Insert the values into the value array.
|
||||
FIXME: I don't think this is correct for structures. */
|
||||
offset = 0;
|
||||
#if MFRAME_STRUCT_BYREF
|
||||
/* Fix up some of the values. Do this on all processors that pass
|
||||
structs by reference. Is there an automatic way to determine this? */
|
||||
for (i = 0; i < ((cifframe_t *)_cframe)->nargs; i++)
|
||||
{
|
||||
((cifframe_t *)_cframe)->values[i] = *vals + offset;
|
||||
|
||||
offset += MAX(((cifframe_t *)_cframe)->arg_types[i]->size,
|
||||
sizeof(smallret_t));
|
||||
const char *t = _info[i+1].type;
|
||||
|
||||
if (*t == _C_STRUCT_B || *t == _C_UNION_B || *t == _C_ARY_B)
|
||||
{
|
||||
memcpy(((cifframe_t *)_cframe)->values[i], *(void **)vals[i],
|
||||
((cifframe_t *)_cframe)->arg_types[i]->size);
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(((cifframe_t *)_cframe)->values[i], vals[i],
|
||||
((cifframe_t *)_cframe)->arg_types[i]->size);
|
||||
}
|
||||
}
|
||||
#else
|
||||
((cifframe_t *)_cframe)->values = vals;
|
||||
#endif
|
||||
_retval = retp;
|
||||
return self;
|
||||
}
|
||||
|
@ -253,21 +258,13 @@ static IMP gs_objc_msg_forward (SEL sel)
|
|||
void
|
||||
GSFFIInvokeWithTargetAndImp(NSInvocation *_inv, id anObject, IMP imp)
|
||||
{
|
||||
int i;
|
||||
NSInvocation_t *inv = (NSInvocation_t*)_inv;
|
||||
|
||||
/* Some arguments need to be promoted to be passed correctly */
|
||||
for (i = 2; i < inv->_numArgs; i++)
|
||||
{
|
||||
const char *type = inv->_info[i+1].type;
|
||||
cifframe_encode_arg(type, cifframe_arg_addr(inv->_cframe, i));
|
||||
}
|
||||
|
||||
/* Do it */
|
||||
ffi_call(inv->_cframe, imp, (inv->_retval),
|
||||
((cifframe_t *)inv->_cframe)->values);
|
||||
|
||||
/* Don't decode the return value here */
|
||||
/* Don't decode the return value here (?) */
|
||||
}
|
||||
|
||||
- (void) invokeWithTarget: (id)anObject
|
||||
|
@ -350,8 +347,8 @@ GSFFIInvocationCallback(ffi_cif *cif, void *retp, void **args, void *user)
|
|||
NSMethodSignature *sig;
|
||||
Method_t fwdInvMethod;
|
||||
|
||||
memcpy(&obj, *args, sizeof(id));
|
||||
memcpy(&selector, *args+sizeof(id *), sizeof(SEL));
|
||||
obj = *(id *)args[0];
|
||||
selector = *(SEL *)args[1];
|
||||
|
||||
fwdInvMethod = gs_method_for_receiver_and_selector
|
||||
(obj, @selector (forwardInvocation:));
|
||||
|
|
|
@ -54,7 +54,7 @@ typedef struct rs6000_args
|
|||
(CUM).stack_position = 0; \
|
||||
(CUM).regs_position = \
|
||||
((*(RTYPE)==_C_STRUCT_B || *(RTYPE)==_C_UNION_B || *(RTYPE)==_C_ARY_B) ? \
|
||||
4 + sizeof(void*) : 4); \
|
||||
sizeof(void*) : 4); \
|
||||
})
|
||||
|
||||
#define MFRAME_ARG_ENCODING(CUM, TYPE, STACK, DEST) \
|
||||
|
|
|
@ -54,7 +54,7 @@ typedef struct rs6000_args
|
|||
(CUM).stack_position = 0; \
|
||||
(CUM).regs_position = \
|
||||
((*(RTYPE)==_C_STRUCT_B || *(RTYPE)==_C_UNION_B || *(RTYPE)==_C_ARY_B) ? \
|
||||
4 + sizeof(void*) : 4); \
|
||||
sizeof(void*) : 4); \
|
||||
})
|
||||
|
||||
#define MFRAME_ARG_ENCODING(CUM, TYPE, STACK, DEST) \
|
||||
|
|
|
@ -190,6 +190,7 @@ int con_data (id prx)
|
|||
printf("Many Arguments:\n");
|
||||
[prx manyArgs:1 :2 :3 :4 :5 :6 :7 :8 :9 :10 :11 :12];
|
||||
|
||||
printf("Done\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -268,6 +269,7 @@ con_messages (id prx)
|
|||
#endif
|
||||
printf(" ok\n");
|
||||
|
||||
printf("Done\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -300,6 +302,7 @@ con_benchmark (id prx)
|
|||
}
|
||||
|
||||
printf(" Delay is %f\n", [d timeIntervalSinceNow]);
|
||||
printf("Done\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,8 @@ typedef struct {
|
|||
- (small) loopSmallPtr: (small*)v;
|
||||
- (char*) loopString: (char*)v;
|
||||
|
||||
- (double) loopMulti: (float)f int: (float)v ch: (char)c;
|
||||
|
||||
- (char) retChar;
|
||||
- (double) retDouble;
|
||||
- (float) retFloat;
|
||||
|
@ -91,6 +93,11 @@ typedef struct {
|
|||
return v;
|
||||
}
|
||||
|
||||
- (double) loopMulti: (float)f int: (float)v ch: (char)c
|
||||
{
|
||||
return v+1.0;
|
||||
}
|
||||
|
||||
- (char) retChar
|
||||
{
|
||||
return (char)99;
|
||||
|
@ -357,6 +364,11 @@ printf("Calling proxy\n");
|
|||
d = [p loopDouble: 5.0];
|
||||
printf("forward: %.1f\n", d);
|
||||
|
||||
SETUP(loopMulti:int:ch:);
|
||||
printf("Expect: 6.0, ");
|
||||
f = [p loopMulti: 3.0 int: 5.0 ch: 'a'];
|
||||
printf("forward: %.1f\n", f);
|
||||
|
||||
SETUP(loopObject:);
|
||||
[inv setArgument: &p atIndex: 2];
|
||||
[inv invokeWithTarget: t];
|
||||
|
|
Loading…
Reference in a new issue