Skip to content

Commit eaa9c69

Browse files
committed
fix(macros): make get_module() startup idempotent
1 parent 797e8e3 commit eaa9c69

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

crates/macros/src/module.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,16 @@ pub fn parser(input: ItemFn) -> Result<TokenStream> {
3535
let b = __EXT_PHP_RS_MODULE_STARTUP
3636
.lock()
3737
.take()
38-
.inspect(|_| ::ext_php_rs::internal::ext_php_rs_startup())
39-
.expect("Module startup function has already been called.")
40-
.startup(ty, mod_num)
41-
.map(|_| 0)
42-
.unwrap_or(1);
38+
.map(|startup| {
39+
::ext_php_rs::internal::ext_php_rs_startup();
40+
startup.startup(ty, mod_num).map(|_| 0).unwrap_or(1)
41+
})
42+
.unwrap_or_else(|| {
43+
// Module already started, call ext_php_rs_startup for idempotent
44+
// initialization (e.g., Closure::build early-returns if already built)
45+
::ext_php_rs::internal::ext_php_rs_startup();
46+
0
47+
});
4348
a | b
4449
}
4550

0 commit comments

Comments
 (0)