dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnet/engine cvm.h,1.37,1.38 cvm_conv.c,1.23,


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnet/engine cvm.h,1.37,1.38 cvm_conv.c,1.23,1.24 cvm_dasm.c,1.43,1.44 cvmc_setup.c,1.27,1.28 lib_string.c,1.30,1.31 pinvoke.c,1.16,1.17
Date: Tue, 28 Jan 2003 01:25:03 -0500

Update of /cvsroot/dotgnu-pnet/pnet/engine
In directory subversions:/tmp/cvs-serv3031/engine

Modified Files:
        cvm.h cvm_conv.c cvm_dasm.c cvmc_setup.c lib_string.c 
        pinvoke.c 
Log Message:


Implement marshalling for the LPWSTR type.


Index: cvm.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/cvm.h,v
retrieving revision 1.37
retrieving revision 1.38
diff -C2 -r1.37 -r1.38
*** cvm.h       1 Dec 2002 07:39:39 -0000       1.37
--- cvm.h       28 Jan 2003 06:25:01 -0000      1.38
***************
*** 462,498 ****
  #define       COP_PREFIX_ANSI2STR                     0x3E
  #define       COP_PREFIX_UTF82STR                     0x3F
! #define       COP_PREFIX_DELEGATE2FNPTR       0x40
! #define       COP_PREFIX_ARRAY2PTR            0x41
! #define       COP_PREFIX_REFARRAY2ANSI        0x42
! #define       COP_PREFIX_REFARRAY2UTF8        0x43
  
  /*
   * Inline method replacements.
   */
! #define       COP_PREFIX_STRING_CONCAT_2      0x44
! #define       COP_PREFIX_STRING_CONCAT_3      0x45
! #define       COP_PREFIX_STRING_CONCAT_4      0x46
! #define       COP_PREFIX_STRING_EQ            0x47
! #define       COP_PREFIX_STRING_NE            0x48
! #define       COP_PREFIX_STRING_GET_CHAR      0x49
! #define       COP_PREFIX_TYPE_FROM_HANDLE     0x4A
! #define       COP_PREFIX_MONITOR_ENTER        0x4B
! #define       COP_PREFIX_MONITOR_EXIT         0x4C
  
  /*
   * Binary value fixups.
   */
! #define       COP_PREFIX_FIX_I4_I                     0x4D
! #define       COP_PREFIX_FIX_I4_U                     0x4E
  
  /*
   * Trigger method unrolling.
   */
! #define       COP_PREFIX_UNROLL_METHOD        0x4F
  
  /*
   * Allocate local stack space.
   */
! #define       COP_PREFIX_LOCAL_ALLOC          0x50
  
  /*
--- 462,500 ----
  #define       COP_PREFIX_ANSI2STR                     0x3E
  #define       COP_PREFIX_UTF82STR                     0x3F
! #define       COP_PREFIX_STR2UTF16            0x40
! #define       COP_PREFIX_UTF162STR            0x41
! #define       COP_PREFIX_DELEGATE2FNPTR       0x42
! #define       COP_PREFIX_ARRAY2PTR            0x43
! #define       COP_PREFIX_REFARRAY2ANSI        0x44
! #define       COP_PREFIX_REFARRAY2UTF8        0x45
  
  /*
   * Inline method replacements.
   */
! #define       COP_PREFIX_STRING_CONCAT_2      0x46
! #define       COP_PREFIX_STRING_CONCAT_3      0x47
! #define       COP_PREFIX_STRING_CONCAT_4      0x48
! #define       COP_PREFIX_STRING_EQ            0x49
! #define       COP_PREFIX_STRING_NE            0x4A
! #define       COP_PREFIX_STRING_GET_CHAR      0x4B
! #define       COP_PREFIX_TYPE_FROM_HANDLE     0x4C
! #define       COP_PREFIX_MONITOR_ENTER        0x4D
! #define       COP_PREFIX_MONITOR_EXIT         0x4E
  
  /*
   * Binary value fixups.
   */
! #define       COP_PREFIX_FIX_I4_I                     0x4F
! #define       COP_PREFIX_FIX_I4_U                     0x50
  
  /*
   * Trigger method unrolling.
   */
! #define       COP_PREFIX_UNROLL_METHOD        0x51
  
  /*
   * Allocate local stack space.
   */
