Skip to content

Commit

Permalink
!30 Return -1 when there are errors in evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
da-liii committed Aug 9, 2024
1 parent 9913734 commit 53d4208
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
15 changes: 14 additions & 1 deletion src/goldfish.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ main (int argc, char** argv) {
sc= s7_init ();
s7_load (sc, gf_boot);
s7_add_to_load_path (sc, gf_lib);
const char* errmsg= NULL;
s7_pointer old_port=
s7_set_current_error_port (sc, s7_open_output_string (sc));
int gc_loc= -1;
if (old_port != s7_nil (sc)) gc_loc= s7_gc_protect (sc, old_port);

// Init tbox
if (!tb_init (tb_null, tb_null)) exit (-1);
Expand Down Expand Up @@ -156,5 +161,13 @@ main (int argc, char** argv) {
else {
display_for_invalid_options ();
}
return 0;

errmsg= s7_get_output_string (sc, s7_current_error_port (sc));
if ((errmsg) && (*errmsg)) cout << errmsg;
s7_close_output_port (sc, s7_current_error_port (sc));
s7_set_current_error_port (sc, old_port);
if (gc_loc != -1) s7_gc_unprotect_at (sc, gc_loc);

if ((errmsg) && (*errmsg)) return -1;
else return 0;
}
4 changes: 2 additions & 2 deletions tests/scheme/boot-test.scm
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
(check (file-exists? "/tmp") => #t)
(check (file-exists? "/not_exists") => #f))

(when (and (os-linux?) (not (string=? "root" (getenv "USER"))))
(when (and (os-linux?) (not (string=? "/root" (getenv "HOME"))))
(check-catch 'permission-error (lambda () (file-exists? "/root"))))

(when (os-windows?)
(check (file-exists? "C:") => #t))

(when (and (os-linux?) (not (string=? "root" (getenv "USER"))))
(when (and (os-linux?) (not (string=? "/root" (getenv "HOME"))))
(check-catch 'permission-error (lambda () (delete-file "/root"))))

(when (not (os-windows?))
Expand Down

0 comments on commit 53d4208

Please sign in to comment.