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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
use crate::{
impl_julia_typecheck,
memory::output::Output,
private::Private,
wrappers::ptr::{
array::ArrayRef, module::ModuleRef, private::WrapperPriv, symbol::SymbolRef,
value::ValueRef, Ref,
},
};
use cfg_if::cfg_if;
use jl_sys::{jl_methtable_t, jl_methtable_type};
use std::{marker::PhantomData, ptr::NonNull};
cfg_if! {
if #[cfg(any(not(feature = "lts"), feature = "all-features-override"))] {
use jl_sys::jl_value_t;
use crate::wrappers::ptr::atomic_value;
use std::sync::atomic::Ordering;
}
}
#[derive(Copy, Clone)]
#[repr(transparent)]
pub struct MethodTable<'scope>(NonNull<jl_methtable_t>, PhantomData<&'scope ()>);
impl<'scope> MethodTable<'scope> {
pub fn name(self) -> SymbolRef<'scope> {
unsafe { SymbolRef::wrap(self.unwrap_non_null(Private).as_ref().name) }
}
pub fn defs(self) -> ValueRef<'scope, 'static> {
cfg_if! {
if #[cfg(all(feature = "lts", not(feature = "all-features-override")))] {
unsafe { ValueRef::wrap(self.unwrap_non_null(Private).as_ref().defs) }
} else {
unsafe {
let defs = atomic_value::<jl_value_t>(&self.unwrap_non_null(Private).as_mut().defs as *const _);
let ptr = defs.load(Ordering::Relaxed);
ValueRef::wrap(ptr)
}
}
}
}
pub fn leafcache(self) -> ArrayRef<'scope, 'static> {
cfg_if! {
if #[cfg(all(feature = "lts", not(feature = "all-features-override")))] {
unsafe { ArrayRef::wrap(self.unwrap_non_null(Private).as_ref().leafcache) }
} else {
unsafe {
let leafcache =
atomic_value::<jl_value_t>(&self.unwrap_non_null(Private).as_mut().leafcache as *const _);
let ptr = leafcache.load(Ordering::Relaxed);
ArrayRef::wrap(ptr.cast())
}
}
}
}
pub fn cache(self) -> ValueRef<'scope, 'static> {
cfg_if! {
if #[cfg(all(feature = "lts", not(feature = "all-features-override")))] {
unsafe { ValueRef::wrap(self.unwrap_non_null(Private).as_ref().cache) }
} else {
unsafe {
let cache = atomic_value::<jl_value_t>(&self.unwrap_non_null(Private).as_mut().cache as *const _);
let ptr = cache.load(Ordering::Relaxed);
ValueRef::wrap(ptr)
}
}
}
}
pub fn max_args(self) -> isize {
unsafe { self.unwrap_non_null(Private).as_ref().max_args }
}
pub fn kw_sorter(self) -> ValueRef<'scope, 'static> {
unsafe { ValueRef::wrap(self.unwrap_non_null(Private).as_ref().kwsorter) }
}
pub fn module(self) -> ModuleRef<'scope> {
unsafe { ModuleRef::wrap(self.unwrap_non_null(Private).as_ref().module) }
}
pub fn backedges(self) -> ArrayRef<'scope, 'static> {
unsafe { ArrayRef::wrap(self.unwrap_non_null(Private).as_ref().backedges) }
}
pub fn offs(self) -> u8 {
unsafe { self.unwrap_non_null(Private).as_ref().offs }
}
pub fn frozen(self) -> u8 {
unsafe { self.unwrap_non_null(Private).as_ref().frozen }
}
pub fn root<'target>(self, output: Output<'target>) -> MethodTable<'target> {
unsafe {
let ptr = self.unwrap_non_null(Private);
output.set_root::<MethodTable>(ptr);
MethodTable::wrap_non_null(ptr, Private)
}
}
}
impl_julia_typecheck!(MethodTable<'scope>, jl_methtable_type, 'scope);
impl_debug!(MethodTable<'_>);
impl<'scope> WrapperPriv<'scope, '_> for MethodTable<'scope> {
type Wraps = jl_methtable_t;
const NAME: &'static str = "<MethodTable";
unsafe fn wrap_non_null(inner: NonNull<Self::Wraps>, _: Private) -> Self {
Self(inner, PhantomData)
}
fn unwrap_non_null(self, _: Private) -> NonNull<Self::Wraps> {
self.0
}
}
impl_root!(MethodTable, 1);
pub type MethodTableRef<'scope> = Ref<'scope, 'static, MethodTable<'scope>>;
impl_valid_layout!(MethodTableRef, MethodTable);
impl_ref_root!(MethodTable, MethodTableRef, 1);