Skip to content

Commit

Permalink
Provide separate output vs input encodings for textdumps
Browse files Browse the repository at this point in the history
  • Loading branch information
rdaum committed Dec 14, 2024
1 parent 9c4c878 commit 5d0e9a1
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 66 deletions.
25 changes: 17 additions & 8 deletions crates/daemon/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ pub struct Args {
feature_args: Option<FeatureArgs>,

#[arg(
short,
long,
value_name = "write-merged-config",
help = "If set, this is a path to write the current configuration (with merged values from command line arguments), in JSON format",
Expand All @@ -49,7 +48,6 @@ pub struct Args {
pub write_merged_config: Option<PathBuf>,

#[arg(
short,
long,
value_name = "config",
help = "Path to configuration (json) file to use, if any. If not specified, defaults are used.\
Expand Down Expand Up @@ -212,13 +210,21 @@ pub struct TextdumpArgs {
#[arg(
long,
value_name = "textdump-encoding",
help = "Encoding to use for reading and writing textdump files. utf8 or iso8859-1. \
LambdaMOO textdumps that contain 8-bit strings are written using iso8859-1, so for full compatibility, \
choose iso8859-1.
help = "Encoding to use for reading textdump files. utf8 or iso8859-1. \
LambdaMOO textdumps that contain 8-bit strings are written using iso8859-1, so if you're importing a LambdaMOO textdump, choose iso8859-1. \
If you know your textdump contains no such strings, or if your textdump is from moor choose utf8,
which is faster to read."
)]
pub textdump_encoding: Option<EncodingMode>,
pub textdump_input_encoding: Option<EncodingMode>,

#[arg(
long,
value_name = "textdump-output-encoding",
help = "Encoding to use for writing textdump files. utf8 or iso8859-1. \
LambdaMOO textdumps that contain 8-bit strings are written using iso8859-1, so if you want to write a LambdaMOO-compatible textdump, choose iso8859-1. \
(But make sure your features are set to match LambdaMOO's capabilities!)"
)]
pub textdump_output_encoding: Option<EncodingMode>,
}

