@@ -68,11 +68,9 @@ pub use bindings::*;
68
68
/// let data: &str = "example"; // The string to convert
69
69
/// let ptr = str_to_uchar(pool, data);
70
70
/// ```
71
- pub fn str_to_uchar ( pool : * mut ngx_pool_t , data : & str ) -> * mut u_char {
72
- let ptr: * mut u_char = unsafe { ngx_palloc ( pool, data. len ( ) as _ ) as _ } ;
73
- unsafe {
74
- copy_nonoverlapping ( data. as_ptr ( ) , ptr, data. len ( ) ) ;
75
- }
71
+ pub unsafe fn str_to_uchar ( pool : * mut ngx_pool_t , data : & str ) -> * mut u_char {
72
+ let ptr: * mut u_char = ngx_palloc ( pool, data. len ( ) as _ ) as _ ;
73
+ copy_nonoverlapping ( data. as_ptr ( ) , ptr, data. len ( ) ) ;
76
74
ptr
77
75
}
78
76
@@ -99,9 +97,14 @@ impl ngx_str_t {
99
97
/// * `pool` - A pointer to the nginx memory pool (`ngx_pool_t`).
100
98
/// * `data` - The `String` from which to create the nginx string.
101
99
///
100
+ /// # Safety
101
+ /// This function is marked as unsafe because it accepts a raw pointer argument. There is no
102
+ /// way to know if `pool` is pointing to valid memory. The caller must provide a valid pool to
103
+ /// avoid indeterminate behavior.
104
+ ///
102
105
/// # Returns
103
106
/// An `ngx_str_t` instance representing the given `String`.
104
- pub fn from_string ( pool : * mut ngx_pool_t , data : String ) -> Self {
107
+ pub unsafe fn from_string ( pool : * mut ngx_pool_t , data : String ) -> Self {
105
108
ngx_str_t {
106
109
data : str_to_uchar ( pool, data. as_str ( ) ) ,
107
110
len : data. len ( ) as _ ,
@@ -115,9 +118,14 @@ impl ngx_str_t {
115
118
/// * `pool` - A pointer to the nginx memory pool (`ngx_pool_t`).
116
119
/// * `data` - The string slice from which to create the nginx string.
117
120
///
121
+ /// # Safety
122
+ /// This function is marked as unsafe because it accepts a raw pointer argument. There is no
123
+ /// way to know if `pool` is pointing to valid memory. The caller must provide a valid pool to
124
+ /// avoid indeterminate behavior.
125
+ ///
118
126
/// # Returns
119
127
/// An `ngx_str_t` instance representing the given string slice.
120
- pub fn from_str ( pool : * mut ngx_pool_t , data : & str ) -> Self {
128
+ pub unsafe fn from_str ( pool : * mut ngx_pool_t , data : & str ) -> Self {
121
129
ngx_str_t {
122
130
data : str_to_uchar ( pool, data) ,
123
131
len : data. len ( ) as _ ,
@@ -180,11 +188,16 @@ impl TryFrom<ngx_str_t> for &str {
180
188
/// let value: &str = "value"; // The value to add
181
189
/// let result = add_to_ngx_table(table, pool, key, value);
182
190
/// ```
183
- pub fn add_to_ngx_table ( table : * mut ngx_table_elt_t , pool : * mut ngx_pool_t , key : & str , value : & str ) -> Option < ( ) > {
191
+ pub unsafe fn add_to_ngx_table (
192
+ table : * mut ngx_table_elt_t ,
193
+ pool : * mut ngx_pool_t ,
194
+ key : & str ,
195
+ value : & str ,
196
+ ) -> Option < ( ) > {
184
197
if table. is_null ( ) {
185
198
return None ;
186
199
}
187
- unsafe { table. as_mut ( ) } . map ( |table| {
200
+ table. as_mut ( ) . map ( |table| {
188
201
table. hash = 1 ;
189
202
table. key . len = key. len ( ) as _ ;
190
203
table. key . data = str_to_uchar ( pool, key) ;
0 commit comments