Skip to content

Commit

Permalink
Fix memory exhaustion in make-vector elprop
Browse files Browse the repository at this point in the history
Fixes #102
  • Loading branch information
CeleritasCelery committed Jan 14, 2025
1 parent bc24753 commit 4db07a5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions elprop/src/bin/code/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub(crate) enum Type {
HashTable,
Record,
ByteFn,
Byte,
Subr,
Buffer,
Nil,
Expand Down Expand Up @@ -57,6 +58,7 @@ impl Type {
}
Type::HashTable => todo!("Strategy for HashTable not implemented"),
Type::ByteFn => any::<u8>().prop_map(ArbitraryType::ByteFn).boxed(),
Type::Byte => any::<u8>().prop_map(ArbitraryType::Byte).boxed(),
Type::Subr => todo!("Strategy for Subr not implemented"),
Type::Buffer => any::<String>().prop_map(ArbitraryType::Buffer).boxed(),
Type::Nil => Just(ArbitraryType::Nil).boxed(),
Expand Down Expand Up @@ -160,6 +162,7 @@ pub(crate) enum ArbitraryType {
Nil,
Function(u8),
ByteFn(u8),
Byte(u8),
Char(char),
Buffer(String),
Subr(u8),
Expand Down Expand Up @@ -267,6 +270,7 @@ impl std::fmt::Display for ArbitraryType {
}
write!(f, ") nil)")
}
ArbitraryType::Byte(n) => write!(f, "{n}"),
ArbitraryType::Buffer(name) => {
write!(f, "(generate-new-buffer {name})")
}
Expand Down Expand Up @@ -369,6 +373,7 @@ impl Function {
"Number" | "NumberValue" => Type::Multiple(vec![Type::Integer, Type::Float]),
"Object" => Type::Unknown,
"usize" | "u64" => Type::PosInteger,
"u8" => Type::Byte,
"isize" | "i64" => Type::Integer,
"str" | "String" | "LispString" => Type::String,
"bool" | "OptionalFlag" => Type::Boolean,
Expand Down
1 change: 1 addition & 0 deletions elprop/src/elprop.el
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
(kill-buffer "*elprop-output*"))

(let* ((buffer "*elprop-output*")
(process-connection-type nil)
(process (start-process "elprop-process" buffer (getenv "ELPROP_RUNNER")))
(runner-count 0)
(pointer 1))
Expand Down
3 changes: 2 additions & 1 deletion src/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::core::object::{
ByteFn, ByteString, FnArgs, Gc, IntoObject, LispVec, Object, RecordBuilder, Symbol, NIL,
};
use anyhow::{ensure, Result};
use rune_macros::defun;
use rune_macros::{defun, elprop};

#[defun]
pub(crate) fn list<'ob>(objects: &[Object<'ob>], cx: &'ob Context) -> Object<'ob> {
Expand Down Expand Up @@ -63,6 +63,7 @@ pub(crate) fn make_byte_code<'ob>(
}

#[defun]
#[elprop(u8, _)]
fn make_vector(length: usize, init: Object) -> Vec<Object> {
vec![init; length]
}
Expand Down

0 comments on commit 4db07a5

Please sign in to comment.