Skip to content

Commit 5b18691

Browse files
authored
warn if Mono version is <= 6.12 (#21)
1 parent 8293122 commit 5b18691

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

clr_loader/ffi/mono.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
MONO_DEBUG_FORMAT_DEBUGGER
1919
} MonoDebugFormat;
2020
21+
char* mono_get_runtime_build_info (void);
22+
2123
MonoDomain* mono_jit_init(const char *root_domain_name);
2224
void mono_jit_cleanup(MonoDomain *domain);
2325
void mono_jit_parse_options(int argc, char * argv[]);

clr_loader/mono.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import atexit
2+
import re
23
from typing import Optional, Sequence
34

45
from .ffi import load_mono, ffi
@@ -122,13 +123,29 @@ def initialize(
122123
if jit_options:
123124
options = [ffi.new("char[]", o.encode("utf8")) for o in jit_options]
124125
_MONO.mono_jit_parse_options(len(options), options)
126+
else:
127+
options = []
125128

126129
if debug:
127130
_MONO.mono_debug_init(_MONO.MONO_DEBUG_FORMAT_MONO)
128131

129132
_ROOT_DOMAIN = _MONO.mono_jit_init(b"clr_loader")
130133
_MONO.mono_domain_set_config(_ROOT_DOMAIN, b".", config_encoded)
131134
_check_result(_ROOT_DOMAIN, "Failed to initialize Mono")
135+
136+
build = _MONO.mono_get_runtime_build_info()
137+
_check_result(build, "Failed to get Mono version")
138+
ver_str = ffi.string(build).decode('utf8') # e.g. '6.12.0.122 (tarball)'
139+
140+
ver = re.match(r'^(?P<major>\d+)\.(?P<minor>\d+)\.[\d.]+', ver_str)
141+
if ver is not None:
142+
major = int(ver.group('major'))
143+
minor = int(ver.group('minor'))
144+
145+
if major < 6 or (major == 6 and minor < 12):
146+
import warnings
147+
warnings.warn('Hosting Mono versions before v6.12 is known to be problematic. If the process crashes shortly after you see this message, try updating Mono to at least v6.12.')
148+
132149
atexit.register(_release)
133150

134151

0 commit comments

Comments
 (0)