Mercurial > crates > nonstick
comparison libpam-sys/src/helpers.rs @ 125:2b255c92417b
Introduce base PAM functions; use the real X/SSO PAM header for tests.
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Mon, 30 Jun 2025 17:47:32 -0400 |
parents | 98a624cacd82 |
children | c77846f3a979 |
comparison
equal
deleted
inserted
replaced
124:f469b8d9ad78 | 125:2b255c92417b |
---|---|
55 /// ║ ... ║ | 55 /// ║ ... ║ |
56 /// | 56 /// |
57 /// ``` | 57 /// ``` |
58 /// | 58 /// |
59 /// [conversation callback]: crate::ConversationCallback | 59 /// [conversation callback]: crate::ConversationCallback |
60 /// [message]: crate::Message | 60 /// [message]: crate::pam_message |
61 #[derive(Debug)] | 61 #[derive(Debug)] |
62 pub struct PtrPtrVec<T> { | 62 pub struct PtrPtrVec<T> { |
63 data: Vec<T>, | 63 data: Vec<T>, |
64 pointers: Vec<*const T>, | 64 pointers: Vec<*const T>, |
65 } | 65 } |
66 | |
67 // Since this is a wrapper around a Vec with no dangerous functionality*, | |
68 // this can be Send and Sync provided the original Vec is. | |
69 // | |
70 // * It will only become unsafe when the user dereferences a pointer or sends it | |
71 // to an unsafe function. | |
72 unsafe impl<T> Send for PtrPtrVec<T> where Vec<T>: Send {} | |
73 unsafe impl<T> Sync for PtrPtrVec<T> where Vec<T>: Sync {} | |
66 | 74 |
67 impl<T> PtrPtrVec<T> { | 75 impl<T> PtrPtrVec<T> { |
68 /// Takes ownership of the given Vec and creates a vec of pointers to it. | 76 /// Takes ownership of the given Vec and creates a vec of pointers to it. |
69 pub fn new(data: Vec<T>) -> Self { | 77 pub fn new(data: Vec<T>) -> Self { |
70 let pointers: Vec<_> = data.iter().map(|r| r as *const T).collect(); | 78 let pointers: Vec<_> = data.iter().map(|r| r as *const T).collect(); |
507 #[allow(deprecated)] | 515 #[allow(deprecated)] |
508 #[test] | 516 #[test] |
509 fn test_iter_ptr_ptr() { | 517 fn test_iter_ptr_ptr() { |
510 let strs = vec![Box::new("a"), Box::new("b"), Box::new("c"), Box::new("D")]; | 518 let strs = vec![Box::new("a"), Box::new("b"), Box::new("c"), Box::new("D")]; |
511 let ptr: *const *const &str = strs.as_ptr().cast(); | 519 let ptr: *const *const &str = strs.as_ptr().cast(); |
512 let got: Vec<&str> = unsafe { | 520 let got: Vec<&str> = unsafe { PtrPtrVec::iter_over_linux(ptr, 4) } |
513 PtrPtrVec::iter_over_linux(ptr, 4) | 521 .cloned() |
514 }.cloned().collect(); | 522 .collect(); |
515 assert_eq!(vec!["a", "b", "c", "D"], got); | 523 assert_eq!(vec!["a", "b", "c", "D"], got); |
516 | 524 |
517 let nums = [-1i8, 2, 3]; | 525 let nums = [-1i8, 2, 3]; |
518 let ptr = nums.as_ptr(); | 526 let ptr = nums.as_ptr(); |
519 let got: Vec<u8> = unsafe { PtrPtrVec::iter_over_xsso(&ptr, 3)}.cloned().collect(); | 527 let got: Vec<u8> = unsafe { PtrPtrVec::iter_over_xsso(&ptr, 3) } |
528 .cloned() | |
529 .collect(); | |
520 assert_eq!(vec![255, 2, 3], got); | 530 assert_eq!(vec![255, 2, 3], got); |
521 } | 531 } |
522 } | 532 } |