From dfd83fa5813fa3de41ca76616f8a970c7ec2b8f4 Mon Sep 17 00:00:00 2001 From: Dummi26 Date: Fri, 14 Apr 2023 17:10:54 +0200 Subject: [PATCH] fixed warnings in mers, but one warning in parse.rs will stay --- mers/src/libs/mod.rs | 16 +++++++++++++++- mers/src/main.rs | 8 +++----- mers/src/script/block.rs | 2 +- mers/src/script/mod.rs | 1 - 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/mers/src/libs/mod.rs b/mers/src/libs/mod.rs index 2070b1e..f9e03f0 100755 --- a/mers/src/libs/mod.rs +++ b/mers/src/libs/mod.rs @@ -2,7 +2,7 @@ pub mod inlib; pub mod path; use std::{ - collections::{HashMap, HashSet}, + collections::HashMap, io::{self, BufRead, BufReader, Read, Write}, path::PathBuf, process::{Child, ChildStdin, ChildStdout, Command, Stdio}, @@ -55,11 +55,24 @@ sending data: (all ints are encoded so that the most significant data is sent FI #[derive(Debug)] pub struct Lib { + name: String, process: Child, stdin: Arc>, stdout: Arc>>, pub registered_fns: Vec<(String, Vec, VType)>, } +impl Drop for Lib { + fn drop(&mut self) { + if self.process.try_wait().is_err() { + if let Err(e) = self.process.kill() { + eprint!( + "Warn: tried to kill lib process for library \"{}\", but failed: {e:?}", + self.name + ); + } + } + } +} impl Lib { pub fn launch( mut exec: Command, @@ -131,6 +144,7 @@ impl Lib { } writeln!(stdin, "init_finished").unwrap(); Ok(Self { + name: name.to_string(), process: handle, stdin: Arc::new(Mutex::new(stdin)), stdout: Arc::new(Mutex::new(stdout)), diff --git a/mers/src/main.rs b/mers/src/main.rs index d3a0cca..d2b2ba8 100755 --- a/mers/src/main.rs +++ b/mers/src/main.rs @@ -1,8 +1,4 @@ -use std::{ - fs, - sync::{Arc, Mutex}, - time::Instant, -}; +use std::{fs, sync::Arc, time::Instant}; use notify::Watcher as FsWatcher; @@ -10,6 +6,8 @@ pub mod libs; pub mod parse; pub mod script; +// necessary because the lib target in Cargo.toml also points here. TODO: update Cargo.toml to have a lib target that is separate from the bin one (=> doesn't point to main) +#[allow(unused)] fn main() { let args: Vec<_> = std::env::args().skip(1).collect(); let path = std::env::args().nth(1).unwrap(); diff --git a/mers/src/script/block.rs b/mers/src/script/block.rs index a774f0b..bbd9a96 100755 --- a/mers/src/script/block.rs +++ b/mers/src/script/block.rs @@ -8,7 +8,7 @@ use std::{ use crate::libs; -use self::to_runnable::{GInfo, ToRunnableError}; +use self::to_runnable::ToRunnableError; use super::{ builtins::BuiltinFunction, diff --git a/mers/src/script/mod.rs b/mers/src/script/mod.rs index 40451b6..3ca51de 100755 --- a/mers/src/script/mod.rs +++ b/mers/src/script/mod.rs @@ -2,4 +2,3 @@ pub mod block; pub mod builtins; pub mod val_data; pub mod val_type; -pub mod value;