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

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

[dotgnu-pnet-commits] pnet ChangeLog include/il_meta.h include/il_pro...


From: Klaus Treichel
Subject: [dotgnu-pnet-commits] pnet ChangeLog include/il_meta.h include/il_pro...
Date: Fri, 20 Oct 2006 19:30:55 +0000

CVSROOT:        /cvsroot/dotgnu-pnet
Module name:    pnet
Changes by:     Klaus Treichel <ktreichel>      06/10/20 19:30:55

Modified files:
        .              : ChangeLog 
        include        : il_meta.h il_program.h 
        image          : marshal.c 
        engine         : convert.c jitc.c 

Log message:
        2006-10-20  Klaus Treichel  <address@hidden>
        
                * include/il_meta.h, include/il_program.h, image/marshal.c: Add
                ILPInvokeGetCharSet in image/marshal.c to get the characterset 
used to
                marshal a method or struct. On a Windows platform the automatic
                characterset depends on the current windows version 
(GetVersion()).
                For Windows 9x and older the ansi characterset is used and for 
all
                NT versions utf16.
        
                * engine/convert.c, engine/jitc.c: Add name mangling  for the 
method name
                on Windows platforms if ExactSpelling = false in the 
DllImportAttribute.
                This allows using unicode versions of functions on NT and the 
ansi versions
                on older systems.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/pnet/ChangeLog?cvsroot=dotgnu-pnet&r1=1.3378&r2=1.3379
http://cvs.savannah.gnu.org/viewcvs/pnet/include/il_meta.h?cvsroot=dotgnu-pnet&r1=1.11&r2=1.12
http://cvs.savannah.gnu.org/viewcvs/pnet/include/il_program.h?cvsroot=dotgnu-pnet&r1=1.53&r2=1.54
http://cvs.savannah.gnu.org/viewcvs/pnet/image/marshal.c?cvsroot=dotgnu-pnet&r1=1.14&r2=1.15
http://cvs.savannah.gnu.org/viewcvs/pnet/engine/convert.c?cvsroot=dotgnu-pnet&r1=1.26&r2=1.27
http://cvs.savannah.gnu.org/viewcvs/pnet/engine/jitc.c?cvsroot=dotgnu-pnet&r1=1.58&r2=1.59

Patches:
Index: ChangeLog
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/ChangeLog,v
retrieving revision 1.3378
retrieving revision 1.3379
diff -u -b -r1.3378 -r1.3379
--- ChangeLog   18 Oct 2006 11:06:08 -0000      1.3378
+++ ChangeLog   20 Oct 2006 19:30:54 -0000      1.3379
@@ -1,3 +1,17 @@
+2006-10-20  Klaus Treichel  <address@hidden>
+
+       * include/il_meta.h, include/il_program.h, image/marshal.c: Add
+       ILPInvokeGetCharSet in image/marshal.c to get the characterset used to
+       marshal a method or struct. On a Windows platform the automatic
+       characterset depends on the current windows version (GetVersion()).
+       For Windows 9x and older the ansi characterset is used and for all
+       NT versions utf16.
+
+       * engine/convert.c, engine/jitc.c: Add name mangling  for the method 
name
+       on Windows platforms if ExactSpelling = false in the DllImportAttribute.
+       This allows using unicode versions of functions on NT and the ansi 
versions
+       on older systems.
+
 2006-10-18  Klaus Treichel  <address@hidden>
 
        * engine/jitc_array.c: Change the allocation scheme for the arrays. Use

Index: include/il_meta.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/include/il_meta.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- include/il_meta.h   29 Jul 2004 04:37:27 -0000      1.11
+++ include/il_meta.h   20 Oct 2006 19:30:54 -0000      1.12
@@ -550,6 +550,8 @@
 #define        IL_META_MARSHAL_CUSTOM                                  0x0008
 #define        IL_META_MARSHAL_ANSI_ARRAY                              0x0009
 #define        IL_META_MARSHAL_UTF8_ARRAY                              0x000A
