summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQrius <[email protected]>2025-01-15 13:29:51 +0100
committerQrius <[email protected]>2025-01-15 13:29:51 +0100
commitc335325ad76dc7620726d9797832e5fd85fc6e76 (patch)
tree97ac17a085a789aeac3cf45d066e57f3a69e5372
parentfc3922b4bf4d712b78ffcdd48abef958f78c36f6 (diff)
downloadskaldpress-master.tar.gz
skaldpress-master.zip
Fix guile thingsHEADmaster
-rw-r--r--Cargo.lock2
-rw-r--r--Cargo.toml4
-rw-r--r--packaging/DEBIAN/control2
-rwxr-xr-xpackaging/package_debian.sh4
-rw-r--r--src/guile/guile.rs61
-rw-r--r--src/guile/guiledefs.c2
6 files changed, 58 insertions, 17 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 874d526..7065eef 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -236,7 +236,7 @@ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
[[package]]
name = "skaldpress"
-version = "2.2.0"
+version = "2.2.1"
dependencies = [
"chrono",
"markdown",
diff --git a/Cargo.toml b/Cargo.toml
index c85f857..77bb4ca 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,11 +1,11 @@
[package]
name = "skaldpress"
-version = "2.2.0"
+version = "2.2.1"
edition = "2021"
default-run = "skaldpress"
[features]
-default = ["time", "markdown", "deadlinks", "readline"]
+default = ["time", "markdown", "deadlinks", "guile", "readline"]
time = ["dep:chrono"]
markdown = ["dep:markdown"]
deadlinks = ["dep:minreq"]
diff --git a/packaging/DEBIAN/control b/packaging/DEBIAN/control
index 2d53eb2..12bc623 100644
--- a/packaging/DEBIAN/control
+++ b/packaging/DEBIAN/control
@@ -1,5 +1,5 @@
Package: skaldpress
-Version: 2.0.0
+Version: 2.2.1
Maintainer: qirus
Architecture: all
Description: Templating and macro engine
diff --git a/packaging/package_debian.sh b/packaging/package_debian.sh
index f583ce4..59f5774 100755
--- a/packaging/package_debian.sh
+++ b/packaging/package_debian.sh
@@ -2,6 +2,8 @@
set -x
set -o pipefail
+FEATURES="--features guile,readline"
+
tmpdir=$(mktemp -d)
dir="${tmpdir}/skaldpress"
@@ -10,7 +12,7 @@ origdir="$(pwd)"
mkdir -p ${dir}
rm -r ${dir}
mkdir -p ${dir}
-cargo build --features guile --release
+cargo build $FEATURES --release
bindir=${dir}/usr/local/bin
mkdir -p ${bindir}
diff --git a/src/guile/guile.rs b/src/guile/guile.rs
index fc49c70..e8e9b4d 100644
--- a/src/guile/guile.rs
+++ b/src/guile/guile.rs
@@ -2,9 +2,6 @@ use crate::macro_processor::macro_processor::MacroProcessor;
use std::ffi::{CStr, CString};
use std::os::raw::{c_char, c_int, c_void};
-use std::sync::mpsc;
-use std::thread;
-
macro_rules! dprint {
($($x:tt)*) => {
#[cfg(debug_assertions)]
@@ -17,7 +14,6 @@ extern "C" {
fn scm_init_guile();
fn scm_c_eval_string(expr: *const c_char) -> *mut c_void;
fn scm_from_utf8_string(expr: *const c_char) -> *mut c_void;
- fn scm_from_locale_string(scm_obj: *const c_char) -> *mut c_void;
fn scm_to_locale_string(scm_obj: *mut c_void) -> *const c_char;
fn scm_is_string(scm_obj: *mut c_void) -> c_int;
fn scm_object_to_string(scm_obj: *mut c_void, printer: *mut c_void) -> *mut c_void;
@@ -29,20 +25,24 @@ extern "C" {
rst: c_int,
func: extern "C" fn(scm_obj: *mut c_void) -> *mut c_void,
);
+ fn scm_c_catch(
+ tag: *mut c_void,
+ body: extern "C" fn(*mut c_void) -> *mut c_void,
+ body_data: *mut c_void,
+ handler: extern "C" fn(*mut c_void, *mut c_void, *mut c_void) -> *mut c_void,
+ handler_data: *mut c_void,
+ pre_unwind_handler: extern "C" fn(*mut c_void, *mut c_void, *mut c_void) -> *mut c_void,
+ pre_unwind_handler_data: *mut c_void,
+ ) -> *mut c_void;
fn scm_c_define(name: *const c_char, value: *mut c_void);
fn scm_from_pointer(value: *mut c_void) -> *mut c_void;
- //fn scm_with_guile(func: extern "C" fn(data: *mut c_void) -> *mut c_void, data: *mut c_void) -> *mut c_void;
- //fn scm_is_number(scm_obj: *mut c_void) -> c_int;
- //fn scm_without_guile(func: extern "C" fn(data: *mut c_void) -> *mut c_void, data: *mut c_void) -> *mut c_void;
- //fn scm_c_write(scm_obj: *mut c_void, port: *mut c_void);
- //fn scm_get_output_string(port: *mut c_void) -> *mut c_void;
- //fn scm_open_output_string() -> *mut c_void;
}
#[link(name = "guiledefs")]
extern "C" {
pub static scm_undefined: *mut c_void;
pub static scm_unspecified: *mut c_void;
+ pub static scm_bool_t: *mut c_void;
fn defs_scm_is_eq(x: *mut c_void, y: *mut c_void) -> c_int;
fn defs_scm_define_string(name: *const c_char, value: *const c_char);
}
@@ -99,6 +99,37 @@ extern "C" fn scm_smp_macro(arg: *mut c_void) -> *mut c_void {
#[derive(Debug)]
pub struct Guile {}
+extern "C" fn error_handler(
+ _data: *mut c_void,
+ _tag: *mut c_void,
+ _args: *mut c_void,
+) -> *mut c_void {
+ eprintln!("Guile error occurred!");
+ unsafe { scm_undefined }
+}
+
+/*
+/* A "pre-unwind handler" to scm_c_catch that prints the exception
+ according to "set guile print-stack". */
+static SCM scscm_printing_pre_unwind_handler (void *data, SCM key, SCM args) {
+ SCM stack = scm_make_stack (SCM_BOOL_T, scm_list_1 (scm_from_int (2)));
+ gdbscm_print_exception_with_stack (SCM_BOOL_F, stack, key, args);
+ return SCM_UNSPECIFIED;
+}
+*/
+extern "C" fn pre_unwind_handler(
+ _data: *mut c_void,
+ _tag: *mut c_void,
+ _args: *mut c_void,
+) -> *mut c_void {
+ unsafe { scm_undefined }
+}
+
+extern "C" fn eval_body(data: *mut c_void) -> *mut c_void {
+ let expr = data as *const c_char;
+ unsafe { scm_c_eval_string(expr) }
+}
+
impl Guile {
pub fn new() -> Self {
unsafe {
@@ -116,7 +147,15 @@ impl Guile {
dprint!("(eval \"{}\")\n", expr);
unsafe {
let c_expr = CString::new(expr).map_err(|_| ())?;
- let result = scm_c_eval_string(c_expr.as_ptr());
+ let result = scm_c_catch(
+ scm_bool_t,
+ eval_body,
+ c_expr.as_ptr() as *mut c_void,
+ error_handler,
+ scm_bool_t,
+ pre_unwind_handler,
+ scm_bool_t,
+ );
string_from_scm(result)
}
}
diff --git a/src/guile/guiledefs.c b/src/guile/guiledefs.c
index bf050af..db7bf72 100644
--- a/src/guile/guiledefs.c
+++ b/src/guile/guiledefs.c
@@ -2,6 +2,7 @@
struct scm_unused_struct * scm_undefined = SCM_UNDEFINED;
struct scm_unused_struct * scm_unspecified = SCM_UNSPECIFIED;
+void * scm_bool_t = SCM_BOOL_T;
int defs_scm_is_eq(SCM x, SCM y) {
return scm_is_eq(x, y);
@@ -10,4 +11,3 @@ int defs_scm_is_eq(SCM x, SCM y) {
void defs_scm_define_string(const char* name, const char* value) {
scm_c_define(name, scm_from_utf8_string(value));
}
-