Skip to content

Commit 5f91db5

Browse files
committed
chore: satisfy clippy and make the dev image portable
Clippy runs in CI now, so the warnings it had are fixed: pointer casts made explicit, the mutable static reached through a raw pointer, the large enum variant boxed. The dev image installs clippy and picks its benchmark binaries by architecture instead of assuming arm64.
1 parent a519a0f commit 5f91db5

7 files changed

Lines changed: 55 additions & 43 deletions

File tree

docker/Dockerfile.dev

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,20 @@ ENV PATH="/opt/php/bin:${PATH}"
1414
ENV CARGO_TARGET_DIR=/target
1515
ENV RUSTFLAGS="-C target-cpu=native"
1616

17+
RUN rustup component add clippy
18+
19+
# Benchmark tools, for comparing against the reference stacks by hand.
1720
ARG BOMBARDIER_VERSION=1.2.6
18-
RUN curl -fsSL -o /usr/local/bin/bombardier \
19-
"https://github.com/codesenberg/bombardier/releases/download/v${BOMBARDIER_VERSION}/bombardier-linux-arm64" \
20-
&& chmod +x /usr/local/bin/bombardier \
21+
RUN arch="$(dpkg --print-architecture)" \
22+
&& case "$arch" in \
23+
arm64) fp_arch=aarch64 ;; \
24+
amd64) fp_arch=x86_64 ;; \
25+
*) echo "unsupported architecture: $arch" >&2; exit 1 ;; \
26+
esac \
27+
&& curl -fsSL -o /usr/local/bin/bombardier \
28+
"https://github.com/codesenberg/bombardier/releases/download/v${BOMBARDIER_VERSION}/bombardier-linux-${arch}" \
2129
&& curl -fsSL -o /usr/local/bin/frankenphp \
22-
"https://github.com/php/frankenphp/releases/latest/download/frankenphp-linux-aarch64" \
23-
&& chmod +x /usr/local/bin/frankenphp
30+
"https://github.com/php/frankenphp/releases/latest/download/frankenphp-linux-${fp_arch}" \
31+
&& chmod +x /usr/local/bin/bombardier /usr/local/bin/frankenphp
2432

2533
WORKDIR /work

docker/compose.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ services:
1212
- cargo-registry:/usr/local/cargo/registry
1313
working_dir: /work
1414
command: sleep infinity
15+
dns:
16+
- 1.1.1.1
17+
- 8.8.8.8
1518
security_opt:
1619
- seccomp=unconfined
1720
ports:

src/php/engine.rs

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -62,30 +62,34 @@ impl Engine {
6262
}
6363

6464
pub(crate) unsafe fn apply_request_info(&mut self) {
65-
let info = unsafe { &mut *(&raw mut sapi_globals.request_info) };
66-
info.request_method = self.ctx.method.as_ptr();
67-
info.query_string = self.ctx.query.as_ptr() as *mut c_char;
68-
info.request_uri = self.ctx.uri.as_ptr() as *mut c_char;
69-
info.path_translated = self.ctx.script.as_ptr() as *mut c_char;
70-
info.content_length = self.ctx.post.len() as zend_long;
71-
info.content_type = match &self.ctx.content_type {
72-
Some(t) => t.as_ptr(),
73-
None => ptr::null(),
74-
};
75-
info.proto_num = 1001;
76-
info.headers_only = self.ctx.method.as_bytes() == b"HEAD";
77-
sapi_globals.server_context = 1 as *mut c_void;
65+
let info = &raw mut sapi_globals.request_info;
66+
unsafe {
67+
(*info).request_method = self.ctx.method.as_ptr();
68+
(*info).query_string = self.ctx.query.as_ptr() as *mut c_char;
69+
(*info).request_uri = self.ctx.uri.as_ptr() as *mut c_char;
70+
(*info).path_translated = self.ctx.script.as_ptr() as *mut c_char;
71+
(*info).content_length = self.ctx.post.len() as zend_long;
72+
(*info).content_type = match &self.ctx.content_type {
73+
Some(t) => t.as_ptr(),
74+
None => ptr::null(),
75+
};
76+
(*info).proto_num = 1001;
77+
(*info).headers_only = self.ctx.method.as_bytes() == b"HEAD";
78+
}
79+
sapi_globals.server_context = std::ptr::dangling_mut::<c_void>();
7880
sapi_globals.sapi_headers.http_response_code = 200;
7981
}
8082

