|
149 | 149 | <a href="#148" id="148">148</a> |
150 | 150 | <a href="#149" id="149">149</a> |
151 | 151 | <a href="#150" id="150">150</a> |
152 | | -<a href="#151" id="151">151</a></pre></div><pre class="rust"><code><span class="attr">#![cfg(all(unix, not(target_vendor = <span class="string">"apple"</span>), not(target_family = <span class="string">"wasm"</span>)))] |
| 152 | +<a href="#151" id="151">151</a> |
| 153 | +<a href="#152" id="152">152</a> |
| 154 | +<a href="#153" id="153">153</a> |
| 155 | +<a href="#154" id="154">154</a> |
| 156 | +<a href="#155" id="155">155</a> |
| 157 | +<a href="#156" id="156">156</a> |
| 158 | +<a href="#157" id="157">157</a> |
| 159 | +<a href="#158" id="158">158</a> |
| 160 | +<a href="#159" id="159">159</a> |
| 161 | +<a href="#160" id="160">160</a> |
| 162 | +<a href="#161" id="161">161</a> |
| 163 | +<a href="#162" id="162">162</a> |
| 164 | +<a href="#163" id="163">163</a> |
| 165 | +<a href="#164" id="164">164</a> |
| 166 | +<a href="#165" id="165">165</a> |
| 167 | +<a href="#166" id="166">166</a></pre></div><pre class="rust"><code><span class="attr">#![cfg(all(unix, not(target_vendor = <span class="string">"apple"</span>), not(target_family = <span class="string">"wasm"</span>)))] |
153 | 168 |
|
154 | 169 | </span><span class="kw">use </span>alloc::{string::ToString, vec::Vec}; |
155 | 170 | <span class="kw">use </span>core::mem::MaybeUninit; |
156 | 171 |
|
157 | 172 | <span class="kw">use </span>ash::{ext, khr, vk}; |
158 | 173 |
|
| 174 | +<span class="macro">macro_rules!</span> to_u64 { |
| 175 | + (<span class="macro-nonterminal">$expr</span>:expr) => {{ |
| 176 | + <span class="attr">#[allow(trivial_numeric_casts)] |
| 177 | + </span><span class="kw">let </span>expr = <span class="macro-nonterminal">$expr </span><span class="kw">as </span>u64; |
| 178 | + <span class="macro">assert!</span>(size_of_val(<span class="kw-2">&</span>expr) <= size_of::<u64>()); |
| 179 | + expr |
| 180 | + }}; |
| 181 | +} |
| 182 | + |
159 | 183 | <span class="kw">impl </span><span class="kw">super</span>::Instance { |
160 | 184 | <span class="doccomment">/// Creates a new surface from the given drm configuration. |
161 | 185 | /// |
|
228 | 252 | <span class="kw">let </span>render_devid = |
229 | 253 | libc::makedev(drm_props.render_major <span class="kw">as _</span>, drm_props.render_minor <span class="kw">as _</span>); |
230 | 254 |
|
231 | | - <span class="comment">// Various platforms use different widths between `dev_t` and `c_int`, so just |
232 | | - // force-convert to `u64` to keep things portable. |
| 255 | + <span class="comment">// On most platforms, both `*_devid`s and `st_rdev` are `dev_t`s (which is generally |
| 256 | + // observed to be an unsigned integral type no greater than 64 bits). However, on some |
| 257 | + // platforms, there divergences from this pattern: |
| 258 | + // |
| 259 | + // - `armv7-linux-androideabi`: `dev_t` is `c_ulong`, and `*_devid`s are `dev_t`, but |
| 260 | + // `st_rdev` is `c_ulonglong`. So, we can't just do a `==` comparison. |
| 261 | + // - OpenBSD has `dev_t` on both sides, but is `i32` (N.B., unsigned). Therefore, we |
| 262 | + // can't just use `u64::from`. |
233 | 263 | </span><span class="attr">#[allow(clippy::useless_conversion)] |
234 | 264 | </span><span class="kw">if </span>[primary_devid, render_devid] |
235 | | - .map(u64::from) |
236 | | - .contains(<span class="kw-2">&</span>drm_stat.st_rdev) |
| 265 | + .map(|devid| <span class="macro">to_u64!</span>(devid)) |
| 266 | + .contains(<span class="kw-2">&</span><span class="macro">to_u64!</span>(drm_stat.st_rdev)) |
237 | 267 | { |
238 | 268 | physical_device = <span class="prelude-val">Some</span>(device) |
239 | 269 | } |
|
0 commit comments