Skip to content

Commit 4dcc7dd

Browse files
authored
Fix exception guard. (#109)
1 parent 82c4ffd commit 4dcc7dd

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

phper/src/errors.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -478,21 +478,21 @@ pub struct ExceptionGuard(PhantomData<*mut ()>);
478478

479479
impl Default for ExceptionGuard {
480480
fn default() -> Self {
481-
EXCEPTION_GUARD_COUNT.fetch_add(1, atomic::Ordering::Acquire);
482-
unsafe {
483-
zend_exception_save();
481+
if EXCEPTION_GUARD_COUNT.fetch_add(1, atomic::Ordering::Acquire) == 0 {
482+
unsafe {
483+
zend_exception_save();
484+
}
484485
}
485486
Self(PhantomData)
486487
}
487488
}
488489

489490
impl Drop for ExceptionGuard {
490491
fn drop(&mut self) {
491-
if EXCEPTION_GUARD_COUNT.fetch_sub(1, atomic::Ordering::Acquire) > 1 {
492-
return;
493-
}
494-
unsafe {
495-
zend_exception_restore();
492+
if EXCEPTION_GUARD_COUNT.fetch_sub(1, atomic::Ordering::Acquire) == 1 {
493+
unsafe {
494+
zend_exception_restore();
495+
}
496496
}
497497
}
498498
}

0 commit comments

Comments
 (0)