Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit edafdf2

Browse files
committed
Remove internal PyUnicode_AS_UNICODE
Its redundant with PyUnicode_AsUnicode now that the signature is fixed between UCS2/UCS4. Apply char conversion that work on both UCS2/UCS4
1 parent 07f87de commit edafdf2

File tree

2 files changed

+4
-39
lines changed

2 files changed

+4
-39
lines changed

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/runtime.cs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,12 +1575,6 @@ internal unsafe static extern int
15751575
internal unsafe static extern IntPtr
15761576
PyUnicode_AsUnicode(IntPtr ob);
15771577

1578-
[DllImport(Runtime.dll, CallingConvention = CallingConvention.Cdecl,
1579-
EntryPoint = "PyUnicode_AsUnicode",
1580-
ExactSpelling = true, CharSet = CharSet.Unicode)]
1581-
internal unsafe static extern IntPtr
1582-
PyUnicode_AS_UNICODE(IntPtr op);
1583-
15841578
[DllImport(Runtime.dll, CallingConvention = CallingConvention.Cdecl,
15851579
ExactSpelling = true, CharSet = CharSet.Unicode)]
15861580
internal unsafe static extern IntPtr
@@ -1616,12 +1610,6 @@ internal unsafe static extern int
16161610
internal unsafe static extern IntPtr
16171611
PyUnicode_AsUnicode(IntPtr ob);
16181612

1619-
[DllImport(Runtime.dll, CallingConvention = CallingConvention.Cdecl,
1620-
EntryPoint = "PyUnicodeUCS2_AsUnicode",
1621-
ExactSpelling = true, CharSet = CharSet.Unicode)]
1622-
internal unsafe static extern IntPtr
1623-
PyUnicode_AS_UNICODE(IntPtr op);
1624-
16251613
[DllImport(Runtime.dll, CallingConvention = CallingConvention.Cdecl,
16261614
EntryPoint = "PyUnicodeUCS2_FromOrdinal",
16271615
ExactSpelling = true, CharSet = CharSet.Unicode)]
@@ -1663,12 +1651,6 @@ internal unsafe static extern int
16631651
internal unsafe static extern IntPtr
16641652
PyUnicode_AsUnicode(IntPtr ob);
16651653

1666-
[DllImport(Runtime.dll, CallingConvention = CallingConvention.Cdecl,
1667-
EntryPoint = "PyUnicode_AsUnicode",
1668-
ExactSpelling = true, CharSet = CharSet.Unicode)]
1669-
internal unsafe static extern IntPtr
1670-
PyUnicode_AS_UNICODE(IntPtr op);
1671-
16721654
[DllImport(Runtime.dll, CallingConvention = CallingConvention.Cdecl,
16731655
ExactSpelling = true, CharSet = CharSet.Unicode)]
16741656
internal unsafe static extern IntPtr
@@ -1707,12 +1689,6 @@ internal unsafe static extern int
17071689
internal unsafe static extern IntPtr
17081690
PyUnicode_AsUnicode(IntPtr ob);
17091691

1710-
[DllImport(Runtime.dll, CallingConvention = CallingConvention.Cdecl,
1711-
EntryPoint = "PyUnicodeUCS4_AsUnicode",
1712-
ExactSpelling = true, CharSet = CharSet.Unicode)]
1713-
internal unsafe static extern IntPtr
1714-
PyUnicode_AS_UNICODE(IntPtr op);
1715-
17161692
[DllImport(Runtime.dll, CallingConvention = CallingConvention.Cdecl,
17171693
EntryPoint = "PyUnicodeUCS4_FromOrdinal",
17181694
ExactSpelling = true, CharSet = CharSet.Unicode)]

0 commit comments

Comments
 (0)