Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb6417ca

Browse files
yagwebfilmor
authored andcommitted
fixed bug of method PyString_FromString (#670)
* fixed bug of method PyString_FromString* fixup! fixed bug of method PyString_FromString* removed spaces* Update appveyor.yml* Update requirements.txt* Update conversiontest.cs* Update test_conversion.py
1 parentfb84cd2 commitb6417ca

File tree

3 files changed

+30
-9
lines changed

3 files changed

+30
-9
lines changed

‎src/runtime/runtime.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,11 @@ internal static bool PyString_Check(IntPtr ob)
11901190

11911191
internalstatic IntPtr PyString_FromString(string value)
11921192
{
1193+
#if PYTHON3
1194+
return PyUnicode_FromKindAndData(_UCS, value, value.Length);
1195+
#elif PYTHON2
11931196
return PyString_FromStringAndSize(value, value.Length);
1197+
#endif
11941198
}
11951199

11961200
#if PYTHON3
@@ -1205,13 +1209,6 @@ internal static IntPtr PyBytes_AS_STRING(IntPtr ob)
12051209
return ob+ BytesOffset.ob_sval;
12061210
}
12071211

1208-
[DllImport(_PythonDll, CallingConvention= CallingConvention.Cdecl,
1209-
EntryPoint= "PyUnicode_FromStringAndSize")]
1210-
internalstaticextern IntPtr PyString_FromStringAndSize(
1211-
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Utf8Marshaler))]string value,
1212-
int size
1213-
);
1214-
12151212
[DllImport(_PythonDll, CallingConvention= CallingConvention.Cdecl)]
12161213
internalstaticextern IntPtr PyUnicode_FromStringAndSize(IntPtr value,int size);
12171214
#elif PYTHON2

‎src/testing/conversiontest.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,19 @@ public string GetValue()
6060
returnvalue;
6161
}
6262
}
63+
64+
publicclassUnicodeString
65+
{
66+
publicstringvalue="안녕";
67+
68+
publicstringGetString()
69+
{
70+
returnvalue;
71+
}
72+
73+
publicoverridestringToString()
74+
{
75+
returnvalue;
76+
}
77+
}
6378
}

‎src/tests/test_conversion.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
"""Test CLR <-> Python type conversions."""
44

5+
from __future__importunicode_literals
56
importSystem
67
importpytest
7-
fromPython.TestimportConversionTest
8+
fromPython.TestimportConversionTest,UnicodeString
89

9-
from ._compatimportindexbytes,long,unichr
10+
from ._compatimportindexbytes,long,unichr,text_type,PY2,PY3
1011

1112

1213
deftest_bool_conversion():
@@ -535,6 +536,14 @@ def test_string_conversion():
535536

536537
withpytest.raises(TypeError):
537538
ConversionTest().StringField=1
539+
540+
world=UnicodeString()
541+
test_unicode_str=u"안녕"
542+
asserttest_unicode_str==text_type(world.value)
543+
asserttest_unicode_str==text_type(world.GetString())
544+
# TODO: not sure what to do for Python 2 here (GH PR #670)
545+
ifPY3:
546+
asserttest_unicode_str==text_type(world)
538547

539548

540549
deftest_interface_conversion():

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp