Skip to content

Commit f69893e

Browse files
authored
Merge pull request #201 from chrisws/12_27
12 27
2 parents 14fc195 + c53736b commit f69893e

File tree

5 files changed

+49
-8
lines changed

5 files changed

+49
-8
lines changed

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2023-08-27 (12.27)
2+
COMMON: Fix parameter number error when calling a unit sub/func
3+
COMMON: Show a runtime error if a module calls exit()
4+
15
2023-06-18 (12.27)
26
COMMON: Fix redim regression
37
PLUGINS: Added mechanism for cleaning up resources when the associated map falls out of scope

src/common/sberr.c

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,31 @@
1414
#include <string.h>
1515
#include <errno.h>
1616

17-
void err_title_msg(const char *seg, const char *file, int line) {
17+
void err_title_msg(int compileError, int parameterError) {
18+
const char *seg;
19+
const char *file;
20+
int line;
21+
22+
if (compileError) {
23+
file = comp_bc_sec;
24+
line = comp_line;
25+
seg = WORD_COMP;
26+
} else {
27+
file = prog_file;
28+
line = prog_line;
29+
seg = WORD_RTE;
30+
if (ctask->parent > 0 && parameterError) {
31+
task_t *parent = taskinfo(ctask->parent);
32+
line = parent->line;
33+
file = parent->file;
34+
}
35+
}
36+
37+
const char *slash = strrchr(file, '/');
38+
if (slash) {
39+
file = slash + 1;
40+
}
41+
1842
gsb_last_line = line;
1943
gsb_last_error = prog_error;
2044
strlcpy(gsb_last_file, file, sizeof(gsb_last_file));
@@ -80,7 +104,7 @@ void sc_raise(const char *format, ...) {
80104
va_end(args);
81105

82106
if (comp_bc_sec) {
83-
err_title_msg(WORD_COMP, comp_bc_sec, comp_line);
107+
err_title_msg(1, 0);
84108
}
85109
if (size) {
86110
va_start(args, format);
@@ -102,7 +126,7 @@ void rt_raise(const char *format, ...) {
102126
unsigned size = vsnprintf(NULL, 0, format, args);
103127
va_end(args);
104128

105-
err_title_msg(WORD_RTE, prog_file, prog_line);
129+
err_title_msg(0, strcmp(format, ERR_PARAM_NUM) == 0);
106130
if (size) {
107131
va_start(args, format);
108132
va_err_detail_msg(format, args, size);
@@ -161,7 +185,7 @@ void err_syntax(int keyword, const char *fmt) {
161185
fmt_p++;
162186
}
163187

164-
err_title_msg(WORD_RTE, prog_file, prog_line);
188+
err_title_msg(0, 0);
165189
err_detail_msg(ERR_SYNTAX);
166190
err_stack_msg();
167191
log_printf("Expected:");
@@ -355,6 +379,10 @@ void err_network() {
355379
rt_raise(ERR_NETWORK);
356380
}
357381

382+
void err_abnormal_exit() {
383+
rt_raise(ERR_ABNORMAL_EXIT);
384+
}
385+
358386
/**
359387
* the DONE message
360388
*/
@@ -458,7 +486,7 @@ void err_throw_str(const char *err) {
458486
}
459487

460488
if (!caught) {
461-
err_title_msg(WORD_RTE, prog_file, prog_line);
489+
err_title_msg(0, 0);
462490
err_detail_msg(err);
463491
err_stack_msg();
464492
trace_done = 1;
@@ -477,7 +505,7 @@ void err_throw_str(const char *err) {
477505
if (!caught) {
478506
prog_error = errRuntime;
479507
if (!trace_done) {
480-
err_title_msg(WORD_RTE, prog_file, prog_line);
508+
err_title_msg(0, 0);
481509
err_detail_msg(err);
482510
err_stack_msg();
483511
}

src/common/sberr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ void err_array();
7979
void err_form_input();
8080
void err_memory();
8181
void err_network();
82+
void err_abnormal_exit();
8283
void err_throw(const char *fmt, ...);
8384
int err_handle_error(const char *err, var_p_t var);
8485
void inf_done(void);

src/languages/messages.en.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,4 @@
231231
#define ERR_DIRWALK_MISSING_USE "DIRWALK: missing USE statement"
232232
#define ERR_DIRWALK_CANT_OPEN "DIRWALK: can't open %s"
233233
#define ERR_LINE_LENGTH "Line length limit exceeded at text: '%s'"
234+
#define ERR_ABNORMAL_EXIT "Abnormal exit"

src/platform/console/main.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ uint32_t get_modified_time(const char *file) {
375375
bool wait_for_file(const char *file, uint32_t modifiedTime) {
376376
bool result = false;
377377
fcntl(0, F_SETFL, fcntl(0, F_GETFL) | O_NONBLOCK);
378-
fprintf(stdout, "Fix the error [in %s] to continue, or press enter to exit...\n", file);
378+
fprintf(stdout, "Fix the error in [%s] to continue, or press enter to exit...\n", file);
379379
while (!result && modifiedTime == get_modified_time(file)) {
380380
char c = 0;
381381
read(0, &c, 1);
@@ -390,14 +390,20 @@ bool wait_for_file(const char *file, uint32_t modifiedTime) {
390390
#else
391391
bool wait_for_file(const char *file, uint32_t modifiedTime) {
392392
bool result = false;
393-
fprintf(stdout, "Fix the error [in %s] to continue...\n", file);
393+
fprintf(stdout, "Fix the error in [%s] to continue...\n", file);
394394
while (!result && modifiedTime == get_modified_time(file)) {
395395
usleep(500 * 1000);
396396
}
397397
return result;
398398
}
399399
#endif
400400

401+
static void exit_handler(void) {
402+
if (count_tasks()) {
403+
err_abnormal_exit();
404+
}
405+
}
406+
401407
//
402408
// program entry point
403409
//
@@ -416,6 +422,7 @@ int main(int argc, char *argv[]) {
416422
os_graphics = 1;
417423

418424
console_init();
425+
atexit(exit_handler);
419426

420427
char *file = nullptr;
421428
bool tmpFile = false;

0 commit comments

Comments
 (0)