mirror of
https://git.proxmox.com/git/perlmod
synced 2025-11-01 13:29:52 +00:00
perlmod: add Value::new_xsub as an unsafe fn
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
af31038b48
commit
25d21384ae
@ -6,9 +6,9 @@ use std::fmt;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::ffi::{self, SV};
|
||||
use crate::raw_value;
|
||||
use crate::scalar::ScalarRef;
|
||||
use crate::Error;
|
||||
use crate::{perl_fn, raw_value};
|
||||
use crate::{Array, Hash, Scalar};
|
||||
|
||||
/// A higher level value. This is basically an [`SV`] already cast to [`AV`](crate::ffi::AV) or
|
||||
@ -52,6 +52,23 @@ impl Value {
|
||||
Value::Scalar(Scalar::new_bytes(s))
|
||||
}
|
||||
|
||||
/// Create a new reference code reference.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// It is up to the user to ensure that only a valid perl XSUB is used. You should know what
|
||||
/// you're doing, as perl code WILL execute the function and expect it to behave in a
|
||||
/// particular way!
|
||||
pub unsafe fn new_xsub(xsub: perl_fn!(extern "C" fn(*mut crate::ffi::CV))) -> Self {
|
||||
Self::from_raw_move(crate::ffi::RSPL_newXS_flags(
|
||||
std::ptr::null(),
|
||||
xsub as _,
|
||||
std::ptr::null(),
|
||||
std::ptr::null(),
|
||||
0,
|
||||
) as _)
|
||||
}
|
||||
|
||||
/// If the value is an array, returns the associated [`Array`].
|
||||
pub fn as_array(&self) -> Option<&Array> {
|
||||
match self {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user