mirror of
git://git.proxmox.com/git/perlmod.git
synced 2025-03-13 04:58:16 +03:00
add 'pseudo_block' helper
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
1182e7f5d7
commit
ccde914a4c
@ -99,6 +99,11 @@ extern "C" {
|
||||
|
||||
pub fn RSPL_gv_stashsv(name: *const SV, flags: i32) -> *mut HV;
|
||||
pub fn RSPL_sv_bless(sv: *mut SV, stash: *mut HV) -> *mut SV;
|
||||
|
||||
pub fn RSPL_ENTER();
|
||||
pub fn RSPL_SAVETMPS();
|
||||
pub fn RSPL_FREETMPS();
|
||||
pub fn RSPL_LEAVE();
|
||||
}
|
||||
|
||||
/// Argument marker for the stack.
|
||||
@ -233,3 +238,24 @@ pub fn stack_push(value: crate::Mortal) {
|
||||
pub unsafe fn croak(sv: *mut SV) -> ! {
|
||||
RSPL_croak_sv(sv);
|
||||
}
|
||||
|
||||
/// Create a pseudo-block for mortals & temps to be freed after it.
|
||||
/// This calls `ENTER; SAVETMPS;` before and `FREETMPS; LEAVE;` after the provided closure.
|
||||
pub fn pseudo_block<F, R>(func: F) -> R
|
||||
where
|
||||
F: FnOnce() -> R,
|
||||
{
|
||||
unsafe {
|
||||
RSPL_ENTER();
|
||||
RSPL_SAVETMPS();
|
||||
}
|
||||
|
||||
let res = func();
|
||||
|
||||
unsafe {
|
||||
RSPL_FREETMPS();
|
||||
RSPL_LEAVE();
|
||||
}
|
||||
|
||||
res
|
||||
}
|
||||
|
@ -278,6 +278,22 @@ extern SV* RSPL_sv_bless(SV *sv, HV *stash) {
|
||||
return sv_bless(sv, stash);
|
||||
}
|
||||
|
||||
extern void RSPL_ENTER() {
|
||||
ENTER;
|
||||
}
|
||||
|
||||
extern void RSPL_SAVETMPS() {
|
||||
SAVETMPS;
|
||||
}
|
||||
|
||||
extern void RSPL_FREETMPS() {
|
||||
FREETMPS;
|
||||
}
|
||||
|
||||
extern void RSPL_LEAVE() {
|
||||
LEAVE;
|
||||
}
|
||||
|
||||
/*
|
||||
These make are convoluted brainfarts:
|
||||
SVt_NULL undef
|
||||
|
Loading…
x
Reference in New Issue
Block a user