Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/runvil-plugin-sdk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "runvil-plugin-sdk"
version = "0.9.0"
version = "0.10.0"
description = "Write a runvil Plugin in safe Rust, over runvil-plugin-sys"
edition.workspace = true
# The floor a Plugin author's toolchain needs; CI's msrv job builds it.
Expand Down
24 changes: 17 additions & 7 deletions crates/runvil-plugin-sdk/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ use std::panic::{self, AssertUnwindSafe};
use std::slice;

use runvil_plugin_sys::{
RV_ERR_MISUSE, RV_ERR_UNSUPPORTED, RV_PACK_DELETE, RV_PACK_NEW, RV_PACK_RENDER, RV_PLUGIN_LOAD,
RV_PLUGIN_UNLOAD, RV_TOOL_CALL, RV_TOOL_CANCEL, RvCall, RvStatus, RvStr,
RV_ERR_MISUSE, RV_ERR_UNSUPPORTED, RV_PACK_DELETE, RV_PACK_NEW, RV_PACK_OPEN, RV_PACK_RENDER,
RV_PLUGIN_LOAD, RV_PLUGIN_UNLOAD, RV_TOOL_CALL, RV_TOOL_CANCEL, RvCall, RvStatus, RvStr,
};

use crate::names::{
is_valid_description, is_valid_name, is_valid_pack_name, is_valid_version, same,
is_valid_description, is_valid_lua_prelude, is_valid_name, is_valid_pack_name,
is_valid_version, same,
};
use crate::{Plugin, Refusal};

Expand Down Expand Up @@ -86,6 +87,7 @@ pub unsafe extern "C" fn entry<P: Plugin>(call: *mut RvCall) -> RvStatus {
RV_PACK_NEW => pack::new::<P>(call),
RV_PACK_DELETE => pack::delete(call),
RV_PACK_RENDER => pack::render(call),
RV_PACK_OPEN => pack::open(call),
RV_TOOL_CALL => tool::step(call),
RV_TOOL_CANCEL => tool::cancel(call),
_ => RV_ERR_UNSUPPORTED,
Expand Down Expand Up @@ -115,6 +117,10 @@ const fn check_constants<P: Plugin>() {
is_valid_description(pack.description),
"each description in Plugin::PACKS must be at most 1024 bytes with no control characters"
);
assert!(
is_valid_lua_prelude(pack.lua_prelude),
"each lua_prelude in Plugin::PACKS must be at most 65536 bytes"
);
let mut earlier = 0;
while earlier < at {
assert!(
Expand Down Expand Up @@ -189,13 +195,17 @@ unsafe fn refuse(
}

/// Runs `f`, which drops something the Plugin owns, and keeps a panic in
/// it from unwinding across the C boundary.
fn contain(f: impl FnOnce()) {
let _panicked = panic::catch_unwind(AssertUnwindSafe(f));
/// it from unwinding across the C boundary. If `f` panics, the panic
/// payload itself is forgotten so a destructor on the payload that also
/// panics cannot unwind out of `contain`.
pub(crate) fn contain(f: impl FnOnce()) {
if let Err(payload) = panic::catch_unwind(AssertUnwindSafe(f)) {
std::mem::forget(payload);
}
}

/// The text of a panic's payload, when it has one.
fn panic_message(payload: &(dyn Any + Send)) -> &str {
pub(crate) fn panic_message(payload: &(dyn Any + Send)) -> &str {
if let Some(message) = payload.downcast_ref::<&str>() {
message
} else if let Some(message) = payload.downcast_ref::<String>() {
Expand Down
Loading
Loading