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

fixed bug of method PyString_FromString#670

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
filmor merged 15 commits intopythonnet:masterfromyagweb:bug_of_pystring
Aug 24, 2018
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
15 commits
Select commitHold shift + click to select a range
a0f4c33
fixed bug of method PyString_FromString
yagwebMay 10, 2018
e9451db
fixup! fixed bug of method PyString_FromString
yagwebMay 11, 2018
7aaa644
removed spaces
yagwebMay 11, 2018
083abfc
Update appveyor.yml
den-run-aiMay 11, 2018
9c724e3
Update requirements.txt
den-run-aiMay 11, 2018
b8c6917
Merge branch 'master' into bug_of_pystring
filmorMay 28, 2018
42999f7
Update conversiontest.cs
den-run-aiJun 3, 2018
1f3255a
Update test_conversion.py
den-run-aiJun 3, 2018
36def5d
Update test_conversion.py
den-run-aiJun 3, 2018
084d743
Update test_conversion.py
den-run-aiJun 3, 2018
92ea629
Update test_conversion.py
den-run-aiJun 3, 2018
947cb01
Update test_conversion.py
den-run-aiJun 3, 2018
c5ec6b3
Update test_conversion.py
den-run-aiJun 12, 2018
a3da211
Merge branch 'master' into bug_of_pystring
den-run-aiJun 12, 2018
050f8cc
Merge branch 'master' into bug_of_pystring
filmorJul 23, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletionssrc/runtime/runtime.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1190,7 +1190,11 @@ internal static bool PyString_Check(IntPtr ob)

internal static IntPtr PyString_FromString(string value)
{
#if PYTHON3
return PyUnicode_FromKindAndData(_UCS, value, value.Length);
#elif PYTHON2
return PyString_FromStringAndSize(value, value.Length);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Maybe check here whether the string is ASCII? I'm not sure where this one is used, but we should probably distinguish the case where we actually want Unicode (and should also return that on Python 2) from the cases that should be ASCII-only on Python 2 (like identifiers).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@filmor can you file a separate issue for this with a suggested fix? this PR is now ready to merge!

#endif
}

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

[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "PyUnicode_FromStringAndSize")]
internal static extern IntPtr PyString_FromStringAndSize(
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string value,
int size
);

[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr PyUnicode_FromStringAndSize(IntPtr value, int size);
#elif PYTHON2
Expand Down
15 changes: 15 additions & 0 deletionssrc/testing/conversiontest.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -60,4 +60,19 @@ public string GetValue()
return value;
}
}

public class UnicodeString
{
public string value = "안녕";

public string GetString()
{
return value;
}

public override string ToString()
{
return value;
}
}
}
13 changes: 11 additions & 2 deletionssrc/tests/test_conversion.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,11 +2,12 @@

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

from __future__ import unicode_literals
import System
import pytest
from Python.Test import ConversionTest
from Python.Test import ConversionTest, UnicodeString

from ._compat import indexbytes, long, unichr
from ._compat import indexbytes, long, unichr, text_type, PY2, PY3


def test_bool_conversion():
Expand DownExpand Up@@ -535,6 +536,14 @@ def test_string_conversion():

with pytest.raises(TypeError):
ConversionTest().StringField = 1

world = UnicodeString()
test_unicode_str = u"안녕"
assert test_unicode_str == text_type(world.value)
assert test_unicode_str == text_type(world.GetString())
# TODO: not sure what to do for Python 2 here (GH PR #670)
if PY3:
assert test_unicode_str == text_type(world)


def test_interface_conversion():
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp