Skip to content

Commit

Permalink
fix: use std::ffi::c_char instead of platform specific int
Browse files Browse the repository at this point in the history
This change reverts a previous change that did platform
detection and set a type correspondingly to u8 or i8. By
using std::ffi::c_char we get a portable way to do the
same thing.
  • Loading branch information
dekobon committed Mar 6, 2024
1 parent 920cf3f commit 74792b0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
10 changes: 5 additions & 5 deletions examples/upstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ unsafe extern "C" fn ngx_http_upstream_init_custom(
NGX_LOG_EMERG as usize,
cf,
0,
"CUSTOM UPSTREAM no upstream srv_conf".as_bytes().as_ptr() as *const Ptr,
"CUSTOM UPSTREAM no upstream srv_conf".as_bytes().as_ptr() as *const c_char,
);
return isize::from(Status::NGX_ERROR);
}
Expand All @@ -266,7 +266,7 @@ unsafe extern "C" fn ngx_http_upstream_init_custom(
NGX_LOG_EMERG as usize,
cf,
0,
"CUSTOM UPSTREAM failed calling init_upstream".as_bytes().as_ptr() as *const Ptr,
"CUSTOM UPSTREAM failed calling init_upstream".as_bytes().as_ptr() as *const c_char,
);
return isize::from(Status::NGX_ERROR);
}
Expand Down Expand Up @@ -299,11 +299,11 @@ unsafe extern "C" fn ngx_http_upstream_commands_set_custom(
NGX_LOG_EMERG as usize,
cf,
0,
"invalid value \"%V\" in \"%V\" directive".as_bytes().as_ptr() as *const Ptr,
"invalid value \"%V\" in \"%V\" directive".as_bytes().as_ptr() as *const c_char,
value[1],
&(*cmd).name,
);
return usize::MAX as *mut Ptr;
return usize::MAX as *mut c_char;
}
ccf.max = n as u32;
}
Expand Down Expand Up @@ -344,7 +344,7 @@ impl HTTPModule for Module {
0,
"CUSTOM UPSTREAM could not allocate memory for config"
.as_bytes()
.as_ptr() as *const Ptr,
.as_ptr() as *const c_char,
);
return std::ptr::null_mut();
}
Expand Down
8 changes: 1 addition & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,6 @@ pub mod log;
#[macro_export]
macro_rules! ngx_modules {
($( $mod:ident ),+) => {
#[cfg(target_arch = "aarch64")]
type Ptr = u8;

#[cfg(target_arch = "x86_64")]
type Ptr = i8;

#[no_mangle]
pub static mut ngx_modules: [*const ngx_module_t; $crate::count!($( $mod, )+) + 1] = [
$( unsafe { &$mod } as *const ngx_module_t, )+
Expand All @@ -77,7 +71,7 @@ macro_rules! ngx_modules {

#[no_mangle]
pub static mut ngx_module_names: [*const c_char; $crate::count!($( $mod, )+) + 1] = [
$( concat!(stringify!($mod), "\0").as_ptr() as *const Ptr, )+
$( concat!(stringify!($mod), "\0").as_ptr() as *const c_char, )+
std::ptr::null()
];

Expand Down

0 comments on commit 74792b0

Please sign in to comment.