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

Skip to content

Commit 55171b9

Browse files
authored
Merge branch 'master' into master
2 parents 070a7fc + 677281e commit 55171b9

File tree

8 files changed

+48
-10
lines changed

8 files changed

+48
-10
lines changed

AUTHORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
- Dmitriy Se ([@dmitriyse](https://github.com/dmitriyse))
2727
- He-chien Tsai ([@t3476](https://github.com/t3476))
2828
-   Ivan Cronyn ([@cronan](https://github.com/cronan))
29+
- Jan Krivanek ([@jakrivan](https://github.com/jakrivan))
2930
-   Jeff Reback ([@jreback](https://github.com/jreback))
3031
- Joe Frayne ([@jfrayne](https://github.com/jfrayne))
3132
- John Burnett ([@johnburnett](https://github.com/johnburnett))

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
1919
- Catches exceptions thrown in C# iterators (yield returns) and rethrows them in python ([#475][i475])([#693][p693])
2020
- Implemented GetDynamicMemberNames() for PyObject to allow dynamic object members to be visible in the debugger ([#443][i443])([#690][p690])
2121
- Incorporated reference-style links to issues and pull requests in the CHANGELOG ([#608][i608])
22+
- Added detailed comments about aproaches and dangers to handle multi-app-domains ([#625][p625])
2223

2324
### Changed
2425

@@ -683,4 +684,5 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
683684
[p225]: https://github.com/pythonnet/pythonnet/pull/225
684685
[p78]: https://github.com/pythonnet/pythonnet/pull/78
685686
[p163]: https://github.com/pythonnet/pythonnet/pull/163
687+
[p625]: https://github.com/pythonnet/pythonnet/pull/625
686688
[i131]: https://github.com/pythonnet/pythonnet/issues/131

appveyor.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ environment:
2828
- PYTHON_VERSION: 3.5
2929
- PYTHON_VERSION: 3.6
3030

31+
matrix:
32+
allow_failures:
33+
- PYTHON_VERSION: 3.4
34+
BUILD_OPTS: --xplat
35+
- PYTHON_VERSION: 3.4
36+
3137
init:
3238
# Update Environment Variables based on matrix/platform
3339
- set PY_VER=%PYTHON_VERSION:.=%

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ def _install_packages(self):
344344
self.debug_print("Updating NuGet: {0}".format(cmd))
345345
subprocess.check_call(cmd, shell=use_shell)
346346

347-
cmd = "{0} restore pythonnet.sln -o packages".format(nuget)
347+
cmd = "{0} restore pythonnet.sln -MSBuildVersion 14 -o packages".format(nuget)
348348
self.debug_print("Installing packages: {0}".format(cmd))
349349
subprocess.check_call(cmd, shell=use_shell)
350350

src/runtime/assemblymanager.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,15 @@ internal class AssemblyManager
1717
{
1818
// modified from event handlers below, potentially triggered from different .NET threads
1919
// therefore this should be a ConcurrentDictionary
20+
//
21+
// WARNING: Dangerous if cross-app domain usage is ever supported
22+
// Reusing the dictionary with assemblies accross multiple initializations is problematic.
23+
// Loading happens from CurrentDomain (see line 53). And if the first call is from AppDomain that is later unloaded,
24+
// than it can end up referring to assemblies that are already unloaded (default behavior after unload appDomain -
25+
// unless LoaderOptimization.MultiDomain is used);
26+
// So for multidomain support it is better to have the dict. recreated for each app-domain initialization
2027
private static ConcurrentDictionary<string, ConcurrentDictionary<Assembly, string>> namespaces;
28+
2129
//private static Dictionary<string, Dictionary<string, string>> generics;
2230
private static AssemblyLoadEventHandler lhandler;
2331
private static ResolveEventHandler rhandler;

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
internal static 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-
internal static extern IntPtr PyString_FromStringAndSize(
1211-
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string value,
1212-
int size
1213-
);
1214-
12151212
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
12161213
internal static extern 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
return value;
6161
}
6262
}
63+
64+
public class UnicodeString
65+
{
66+
public string value = "안녕";
67+
68+
public string GetString()
69+
{
70+
return value;
71+
}
72+
73+
public override string ToString()
74+
{
75+
return value;
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__ import unicode_literals
56
import System
67
import pytest
7-
from Python.Test import ConversionTest
8+
from Python.Test import ConversionTest, UnicodeString
89

9-
from ._compat import indexbytes, long, unichr
10+
from ._compat import indexbytes, long, unichr, text_type, PY2, PY3
1011

1112

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

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

539548

540549
def test_interface_conversion():

0 commit comments

Comments
 (0)