Skip to content

Commit ae51434

Browse files
committed
Fix #1604 - Add JANET_DO_ERROR_* defines for failure flags from janet_dobytes.
1 parent bb6ac42 commit ae51434

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

src/core/ev.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2175,7 +2175,7 @@ void janet_ev_post_event(JanetVM *vm, JanetCallback cb, JanetEVGenericMessage ms
21752175
event.cb = cb;
21762176
int fd = vm->selfpipe[1];
21772177
/* handle a bit of back pressure before giving up. */
2178-
int tries = 4;
2178+
int tries = 20;
21792179
while (tries > 0) {
21802180
int status;
21812181
do {

src/core/run.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
#include "state.h"
2727
#endif
2828

29-
/* Run a string */
29+
/* Run a string of code. The return value is a set of error flags, JANET_DO_ERROR_RUNTIME, JANET_DO_ERROR_COMPILE, and JANET_DOR_ERROR_PARSE if
30+
* any errors were encountered in those phases. More information is printed to stderr. */
3031
int janet_dobytes(JanetTable *env, const uint8_t *bytes, int32_t len, const char *sourcePath, Janet *out) {
3132
JanetParser *parser;
3233
int errflags = 0, done = 0;
@@ -55,7 +56,7 @@ int janet_dobytes(JanetTable *env, const uint8_t *bytes, int32_t len, const char
5556
JanetSignal status = janet_continue(fiber, janet_wrap_nil(), &ret);
5657
if (status != JANET_SIGNAL_OK && status != JANET_SIGNAL_EVENT) {
5758
janet_stacktrace_ext(fiber, ret, "");
58-
errflags |= 0x01;
59+
errflags |= JANET_DO_ERROR_RUNTIME;
5960
done = 1;
6061
}
6162
} else {
@@ -75,7 +76,7 @@ int janet_dobytes(JanetTable *env, const uint8_t *bytes, int32_t len, const char
7576
janet_eprintf("%s:%d:%d: compile error: %s\n", sourcePath,
7677
line, col, (const char *)cres.error);
7778
}
78-
errflags |= 0x02;
79+
errflags |= JANET_DO_ERROR_COMPILE;
7980
done = 1;
8081
}
8182
}
@@ -89,7 +90,7 @@ int janet_dobytes(JanetTable *env, const uint8_t *bytes, int32_t len, const char
8990
break;
9091
case JANET_PARSE_ERROR: {
9192
const char *e = janet_parser_error(parser);
92-
errflags |= 0x04;
93+
errflags |= JANET_DO_ERROR_PARSE;
9394
ret = janet_cstringv(e);
9495
int32_t line = (int32_t) parser->line;
9596
int32_t col = (int32_t) parser->column;

src/include/janet.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,6 +1616,9 @@ JANET_API JanetTable *janet_core_env(JanetTable *replacements);
16161616
JANET_API JanetTable *janet_core_lookup_table(JanetTable *replacements);
16171617

16181618
/* Execute strings */
1619+
#define JANET_DO_ERROR_RUNTIME 0x01
1620+
#define JANET_DO_ERROR_COMPILE 0x02
1621+
#define JANET_DO_ERROR_PARSE 0x04
16191622
JANET_API int janet_dobytes(JanetTable *env, const uint8_t *bytes, int32_t len, const char *sourcePath, Janet *out);
16201623
JANET_API int janet_dostring(JanetTable *env, const char *str, const char *sourcePath, Janet *out);
16211624

0 commit comments

Comments
 (0)