8183
pub(crate) unsafe fn clear_request_info(&mut self) {
82-
let info = unsafe { &mut *(&raw mut sapi_globals.request_info) };
83-
info.request_method = ptr::null();
84-
info.query_string = ptr::null_mut();
85-
info.request_uri = ptr::null_mut();
86-
info.path_translated = ptr::null_mut();
87-
info.content_type = ptr::null();
88-
info.cookie_data = ptr::null_mut();
84+
let info = &raw mut sapi_globals.request_info;
85+
unsafe {
86+
(*info).request_method = ptr::null();
87+
(*info).query_string = ptr::null_mut();
88+
(*info).request_uri = ptr::null_mut();
89+
(*info).path_translated = ptr::null_mut();
90+
(*info).content_type = ptr::null();
91+
(*info).cookie_data = ptr::null_mut();
92+
}
8993
sapi_globals.server_context = ptr::null_mut();
9094
}
9195

@@ -109,7 +113,7 @@ impl Engine {
109113
php_execute_script(&mut handle);
110114
zend_destroy_file_handle(&mut handle);
111115

112-
let fatal = (core_globals.last_error_type as i32 & FATAL_ERRORS) != 0;
116+
let fatal = (core_globals.last_error_type & FATAL_ERRORS) != 0;
113117
php_request_shutdown(ptr::null_mut());
114118
self.clear_request_info();
115119

src/php/sapi.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ opcache.jit_buffer_size=64M
3232
pub(crate) fn ini_entries(extra: Option<&str>) -> CString {
3333
let mut ini = String::from(BASE_INI);
3434
if let Some(extra) = extra {
35-
for entry in extra.split(|c| c == ',' || c == '\n') {
35+
for entry in extra.split([',', '\n']) {
3636
let entry = entry.trim();
3737
if !entry.is_empty() {
3838
ini.push_str(entry);
@@ -52,7 +52,7 @@ pub(crate) fn functions() -> *const zend_function_entry {
5252
unsafe { std::mem::zeroed() },
5353
unsafe { std::mem::zeroed() },
5454
]));
55-
arg_info[0].name = 1 as *const c_char;
55+
arg_info[0].name = std::ptr::dangling::<c_char>();
5656
arg_info[1].name = c"handler".as_ptr();
5757

5858
let mut table: Vec<zend_function_entry> = Vec::with_capacity(NAMES.len() + 1);
@@ -89,7 +89,7 @@ unsafe extern "C" fn ub_write(buf: *const c_char, len: usize) -> usize {
8989
match ctx() {
9090
Some(c) => {
9191
c.out
92-
.extend_from_slice(unsafe { slice::from_raw_parts(buf as *const u8, len) });
92+
.extend_from_slice(unsafe { slice::from_raw_parts(buf.cast::<u8>(), len) });
9393
if c.stream.is_some() && c.out.len() >= STREAM_CHUNK {
9494
c.flush_stream();
9595
}
@@ -136,7 +136,7 @@ unsafe extern "C" fn read_post(buf: *mut c_char, count: usize) -> usize {
136136
let remaining = c.post.len() - c.post_read;
137137
let n = remaining.min(count);
138138
if n > 0 {
139-
unsafe { ptr::copy_nonoverlapping(c.post.as_ptr().add(c.post_read), buf as *mut u8, n) };
139+
unsafe { ptr::copy_nonoverlapping(c.post.as_ptr().add(c.post_read), buf.cast::<u8>(), n) };
140140
c.post_read += n;
141141
}
142142
n

src/php/worker.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ unsafe fn install_super_global(
159159
let slot = &mut core_globals.http_globals[track as usize];
160160
zval_ptr_dtor_nogc(slot);
161161
slot.value.arr = array;
162-
slot.u1.type_info = IS_ARRAY | ((IS_TYPE_REFCOUNTED as u32) << Z_TYPE_FLAGS_SHIFT);
162+
slot.u1.type_info = IS_ARRAY | (IS_TYPE_REFCOUNTED << Z_TYPE_FLAGS_SHIFT);
163163

164164
let key = zend_string_init(name.as_ptr(), name_str.len(), false);
165165
zend_hash_update(&raw mut executor_globals.symbol_table, key, slot);
@@ -355,7 +355,7 @@ unsafe fn build_prepared_env(entries: &[(CString, CString)]) -> *mut HashTable {
355355
let string = unsafe { zend_string_init(value.as_ptr(), value.as_bytes().len(), true) };
356356
let mut zv: zval = unsafe { std::mem::zeroed() };
357357
zv.value.str_ = string;
358-
zv.u1.type_info = IS_STRING | ((IS_TYPE_REFCOUNTED as u32) << Z_TYPE_FLAGS_SHIFT);
358+
zv.u1.type_info = IS_STRING | (IS_TYPE_REFCOUNTED << Z_TYPE_FLAGS_SHIFT);
359359
unsafe { zend_hash_update(array, key, &mut zv) };
360360
}
361361
array
@@ -392,14 +392,14 @@ unsafe fn snapshot_super_global(name: &str, skip_request_keys: bool) -> Vec<(CSt
392392
unsafe { zend_hash_internal_pointer_reset_ex(array, &mut pos) };
393393

394394
loop {
395-
let data = unsafe { zend_hash_get_current_data_ex(array, &mut pos) };
395+
let data = unsafe { zend_hash_get_current_data_ex(array, &pos) };
396396
if data.is_null() {
397397
break;
398398
}
399399

400400
let mut key: *mut zend_string = ptr::null_mut();
401401
let mut index: zend_ulong = 0;
402-
let kind = unsafe { zend_hash_get_current_key_ex(array, &mut key, &mut index, &mut pos) };
402+
let kind = unsafe { zend_hash_get_current_key_ex(array, &mut key, &mut index, &pos) };
403403

404404
if kind == zend_hash_key_type_HASH_KEY_IS_STRING && !key.is_null() {
405405
let name = unsafe { zend_str(key) };
@@ -430,7 +430,7 @@ unsafe fn zend_str(s: *mut zend_string) -> String {
430430
return String::new();
431431
}
432432
let len = unsafe { (*s).len };
433-
let bytes = unsafe { std::slice::from_raw_parts((*s).val.as_ptr() as *const u8, len) };
433+
let bytes = unsafe { std::slice::from_raw_parts((*s).val.as_ptr().cast::<u8>(), len) };
434434
String::from_utf8_lossy(bytes).into_owned()
435435
}
436436

@@ -489,7 +489,7 @@ pub fn handle(engine: &mut Engine, worker: &mut WorkerHandle) -> u16 {
489489
let ok = php_execute_script(&mut handle);
490490
zend_destroy_file_handle(&mut handle);
491491

492-
let fatal = (core_globals.last_error_type as i32 & FATAL_ERRORS) != 0;
492+
let fatal = (core_globals.last_error_type & FATAL_ERRORS) != 0;
493493
let produced = engine.ctx().out.len();
494494

495495
request_shutdown();

src/runtime.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,8 @@ impl Runtime {
3333

3434
pub fn handle(&mut self, mut job: Job) {
3535
let reply = job.reply.take();
36-
match self.respond(&job, reply) {
37-
Some((reply, outcome)) => {
38-
let _ = reply.send(outcome);
39-
}
40-
None => {}
36+
if let Some((reply, outcome)) = self.respond(&job, reply) {
37+
let _ = reply.send(outcome);
4138
}
4239
}
4340

src/server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl Reply {
8080
/// its own and pays a queue hop per request — measured at a quarter of the throughput, which
8181
/// is why buffering stays the default.
8282
enum Sink {
83-
Inline(RefCell<Runtime>),
83+
Inline(Box<RefCell<Runtime>>),
8484
Queue(Arc<Dispatcher>),
8585
}
8686

@@ -285,7 +285,7 @@ pub fn run(
285285
.build()
286286
.map_err(|e| format!("tokio runtime: {e}"))?;
287287

288-
SINK.with_borrow_mut(|slot| *slot = Some(Sink::Inline(RefCell::new(runtime))));
288+
SINK.with_borrow_mut(|slot| *slot = Some(Sink::Inline(Box::new(RefCell::new(runtime)))));
289289
let result = tokio_runtime.block_on(accept_loop(socket, tls));
290290
SINK.with_borrow_mut(|slot| *slot = None);
291291
return result;

0 commit comments

Comments
 (0)