Changes between Initial Version and Version 1 of Ticket #1047


Ignore:
Timestamp:
07/24/09 14:40:48 (15 years ago)
Author:
tomfukushima
Comment:

Just reformatted a bit.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #1047

    • Property Component GeneralWeb API
    • Property Milestone2.2
    • Property Version 2.0.2
  • Ticket #1047 – Description

    initial v1  
    1 There appears to be a bug in the marshalling of unmanaged ANSI strings across the unmanaged/managed boundary in the .NET wrappers due to changes made for RFC 68.  This has caused heap corruption issues when the .NET wrappers are called on a product that uses the MapGuide OS code.
     1There appears to be a bug in the marshalling of unmanaged ANSI strings across the unmanaged/managed boundary in the .NET wrappers due to changes made for RFC 68.  This has caused heap corruption issues when the .NET wrappers are called on a product that uses the !MapGuide OS code.
    22
    3 MapGuide RFC 68 can be found here:
     3!MapGuide RFC 68 can be found here:
    44
    55http://trac.osgeo.org/mapguide/wiki/MapGuideRfc68
     
    1313readily evident in heap corruption assertions on 64-bit platforms, but should
    1414also be present in 32-bit platforms.  The heap corruptions occurred at startup
    15 of the product using MapGuide OS code via the .NET API and would result in the product failing to successfully start.
     15of the product using !MapGuide OS code via the .NET API and would result in the product failing to successfully start.
    1616
    17 In the submission, the following methods were added to MgObject:
     17In the submission, the following methods were added to !MgObject:
    1818
     19{{{
    1920virtual char* GetMultiByteClassName();
    2021virtual char* GetNameSpace();
     22}}}
    2123
    2224These methods returned a string with the class name or name space.  On the
     
    2426getclassid.code:
    2527
     28{{{
    2629DllExport char* getClassName(void* ptrObj)
    2730{
     
    3336  return ((MgObject*)ptrObj)->GetNameSpace();
    3437}
     38}}}
    3539
    3640These methods are exported from the unmanaged DLL and called from the managed
     
    3842like this:
    3943
     44{{{
    4045  [DllImport("unmanagedDllName", EntryPoint="getClassName")]
    4146  public static extern string getClassName(IntPtr objectRef);
     
    4348  [DllImport("unManagedDllName", EntryPoint="getNameSpace")]
    4449  public static extern string getNameSpace(IntPtr objectRef);
     50}}}
    4551
    4652The problem occurs because the DLLImport mechanism doesn't marshall the char *
     
    6268void/IntPtr to the managed wrapper.  The code now looks like this:
    6369
     70{{{
    6471DllExport void* getClassName(void* ptrObj)
    6572{
     
    7582    return jresult;
    7683}
     84}}}
    7785
    7886(similar changes to getNameSpace)
    7987
    8088The return type should also be changed on the managed side DLLImports from string to
    81 IntPtr:
     89!IntPtr:
    8290
     91{{{
    8392  [DllImport("unManagedDllName", EntryPoint="getClassName")]
    8493  public static extern IntPtr getClassName(IntPtr objectRef);
     
    8695  [DllImport("unManagedDllName", EntryPoint="getNameSpace")]
    8796  public static extern IntPtr getNameSpace(IntPtr objectRef);
     97}}}
    8898
    89 Since the getClassName and getNameSpace functions now return IntPtr, the
     99Since the getClassName and getNameSpace functions now return !IntPtr, the
    90100createObject overload that took these two values as parameters needed to be
    91101modified to match the type.  In addition, code was added to createObject to
     
    93103release the shared memory buffer:
    94104
     105{{{
    95106 static public object createObject(int id, IntPtr nameSpaceNamePtr, IntPtr
    96107classNamePtr, IntPtr cPtr, bool ownMemory)
     
    106117
    107118      ...
     119}}}
    108120
    109121A patch file with the proposed fixes is attached to this ticket.