comparison src/libpam/memory.rs @ 185:fb8b547b36b7

Banish al(most al)l use of `i32` in favor of `c_int`.
author Paul Fisher <paul@pfish.zone>
date Thu, 31 Jul 2025 14:45:38 -0400
parents a1bb1d013567
children 5e4ea9650f87
comparison
equal deleted inserted replaced
184:42f747774d94 185:fb8b547b36b7
11 11
12 /// Like the num_enum crate, but with no dependency on `syn`. 12 /// Like the num_enum crate, but with no dependency on `syn`.
13 macro_rules! num_enum { 13 macro_rules! num_enum {
14 ( 14 (
15 $(#[$m:meta])* 15 $(#[$m:meta])*
16 $viz:vis enum $name:ident($repr:ty) { 16 $viz:vis enum $name:ident {
17 $( 17 $(
18 $(#[$im:meta])* 18 $(#[$im:meta])*
19 $item_name:ident = $item_value:path, 19 $item_name:ident = $item_value:path,
20 )* 20 )*
21 } 21 }
22 ) => { 22 ) => {
23 // This is the one place where we depend upon c_int being i32.
24 // Ideally, we would be able to say `repr(c_int)` but we can't.
23 $(#[$m])* 25 $(#[$m])*
24 #[derive(Clone, Copy, Debug, Eq, PartialEq)] 26 #[derive(Clone, Copy, Debug, Eq, PartialEq)]
25 #[repr($repr)] 27 #[repr(i32)]
26 $viz enum $name { 28 $viz enum $name {
27 $( 29 $(
28 $(#[$im])* 30 $(#[$im])*
29 $item_name = $item_value, 31 $item_name = $item_value,
30 )* 32 )*
31 } 33 }
32 34
33 impl TryFrom<$repr> for $name { 35 impl TryFrom<c_int> for $name {
34 type Error = crate::constants::ErrorCode; 36 type Error = crate::constants::ErrorCode;
35 37
36 #[allow(unused_doc_comments)] 38 #[allow(unused_doc_comments)]
37 fn try_from(value: $repr) -> crate::constants::Result<$name> { 39 fn try_from(value: c_int) -> crate::constants::Result<$name> {
38 match value { 40 match value {
39 $( 41 $(
40 $(#[$im])* 42 $(#[$im])*
41 $item_value => Ok(Self::$item_name), 43 $item_value => Ok(Self::$item_name),
42 )* 44 )*
43 _ => Err(crate::constants::ErrorCode::BAD_CONST), 45 _ => Err(crate::constants::ErrorCode::BAD_CONST),
44 } 46 }
45 } 47 }
46 } 48 }
47 49
48 impl From<$name> for $repr { 50 impl From<$name> for c_int {
49 fn from(value: $name) -> $repr { 51 fn from(value: $name) -> c_int {
50 value as $repr 52 value as c_int
51 } 53 }
52 } 54 }
53 } 55 }
54 } 56 }
55 57