@@ -68,11 +68,9 @@ pub use bindings::*;
6868/// let data: &str = "example"; // The string to convert
6969/// let ptr = str_to_uchar(pool, data);
7070/// ```
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 ( ) ) ;
7674 ptr
7775}
7876
@@ -99,9 +97,14 @@ impl ngx_str_t {
9997 /// * `pool` - A pointer to the nginx memory pool (`ngx_pool_t`).
10098 /// * `data` - The `String` from which to create the nginx string.
10199 ///
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+ ///
102105 /// # Returns
103106 /// 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 {
105108 ngx_str_t {
106109 data : str_to_uchar ( pool, data. as_str ( ) ) ,
107110 len : data. len ( ) as _ ,
@@ -115,9 +118,14 @@ impl ngx_str_t {
115118 /// * `pool` - A pointer to the nginx memory pool (`ngx_pool_t`).
116119 /// * `data` - The string slice from which to create the nginx string.
117120 ///
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+ ///
118126 /// # Returns
119127 /// 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 {
121129 ngx_str_t {
122130 data : str_to_uchar ( pool, data) ,
123131 len : data. len ( ) as _ ,
@@ -180,11 +188,16 @@ impl TryFrom<ngx_str_t> for &str {
180188/// let value: &str = "value"; // The value to add
181189/// let result = add_to_ngx_table(table, pool, key, value);
182190/// ```
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 < ( ) > {
184197 if table. is_null ( ) {
185198 return None ;
186199 }
187- unsafe { table. as_mut ( ) } . map ( |table| {
200+ table. as_mut ( ) . map ( |table| {
188201 table. hash = 1 ;
189202 table. key . len = key. len ( ) as _ ;
190203 table. key . data = str_to_uchar ( pool, key) ;
0 commit comments