Skip to content

Commit 6fed5f3

Browse files
committed
Update tests, fix unsafe warnings
1 parent b2e2003 commit 6fed5f3

File tree

10 files changed

+207
-118
lines changed

10 files changed

+207
-118
lines changed

.vscode/settings.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"rust-analyzer.cargo.features": [
3+
"export-modules",
4+
"extproc-mock",
5+
"vendored"
6+
],
7+
"rust-analyzer.cargo.allFeatures": false,
8+
"rust-analyzer.cargo.buildScripts.enable": true,
9+
"rust-analyzer.check.command": "check",
10+
"rust-analyzer.check.allTargets": true,
11+
"rust-analyzer.procMacro.enable": true,
12+
"rust-analyzer.diagnostics.disabled": [
13+
"inactive-code"
14+
],
15+
"rust-analyzer.server.extraEnv": {
16+
"NGX_NO_SIGNATURE_CHECK": "1"
17+
}
18+
}

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ lint:
148148
@echo "==> Running Rust linting and formatting checks..."
149149
@echo "Checking code formatting..."
150150
@cargo fmt --all -- --check || (echo "❌ Code formatting issues found. Run 'cargo fmt --all' to fix." && exit 1)
151+
@echo "Running strict compilation check for memory safety errors..."
152+
@RUSTFLAGS="-D unsafe-op-in-unsafe-fn -D warnings" cargo check --all-targets --all-features || (echo "❌ Memory safety or compilation errors found." && exit 1)
151153
@echo "Running Clippy linter..."
152154
@cargo clippy --all-targets --all-features -- -D warnings -A clippy::doc-lazy-continuation -A clippy::enum-variant-names || (echo "❌ Clippy issues found." && exit 1)
153155
@echo "Checking for whitespace issues using git..."

build.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ fn main() {
44

55
// Ensure protoc is available using vendored binary to avoid system dependency.
66
let protoc_path = protoc_bin_vendored::protoc_bin_path().expect("vendored protoc not found");
7-
std::env::set_var("PROTOC", &protoc_path);
7+
unsafe {
8+
std::env::set_var("PROTOC", &protoc_path);
9+
}
810

911
// On macOS, allow unresolved NGINX symbols to be resolved at load time.
1012
// This enables building the dynamic module outside of the NGINX build system.

src/lib.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ impl http::HttpModule for Module {
5353

5454
unsafe extern "C" fn preconfiguration(cf: *mut ngx_conf_t) -> ngx_int_t {
5555
// Register $inference_upstream variable so it can be used in NGINX config (e.g. proxy_pass http://$inference_upstream;)
56-
let cf_ref = &mut *cf;
56+
let cf_ref = unsafe { &mut *cf };
5757
// Allocate variable name from configuration pool
58-
let name = &mut ngx_str_t::from_str(cf_ref.pool, "inference_upstream") as *mut _;
58+
let name = unsafe { &mut ngx_str_t::from_str(cf_ref.pool, "inference_upstream") as *mut _ };
5959
// Add variable with no special flags
60-
let v = ngx_http_add_variable(cf, name, 0);
60+
let v = unsafe { ngx_http_add_variable(cf, name, 0) };
6161
if v.is_null() {
6262
return core::Status::NGX_ERROR.into();
6363
}
@@ -71,17 +71,19 @@ impl http::HttpModule for Module {
7171

7272
unsafe extern "C" fn postconfiguration(cf: *mut ngx_conf_t) -> ngx_int_t {
7373
// SAFETY: called by NGINX with non-null cf
74-
let cf = &mut *cf;
74+
let cf = unsafe { &mut *cf };
7575
let cmcf = NgxHttpCoreModule::main_conf_mut(cf).expect("http core main conf");
7676

7777
// Register an Access phase handler to run before upstream selection.
78-
let h = ngx_array_push(
79-
&mut cmcf.phases[ngx_http_phases_NGX_HTTP_ACCESS_PHASE as usize].handlers,
80-
) as *mut ngx_http_handler_pt;
78+
let h = unsafe {
79+
ngx_array_push(
80+
&mut cmcf.phases[ngx_http_phases_NGX_HTTP_ACCESS_PHASE as usize].handlers,
81+
) as *mut ngx_http_handler_pt
82+
};
8183
if h.is_null() {
8284
return core::Status::NGX_ERROR.into();
8385
}
84-
*h = Some(inference_access_handler);
86+
unsafe { *h = Some(inference_access_handler) };
8587
core::Status::NGX_OK.into()
8688
}
8789
}

0 commit comments

Comments
 (0)