+#define        IL_META_MARSHAL_UTF16_ARRAY                             0x000B
+#define        IL_META_MARSHAL_REF_UTF16_ARRAY                 0x000C
 
 /*
  * Control data structure for reading from the metadata section.

Index: include/il_program.h
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/include/il_program.h,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -b -r1.53 -r1.54
--- include/il_program.h        12 Jun 2004 13:13:41 -0000      1.53
+++ include/il_program.h        20 Oct 2006 19:30:54 -0000      1.54
@@ -1532,6 +1532,11 @@
 ILPInvoke *ILPInvokeFindField(ILField *field);
 
 /*
+ * Determine the character set to use when marshalling this pinvoke or method.
+ */
+ILUInt32 ILPInvokeGetCharSet(ILPInvoke *pinvoke, ILMethod *method);
+
+/*
  * Get the marshal conversion type for a method parameter.
  * If "param" is 0, then report about the return type.
  */

Index: image/marshal.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/image/marshal.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- image/marshal.c     18 Nov 2003 20:26:46 -0000      1.14
+++ image/marshal.c     20 Oct 2006 19:30:54 -0000      1.15
@@ -19,6 +19,9 @@
  */
 
 #include "program.h"
+#ifdef IL_WIN32_PLATFORM
+#include <windows.h>
+#endif
 
 #ifdef __cplusplus
 extern "C" {
@@ -26,10 +29,18 @@
 
 #ifdef IL_CONFIG_PINVOKE
 
+#ifdef IL_WIN32_PLATFORM
+/*
+ * The information returned by GetVersion on the box we're running on.
+ */
+static DWORD _ILPInvokeWindowsVersion = 0;
+
+#endif
+
 /*
- * Determine the character set to use for strings.
+ * Determine the character set to use when marshalling this pinvoke or method.
  */
-static ILUInt32 StringCharSet(ILPInvoke *pinvoke, ILMethod *method)
+ILUInt32 ILPInvokeGetCharSet(ILPInvoke *pinvoke, ILMethod *method)
 {
        /* Check the PInvoke record for character set information */
        if(pinvoke)
@@ -37,7 +48,6 @@
                switch(pinvoke->member.attributes & 
IL_META_PINVOKE_CHAR_SET_MASK)
                {
                        case IL_META_PINVOKE_CHAR_SET_ANSI:
-                       case IL_META_PINVOKE_CHAR_SET_AUTO:
                        {
                                return IL_META_MARSHAL_ANSI_STRING;
                        }
@@ -45,23 +55,84 @@
        
                        case IL_META_PINVOKE_CHAR_SET_UNICODE:
                        {
+                       #ifdef IL_WIN32_PLATFORM
+                               return IL_META_MARSHAL_UTF16_STRING;
+                       #else
                                return IL_META_MARSHAL_UTF8_STRING;
+                       #endif
+                       }
+                       /* Not reached */
+
+                       case IL_META_PINVOKE_CHAR_SET_AUTO:
+                       {
+                       #ifdef IL_WIN32_PLATFORM
+                               if(!_ILPInvokeWindowsVersion)
+                               {
+                                       _ILPInvokeWindowsVersion = GetVersion();
+                               }
+                               if(_ILPInvokeWindowsVersion & 0xC0000000)
+                               {
+                                       /* Windows 9x and less. */
+                                       return IL_META_MARSHAL_ANSI_STRING;
+                               }
+                               else
+                               {
+                                       return IL_META_MARSHAL_UTF16_STRING;
+                               }
+                       #else
+                               return IL_META_MARSHAL_ANSI_STRING;
+                       #endif
                        }
                        /* Not reached */
                }
        }
 
        /* Check the class for character set information */
-       if(method && (method->member.owner->attributes &
-                                               
IL_META_TYPEDEF_STRING_FORMAT_MASK) ==
-                       IL_META_TYPEDEF_UNICODE_CLASS)
+       if(method)
+       {
+               switch(method->member.owner->attributes & 
+                               IL_META_TYPEDEF_STRING_FORMAT_MASK)
+               {
+                       case IL_META_TYPEDEF_ANSI_CLASS:
+                       {
+                               return IL_META_MARSHAL_ANSI_STRING;
+                       }
+                       /* Not reached */
+
+                       case IL_META_TYPEDEF_UNICODE_CLASS:
        {
+                       #ifdef IL_WIN32_PLATFORM
+                               return IL_META_MARSHAL_UTF16_STRING;
+                       #else
                return IL_META_MARSHAL_UTF8_STRING;
+                       #endif
+                       }
+                       /* Not reached */
+
+                       case IL_META_TYPEDEF_AUTO_CLASS:
+                       {
+                       #ifdef IL_WIN32_PLATFORM
+                               if(!_ILPInvokeWindowsVersion)
+                               {
+                                       _ILPInvokeWindowsVersion = GetVersion();
+                               }
+                               if(_ILPInvokeWindowsVersion & 0xC0000000)
+                               {
+                                       /* Windows 9x and less. */
+                                       return IL_META_MARSHAL_ANSI_STRING;
        }
        else
        {
+                                       return IL_META_MARSHAL_UTF16_STRING;
+                               }
+                       #else
                return IL_META_MARSHAL_ANSI_STRING;
+                       #endif
        }
+                       /* Not reached */
+               }
+       }
+       return IL_META_MARSHAL_ANSI_STRING;
 }
 
 /*
@@ -165,11 +236,19 @@
                /* Value string type */
                if(nativeTypeCode == IL_META_NATIVETYPE_LPWSTR)
                {
+               #ifdef IL_WIN32_PLATFORM
                        return IL_META_MARSHAL_UTF16_STRING;
+               #else
+                       return IL_META_MARSHAL_UTF8_STRING;
+               #endif
+               }
+               else if(nativeTypeCode == IL_META_NATIVETYPE_LPSTR)
+               {
+                       return IL_META_MARSHAL_ANSI_STRING;
                }
                else
                {
-                       return StringCharSet(pinvoke, method);
+                       return ILPInvokeGetCharSet(pinvoke, method);
                }
        }
        else if(ILTypeIsDelegateSubClass(type))
