[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: pnet/engine lib_reflect.c,1.37,1.38 pinvoke.
From: |
Rhys Weatherley <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: pnet/engine lib_reflect.c,1.37,1.38 pinvoke.c,1.21,1.22 |
Date: |
Sat, 14 Jun 2003 08:21:35 -0400 |
Update of /cvsroot/dotgnu-pnet/pnet/engine
In directory subversions:/tmp/cvs-serv23917/engine
Modified Files:
lib_reflect.c pinvoke.c
Log Message:
Implement "RuntimeMethodHandle.GetFunctionPointer".
Index: lib_reflect.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/lib_reflect.c,v
retrieving revision 1.37
retrieving revision 1.38
diff -C2 -r1.37 -r1.38
*** lib_reflect.c 2 Jun 2003 06:55:17 -0000 1.37
--- lib_reflect.c 14 Jun 2003 12:21:32 -0000 1.38
***************
*** 1839,1844 ****
(ILExecThread *thread, void *_this)
{
! /* Function pointers don't make any sense for us, so always return NULL
*/
! return 0;
}
--- 1839,1853 ----
(ILExecThread *thread, void *_this)
{
! ILMethod *method = *((ILMethod **)_this);
! if(method)
! {
! /* Create a closure for the method, without a delegate around
it */
! return (ILNativeInt)(_ILMakeClosureForDelegate(0, method));
! }
! else
! {
! /* Invalid RuntimeMethodHandle value */
! return 0;
! }
}
Index: pinvoke.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/pinvoke.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -r1.21 -r1.22
*** pinvoke.c 20 Feb 2003 04:54:04 -0000 1.21
--- pinvoke.c 14 Jun 2003 12:21:32 -0000 1.22
***************
*** 448,451 ****
--- 448,452 ----
void **args;
ILMethod *pinvokeInfo;
+ int needThis;
} PackDelegateUserData;
***************
*** 482,486 ****
/* Push the "this" argument */
CHECK_SPACE(1);
! stacktop->ptrValue = _this;
++stacktop;
}
--- 483,497 ----
/* Push the "this" argument */
CHECK_SPACE(1);
! if(((PackDelegateUserData *)userData)->needThis)
! {
! /* We get the "this" value from the incoming arguments
*/
! stacktop->ptrValue = *((void **)(*args));
! ++args;
! }
! else
! {
! /* We get the "this" value from the delegate object */
! stacktop->ptrValue = _this;
! }
++stacktop;
}
***************
*** 935,938 ****
--- 946,950 ----
userData.pinvokeInfo = (ILMethod *)ILTypeGetDelegateMethod
(ILType_FromClass(GetObjectClass(delegate)));
+ userData.needThis = 0;
if(_ILCallMethod(thread, method,
UnpackDelegateResult, result,
***************
*** 953,956 ****
--- 965,1001 ----
}
+ /*
+ * Invoke a method from a closure.
+ */
+ static void MethodInvoke(ffi_cif *cif, void *result,
+ void **args, void *_method)
+ {
+ ILExecThread *thread = ILExecThreadCurrent();
+ ILMethod *method = (ILMethod *)_method;
+ ILType *type;
+ ILUInt32 size;
+ PackDelegateUserData userData;
+
+ /* Call the method */
+ userData.args = args;
+ userData.pinvokeInfo = method;
+ userData.needThis = 0;
+ if(_ILCallMethod(thread, method,
+ UnpackDelegateResult, result, 0, 0,
+ PackDelegateParams, &userData))
+ {
+ /* An exception occurred, which is already stored in the thread
*/
+ type = ILMethod_Signature(method);
+ type = ILTypeGetEnumType(ILTypeGetReturn(type));
+ if(type != ILType_Void)
+ {
+ /* Clear the native return value, because we cannot
assume
+ that the native caller knows how to handle
exceptions */
+ size = ILSizeOfType(thread, type);
+ ILMemZero(result, size);
+ }
+ }
+ }
+
#endif /* FFI_CLOSURES */
***************
*** 973,977 ****
/* Allocate space for the cif */
cif = (ffi_cif *)ILMalloc(sizeof(ffi_cif) +
! sizeof(ffi_type *) *
numArgs);
if(!cif)
{
--- 1018,1022 ----
/* Allocate space for the cif */
cif = (ffi_cif *)ILMalloc(sizeof(ffi_cif) +
! sizeof(ffi_type *) *
(numArgs + 1));
if(!cif)
{
***************
*** 985,988 ****
--- 1030,1038 ----
/* Convert the argument types */
arg = 0;
+ if(!delegate && ILType_HasThis(signature))
+ {
+ /* We need an extra argument for the method's "this" value */
+ args[arg++] = &ffi_type_pointer;
+ }
for(param = 1; param <= numArgs; ++param)
{
***************
*** 992,996 ****
/* Prepare the "ffi_cif" structure for the call */
! if(ffi_prep_cif(cif, FFI_DEFAULT_ABI, numArgs, rtype, args) != FFI_OK)
{
fprintf(stderr, "Cannot marshal a type in the definition of
%s::%s\n",
--- 1042,1046 ----
/* Prepare the "ffi_cif" structure for the call */
! if(ffi_prep_cif(cif, FFI_DEFAULT_ABI, arg, rtype, args) != FFI_OK)
{
fprintf(stderr, "Cannot marshal a type in the definition of
%s::%s\n",
***************
*** 1009,1018 ****
/* Prepare the closure using the call parameters */
! if(ffi_prep_closure(closure, cif, DelegateInvoke, (void *)delegate)
! != FFI_OK)
{
! fprintf(stderr, "Cannot create a closure for %s::%s\n",
ILClass_Name(ILMethod_Owner(method)),
ILMethod_Name(method));
! return 0;
}
--- 1059,1081 ----
/* Prepare the closure using the call parameters */
! if(delegate)
{
! if(ffi_prep_closure(closure, cif, DelegateInvoke, (void
*)delegate)
! != FFI_OK)
! {
! fprintf(stderr, "Cannot create a closure for %s::%s\n",
ILClass_Name(ILMethod_Owner(method)),
ILMethod_Name(method));
! return 0;
! }
! }
! else
! {
! if(ffi_prep_closure(closure, cif, MethodInvoke, (void *)method)
! != FFI_OK)
! {
! fprintf(stderr, "Cannot create a closure for %s::%s\n",
! ILClass_Name(ILMethod_Owner(method)),
ILMethod_Name(method));
! return 0;
! }
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnet/engine lib_reflect.c,1.37,1.38 pinvoke.c,1.21,1.22,
Rhys Weatherley <address@hidden> <=
- Prev by Date:
[Dotgnu-pnet-commits] CVS: pnet ChangeLog,1.2409,1.2410
- Next by Date:
[Dotgnu-pnet-commits] CVS: pnet/cscc/csharp cs_grammar.y,1.62,1.63 cs_internal.h,1.17,1.18 cs_modifiers.c,1.5,1.6
- Previous by thread:
[Dotgnu-pnet-commits] CVS: pnet ChangeLog,1.2409,1.2410
- Next by thread:
[Dotgnu-pnet-commits] CVS: pnet/cscc/csharp cs_grammar.y,1.62,1.63 cs_internal.h,1.17,1.18 cs_modifiers.c,1.5,1.6
- Index(es):