Skip to content

Commit 63d7f69

Browse files
authored
Fix handling of non-ASCII assembly paths on .NET Framework (#62)
1 parent d8f51e9 commit 63d7f69

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

Diff for: netfx_loader/ClrLoader.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ public static IntPtr CreateAppDomain(
5151
[DllExport("pyclr_get_function", CallingConvention.Cdecl)]
5252
public static IntPtr GetFunction(
5353
IntPtr domain,
54-
[MarshalAs(UnmanagedType.LPStr)] string assemblyPath,
55-
[MarshalAs(UnmanagedType.LPStr)] string typeName,
56-
[MarshalAs(UnmanagedType.LPStr)] string function
54+
[MarshalAs(UnmanagedType.LPUTF8Str)] string assemblyPath,
55+
[MarshalAs(UnmanagedType.LPUTF8Str)] string typeName,
56+
[MarshalAs(UnmanagedType.LPUTF8Str)] string function
5757
)
5858
{
5959
try

Diff for: tests/test_common.py

+27-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import shutil
12
import pytest
23
from subprocess import check_call
34
import os
@@ -24,7 +25,7 @@ def build_example(tmpdir_factory, framework):
2425
return out
2526

2627

27-
def test_mono(example_netstandard):
28+
def test_mono(example_netstandard: Path):
2829
from clr_loader import get_mono
2930

3031
mono = get_mono()
@@ -33,7 +34,7 @@ def test_mono(example_netstandard):
3334
run_tests(asm)
3435

3536

36-
def test_mono_debug(example_netstandard):
37+
def test_mono_debug(example_netstandard: Path):
3738
from clr_loader import get_mono
3839

3940
mono = get_mono(
@@ -46,23 +47,26 @@ def test_mono_debug(example_netstandard):
4647

4748
run_tests(asm)
4849

49-
def test_mono_signal_chaining(example_netstandard):
50+
51+
def test_mono_signal_chaining(example_netstandard: Path):
5052
from clr_loader import get_mono
5153

5254
mono = get_mono(set_signal_chaining=True)
5355
asm = mono.get_assembly(example_netstandard / "example.dll")
5456

5557
run_tests(asm)
5658

57-
def test_mono_set_dir(example_netstandard):
59+
60+
def test_mono_set_dir(example_netstandard: Path):
5861
from clr_loader import get_mono
5962

6063
mono = get_mono(assembly_dir="/usr/lib", config_dir="/etc")
6164
asm = mono.get_assembly(example_netstandard / "example.dll")
6265

6366
run_tests(asm)
6467

65-
def test_coreclr(example_netcore):
68+
69+
def test_coreclr(example_netcore: Path):
6670
from clr_loader import get_coreclr
6771

6872
coreclr = get_coreclr(runtime_config=example_netcore / "example.runtimeconfig.json")
@@ -71,7 +75,7 @@ def test_coreclr(example_netcore):
7175
run_tests(asm)
7276

7377

74-
def test_coreclr_autogenerated_runtimeconfig(example_netstandard):
78+
def test_coreclr_autogenerated_runtimeconfig(example_netstandard: Path):
7579
from multiprocessing import get_context
7680

7781
p = get_context("spawn").Process(
@@ -82,7 +86,7 @@ def test_coreclr_autogenerated_runtimeconfig(example_netstandard):
8286
p.close()
8387

8488

85-
def _do_test_coreclr_autogenerated_runtimeconfig(example_netstandard):
89+
def _do_test_coreclr_autogenerated_runtimeconfig(example_netstandard: Path):
8690
from clr_loader import get_coreclr
8791

8892
coreclr = get_coreclr()
@@ -94,9 +98,24 @@ def _do_test_coreclr_autogenerated_runtimeconfig(example_netstandard):
9498
@pytest.mark.skipif(
9599
sys.platform != "win32", reason=".NET Framework only exists on Windows"
96100
)
97-
def test_netfx(example_netstandard):
101+
def test_netfx(example_netstandard: Path):
102+
from clr_loader import get_netfx
103+
104+
netfx = get_netfx()
105+
asm = netfx.get_assembly(example_netstandard / "example.dll")
106+
107+
run_tests(asm)
108+
109+
110+
@pytest.mark.skipif(
111+
sys.platform != "win32", reason=".NET Framework only exists on Windows"
112+
)
113+
def test_netfx_chinese_path(example_netstandard: Path, tmpdir_factory):
98114
from clr_loader import get_netfx
99115

116+
tmp_path = Path(tmpdir_factory.mktemp("example-中国"))
117+
shutil.copytree(example_netstandard, tmp_path, dirs_exist_ok=True)
118+
100119
netfx = get_netfx()
101120
asm = netfx.get_assembly(os.path.join(example_netstandard, "example.dll"))
102121

0 commit comments

Comments
 (0)