@@ -182,14 +261,26 @@
                if(ILTypeIsStringClass(ILTypeGetElemType(type)))
                {
                        /* Array of strings, passed as "char **" */
-                       if(StringCharSet(pinvoke, method) == 
IL_META_MARSHAL_ANSI_STRING)
+                       switch(ILPInvokeGetCharSet(pinvoke, method))
                        {
-                               return IL_META_MARSHAL_ANSI_ARRAY;
-                       }
-                       else
+                               case IL_META_MARSHAL_UTF8_STRING:
                        {
                                return IL_META_MARSHAL_UTF8_ARRAY;
                        }
+                               /* not reached */
+       
+                               case IL_META_MARSHAL_UTF16_STRING:
+                               {
+                                       return IL_META_MARSHAL_UTF16_ARRAY;
+                               }
+                               /* not reached */
+
+                               default:
+                               {
+                                       return IL_META_MARSHAL_ANSI_ARRAY;
+                               }
+                               /* not reached */
+                       }
                }
                else
                {
@@ -205,14 +296,27 @@
                if(ILType_IsSimpleArray(ILType_Ref(type)) &&
                   ILTypeIsStringClass(ILTypeGetElemType(ILType_Ref(type))))
                {
-                       if(StringCharSet(pinvoke, method) == 
IL_META_MARSHAL_ANSI_STRING)
+                       switch(ILPInvokeGetCharSet(pinvoke, method))
                        {
-                               return IL_META_MARSHAL_REF_ANSI_ARRAY;
-                       }
-                       else
+                               case IL_META_MARSHAL_UTF8_STRING:
                        {
                                return IL_META_MARSHAL_REF_UTF8_ARRAY;
                        }
+                               /* not reached */
+       
+                               case IL_META_MARSHAL_UTF16_STRING:
+                               {
+                                       return IL_META_MARSHAL_REF_UTF16_ARRAY;
+                               }
+                               /* not reached */
+
+                               default:
+                               {
+                                       return IL_META_MARSHAL_REF_ANSI_ARRAY;
+                               }
+                               /* not reached */
+                       }
+                       return IL_META_MARSHAL_REF_ANSI_ARRAY;
                }
        }
 

Index: engine/convert.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/convert.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -b -r1.26 -r1.27
--- engine/convert.c    1 Aug 2006 18:12:56 -0000       1.26
+++ engine/convert.c    20 Oct 2006 19:30:54 -0000      1.27
@@ -294,8 +294,40 @@
                                        name = ILMethod_Name(method);
                                }
 