impl TextdumpArgs {
Expand All @@ -229,8 +235,11 @@ impl TextdumpArgs {
if let Some(args) = self.textdump_out.as_ref() {
config.output_path = Some(args.clone());
}
if let Some(args) = self.textdump_encoding {
config.encoding = args;
if let Some(args) = self.textdump_input_encoding {
config.input_encoding = args;
}
if let Some(args) = self.textdump_output_encoding {
config.output_encoding = args;
}
if let Some(args) = self.checkpoint_interval_seconds {
config.checkpoint_interval = Some(std::time::Duration::from_secs(u64::from(args)));
Expand Down
11 changes: 7 additions & 4 deletions crates/daemon/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ fn main() -> Result<(), Report> {
textdump_load(
loader_interface.as_ref(),
textdump.clone(),
config.textdump_config.encoding,
config.textdump_config.input_encoding,
config.features_config.compile_options(),
)
.unwrap();
Expand Down Expand Up @@ -178,10 +178,13 @@ fn main() -> Result<(), Report> {
.spawn(move || scheduler.run(scheduler_rpc_server))?;

// Background DB checkpoint thread.
let checkpoint_kill_switch = kill_switch.clone();
let checkpoint_scheduler_client = scheduler_client.clone();

if let Some(checkpoint_interval) = config.textdump_config.checkpoint_interval {
if config.textdump_config.output_path.is_none() {
warn!("Checkpointing interval specified, but no output path specified. Checkpointing will be disabled.");
}

let checkpoint_kill_switch = kill_switch.clone();
let checkpoint_scheduler_client = scheduler_client.clone();
info!("Checkpointing enabled. Interval: {:?}", checkpoint_interval);
std::thread::Builder::new()
.name("moor-checkpoint".to_string())
Expand Down
54 changes: 9 additions & 45 deletions crates/kernel/src/builtins/bf_verbs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@ fn bf_verb_info(bf_args: &mut BfCallState<'_>) -> Result<BfRet, BfErr> {
return Err(BfErr::Code(E_TYPE));
};

if !bf_args
.world_state
.valid(obj)
.map_err(world_state_bf_err)?
{
if !bf_args.world_state.valid(obj).map_err(world_state_bf_err)? {
return Err(BfErr::Code(E_INVARG));
}

Expand Down Expand Up @@ -194,11 +190,7 @@ fn bf_set_verb_info(bf_args: &mut BfCallState<'_>) -> Result<BfRet, BfErr> {
}
let update_attrs = parse_verb_info(info).map_err(BfErr::Code)?;

if !bf_args
.world_state
.valid(obj)
.map_err(world_state_bf_err)?
{
if !bf_args.world_state.valid(obj).map_err(world_state_bf_err)? {
return Err(BfErr::Code(E_INVARG));
}

Expand Down Expand Up @@ -238,11 +230,7 @@ fn bf_verb_args(bf_args: &mut BfCallState<'_>) -> Result<BfRet, BfErr> {
let Variant::Obj(obj) = bf_args.args[0].variant() else {
return Err(BfErr::Code(E_TYPE));
};
if !bf_args
.world_state
.valid(obj)
.map_err(world_state_bf_err)?
{
if !bf_args.world_state.valid(obj).map_err(world_state_bf_err)? {
return Err(BfErr::Code(E_INVARG));
}

Expand Down Expand Up @@ -299,11 +287,7 @@ fn bf_set_verb_args(bf_args: &mut BfCallState<'_>) -> Result<BfRet, BfErr> {
if verbinfo.len() != 3 {
return Err(BfErr::Code(E_INVARG));
}
if !bf_args
.world_state
.valid(obj)
.map_err(world_state_bf_err)?
{
if !bf_args.world_state.valid(obj).map_err(world_state_bf_err)? {
return Err(BfErr::Code(E_INVARG));
}

Expand Down Expand Up @@ -354,11 +338,7 @@ fn bf_verb_code(bf_args: &mut BfCallState<'_>) -> Result<BfRet, BfErr> {
let Variant::Obj(obj) = bf_args.args[0].variant() else {
return Err(BfErr::Code(E_TYPE));
};
if !bf_args
.world_state
.valid(obj)
.map_err(world_state_bf_err)?
{
if !bf_args.world_state.valid(obj).map_err(world_state_bf_err)? {
return Err(BfErr::Code(E_INVARG));
}

Expand Down Expand Up @@ -433,11 +413,7 @@ fn bf_set_verb_code(bf_args: &mut BfCallState<'_>) -> Result<BfRet, BfErr> {
let Variant::Obj(obj) = bf_args.args[0].variant() else {
return Err(BfErr::Code(E_TYPE));
};
if !bf_args
.world_state
.valid(obj)
.map_err(world_state_bf_err)?
{
if !bf_args.world_state.valid(obj).map_err(world_state_bf_err)? {
return Err(BfErr::Code(E_INVARG));
}

Expand Down Expand Up @@ -520,11 +496,7 @@ fn bf_add_verb(bf_args: &mut BfCallState<'_>) -> Result<BfRet, BfErr> {
let Variant::List(args) = bf_args.args[2].variant() else {
return Err(BfErr::Code(E_TYPE));
};
if !bf_args
.world_state
.valid(obj)
.map_err(world_state_bf_err)?
{
if !bf_args.world_state.valid(obj).map_err(world_state_bf_err)? {
return Err(BfErr::Code(E_INVARG));
}

Expand Down Expand Up @@ -566,11 +538,7 @@ fn bf_delete_verb(bf_args: &mut BfCallState<'_>) -> Result<BfRet, BfErr> {
let Variant::Obj(obj) = bf_args.args[0].variant() else {
return Err(BfErr::Code(E_TYPE));
};
if !bf_args
.world_state
.valid(obj)
.map_err(world_state_bf_err)?
{
if !bf_args.world_state.valid(obj).map_err(world_state_bf_err)? {
return Err(BfErr::Code(E_INVARG));
}

Expand Down Expand Up @@ -610,11 +578,7 @@ fn bf_disassemble(bf_args: &mut BfCallState<'_>) -> Result<BfRet, BfErr> {
let Variant::Obj(obj) = bf_args.args[0].variant() else {
return Err(BfErr::Code(E_TYPE));
};
if !bf_args
.world_state
.valid(obj)
.map_err(world_state_bf_err)?
{
if !bf_args.world_state.valid(obj).map_err(world_state_bf_err)? {
return Err(BfErr::Code(E_INVARG));
}

Expand Down
11 changes: 9 additions & 2 deletions crates/kernel/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ impl FeaturesConfig {
flyweight_type: self.flyweight_type,
}
}

/// Returns true if the configuration is backwards compatible with LambdaMOO 1.8 features.
pub fn is_lambdammoo_compatible(&self) -> bool {
!self.lexical_scopes && !self.map_type && !self.type_dispatch && !self.flyweight_type
}
}

#[derive(Clone, Debug, Default, Serialize, Deserialize)]
Expand All @@ -75,8 +80,10 @@ pub struct TextdumpConfig {
pub input_path: Option<PathBuf>,
/// Where to write periodic textdumps of the database, if any.
pub output_path: Option<PathBuf>,
/// What encoding to use for textdumps (ISO-8859-1 or UTF-8).
pub encoding: EncodingMode,
/// What encoding to use for reading textdumps (ISO-8859-1 or UTF-8).
pub input_encoding: EncodingMode,
/// What encoding to use for writing textdumps (ISO-8859-1 or UTF-8).
pub output_encoding: EncodingMode,
/// Interval between database checkpoints.
/// If None, no checkpoints will be made.
pub checkpoint_interval: Option<Duration>,
Expand Down
2 changes: 1 addition & 1 deletion crates/kernel/src/tasks/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1198,7 +1198,7 @@ impl Scheduler {
return Err(SchedulerError::CouldNotStartTask);
};

let encoding_mode = self.config.textdump_config.encoding;
let encoding_mode = self.config.textdump_config.output_encoding;

let loader_client = {
match self.database.loader_client() {
Expand Down
7 changes: 1 addition & 6 deletions crates/kernel/src/textdump/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,7 @@ impl<R: Read> TextdumpReader<R> {
None
};

v_flyweight(
delegate,
&slots,
List::from_iter(contents),
seal,
)
v_flyweight(delegate, &slots, List::from_iter(contents), seal)
}
};
Ok(v)
Expand Down

0 comments on commit 5d0e9a1

Please sign in to comment.