mirror of
https://git.proxmox.com/git/perlmod
synced 2025-10-19 22:46:07 +00:00
experimental PVLV support
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
ec6f42c37e
commit
61143f5d12
@ -10,4 +10,16 @@ mod export {
|
|||||||
|
|
||||||
Ok(a + b)
|
Ok(a + b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[export]
|
||||||
|
fn test(t: Option<String>) -> Result<(), Error> {
|
||||||
|
println!("test called with {:?}", t);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[export]
|
||||||
|
fn teststr(t: Option<&str>) -> Result<(), Error> {
|
||||||
|
println!("teststr called with {:?}", t);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -107,6 +107,10 @@ extern "C" {
|
|||||||
pub fn RSPL_LEAVE();
|
pub fn RSPL_LEAVE();
|
||||||
|
|
||||||
pub fn RSPL_sv_reftype(sv: *const SV, ob: libc::c_int) -> *const libc::c_char;
|
pub fn RSPL_sv_reftype(sv: *const SV, ob: libc::c_int) -> *const libc::c_char;
|
||||||
|
|
||||||
|
pub fn RSPL_PVLV() -> u32;
|
||||||
|
pub fn RSPL_LvTARG(sv: *mut SV) -> *mut SV;
|
||||||
|
pub fn RSPL_vivify_defelem(sv: *mut SV);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Argument marker for the stack.
|
/// Argument marker for the stack.
|
||||||
|
@ -301,6 +301,19 @@ extern const char* RSPL_sv_reftype(const SV *const sv, const int ob) {
|
|||||||
return sv_reftype(sv, ob);
|
return sv_reftype(sv, ob);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We we don't need to generate the numeric value:
|
||||||
|
extern uint32_t RSPL_PVLV() {
|
||||||
|
return SVt_PVLV;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern SV* RSPL_LvTARG(SV *sv) {
|
||||||
|
return LvTARG(sv);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern void RSPL_vivify_defelem(SV *sv) {
|
||||||
|
Perl_vivify_defelem(aTHX_ sv);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
These make are convoluted brainfarts:
|
These make are convoluted brainfarts:
|
||||||
SVt_NULL undef
|
SVt_NULL undef
|
||||||
|
@ -205,6 +205,10 @@ impl ScalarRef {
|
|||||||
let ty = ffi::RSPL_svtype(self.sv());
|
let ty = ffi::RSPL_svtype(self.sv());
|
||||||
if ty == 0 {
|
if ty == 0 {
|
||||||
Type::Scalar(Flags::empty())
|
Type::Scalar(Flags::empty())
|
||||||
|
} else if ty == ffi::RSPL_PVLV() {
|
||||||
|
self.get_target()
|
||||||
|
.map(|s| s.ty())
|
||||||
|
.unwrap_or(Type::Other(99))
|
||||||
} else {
|
} else {
|
||||||
Type::Other(ty as u8)
|
Type::Other(ty as u8)
|
||||||
}
|
}
|
||||||
@ -213,6 +217,19 @@ impl ScalarRef {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Dereference this PVLV.
|
||||||
|
pub fn get_target(&self) -> Option<Scalar> {
|
||||||
|
let ptr = unsafe {
|
||||||
|
ffi::RSPL_vivify_defelem(self.sv());
|
||||||
|
ffi::RSPL_LvTARG(self.sv())
|
||||||
|
};
|
||||||
|
if ptr.is_null() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(unsafe { Scalar::from_raw_ref(ptr) })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Dereference this reference.
|
/// Dereference this reference.
|
||||||
pub fn dereference(&self) -> Option<Scalar> {
|
pub fn dereference(&self) -> Option<Scalar> {
|
||||||
let ptr = unsafe { ffi::RSPL_dereference(self.sv()) };
|
let ptr = unsafe { ffi::RSPL_dereference(self.sv()) };
|
||||||
|
8
test.pl
8
test.pl
@ -4,6 +4,7 @@ use v5.28.0;
|
|||||||
|
|
||||||
use lib '.';
|
use lib '.';
|
||||||
use RSPM::Bless;
|
use RSPM::Bless;
|
||||||
|
use RSPM::Foo142;
|
||||||
|
|
||||||
my $v = RSPM::Bless->new("Hello");
|
my $v = RSPM::Bless->new("Hello");
|
||||||
$v->something();
|
$v->something();
|
||||||
@ -13,3 +14,10 @@ my @ret = $v->multi_return();
|
|||||||
say "Got: ".scalar(@ret)." values: @ret";
|
say "Got: ".scalar(@ret)." values: @ret";
|
||||||
|
|
||||||
$v->another(54);
|
$v->another(54);
|
||||||
|
|
||||||
|
my $param = { a => 1 };
|
||||||
|
my $s = "Hello You";
|
||||||
|
RSPM::Foo142::test(substr($s, 3, 3));
|
||||||
|
RSPM::Foo142::teststr(substr($s, 3, 3));
|
||||||
|
RSPM::Foo142::test($param->{x});
|
||||||
|
RSPM::Foo142::teststr($param->{x});
|
||||||
|
Loading…
Reference in New Issue
Block a user