! #define       COP_PREFIX_LOCAL_ALLOC          0x52
  
  /*

Index: cvm_conv.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/cvm_conv.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -r1.23 -r1.24
*** cvm_conv.c  9 Dec 2002 08:59:00 -0000       1.23
--- cvm_conv.c  28 Jan 2003 06:25:01 -0000      1.24
***************
*** 1912,1915 ****
--- 1912,1989 ----
  
  /**
+  * <opcode name="str2utf16" group="Conversion operators">
+  *   <operation>Convert <code>string</code> to <code>utf16 char *</code>
+  *              </operation>
+  *
+  *   <format>prefix<fsep/>str2utf16</format>
+  *   <dformat>{str2utf16}</dformat>
+  *
+  *   <form name="str2utf16" code="COP_PREFIX_STR2UTF16"/>
+  *
+  *   <before>..., value</before>
+  *   <after>..., result</after>
+  *
+  *   <description>The <i>value</i> is popped from the stack as
+  *   type <code>string</code>.  The string is converted into a
+  *   <i>result</i> wide character buffer using the UTF-16 encoding.
+  *   A pointer to the buffer is pushed onto the stack as type
+  *   <code>ptr</code>.</description>
+  *
+  *   <notes>This instruction is used to convert C# strings into wide
+  *   character buffers during "PInvoke" marshalling operations.</notes>
+  * </opcode>
+  */
+ VMCASE(COP_PREFIX_STR2UTF16):
+ {
+       /* Convert a string object into a UTF-16 character buffer */
+       if(stacktop[-1].ptrValue)
+       {
+               COPY_STATE_TO_THREAD();
+               stacktop[-1].ptrValue =
+                       (void *)ILStringToUTF16
+                               (thread, (ILString *)(stacktop[-1].ptrValue));
+               RESTORE_STATE_FROM_THREAD();
+       }
+       MODIFY_PC_AND_STACK(CVMP_LEN_NONE, 0);
+ }
+ VMBREAK(COP_PREFIX_STR2UTF16);
+ 
+ /**
+  * <opcode name="utf162str" group="Conversion operators">
+  *   <operation>Convert <code>utf16 char *</code> to <code>string</code>
+  *              </operation>
+  *
+  *   <format>prefix<fsep/>utf162str</format>
+  *   <dformat>{utf162str}</dformat>
+  *
+  *   <form name="utf162str" code="COP_PREFIX_UTF162STR"/>
+  *
+  *   <before>..., value</before>
+  *   <after>..., result</after>
+  *
+  *   <description>The <i>value</i> is popped from the stack as
+  *   type <code>utf16 char *</code>.  The wide character buffer
+  *   is converted into a <i>result</i> of type <code>string</code>,
+  *   which is pushed onto the stack.</description>
+  *
+  *   <notes>This instruction is used to convert wide character buffers
+  *   into C# strings during "PInvoke" marshalling operations.</notes>
+  * </opcode>
+  */
+ VMCASE(COP_PREFIX_UTF162STR):
+ {
+       /* Convert a UTF-16 character buffer into a string */
+       if(stacktop[-1].ptrValue)
+       {
+               COPY_STATE_TO_THREAD();
+               stacktop[-1].ptrValue = (void *)ILStringWCreate
+                       (thread, (const ILUInt16 *)(stacktop[-1].ptrValue));
+               RESTORE_STATE_FROM_THREAD();
+       }
+       MODIFY_PC_AND_STACK(CVMP_LEN_NONE, 0);
+ }
+ VMBREAK(COP_PREFIX_UTF162STR);
+ 
+ /**
   * <opcode name="delegate2fnptr" group="Conversion operators">
   *   <operation>Convert a delegate into a function pointer</operation>

Index: cvm_dasm.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/cvm_dasm.c,v
retrieving revision 1.43
retrieving revision 1.44
diff -C2 -r1.43 -r1.44
*** cvm_dasm.c  1 Dec 2002 07:39:39 -0000       1.43
--- cvm_dasm.c  28 Jan 2003 06:25:01 -0000      1.44
***************
*** 520,523 ****
--- 520,525 ----
        {"ansi2str",            CVM_OPER_NONE},
        {"utf82str",            CVM_OPER_NONE},
+       {"str2utf16",           CVM_OPER_NONE},
+       {"utf162str",           CVM_OPER_NONE},
        {"delegate2fnptr",      CVM_OPER_NONE},
        {"array2ptr",           CVM_OPER_NONE},
***************
*** 557,562 ****
         * Reserved opcodes.
         */
