aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-php-rpc/src
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-08-04 04:07:41 +0900
committernsfisis <nsfisis@gmail.com>2026-08-04 05:43:24 +0900
commit695365a0ad68e4534425c64b7a6a4b6598b68ef7 (patch)
treea906972618f08e31012f721c717321bd08164cde /crates/shirabe-php-rpc/src
parent261516d5ce6f8b0d69cf9e3da7dd2f0ef1cdc36a (diff)
downloadphp-shirabe-695365a0ad68e4534425c64b7a6a4b6598b68ef7.tar.gz
php-shirabe-695365a0ad68e4534425c64b7a6a4b6598b68ef7.tar.zst
php-shirabe-695365a0ad68e4534425c64b7a6a4b6598b68ef7.zip
feat(plugin): dispatch plugin event subscribers through the RPC worker
Wires the addPlugin subscriber branch end to end: EventSubscriberInterface and Capable become fallible and dyn-compatible (their sole implementor is the PHP plugin proxy, which answers getSubscribedEvents over RPC), listeners register as Callable::PhpMethod and are invoked with a per-call event handle, and the R table now drops entries when a child-side stub destructs. The R table keeps its IndexMap with monotonically increasing handles, so released handles are never reused and no generation counter is needed. Upstream has no subscriber-plugin test, so the path is covered by a Shirabe-owned fixture exercising all three getSubscribedEvents shapes. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe-php-rpc/src')
-rw-r--r--crates/shirabe-php-rpc/src/lib.rs27
1 files changed, 23 insertions, 4 deletions
diff --git a/crates/shirabe-php-rpc/src/lib.rs b/crates/shirabe-php-rpc/src/lib.rs
index 23996a95..e41f289f 100644
--- a/crates/shirabe-php-rpc/src/lib.rs
+++ b/crates/shirabe-php-rpc/src/lib.rs
@@ -348,6 +348,20 @@ static NEXT_CORR_ID: AtomicU64 = AtomicU64::new(1);
/// (e.g. `__shirabe_find_file` autoload queries), so ids start at 1.
static NEXT_RHANDLE: AtomicU64 = AtomicU64::new(1);
+thread_local! {
+ /// Listener for ReleaseRustHandle notifications, thread-local like the R table it prunes.
+ static RELEASE_RUST_HANDLE_HOOK: std::cell::RefCell<Option<Box<dyn Fn(u64)>>> =
+ const { std::cell::RefCell::new(None) };
+}
+
+/// Registers the listener invoked with the released handle whenever a ReleaseRustHandle
+/// notification arrives on this thread. Replaces any previously registered listener.
+pub fn set_release_rust_handle_hook(hook: impl Fn(u64) + 'static) {
+ RELEASE_RUST_HANDLE_HOOK.with(|slot| {
+ *slot.borrow_mut() = Some(Box::new(hook));
+ });
+}
+
pub fn alloc_rhandle() -> u64 {
NEXT_RHANDLE.fetch_add(1, Ordering::Relaxed)
}
@@ -507,10 +521,15 @@ fn rpc_call(
};
send_frame(&reply)?;
}
- Frame::ReleaseRustHandle { .. } => {
- // TODO(plugin): R-table garbage collection is deferred — the shirabe crate
- // keeps its entries alive for the worker's lifetime, and per-call script-event
- // handles carry no state either, so the notification is dropped here.
+ Frame::ReleaseRustHandle { rhandle } => {
+ // A one-way notification sent by a child-side stub's __destruct; the shirabe
+ // crate registers a hook that drops the matching R-table entry. Per-call
+ // script-event handles carry no table state, so an unhooked release is a no-op.
+ RELEASE_RUST_HANDLE_HOOK.with(|hook| {
+ if let Some(hook) = hook.borrow().as_ref() {
+ hook(rhandle);
+ }
+ });
continue;
}
Frame::EpochBump { .. } => {