+                       #ifdef IL_WIN32_PLATFORM
+
+                               if(!(pinv->member.attributes & 
IL_META_PINVOKE_NO_MANGLE))
+                               {
+                                       /* We have to append an A or W to the 
function */
+                                       /* name depending on the characterset 
used. */
+                                       /* On Windows we have only either Ansi 
or Utf16 */
+                                       int nameLength = strlen(name);
+                                       ILUInt32 charSetUsed = 
ILPInvokeGetCharSet(pinv, method);
+                                       char newName[nameLength + 2];
+
+                                       strcpy(newName, name);
+                                       if(charSetUsed == 
IL_META_MARSHAL_UTF16_STRING)
+                                       {
+                                               newName[nameLength] = 'W';
+                                       }
+                                       else
+                                       {
+                                               newName[nameLength] = 'A';
+                                       }
+                                       newName[nameLength + 1] = '\0';
+
+                                       /* Look up the method within the module 
*/
+                                       fnInfo.func = 
ILDynLibraryGetSymbol(moduleHandle, newName);
+                               }
+                               if(!fnInfo.func)
+                               {
+                                       /* Look up the method within the module 
*/
+                                       fnInfo.func = 
ILDynLibraryGetSymbol(moduleHandle, name);
+                               }
+                       #else   /* !IL_WIN32_PLATFORM */
                                /* Look up the method within the module */
                                fnInfo.func = 
ILDynLibraryGetSymbol(moduleHandle, name);
+                       #endif  /* !IL_WIN32_PLATFORM */
                        #else /* !IL_CONFIG_PINVOKE */
                                METADATA_UNLOCK(thread);
                                *errorCode = IL_CONVERT_NOT_IMPLEMENTED;

Index: engine/jitc.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/engine/jitc.c,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -b -r1.58 -r1.59
--- engine/jitc.c       17 Oct 2006 12:24:18 -0000      1.58
+++ engine/jitc.c       20 Oct 2006 19:30:54 -0000      1.59
@@ -3487,6 +3487,44 @@
                                                        name = 
ILMethod_Name(method);
                                                }
 
+                                       #ifdef IL_WIN32_PLATFORM
+
+                                               if(!(pinv->member.attributes & 
IL_META_PINVOKE_NO_MANGLE))
+                                               {
+                                                       /* We have to append an 
A or W to the function */
+                                                       /* name depending on 
the characterset used. */
+                                                       /* On Windows we have 
only either Ansi or Utf16 */
+                                                       int nameLength = 
strlen(name);
+                                                       ILUInt32 charSetUsed = 
ILPInvokeGetCharSet(pinv, method);
+                                                       char newName[nameLength 
+ 2];
+
+                                                       strcpy(newName, name);
+                                                       if(charSetUsed == 
IL_META_MARSHAL_UTF16_STRING)
+                                                       {
+                                                               
newName[nameLength] = 'W';
+                                                       }
+                                                       else
+                                                       {
+                                                               
newName[nameLength] = 'A';
+                                                       }
+                                                       newName[nameLength + 1] 
= '\0';
+
+                                                       /* Look up the method 
within the module */
+                                                       fnInfo.func = 
ILDynLibraryGetSymbol(moduleHandle, newName);
+                                               }
+                                               if(!fnInfo.func)
+                                               {
+                                                       /* Look up the method 
within the module */
+                                                       fnInfo.func = 
ILDynLibraryGetSymbol(moduleHandle, name);
+                                               }
+
+                                               if(!(fnInfo.func))
+                                               {
+                                                       fnInfo.func = 
_IL_JIT_PINVOKE_ENTRYPOINTNOTFOUND;
+                                               }
+
+                                       #else   /* !IL_WIN32_PLATFORM */
+
                                                /* Look up the method within 
the module */
                                                fnInfo.func = 
ILDynLibraryGetSymbol(moduleHandle, name);
 
@@ -3494,6 +3532,7 @@
                                                {
                                                        fnInfo.func = 
_IL_JIT_PINVOKE_ENTRYPOINTNOTFOUND;
                                                }
+                                       #endif  /* !IL_WIN32_PLATFORM */
                                        }
                                        else
                                        {




reply via email to

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