-       {"preserved_51",        CVM_OPER_NONE},
-       {"preserved_52",        CVM_OPER_NONE},
        {"preserved_53",        CVM_OPER_NONE},
        {"preserved_54",        CVM_OPER_NONE},
--- 559,562 ----

Index: cvmc_setup.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/cvmc_setup.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -C2 -r1.27 -r1.28
*** cvmc_setup.c        29 Jun 2002 11:21:15 -0000      1.27
--- cvmc_setup.c        28 Jan 2003 06:25:01 -0000      1.28
***************
*** 598,601 ****
--- 598,607 ----
                                break;
  
+                               case IL_META_MARSHAL_UTF16_STRING:
+                               {
+                                       CVMP_OUT_NONE(COP_PREFIX_STR2UTF16);
+                               }
+                               break;
+ 
                                case IL_META_MARSHAL_FNPTR:
                                {
***************
*** 1018,1021 ****
--- 1024,1033 ----
                                {
                                        CVMP_OUT_NONE(COP_PREFIX_UTF82STR);
+                               }
+                               break;
+ 
+                               case IL_META_MARSHAL_UTF16_STRING:
+                               {
+                                       CVMP_OUT_NONE(COP_PREFIX_UTF162STR);
                                }
                                break;

Index: lib_string.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/lib_string.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -C2 -r1.30 -r1.31
*** lib_string.c        10 Jan 2003 00:44:11 -0000      1.30
--- lib_string.c        28 Jan 2003 06:25:01 -0000      1.31
***************
*** 1974,1977 ****
--- 1974,2010 ----
  }
  
+ ILUInt16 *ILStringToUTF16(ILExecThread *thread, ILString *str)
+ {
+       ILUInt16 *buffer;
+       ILInt32 length;
+       ILUInt16 *newStr;
+ 
+       /* Bail out immediately if the string is NULL */
+       if(!str)
+       {
+               return 0;
+       }
+ 
+       /* Determine the length of the string in UTF-16 characters */
+       buffer = StringToBuffer(str);
+       length = ((System_String *)str)->length;
+ 
+       /* Allocate space within the garbage-collected heap */
+       newStr = (ILUInt16 *)ILGCAllocAtomic((length + 1) * sizeof(ILUInt16));
+       if(!newStr)
+       {
+               ILExecThreadThrowOutOfMemory(thread);
+               return 0;
+       }
+ 
+       /* Copy the characters into the allocated buffer */
+       if(length > 0)
+       {
+               ILMemCpy(newStr, buffer, length * sizeof(ILUInt16));
+       }
+       newStr[length] = 0;
+       return newStr;
+ }
+ 
  char *ILStringToAnsi(ILExecThread *thread, ILString *str)
  {

Index: pinvoke.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/pinvoke.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -r1.16 -r1.17
*** pinvoke.c   23 Jun 2002 06:29:21 -0000      1.16
--- pinvoke.c   28 Jan 2003 06:25:01 -0000      1.17
***************
*** 523,526 ****
--- 523,549 ----
                                }
                                continue;
+ 
+                               case IL_META_MARSHAL_UTF16_STRING:
+                               {
+                                       /* Marshal a UTF-16 string from the 
native world */
+                                       CHECK_SPACE(1);
+                                       strValue = *((char **)(*args));
+                                       if(strValue)
+                                       {
+                                               stacktop->ptrValue =
+                                                       ILStringWCreate(thread, 
(ILUInt16 *)strValue);
+                                               if(!(stacktop->ptrValue))
+                                               {
+                                                       return 1;
+                                               }
+                                       }
+                                       else
+                                       {
+                                               stacktop->ptrValue = 0;
+                                       }
+                                       ++args;
+                                       ++stacktop;
+                               }
+                               continue;
                        }
                }
***************
*** 682,685 ****
--- 705,717 ----
                                /* Marshal a UTF-8 string back to the native 
world */
                                *((char **)result) = ILStringToUTF8
+                                       (thread, (ILString 
*)(thread->stackTop[-1].ptrValue));
+                               --(thread->stackTop);
+                       }
+                       return;
+ 
+                       case IL_META_MARSHAL_UTF16_STRING:
+                       {
+                               /* Marshal a UTF-16 string back to the native 
world */
+                               *((ILUInt16 **)result) = ILStringToUTF16
                                        (thread, (ILString 
*)(thread->stackTop[-1].ptrValue));
                                --(thread->stackTop);





reply via email to

[Prev in Thread] Current Thread [Next in Thread]