Merge pull request #407 from vmuriart/custom_marshal · pythonnet/pythonnet@01a35cb · GitHub
Skip to content

Commit 01a35cb

Browse files
authored
Merge pull request #407 from vmuriart/custom_marshal
Refactor Managed-Native conversion - ICustomMarshaler
2 parents 7dba617 + 78939c5 commit 01a35cb

5 files changed

Lines changed: 238 additions & 184 deletions

File tree

src/runtime/CustomMarshaler.cs

Lines changed: 171 additions & 0 deletions

src/runtime/Python.Runtime.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
<Compile Include="constructorbinder.cs" />
9090
<Compile Include="constructorbinding.cs" />
9191
<Compile Include="converter.cs" />
92+
<Compile Include="CustomMarshaler.cs" />
9293
<Compile Include="debughelper.cs" />
9394
<Compile Include="delegatemanager.cs" />
9495
<Compile Include="delegateobject.cs" />

src/runtime/converter.cs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -599,21 +599,10 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo
599599
{
600600
if (Runtime.PyUnicode_GetSize(value) == 1)
601601
{
602-
op = Runtime.PyUnicode_AS_UNICODE(value);
603-
if (Runtime.UCS == 2) // Don't trust linter, statement not always true.
604-
{
605-
// 2011-01-02: Marshal as character array because the cast
606-
// result = (char)Marshal.ReadInt16(op); throws an OverflowException
607-
// on negative numbers with Check Overflow option set on the project
608-
Char[] buff = new Char[1];
609-
Marshal.Copy(op, buff, 0, 1);
610-
result = buff[0];
611-
}
612-
else // UCS4
613-
{
614-
// XXX this is probably NOT correct?
615-
result = (char)Marshal.ReadInt32(op);
616-
}
602+
op = Runtime.PyUnicode_AsUnicode(value);
603+
Char[] buff = new Char[1];
604+
Marshal.Copy(op, buff, 0, 1);
605+
result = buff[0];
617606
return true;
618607
}
619608
goto type_error;

src/runtime/debughelper.cs

Lines changed: 22 additions & 0 deletions

0 commit comments

Comments
 (0)