Skip to content

Commit f022f9f

Browse files
committed
Move files around, rename framework to netfx, add build script
1 parent 7bf7b28 commit f022f9f

16 files changed

+1553
-1113
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,6 @@ dmypy.json
7171

7272
# Pyre type checker
7373
.pyre/
74+
75+
# Compiled DLLs
76+
clr_loader/ffi/dlls/*

build_netfx_loader.sh

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
3+
S=`dirname $0`
4+
P=netfx_loader/
5+
O=clr_loader/ffi/dlls/
6+
7+
dotnet build $P -r win-x86 -o $O/x86
8+
dotnet build $P -r win-x64 -o $O/amd64

clr_loader/__init__.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def get_function(self, name, func=None):
3434

3535
def __getitem__(self, name):
3636
return self.get_function(name)
37+
3738
def __repr__(self):
3839
return f"<Assembly {self._path} in {self._runtime}>"
3940

@@ -45,6 +46,7 @@ def __init__(self, impl):
4546
@classmethod
4647
def get_mono(cls, domain=None):
4748
from .mono import Mono
49+
4850
impl = Mono(domain=domain)
4951
return cls(impl)
5052

@@ -56,10 +58,10 @@ def get_coreclr(cls, runtime_config, dotnet_root=None):
5658
return cls(impl)
5759

5860
@classmethod
59-
def get_framework(cls, name=None, config_file=None):
60-
from .framework import Framework
61+
def get_netfx(cls, name=None, config_file=None):
62+
from .netfx import NetFx
6163

62-
impl = Framework(name=name, config_file=config_file)
64+
impl = NetFx(name=name, config_file=config_file)
6365
return cls(impl)
6466

6567
def get_assembly(self, path):

clr_loader/ffi/__init__.py

+15-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1+
import sys
12
import os
23
import shutil
34

45
import cffi
56

6-
from . import coreclr, hostfxr, mono, framework
7+
from . import coreclr, hostfxr, mono, netfx
78

8-
__all__ = ["ffi", "load_coreclr", "load_hostfxr", "load_mono", "load_framework"]
9+
__all__ = ["ffi", "load_coreclr", "load_hostfxr", "load_mono", "load_netfx"]
910

1011
ffi = cffi.FFI()
1112

12-
for cdef in coreclr.cdef + hostfxr.cdef + mono.cdef + framework.cdef:
13+
for cdef in coreclr.cdef + hostfxr.cdef + mono.cdef + netfx.cdef:
1314
ffi.cdef(cdef)
1415

1516

@@ -40,15 +41,22 @@ def load_mono(path=None, gc=None):
4041
return ffi.dlopen(path)
4142

4243

43-
def load_framework():
44-
path = "netframework_loader/bin/x64/Debug/net472/ClrLoader.dll"
44+
def load_netfx():
45+
if sys.platform != "win32":
46+
raise RuntimeError(".NET Framework is only supported on Windows")
47+
48+
dirname = os.path.join(os.path.dirname(__file__), "dlls")
49+
if sys.maxsize > 2 ** 32:
50+
arch = "amd64"
51+
else:
52+
arch = "x86"
53+
54+
path = os.path.join(dirname, arch, "ClrLoader.dll")
4555

4656
return ffi.dlopen(path)
4757

4858

4959
def _get_dll_name(name):
50-
import sys
51-
5260
if sys.platform == "win32":
5361
return f"{name}.dll"
5462
elif sys.platform == "darwin":

clr_loader/ffi/coreclr.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
cdef = ["""
1+
cdef = [
2+
"""
23
__stdcall unsigned int coreclr_initialize(
34
const char* exePath,
45
const char* appDomainFriendlyName,
@@ -28,4 +29,5 @@
2829
);
2930
3031
__stdcall int coreclr_shutdown(void* hostHandle, unsigned int domainId);
31-
"""]
32+
"""
33+
]

clr_loader/ffi/mono.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@
2121
2222
void* mono_object_unbox(MonoObject *object);
2323
"""
24-
)
24+
)
File renamed without changes.

clr_loader/mono.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ class MethodDesc:
4545
def __init__(self, typename, function):
4646
self._desc = f"{typename}:{function}"
4747
self._ptr = _MONO.mono_method_desc_new(
48-
self._desc.encode("utf8"),
49-
1 # include_namespace
48+
self._desc.encode("utf8"), 1 # include_namespace
5049
)
5150

5251
def search(self, image):
@@ -56,10 +55,11 @@ def __del__(self):
5655
if _MONO:
5756
_MONO.mono_method_desc_free(self._ptr)
5857

58+
5959
class MonoMethod:
6060
def __init__(self, domain, ptr):
6161
self._ptr = ptr
62-
62+
6363
def __call__(self, ptr, size):
6464
exception = ffi.new("MonoObject**")
6565
params = ffi.new("void*[2]")

clr_loader/framework.py renamed to clr_loader/netfx.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
from .ffi import ffi, load_framework
1+
from .ffi import ffi, load_netfx
22

33

44
_FW = None
55

66

7-
class Framework:
7+
class NetFx:
88
def __init__(self, name=None, config_file=None):
99
global _FW
1010
if _FW is None:
11-
_FW = load_framework()
11+
_FW = load_netfx()
1212

1313
self._domain = _FW.pyclr_create_appdomain(
1414
name or ffi.NULL, config_file or ffi.NULL
@@ -23,7 +23,7 @@ def get_callable(self, assembly_path, typename, function):
2323
)
2424

2525
return func
26-
26+
2727
def __del__(self):
2828
if self._domain and _FW:
2929
_FW.pyclr_close_appdomain(self._domain)

clr_loader/util/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ def __str__(self):
1313
else:
1414
return f"{hex(self.hresult)}"
1515

16-
1716
def __repr__(self):
1817
return f"<ClrError {str(self)}>"
1918

0 commit comments

Comments
 (0)