[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] pnet/engine cvm.h, 1.48, 1.49 cvm_conv.c, 1.28, 1
From: |
Rhys Weatherley <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] pnet/engine cvm.h, 1.48, 1.49 cvm_conv.c, 1.28, 1.29 cvm_dasm.c, 1.55, 1.56 cvm_lengths.c, 1.15, 1.16 cvmc_setup.c, 1.37, 1.38 gen_marshal.tc, 1.2, 1.3 lib_marshal.c, 1.4, 1.5 pinvoke.c, 1.22, 1.23 |
Date: |
Tue, 07 Oct 2003 09:38:18 +0000 |
Update of /cvsroot/dotgnu-pnet/pnet/engine
In directory subversions:/tmp/cvs-serv4615/engine
Modified Files:
cvm.h cvm_conv.c cvm_dasm.c cvm_lengths.c cvmc_setup.c
gen_marshal.tc lib_marshal.c pinvoke.c
Log Message:
Marshal structures that contain delegate fields.
Index: lib_marshal.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/lib_marshal.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** lib_marshal.c 4 Jun 2003 03:57:44 -0000 1.4
--- lib_marshal.c 7 Oct 2003 09:38:16 -0000 1.5
***************
*** 606,609 ****
--- 606,659 ----
}
+ void _ILStructToNative(ILExecThread *thread, void *value, ILType *type)
+ {
+ ILClass *classInfo;
+ ILField *field;
+ void *ptr;
+ ILMethod *method;
+ ILPInvoke *pinv;
+ ILUInt32 marshalType;
+ char *customName;
+ int customNameLen;
+ char *customCookie;
+ int customCookieLen;
+
+ /* Bail out if not a struct type */
+ type = ILTypeStripPrefixes(type);
+ if(!ILType_IsValueType(type))
+ {
+ return;
+ }
+
+ /* Get the current method and PInvoke information */
+ method = thread->method;
+ pinv = ILPInvokeFind(method);
+
+ /* Process the fields within the type */
+ classInfo = ILType_ToValueType(type);
+ field = 0;
+ while((field = (ILField *)ILClassNextMemberByKind
+ (classInfo, (ILMember *)field,
+ IL_META_MEMBERKIND_FIELD)) != 0)
+ {
+ if(ILField_IsStatic(field))
+ {
+ continue;
+ }
+ type = ILField_Type(field);
+ ptr = (void *)(((unsigned char *)value) + field->offset);
+ _ILStructToNative(thread, ptr, type);
+ marshalType = ILPInvokeGetMarshalType(pinv, method, 0,
+
&customName, &customNameLen,
+
&customCookie,
+
&customCookieLen, type);
+ /* TODO: convert other kinds of fields, not just delegates */
+ if(marshalType == IL_META_MARSHAL_FNPTR)
+ {
+ *((void **)ptr) = _ILDelegateGetClosure(*((ILObject
**)ptr));
+ }
+ }
+ }
+
#endif /* IL_CONFIG_PINVOKE */
Index: cvmc_setup.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/cvmc_setup.c,v
retrieving revision 1.37
retrieving revision 1.38
diff -C2 -d -r1.37 -r1.38
*** cvmc_setup.c 10 Aug 2003 02:11:58 -0000 1.37
--- cvmc_setup.c 7 Oct 2003 09:38:16 -0000 1.38
***************
*** 539,542 ****
--- 539,618 ----
}
+ #ifdef IL_CONFIG_PINVOKE
+
+ /*
+ * Determine if a parameter will need marshalling conversion on
+ * the members of a by-ref structure.
+ */
+ static int NeedsStructConversion(ILMethod *method, ILPInvoke *pinv,
+ unsigned long
param, ILType *type)
+ {
+ ILClass *classInfo;
+ ILField *field;
+ ILUInt32 marshalType;
+ char *customName;
+ int customNameLen;
+ char *customCookie;
+ int customCookieLen;
+ ILParameter *paramInfo;
+
+ /* Bail out if not a reference to a struct type */
+ if(!type || !ILType_IsComplex(type) ||
+ ILType_Kind(type) != IL_TYPE_COMPLEX_BYREF)
+ {
+ return 0;
+ }
+ type = ILTypeStripPrefixes(ILType_Ref(type));
+ if(!ILType_IsValueType(type))
+ {
+ return 0;
+ }
+
+ /* Don't bother if this is an "out" parameter */
+ paramInfo = 0;
+ while((paramInfo = ILMethodNextParam(method, paramInfo)) != 0)
+ {
+ if(ILParameter_Num(paramInfo) == param &&
+ ILParameter_IsOut(paramInfo))
+ {
+ return 0;
+ }
+ }
+
+ /* Determine if any of the fields need conversion */
+ classInfo = ILType_ToValueType(type);
+ field = 0;
+ while((field = (ILField *)ILClassNextMemberByKind
+ (classInfo, (ILMember *)field,
+ IL_META_MEMBERKIND_FIELD)) != 0)
+ {
+ if(ILField_IsStatic(field))
+ {
+ continue;
+ }
+ type = ILField_Type(field);
+ if(NeedsStructConversion(method, pinv, 0, type))
+ {
+ /* An inner type needs conversion, so convert the outer
type */
+ return 1;
+ }
+ marshalType = ILPInvokeGetMarshalType(pinv, method, 0,
+
&customName, &customNameLen,
+
&customCookie,
+
&customCookieLen, type);
+ /* TODO: convert other kinds of fields, not just delegates */
+ if(marshalType == IL_META_MARSHAL_FNPTR)
+ {
+ /* We have found a field that needs to be marshalled */
+ return 1;
+ }
+ }
+
+ /* We don't need conversion if we get here */
+ return 0;
+ }
+
+ #endif /* IL_CONFIG_PINVOKE */
+
/*
* Push native arguments onto the stack. If "coder" is NULL
***************
*** 596,600 ****
&customName, &customNameLen,
&customCookie,
!
&customCookieLen))
!= IL_META_MARSHAL_DIRECT)
{
--- 672,677 ----
&customName, &customNameLen,
&customCookie,
!
&customCookieLen,
!
paramType))
!= IL_META_MARSHAL_DIRECT)
{
***************
*** 685,688 ****
--- 762,784 ----
CVM_ADJUST(-1);
}
+
+ /* Check for by-ref structures which include fields that
+ need to be marshalled explicitly on entry */
+ if(!isInternal &&
+ NeedsStructConversion(method, pinv, param, paramType))
+ {
+ offset = coder->argOffsets[param - thisAdjust];
+ if(offset < 4)
+ {
+ CVM_OUT_NONE(COP_PLOAD_0 + offset);
+ }
+ else
+ {
+ CVM_OUT_WIDE(COP_PLOAD, offset);
+ }
+ CVM_ADJUST(1);
+ CVMP_OUT_PTR(COP_PREFIX_STRUCT2NATIVE,
ILType_Ref(paramType));
+ CVM_ADJUST(-1);
+ }
#endif /* IL_CONFIG_PINVOKE */
***************
*** 1082,1086 ****
marshalType = ILPInvokeGetMarshalType
(ILPInvokeFind(method), method, 0, &customName,
&customNameLen,
! &customCookie, &customCookieLen);
switch(marshalType)
{
--- 1178,1182 ----
marshalType = ILPInvokeGetMarshalType
(ILPInvokeFind(method), method, 0, &customName,
&customNameLen,
! &customCookie, &customCookieLen, returnType);
switch(marshalType)
{
Index: cvm_conv.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/cvm_conv.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -C2 -d -r1.28 -r1.29
*** cvm_conv.c 15 May 2003 05:06:34 -0000 1.28
--- cvm_conv.c 7 Oct 2003 09:38:15 -0000 1.29
***************
*** 2291,2294 ****
--- 2291,2323 ----
VMBREAK(COP_PREFIX_FROMCUSTOM);
+ /**
+ * <opcode name="struct2native" group="Conversion operators">
+ * <operation>Convert a struct into its native form</operation>
+ *
+ * <format>prefix<fsep/>struct2native<fsep/>type</format>
+ * <dformat>{struct2native}<fsep/>type</dformat>
+ *
+ * <form name="struct2native" code="COP_PREFIX_STRUCT2NATIVE"/>
+ *
+ * <before>..., ptr</before>
+ * <after>...</after>
+ *
+ * <description>The structured value at <i>ptr</i> is converted from
+ * its managed form into its native form, converting field values
+ * as appropriate.</description>
+ * </opcode>
+ */
+ VMCASE(COP_PREFIX_STRUCT2NATIVE):
+ {
+ /* Convert a struct into its native form */
+ extern void _ILStructToNative
+ (ILExecThread *thread, void *value, ILType *type);
+ COPY_STATE_TO_THREAD();
+ _ILStructToNative(thread, stacktop[-1].ptrValue, CVMP_ARG_PTR(ILType
*));
+ RESTORE_STATE_FROM_THREAD();
+ MODIFY_PC_AND_STACK(CVMP_LEN_PTR, -1);
+ }
+ VMBREAK(COP_PREFIX_STRUCT2NATIVE);
+
#else /* !IL_CONFIG_PINVOKE */
***************
*** 2318,2321 ****
--- 2347,2357 ----
}
VMBREAK(COP_PREFIX_TOCUSTOM);
+
+ VMCASE(COP_PREFIX_STRUCT2NATIVE):
+ {
+ /* Stub out PInvoke-related CVM opcodes */
+ MODIFY_PC_AND_STACK(CVMP_LEN_PTR, -1);
+ }
+ VMBREAK(COP_PREFIX_STRUCT2NATIVE);
#endif /* !IL_CONFIG_PINVOKE */
Index: cvm_dasm.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/cvm_dasm.c,v
retrieving revision 1.55
retrieving revision 1.56
diff -C2 -d -r1.55 -r1.56
*** cvm_dasm.c 13 Jul 2003 12:41:01 -0000 1.55
--- cvm_dasm.c 7 Oct 2003 09:38:16 -0000 1.56
***************
*** 61,64 ****
--- 61,65 ----
#define CVM_OPER_TWO_UINT32 28
#define CVM_OPER_TAIL_INTERFACE 29
+ #define CVM_OPER_TYPE 30
/*
***************
*** 422,426 ****
{"prefix", CVM_OPER_PREFIX},
};
! static CVMOpcode const prefixOpcodes[96] = {
/*
* Reserved opcodes.
--- 423,427 ----
{"prefix", CVM_OPER_PREFIX},
};
! static CVMOpcode const prefixOpcodes[0x70] = {
/*
* Reserved opcodes.
***************
*** 535,538 ****
--- 536,540 ----
{"array2ansi", CVM_OPER_NONE},
{"array2utf8", CVM_OPER_NONE},
+ {"struct2native", CVM_OPER_TYPE},
/*
***************
*** 585,589 ****
* Reserved opcodes.
*/
! {"preserved_5F", CVM_OPER_NONE},
};
--- 587,606 ----
* Reserved opcodes.
*/
! {"preserved_60", CVM_OPER_NONE},
! {"preserved_61", CVM_OPER_NONE},
! {"preserved_62", CVM_OPER_NONE},
! {"preserved_63", CVM_OPER_NONE},
! {"preserved_64", CVM_OPER_NONE},
! {"preserved_65", CVM_OPER_NONE},
! {"preserved_66", CVM_OPER_NONE},
! {"preserved_67", CVM_OPER_NONE},
! {"preserved_68", CVM_OPER_NONE},
! {"preserved_69", CVM_OPER_NONE},
! {"preserved_6A", CVM_OPER_NONE},
! {"preserved_6B", CVM_OPER_NONE},
! {"preserved_6C", CVM_OPER_NONE},
! {"preserved_6D", CVM_OPER_NONE},
! {"preserved_6E", CVM_OPER_NONE},
! {"preserved_6F", CVM_OPER_NONE},
};
Index: cvm.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/cvm.h,v
retrieving revision 1.48
retrieving revision 1.49
diff -C2 -d -r1.48 -r1.49
*** cvm.h 20 Jun 2003 05:02:16 -0000 1.48
--- cvm.h 7 Oct 2003 09:38:15 -0000 1.49
***************
*** 476,525 ****
#define COP_PREFIX_ARRAY2ANSI 0x4B
#define COP_PREFIX_ARRAY2UTF8 0x4C
/*
* Inline method replacements.
*/
! #define COP_PREFIX_STRING_CONCAT_2 0x4D
! #define COP_PREFIX_STRING_CONCAT_3 0x4E
! #define COP_PREFIX_STRING_CONCAT_4 0x4F
! #define COP_PREFIX_STRING_EQ 0x50
! #define COP_PREFIX_STRING_NE 0x51
! #define COP_PREFIX_STRING_GET_CHAR 0x52
! #define COP_PREFIX_TYPE_FROM_HANDLE 0x53
! #define COP_PREFIX_MONITOR_ENTER 0x54
! #define COP_PREFIX_MONITOR_EXIT 0x55
! #define COP_PREFIX_APPEND_CHAR 0x56
! #define COP_PREFIX_IS_WHITE_SPACE 0x57
/*
* Binary value fixups.
*/
! #define COP_PREFIX_FIX_I4_I 0x58
! #define COP_PREFIX_FIX_I4_U 0x59
/*
* Trigger method unrolling.
*/
! #define COP_PREFIX_UNROLL_METHOD 0x5A
/*
* Allocate local stack space.
*/
! #define COP_PREFIX_LOCAL_ALLOC 0x5B
/*
* Method profiling.
*/
! #define COP_PREFIX_PROFILE_COUNT 0x5C
/*
* Thread static handling.
*/
! #define COP_PREFIX_THREAD_STATIC 0x5D
/*
* Argument packing for native calls.
*/
! #define COP_PREFIX_WADDR_NATIVE_N 0x5E
/*
--- 476,526 ----
#define COP_PREFIX_ARRAY2ANSI 0x4B
#define COP_PREFIX_ARRAY2UTF8 0x4C
+ #define COP_PREFIX_STRUCT2NATIVE 0x4D
/*
* Inline method replacements.
*/
! #define COP_PREFIX_STRING_CONCAT_2 0x4E
! #define COP_PREFIX_STRING_CONCAT_3 0x4F
! #define COP_PREFIX_STRING_CONCAT_4 0x50
! #define COP_PREFIX_STRING_EQ 0x51
! #define COP_PREFIX_STRING_NE 0x52
! #define COP_PREFIX_STRING_GET_CHAR 0x53
! #define COP_PREFIX_TYPE_FROM_HANDLE 0x54
! #define COP_PREFIX_MONITOR_ENTER 0x55
! #define COP_PREFIX_MONITOR_EXIT 0x56
! #define COP_PREFIX_APPEND_CHAR 0x57
! #define COP_PREFIX_IS_WHITE_SPACE 0x58
/*
* Binary value fixups.
*/
! #define COP_PREFIX_FIX_I4_I 0x59
! #define COP_PREFIX_FIX_I4_U 0x5A
/*
* Trigger method unrolling.
*/
! #define COP_PREFIX_UNROLL_METHOD 0x5B
/*
* Allocate local stack space.
*/
! #define COP_PREFIX_LOCAL_ALLOC 0x5C
/*
* Method profiling.
*/
! #define COP_PREFIX_PROFILE_COUNT 0x5D
/*
* Thread static handling.
*/
! #define COP_PREFIX_THREAD_STATIC 0x5E
/*
* Argument packing for native calls.
*/
! #define COP_PREFIX_WADDR_NATIVE_N 0x5F
/*
Index: gen_marshal.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/gen_marshal.tc,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** gen_marshal.tc 28 Jul 2003 06:39:46 -0000 1.2
--- gen_marshal.tc 7 Oct 2003 09:38:16 -0000 1.3
***************
*** 938,942 ****
&customName, &customNameLen,
&customCookie,
!
&customCookieLen))
!= IL_META_MARSHAL_DIRECT)
{
--- 938,942 ----
&customName, &customNameLen,
&customCookie,
!
&customCookieLen, argType))
!= IL_META_MARSHAL_DIRECT)
{
Index: cvm_lengths.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/cvm_lengths.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -d -r1.15 -r1.16
*** cvm_lengths.c 19 Jun 2003 12:19:40 -0000 1.15
--- cvm_lengths.c 7 Oct 2003 09:38:16 -0000 1.16
***************
*** 489,492 ****
--- 489,493 ----
/* array2ansi */ CVMP_LEN_NONE,
/* array2utf8 */ CVMP_LEN_NONE,
+ /* struct2native */ CVMP_LEN_PTR,
/*
***************
*** 539,544 ****
* Reserved opcodes.
*/
- /* preserved_5f */ CVMP_LEN_NONE,
-
/* preserved_60 */ CVMP_LEN_NONE,
/* preserved_61 */ CVMP_LEN_NONE,
--- 540,543 ----
Index: pinvoke.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/pinvoke.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -d -r1.22 -r1.23
*** pinvoke.c 14 Jun 2003 12:21:32 -0000 1.22
--- pinvoke.c 7 Oct 2003 09:38:16 -0000 1.23
***************
*** 502,506 ****
marshalType = ILPInvokeGetMarshalType(0, pinvokeInfo, param,
&customName, &customNameLen,
!
&customCookie, &customCookieLen);
if(marshalType != IL_META_MARSHAL_DIRECT)
{
--- 502,507 ----
marshalType = ILPInvokeGetMarshalType(0, pinvokeInfo, param,
&customName, &customNameLen,
!
&customCookie, &customCookieLen,
!
ILTypeGetParam(signature, param));
if(marshalType != IL_META_MARSHAL_DIRECT)
{
***************
*** 739,743 ****
marshalType = ILPInvokeGetMarshalType
(0, pinvokeInfo, 0, &customName, &customNameLen,
! &customCookie, &customCookieLen);
if(marshalType != IL_META_MARSHAL_DIRECT)
{
--- 740,744 ----
marshalType = ILPInvokeGetMarshalType
(0, pinvokeInfo, 0, &customName, &customNameLen,
! &customCookie, &customCookieLen,
ILTypeGetReturn(signature));
if(marshalType != IL_META_MARSHAL_DIRECT)
{
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] pnet/engine cvm.h, 1.48, 1.49 cvm_conv.c, 1.28, 1.29 cvm_dasm.c, 1.55, 1.56 cvm_lengths.c, 1.15, 1.16 cvmc_setup.c, 1.37, 1.38 gen_marshal.tc, 1.2, 1.3 lib_marshal.c, 1.4, 1.5 pinvoke.c, 1.22, 1.23,
Rhys Weatherley <address@hidden> <=