Skip to content

Commit

Permalink
Fix handling of non-ASCII assembly paths on .NET Framework
Browse files Browse the repository at this point in the history
  • Loading branch information
filmor committed Aug 7, 2023
1 parent d8f51e9 commit 57e2270
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
6 changes: 3 additions & 3 deletions netfx_loader/ClrLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ public static void Initialize()
[DllExport("pyclr_get_function", CallingConvention.Cdecl)]
public static IntPtr GetFunction(
IntPtr domain,
[MarshalAs(UnmanagedType.LPStr)] string assemblyPath,
[MarshalAs(UnmanagedType.LPStr)] string typeName,
[MarshalAs(UnmanagedType.LPStr)] string function
[MarshalAs(UnmanagedType.LPUTF8Str)] string assemblyPath,
[MarshalAs(UnmanagedType.LPUTF8Str)] string typeName,
[MarshalAs(UnmanagedType.LPUTF8Str)] string function
)
{
try
Expand Down
35 changes: 27 additions & 8 deletions tests/test_common.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import shutil
import pytest
from subprocess import check_call
import os
Expand All @@ -24,7 +25,7 @@ def build_example(tmpdir_factory, framework):
return out


def test_mono(example_netstandard):
def test_mono(example_netstandard: Path):
from clr_loader import get_mono

mono = get_mono()
Expand All @@ -33,7 +34,7 @@ def test_mono(example_netstandard):
run_tests(asm)


def test_mono_debug(example_netstandard):
def test_mono_debug(example_netstandard: Path):
from clr_loader import get_mono

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

run_tests(asm)

def test_mono_signal_chaining(example_netstandard):

def test_mono_signal_chaining(example_netstandard: Path):
from clr_loader import get_mono

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

run_tests(asm)

def test_mono_set_dir(example_netstandard):

def test_mono_set_dir(example_netstandard: Path):
from clr_loader import get_mono

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

run_tests(asm)

def test_coreclr(example_netcore):

def test_coreclr(example_netcore: Path):
from clr_loader import get_coreclr

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


def test_coreclr_autogenerated_runtimeconfig(example_netstandard):
def test_coreclr_autogenerated_runtimeconfig(example_netstandard: Path):
from multiprocessing import get_context

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


def _do_test_coreclr_autogenerated_runtimeconfig(example_netstandard):
def _do_test_coreclr_autogenerated_runtimeconfig(example_netstandard: Path):
from clr_loader import get_coreclr

coreclr = get_coreclr()
Expand All @@ -94,9 +98,24 @@ def _do_test_coreclr_autogenerated_runtimeconfig(example_netstandard):
@pytest.mark.skipif(
sys.platform != "win32", reason=".NET Framework only exists on Windows"
)
def test_netfx(example_netstandard):
def test_netfx(example_netstandard: Path):
from clr_loader import get_netfx

netfx = get_netfx()
asm = netfx.get_assembly(example_netstandard / "example.dll")

run_tests(asm)


@pytest.mark.skipif(
sys.platform != "win32", reason=".NET Framework only exists on Windows"
)
def test_netfx_chinese_path(example_netstandard: Path, tmpdir_factory):
from clr_loader import get_netfx

tmp_path = Path(tmpdir_factory.mktemp("example-中国"))
shutil.copytree(example_netstandard, tmp_path, dirs_exist_ok=True)

netfx = get_netfx()
asm = netfx.get_assembly(os.path.join(example_netstandard, "example.dll"))

Expand Down

0 comments on commit 57e2270

Please sign in to comment.