@@ -1677,37 +1677,6 @@ internal unsafe static extern IntPtr
1677
1677
internal unsafe static extern IntPtr
1678
1678
PyUnicode_FromOrdinal( int c ) ;
1679
1679
#endif
1680
-
1681
- internal static IntPtr PyUnicode_FromString( string s )
1682
- {
1683
- return PyUnicode_FromUnicode( s , ( s . Length ) ) ;
1684
- }
1685
-
1686
- internal unsafe static string GetManagedString ( IntPtr op )
1687
- {
1688
- IntPtr type = PyObject_TYPE( op ) ;
1689
-
1690
- // Python 3 strings are all unicode
1691
- #if PYTHON2
1692
- if ( type = = Runtime . PyStringType )
1693
- {
1694
- return Marshal. PtrToStringAnsi(
1695
- PyString_AS_STRING ( op ) ,
1696
- Runtime . PyString_Size ( op )
1697
- ) ;
1698
- }
1699
- #endif
1700
-
1701
- if ( type = = Runtime . PyUnicodeType )
1702
- {
1703
- char * p = Runtime. PyUnicode_AsUnicode( op ) ;
1704
- int size = Runtime. PyUnicode_GetSize( op ) ;
1705
- return new String( p , 0 , size ) ;
1706
- }
1707
-
1708
- return null ;
1709
- }
1710
-
1711
1680
#endif
1712
1681
#if ( UCS4 )
1713
1682
#if ( PYTHON33 || PYTHON34 || PYTHON35 || PYTHON36 )
@@ -1800,6 +1769,7 @@ internal unsafe static extern IntPtr
1800
1769
internal unsafe static extern IntPtr
1801
1770
PyUnicode_FromOrdinal( int c ) ;
1802
1771
1772
+ #endif
1803
1773
#endif
1804
1774
1805
1775
internal static IntPtr PyUnicode_FromString( string s )
@@ -1811,8 +1781,7 @@ internal unsafe static string GetManagedString(IntPtr op)
1811
1781
{
1812
1782
IntPtr type = PyObject_TYPE( op ) ;
1813
1783
1814
- // Python 3 strings are all unicode
1815
- #if PYTHON2
1784
+ #if PYTHON2 // Python 3 strings are all Unicode
1816
1785
if ( type = = Runtime . PyStringType )
1817
1786
{
1818
1787
return Marshal. PtrToStringAnsi(
@@ -1824,17 +1793,22 @@ internal unsafe static string GetManagedString(IntPtr op)
1824
1793
1825
1794
if ( type = = Runtime . PyUnicodeType )
1826
1795
{
1796
+ #if UCS4
1827
1797
IntPtr p = Runtime. PyUnicode_AsUnicode( op) ;
1828
1798
int length = Runtime. PyUnicode_GetSize( op ) ;
1829
1799
int size = length* 4 ;
1830
1800
byte [ ] buffer = new byte [ size ] ;
1831
1801
Marshal . Copy ( p , buffer , 0 , size ) ;
1832
1802
return Encoding . UTF32 . GetString ( buffer , 0 , size ) ;
1803
+ #elif UCS2
1804
+ char* p = Runtime . PyUnicode_AsUnicode ( op ) ;
1805
+ int size = Runtime. PyUnicode_GetSize( op ) ;
1806
+ return new String( p , 0 , size ) ;
1807
+ #endif
1833
1808
}
1834
1809
1835
1810
return null ;
1836
1811
}
1837
- #endif
1838
1812
1839
1813
//====================================================================
1840
1814
// Python dictionary API
0 commit comments