1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
use crate::{
memory::global::Global,
private::Private,
wrappers::ptr::private::Wrapper,
wrappers::ptr::{symbol::Symbol, value::Value},
};
use jl_sys::{
jl_cpu_threads, jl_get_ARCH, jl_get_UNAME, jl_get_libllvm, jl_getallocationgranularity,
jl_getpagesize, jl_git_branch, jl_git_commit, jl_is_debugbuild, jl_n_threads,
jl_ver_is_release, jl_ver_major, jl_ver_minor, jl_ver_patch, jl_ver_string,
};
use std::{ffi::CStr, marker::PhantomData};
pub struct Info {
_priv: PhantomData<*mut ()>,
}
impl Info {
pub(crate) fn new() -> Self {
Info { _priv: PhantomData }
}
pub fn n_cpu_threads(&self) -> usize {
unsafe { jl_cpu_threads() as usize }
}
pub fn n_threads(&self) -> usize {
unsafe { jl_n_threads as usize }
}
pub fn page_size(&self) -> usize {
unsafe { jl_getpagesize() as usize }
}
pub fn allocation_granularity(&self) -> usize {
unsafe { jl_getallocationgranularity() as usize }
}
pub fn is_debugbuild(&self) -> bool {
unsafe { jl_is_debugbuild() != 0 }
}
pub fn uname(&self) -> StrOrBytes<'static> {
unsafe {
let cstr = Symbol::wrap(jl_get_UNAME(), Private).as_cstr();
if let Ok(rstr) = cstr.to_str() {
Ok(rstr)
} else {
Err(cstr.to_bytes())
}
}
}
pub fn arch(&self) -> StrOrBytes<'static> {
unsafe {
let cstr = Symbol::wrap(jl_get_ARCH(), Private).as_cstr();
if let Ok(rstr) = cstr.to_str() {
Ok(rstr)
} else {
Err(cstr.to_bytes())
}
}
}
pub fn libllvm_path(&self) -> Option<StrOrBytes<'static>> {
unsafe {
let sym = jl_get_libllvm();
if sym == Value::nothing(Global::new()).unwrap(Private) {
return None;
}
let cstr = Symbol::wrap(sym.cast(), Private).as_cstr();
let v = if let Ok(rstr) = cstr.to_str() {
Ok(rstr)
} else {
Err(cstr.to_bytes())
};
Some(v)
}
}
pub fn major_version(&self) -> isize {
unsafe { jl_ver_major() as isize }
}
pub fn minor_version(&self) -> isize {
unsafe { jl_ver_minor() as isize }
}
pub fn patch_version(&self) -> isize {
unsafe { jl_ver_patch() as isize }
}
pub fn is_release(&self) -> bool {
unsafe { jl_ver_is_release() != 0 }
}
pub fn git_branch(&self) -> StrOrBytes<'static> {
unsafe {
let cstr = CStr::from_ptr(jl_git_branch());
if let Ok(rstr) = cstr.to_str() {
Ok(rstr)
} else {
Err(cstr.to_bytes())
}
}
}
pub fn git_commit(&self) -> &'static str {
unsafe { CStr::from_ptr(jl_git_commit()).to_str().unwrap() }
}
pub fn version_string(&self) -> &'static str {
unsafe { CStr::from_ptr(jl_ver_string()).to_str().unwrap() }
}
}
pub type StrOrBytes<'scope> = Result<&'scope str, &'scope [u8]>;