Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A few small bugfixes #490

Merged
merged 8 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
16 changes: 11 additions & 5 deletions src/libfsm/gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <stddef.h>
#include <stdbool.h>
#include <string.h>
#include <errno.h>

#include <fsm/fsm.h>
#include <fsm/pred.h>
Expand Down Expand Up @@ -139,6 +140,11 @@ int
fsm_generate_matches(struct fsm *fsm, size_t max_length,
fsm_generate_matches_cb *cb, void *opaque)
{
if (max_length == 0) {
errno = EINVAL;
return 0;
}

INIT_TIMERS();
TIME(&pre);
int res = gen_init_outer(fsm, max_length, cb, opaque, false, 0);
Expand Down Expand Up @@ -193,7 +199,7 @@ gen_init_outer(struct fsm *fsm, size_t max_length,
fsm_generate_matches_cb *cb, void *opaque,
bool randomized, unsigned seed)
{
int res = 0;
int res = false;
if (fsm == NULL || cb == NULL || max_length == 0) {
return false;
}
Expand Down Expand Up @@ -222,11 +228,11 @@ gen_init_outer(struct fsm *fsm, size_t max_length,
goto cleanup;
}

res = 1;
res = true;

while (!ctx.done) {
if (!gen_iter(&ctx)) {
res = 0;
res = false;
break;
}
}
Expand Down Expand Up @@ -562,8 +568,8 @@ sfs_step_edges(struct gen_ctx *ctx, struct gen_stack_frame *sf)
sf->u.step_edges.initialized = true;
}

if (ctx->buf_used + ctx->sed[sf->s_id] >= ctx->max_length) {
LOG(2, "PRUNING due to max length: used:%zu + sed[%d]:%u >= max_length:%zu\n",
if (ctx->buf_used + ctx->sed[sf->s_id] > ctx->max_length) {
LOG(2, "PRUNING due to max length: used:%zu + sed[%d]:%u > max_length:%zu\n",
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@silentbicycle requesting your review for this please, I was unsure about this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think > is correct here -- this means "if the buffer used so far plus what we'd need for the shortest distance to an end state exceeds the available buffer". re -G 5 '^abcde' should produce "abcde" as a valid 5-character match (which is rejected with >=), not counting the trailing \0, but reject re -G 5 '^abcdef'.

ctx->buf_used, sf->s_id, ctx->sed[sf->s_id], ctx->max_length);
sf->t = GEN_SFS_LEAVING_STATE;
return true;
Expand Down
6 changes: 5 additions & 1 deletion src/libfsm/print/rust.c
Original file line number Diff line number Diff line change
Expand Up @@ -520,14 +520,18 @@ fsm_print_rust(FILE *f,

switch (opt->ambig) {
case AMBIG_NONE:
fprintf(f, "Option<()>");
break;

case AMBIG_ERROR:
case AMBIG_EARLIEST:
fprintf(f, "Option<()>");
fprintf(f, "Option<u32>");
break;

case AMBIG_MULTIPLE:
fprintf(f, "Option<&'static [u32]>");
break;

default:
fprintf(stderr, "unsupported ambig mode\n");
exit(EXIT_FAILURE);
Expand Down
6 changes: 5 additions & 1 deletion src/re/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,11 @@ main(int argc, char *argv[])
}

if (generate_bounds > 0) {
return fsm_generate_matches(fsm, generate_bounds, fsm_generate_cb_printf_escaped, &opt);
if (!fsm_generate_matches(fsm, generate_bounds, fsm_generate_cb_printf_escaped, &opt)) {
exit(EXIT_FAILURE);
}

return 0;
}

if (fsm_lang != FSM_PRINT_NONE) {
Expand Down
16 changes: 8 additions & 8 deletions src/retest/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1270,16 +1270,10 @@ main(int argc, char *argv[])
break;

case 'l':
if (strcmp(optarg, "vm") == 0) {
impl = IMPL_INTERPRET;
if (strcmp(optarg, "asm") == 0) {
impl = IMPL_VMASM;
} else if (strcmp(optarg, "c") == 0) {
impl = IMPL_C;
} else if (strcmp(optarg, "asm") == 0) {
impl = IMPL_VMASM;
} else if (strcmp(optarg, "vmc") == 0) {
impl = IMPL_VMC;
} else if (strcmp(optarg, "vmops") == 0) {
impl = IMPL_VMOPS;
} else if (strcmp(optarg, "go") == 0) {
impl = IMPL_GO;
} else if (strcmp(optarg, "goasm") == 0) {
Expand All @@ -1288,6 +1282,12 @@ main(int argc, char *argv[])
impl = IMPL_LLVM;
} else if (strcmp(optarg, "rust") == 0) {
impl = IMPL_RUST;
} else if (strcmp(optarg, "vm") == 0) {
impl = IMPL_INTERPRET;
} else if (strcmp(optarg, "vmc") == 0) {
impl = IMPL_VMC;
} else if (strcmp(optarg, "vmops") == 0) {
impl = IMPL_VMOPS;
} else {
fprintf(stderr, "unknown argument to -l: %s\n", optarg);
usage();
Expand Down
14 changes: 10 additions & 4 deletions src/retest/reperf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1154,18 +1154,24 @@ main(int argc, char *argv[])
break;

case 'l':
if (strcmp(optarg, "vm") == 0) {
impl = IMPL_INTERPRET;
if (strcmp(optarg, "asm") == 0) {
impl = IMPL_VMASM;
} else if (strcmp(optarg, "c") == 0) {
impl = IMPL_C;
} else if (strcmp(optarg, "go") == 0) {
impl = IMPL_GO;
} else if (strcmp(optarg, "goasm") == 0) {
impl = IMPL_GOASM;
} else if (strcmp(optarg, "llvm") == 0) {
impl = IMPL_LLVM;
} else if (strcmp(optarg, "rust") == 0) {
impl = IMPL_RUST;
} else if (strcmp(optarg, "asm") == 0) {
impl = IMPL_VMASM;
} else if (strcmp(optarg, "vm") == 0) {
impl = IMPL_INTERPRET;
} else if (strcmp(optarg, "vmc") == 0) {
impl = IMPL_VMC;
} else if (strcmp(optarg, "vmops") == 0) {
impl = IMPL_VMOPS;
} else {
fprintf(stderr, "unknown argument to -l: %s\n", optarg);
usage();
Expand Down
2 changes: 1 addition & 1 deletion src/retest/runner.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ compile(enum implementation impl,
break;

case IMPL_RUST:
if (0 != systemf("%s %s --crate-type dylib %s -o %s",
if (0 != systemf("%s %s -C opt-level=3 --crate-type dylib %s -o %s",
"rustc", "--edition 2021",
tmp_src, tmp_so))
{
Expand Down
8 changes: 4 additions & 4 deletions src/retest/runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ enum error_type {

enum implementation {
IMPL_C,
IMPL_RUST,
IMPL_LLVM,
IMPL_GO,
IMPL_GOASM,
IMPL_VMC,
IMPL_VMASM,
IMPL_INTERPRET,
IMPL_LLVM,
IMPL_RUST,
IMPL_VMASM,
IMPL_VMC,
IMPL_VMOPS,
};

Expand Down
Loading