Skip to content

Commit 5876388

Browse files
committed
fix: add ext_php_rs_sapi_per_thread_shutdown
1 parent f70919e commit 5876388

File tree

5 files changed

+14
-19
lines changed

5 files changed

+14
-19
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -225,24 +225,7 @@ jobs:
225225
echo "LLVM_CONFIG_PATH=${{ runner.temp }}/llvm-${{ env.clang }}/bin/llvm-config" >> $GITHUB_ENV
226226
227227
- name: Test with embed feature
228-
run: |
229-
sudo apt-get update && sudo apt-get install -y gdb
230-
sudo sysctl -w kernel.core_pattern='core.%e.%p'
231-
ulimit -c unlimited
232-
echo "Core pattern: $(cat /proc/sys/kernel/core_pattern)"
233-
echo "Ulimit -c: $(ulimit -c)"
234-
cargo test --workspace --release --features closure,embed,anyhow --no-fail-fast || \
235-
(echo "Test failed, looking for core dumps..."; ls -la core.* 2>/dev/null || echo "No core files found"; \
236-
for core in core.*; do \
237-
if [ -f "$core" ]; then \
238-
echo "Found core: $core"; \
239-
exe=$(find target/release/deps -type f -executable -name "sapi_tests-*" ! -name "*.d" | head -1); \
240-
if [ -n "$exe" ]; then \
241-
echo "Using executable: $exe"; \
242-
gdb -batch -ex "thread apply all bt" "$exe" "$core"; \
243-
fi; \
244-
fi; \
245-
done; exit 1)
228+
run: cargo test --workspace --release --features closure,embed,anyhow --no-fail-fast
246229

247230
build-musl:
248231
name: musl / ${{ matrix.php }} / ${{ matrix.phpts[1] }}

src/embed/embed.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ SAPI_API void ext_php_rs_sapi_per_thread_init() {
4444
#endif
4545
}
4646

47+
SAPI_API void ext_php_rs_sapi_per_thread_shutdown() {
48+
#ifdef ZTS
49+
ts_free_thread();
50+
#endif
51+
}
52+
4753
void ext_php_rs_php_error(int type, const char *format, ...) {
4854
va_list args;
4955
va_start(args, format);

src/embed/embed.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ void* ext_php_rs_embed_callback(int argc, char** argv, void* (*callback)(void *)
99
void ext_php_rs_sapi_startup();
1010
void ext_php_rs_sapi_shutdown();
1111
void ext_php_rs_sapi_per_thread_init();
12+
void ext_php_rs_sapi_per_thread_shutdown();
1213

1314
void ext_php_rs_php_error(int type, const char *format, ...);

src/embed/ffi.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ unsafe extern "C" {
2020
pub fn ext_php_rs_sapi_startup();
2121
pub fn ext_php_rs_sapi_shutdown();
2222
pub fn ext_php_rs_sapi_per_thread_init();
23+
pub fn ext_php_rs_sapi_per_thread_shutdown();
2324

2425
pub fn ext_php_rs_php_error(
2526
type_: ::std::os::raw::c_int,

tests/sapi.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use std::ffi::c_char;
2020
use std::sync::Mutex;
2121

2222
#[cfg(php_zts)]
23-
use ext_php_rs::embed::ext_php_rs_sapi_per_thread_init;
23+
use ext_php_rs::embed::{ext_php_rs_sapi_per_thread_init, ext_php_rs_sapi_per_thread_shutdown};
2424
#[cfg(php_zts)]
2525
use std::sync::Arc;
2626
#[cfg(php_zts)]
@@ -178,6 +178,10 @@ fn test_sapi_multithread() {
178178
unsafe {
179179
php_request_shutdown(std::ptr::null_mut());
180180
}
181+
182+
unsafe {
183+
ext_php_rs_sapi_per_thread_shutdown();
184+
}
181185
});
182186

183187
handles.push(handle);

0 commit comments

Comments
 (0)