[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: pnet/engine custom.c,1.1,1.2 cvm_conv.c,1.25
From: |
Rhys Weatherley <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: pnet/engine custom.c,1.1,1.2 cvm_conv.c,1.25,1.26 cvm_format.h,1.6,1.7 cvm_lengths.c,1.7,1.8 cvmc_gen.h,1.5,1.6 cvmc_setup.c,1.30,1.31 engine.h,1.67,1.68 lookup.c,1.9,1.10 pinvoke.c,1.19,1.20 |
Date: |
Mon, 17 Feb 2003 00:20:34 -0500 |
Update of /cvsroot/dotgnu-pnet/pnet/engine
In directory subversions:/tmp/cvs-serv15877/engine
Modified Files:
custom.c cvm_conv.c cvm_format.h cvm_lengths.c cvmc_gen.h
cvmc_setup.c engine.h lookup.c pinvoke.c
Log Message:
Implement the bulk of custom marshalling.
Index: custom.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/custom.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** custom.c 31 Jan 2003 02:00:29 -0000 1.1
--- custom.c 17 Feb 2003 05:20:31 -0000 1.2
***************
*** 20,23 ****
--- 20,24 ----
#include "engine.h"
+ #include "lib_defs.h"
#ifdef __cplusplus
***************
*** 25,40 ****
#endif
! void *_ILObjectToCustom(ILExecThread *thread, ILObject *obj,
! const char *customName, int
customNameLen)
{
/* TODO */
! return (void *)obj;
}
ILObject *_ILCustomToObject(ILExecThread *thread, void *ptr,
! const char *customName,
int customNameLen)
{
! /* TODO */
! return (ILObject *)ptr;
}
--- 26,232 ----
#endif
! /*
! * Get a custom marshalling class. This isn't terribly efficient right now.
! */
! static ILClass *GetCustomMarshaller(ILExecThread *thread, ILClass **customRet,
! const
char *customName, int customNameLen)
! {
! ILString *str;
! ILObject *type;
! ILClass *classInfo;
! ILClass *custom;
!
! /* Bail out if no name */
! if(!customName || !customNameLen)
! {
! return 0;
! }
!
! /* Convert the name into a string */
! str = ILStringCreateLen(thread, customName, customNameLen);
! if(!str)
! {
! return 0;
! }
!
! /* Look up the marshalling type */
! type = _IL_Type_GetType(thread, str, 0, 0);
! if(!type)
! {
! return 0;
! }
!
! /* Convert the type object into an ILClass structure */
! classInfo = _ILGetClrClass(thread, type);
! if(!classInfo)
! {
! return 0;
! }
!
! /* Check to make sure that the class implements "ICustomMarshaler" */
! custom = ILExecThreadLookupClass
! (thread, "System.Runtime.InteropServices.ICustomMarshaler");
! if(!custom)
! {
! return 0;
! }
! if(!ILClassImplements(classInfo, custom))
! {
! return 0;
! }
! *customRet = custom;
! return classInfo;
! }
!
! /*
! * Get a custom marshalling instance.
! */
! static ILObject *GetMarshallingInstance(ILExecThread *thread,
!
ILClass *classInfo,
!
const char *customCookie,
!
int customCookieLen)
! {
! ILMethod *method;
! ILString *str;
! ILObject *result;
!
! /* Find the "GetInstance" method */
! method = ILExecThreadLookupMethodInClass
! (thread, classInfo, "GetInstance",
!
"(oSystem.String;)oSystem.Runtime.InteropServices.ICustomMarshaler;");
! if(!method)
! {
! return 0;
! }
!
! /* Convert the cookie into a string */
! if(customCookie && customCookieLen)
! {
! str = ILStringCreateLen(thread, customCookie, customCookieLen);
! if(!str)
! {
! return 0;
! }
! }
! else
! {
! str = 0;
! }
!
! /* Call the "GetInstance" method */
! result = 0;
! if(ILExecThreadCall(thread, method, &result, str))
! {
! return 0;
! }
! else
! {
! return result;
! }
! }
!
! /*
! * Throw a custom marshalling error.
! */
! static void ThrowCustomError(ILExecThread *thread)
{
+ puts("Hello");
/* TODO */
! }
!
! void *_ILObjectToCustom(ILExecThread *thread, ILObject *obj,
! const char *customName, int
customNameLen,
! const char *customCookie, int
customCookieLen)
! {
! ILClass *classInfo;
! ILClass *custom;
! ILObject *marshal;
! ILMethod *method;
! void *result;
!
! /* Bail out immediately if the object is NULL */
! if(!obj)
! {
! return 0;
! }
!
! /* Find the custom marshalling instance */
! classInfo = GetCustomMarshaller
! (thread, &custom, customName, customNameLen);
! if(!classInfo)
! {
! ThrowCustomError(thread);
! return 0;
! }
! marshal = GetMarshallingInstance
! (thread, classInfo, customCookie, customCookieLen);
! if(!marshal)
! {
! ThrowCustomError(thread);
! return 0;
! }
!
! /* Call the marshalling method and return */
! method = ILExecThreadLookupMethodInClass
! (thread, custom, "MarshalManagedToNative",
"(ToSystem.Object;)j");
! if(!method)
! {
! ThrowCustomError(thread);
! return 0;
! }
! result = 0;
! if(ILExecThreadCallVirtual(thread, method, &result, marshal, obj))
! {
! result = 0;
! }
! return result;
}
ILObject *_ILCustomToObject(ILExecThread *thread, void *ptr,
! const char *customName,
int customNameLen,
! const char
*customCookie, int customCookieLen)
{
! ILClass *classInfo;
! ILClass *custom;
! ILObject *marshal;
! ILMethod *method;
! void *result;
!
! /* Bail out immediately if the pointer is NULL */
! if(!ptr)
! {
! return 0;
! }
!
! /* Find the custom marshalling instance */
! classInfo = GetCustomMarshaller
! (thread, &custom, customName, customNameLen);
! if(!classInfo)
! {
! ThrowCustomError(thread);
! return 0;
! }
! marshal = GetMarshallingInstance
! (thread, classInfo, customCookie, customCookieLen);
! if(!marshal)
! {
! ThrowCustomError(thread);
! return 0;
! }
!
! /* Call the marshalling method and return */
! method = ILExecThreadLookupMethodInClass
! (thread, custom, "MarshalNativeToManaged",
"(Tj)oSystem.Object;");
! if(!method)
! {
! ThrowCustomError(thread);
! return 0;
! }
! result = 0;
! if(ILExecThreadCallVirtual(thread, method, &result, marshal, ptr))
! {
! result = 0;
! }
! return result;
}
Index: cvm_conv.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/cvm_conv.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -r1.25 -r1.26
*** cvm_conv.c 31 Jan 2003 02:00:29 -0000 1.25
--- cvm_conv.c 17 Feb 2003 05:20:31 -0000 1.26
***************
*** 2131,2136 ****
* pointer</operation>
*
! * <format>prefix<fsep/>tocustom<fsep/>len[4]<fsep/>name</format>
! * <dformat>{tocustom}<fsep/>len<fsep/>name</dformat>
*
* <form name="tocustom" code="COP_PREFIX_TOCUSTOM"/>
--- 2131,2136 ----
* pointer</operation>
*
! *
<format>prefix<fsep/>tocustom<fsep/>len1[4]<fsep/>len2[4]<fsep/>name1<fsep/>name2</format>
! *
<dformat>{tocustom}<fsep/>len1<fsep/>len2<fsep/>name1<fsep/>name2</dformat>
*
* <form name="tocustom" code="COP_PREFIX_TOCUSTOM"/>
***************
*** 2140,2146 ****
*
* <description>The <i>value</i> is popped from the stack as
! * type <code>ptr</code>. The custom marshaler called <i>name</i>
! * is used to convert <i>value</i> into a native pointer <i>result</i>.
! * The value <i>len</i> is the length of the <i>name</i>.
* </description>
*
--- 2140,2147 ----
*
* <description>The <i>value</i> is popped from the stack as
! * type <code>ptr</code>. The custom marshaler called <i>name1</i>,
! * with cookie <i>name2</i> is used to convert <i>value</i> into a
! * native pointer <i>result</i>. The values <i>len1</i> and <i>len2</i>
! * are the lengths of <i>name1</i> and <i>name2</i>.
* </description>
*
***************
*** 2155,2161 ****
stacktop[-1].ptrValue = _ILObjectToCustom
(thread, (ILObject *)(stacktop[-1].ptrValue),
! CVMP_ARG_WORD_PTR(const char *), CVMP_ARG_WORD);
RESTORE_STATE_FROM_THREAD();
! MODIFY_PC_AND_STACK(CVMP_LEN_WORD_PTR, 0);
}
VMBREAK(COP_PREFIX_TOCUSTOM);
--- 2156,2163 ----
stacktop[-1].ptrValue = _ILObjectToCustom
(thread, (ILObject *)(stacktop[-1].ptrValue),
! CVMP_ARG_WORD2_PTR(const char *), CVMP_ARG_WORD,
! CVMP_ARG_WORD2_PTR2(const char *), CVMP_ARG_WORD2);
RESTORE_STATE_FROM_THREAD();
! MODIFY_PC_AND_STACK(CVMP_LEN_WORD2_PTR2, 0);
}
VMBREAK(COP_PREFIX_TOCUSTOM);
***************
*** 2166,2171 ****
* reference</operation>
*
! * <format>prefix<fsep/>fromcustom<fsep/>len[4]<fsep/>name</format>
! * <dformat>{fromcustom}<fsep/>len<fsep/>name</dformat>
*
* <form name="fromcustom" code="COP_PREFIX_FROMCUSTOM"/>
--- 2168,2173 ----
* reference</operation>
*
! *
<format>prefix<fsep/>fromcustom<fsep/>len1[4]<fsep/>len2[4]<fsep/>name1<fsep/>name2</format>
! *
<dformat>{fromcustom}<fsep/>len1<fsep/>len2<fsep/>name1<fsep/>name2</dformat>
*
* <form name="fromcustom" code="COP_PREFIX_FROMCUSTOM"/>
***************
*** 2175,2181 ****
*
* <description>The <i>value</i> is popped from the stack as
! * type <code>ptr</code>. The custom marshaler called <i>name</i>
! * is used to convert <i>value</i> into an object refernce <i>result</i>.
! * The value <i>len</i> is the length of the <i>name</i>.
* </description>
*
--- 2177,2184 ----
*
* <description>The <i>value</i> is popped from the stack as
! * type <code>ptr</code>. The custom marshaler called <i>name1</i>,
! * with cookie <i>name2</i>, is used to convert <i>value</i> into an
! * object reference <i>result</i>. The values <i>len1</i> and <i>len2</i>
! * are the lengths of <i>name1</i> and <i>name2</i>.
* </description>
*
***************
*** 2190,2196 ****
stacktop[-1].ptrValue = _ILCustomToObject
(thread, stacktop[-1].ptrValue,
! CVMP_ARG_WORD_PTR(const char *), CVMP_ARG_WORD);
RESTORE_STATE_FROM_THREAD();
! MODIFY_PC_AND_STACK(CVMP_LEN_WORD_PTR, 0);
}
VMBREAK(COP_PREFIX_FROMCUSTOM);
--- 2193,2200 ----
stacktop[-1].ptrValue = _ILCustomToObject
(thread, stacktop[-1].ptrValue,
! CVMP_ARG_WORD2_PTR(const char *), CVMP_ARG_WORD,
! CVMP_ARG_WORD2_PTR2(const char *), CVMP_ARG_WORD2);
RESTORE_STATE_FROM_THREAD();
! MODIFY_PC_AND_STACK(CVMP_LEN_WORD2_PTR2, 0);
}
VMBREAK(COP_PREFIX_FROMCUSTOM);
Index: cvm_format.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/cvm_format.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -r1.6 -r1.7
*** cvm_format.h 24 Jun 2002 05:54:37 -0000 1.6
--- cvm_format.h 17 Feb 2003 05:20:31 -0000 1.7
***************
*** 62,65 ****
--- 62,66 ----
#define CVMP_LEN_WORD_PTR (6 +
sizeof(void *))
#define CVMP_LEN_WORD2_PTR (10 +
sizeof(void *))
+ #define CVMP_LEN_WORD2_PTR2 (10 + 2 *
sizeof(void *))
/*
***************
*** 113,116 ****
--- 114,118 ----
#define CVMP_ARG_WORD_PTR(type) ((type)(ReadPointer(pc
+ 6)))
#define CVMP_ARG_WORD2_PTR(type) ((type)(ReadPointer(pc
+ 10)))
+ #define CVMP_ARG_WORD2_PTR2(type) ((type)(ReadPointer(pc
+ 10 + sizeof(void *))))
#else /* IL_CVM_DIRECT */
***************
*** 153,156 ****
--- 155,159 ----
#define CVMP_LEN_WORD_PTR
_CVM_LEN_FROM_WORDS(3)
#define CVMP_LEN_WORD2_PTR
_CVM_LEN_FROM_WORDS(4)
+ #define CVMP_LEN_WORD2_PTR2
_CVM_LEN_FROM_WORDS(5)
/*
***************
*** 205,208 ****
--- 208,212 ----
#define CVMP_ARG_WORD_PTR(type) ((type)(_CVM_ARG(2)))
#define CVMP_ARG_WORD2_PTR(type) ((type)(_CVM_ARG(3)))
+ #define CVMP_ARG_WORD2_PTR2(type) ((type)(_CVM_ARG(4)))
#endif /* IL_CVM_DIRECT */
Index: cvm_lengths.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/cvm_lengths.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -r1.7 -r1.8
*** cvm_lengths.c 27 Dec 2002 12:25:09 -0000 1.7
--- cvm_lengths.c 17 Feb 2003 05:20:31 -0000 1.8
***************
*** 480,487 ****
--- 480,491 ----
/* ansi2str */ CVMP_LEN_NONE,
/* utf82str */ CVMP_LEN_NONE,
+ /* str2utf16 */ CVMP_LEN_NONE,
+ /* utf162str */ CVMP_LEN_NONE,
/* delegate2fnptr */ CVMP_LEN_NONE,
/* array2ptr */ CVMP_LEN_NONE,
/* refarray2ansi */ CVMP_LEN_NONE,
/* refarray2utf8 */ CVMP_LEN_NONE,
+ /* tocustom */ CVMP_LEN_WORD2_PTR2,
+ /* fromcustom */ CVMP_LEN_WORD2_PTR2,
/*
***************
*** 517,524 ****
* Reserved opcodes.
*/
- /* preserved_51 */ CVMP_LEN_NONE,
- /* preserved_52 */ CVMP_LEN_NONE,
- /* preserved_53 */ CVMP_LEN_NONE,
- /* preserved_54 */ CVMP_LEN_NONE,
/* preserved_55 */ CVMP_LEN_NONE,
/* preserved_56 */ CVMP_LEN_NONE,
--- 521,524 ----
Index: cvmc_gen.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/cvmc_gen.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -r1.5 -r1.6
*** cvmc_gen.h 24 Jun 2002 05:54:37 -0000 1.5
--- cvmc_gen.h 17 Feb 2003 05:20:31 -0000 1.6
***************
*** 271,274 ****
--- 271,287 ----
/*
+ * Output an instruction that has two word arguments and two pointer
arguments.
+ */
+ #define CVMP_OUT_WORD2_PTR2(opcode,value1,value2,value3,value4) \
+ do { \
+ _CVM_BYTE(COP_PREFIX); \
+ _CVM_BYTE((opcode)); \
+ _CVM_WORD((value1)); \
+ _CVM_WORD((value2)); \
+ _CVM_PTR((value3)); \
+ _CVM_PTR((value4)); \
+ } while (0)
+
+ /*
* Output an instruction that has a wide argument and a pointer argument.
*/
***************
*** 756,759 ****
--- 769,784 ----
_CVM_WORD((value2)); \
_CVM_PTR((value3)); \
+ } while (0)
+
+ /*
+ * Output an instruction that has two word arguments and two pointer
arguments.
+ */
+ #define CVMP_OUT_WORD2_PTR2(opcode,value1,value2,value3,value4) \
+ do { \
+ _CVMP_OPCODE((opcode)); \
+ _CVM_WORD((value1)); \
+ _CVM_WORD((value2)); \
+ _CVM_PTR((value3)); \
+ _CVM_PTR((value4)); \
} while (0)
Index: cvmc_setup.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/cvmc_setup.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -C2 -r1.30 -r1.31
*** cvmc_setup.c 31 Jan 2003 03:03:46 -0000 1.30
--- cvmc_setup.c 17 Feb 2003 05:20:31 -0000 1.31
***************
*** 637,643 ****
case IL_META_MARSHAL_CUSTOM:
{
! CVMP_OUT_WORD_PTR(COP_PREFIX_TOCUSTOM,
!
(ILUInt32)(ILInt32)customNameLen,
! (void
*)customName);
}
break;
--- 637,645 ----
case IL_META_MARSHAL_CUSTOM:
{
! CVMP_OUT_WORD2_PTR2(COP_PREFIX_TOCUSTOM,
!
(ILUInt32)(ILInt32)customNameLen,
!
(ILUInt32)(ILInt32)customCookieLen,
!
(void *)customName,
!
(void *)customCookie);
}
break;
***************
*** 1055,1061 ****
case IL_META_MARSHAL_CUSTOM:
{
! CVMP_OUT_WORD_PTR(COP_PREFIX_FROMCUSTOM,
!
(ILUInt32)(ILInt32)customNameLen,
! (void
*)customName);
}
break;
--- 1057,1065 ----
case IL_META_MARSHAL_CUSTOM:
{
!
CVMP_OUT_WORD2_PTR2(COP_PREFIX_FROMCUSTOM,
!
(ILUInt32)(ILInt32)customNameLen,
!
(ILUInt32)(ILInt32)customCookieLen,
!
(void *)customName,
!
(void *)customCookie);
}
break;
Index: engine.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/engine.h,v
retrieving revision 1.67
retrieving revision 1.68
diff -C2 -r1.67 -r1.68
*** engine.h 31 Jan 2003 02:00:29 -0000 1.67
--- engine.h 17 Feb 2003 05:20:31 -0000 1.68
***************
*** 547,551 ****
*/
void *_ILObjectToCustom(ILExecThread *thread, ILObject *obj,
! const char *customName, int
customNameLen);
/*
--- 547,552 ----
*/
void *_ILObjectToCustom(ILExecThread *thread, ILObject *obj,
! const char *customName, int
customNameLen,
! const char *customCookie, int
customCookieLen);
/*
***************
*** 554,558 ****
*/
ILObject *_ILCustomToObject(ILExecThread *thread, void *ptr,
! const char *customName,
int customNameLen);
#ifdef __cplusplus
--- 555,560 ----
*/
ILObject *_ILCustomToObject(ILExecThread *thread, void *ptr,
! const char *customName,
int customNameLen,
! const char
*customCookie, int customCookieLen);
#ifdef __cplusplus
Index: lookup.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/lookup.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -r1.9 -r1.10
*** lookup.c 12 Jun 2002 03:41:56 -0000 1.9
--- lookup.c 17 Feb 2003 05:20:31 -0000 1.10
***************
*** 700,703 ****
--- 700,713 ----
{
ILClass *classInfo;
+ classInfo = ILExecThreadLookupClass(thread, typeName);
+ return ILExecThreadLookupMethodInClass
+ (thread, classInfo, methodName, signature);
+ }
+
+ ILMethod *ILExecThreadLookupMethodInClass(ILExecThread *thread,
+
ILClass *classInfo,
+
const char *methodName,
+
const char *signature)
+ {
ILMethod *method;
ILType *methodSignature;
***************
*** 708,714 ****
return 0;
}
-
- /* Look up the type */
- classInfo = ILExecThreadLookupClass(thread, typeName);
/* Resolve the method within the type or any of its ancestors */
--- 718,721 ----
Index: pinvoke.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/pinvoke.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -r1.19 -r1.20
*** pinvoke.c 31 Jan 2003 03:03:46 -0000 1.19
--- pinvoke.c 17 Feb 2003 05:20:31 -0000 1.20
***************
*** 559,563 ****
stacktop->ptrValue = _ILCustomToObject
(thread, *((void **)(*args)),
! customName, customNameLen);
if(ILExecThreadHasException(thread))
{
--- 559,564 ----
stacktop->ptrValue = _ILCustomToObject
(thread, *((void **)(*args)),
! customName, customNameLen,
! customCookie, customCookieLen);
if(ILExecThreadHasException(thread))
{
***************
*** 777,781 ****
*((void **)result) = _ILObjectToCustom
(thread, (ILObject
*)(thread->stackTop[-1].ptrValue),
! customName, customNameLen);
--(thread->stackTop);
}
--- 778,782 ----
*((void **)result) = _ILObjectToCustom
(thread, (ILObject
*)(thread->stackTop[-1].ptrValue),
! customName, customNameLen,
customCookie, customCookieLen);
--(thread->stackTop);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnet/engine custom.c,1.1,1.2 cvm_conv.c,1.25,1.26 cvm_format.h,1.6,1.7 cvm_lengths.c,1.7,1.8 cvmc_gen.h,1.5,1.6 cvmc_setup.c,1.30,1.31 engine.h,1.67,1.68 lookup.c,1.9,1.10 pinvoke.c,1.19,1.20,
Rhys Weatherley <address@hidden> <=
- Prev by Date:
[Dotgnu-pnet-commits] CVS: pnetC/libc/time .cvsignore,NONE,1.1 Makefile.am,NONE,1.1 clock.c,NONE,1.1 gmtime.c,NONE,1.1 time-defs.h,NONE,1.1 time-glue.cs,NONE,1.1 time-vars.c,NONE,1.1 time.c,NONE,1.1tzset.c,NONE,1.1
- Next by Date:
[Dotgnu-pnet-commits] CVS: pnet/include il_engine.h,1.31,1.32
- Previous by thread:
[Dotgnu-pnet-commits] CVS: pnetC/libc/time .cvsignore,NONE,1.1 Makefile.am,NONE,1.1 clock.c,NONE,1.1 gmtime.c,NONE,1.1 time-defs.h,NONE,1.1 time-glue.cs,NONE,1.1 time-vars.c,NONE,1.1 time.c,NONE,1.1tzset.c,NONE,1.1
- Next by thread:
[Dotgnu-pnet-commits] CVS: pnet/include il_engine.h,1.31,1.32
- Index(es):