From 6f35bd47ab3f1904b39bfb0c5477b9391458328d Mon Sep 17 00:00:00 2001 From: Justine Tunney Date: Thu, 11 Feb 2021 23:18:39 -0800 Subject: [PATCH] Fix JavaScript interpreter example --- examples/hellojs.c | 4 +++- third_party/duktape/duk_js_compiler.c | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/examples/hellojs.c b/examples/hellojs.c index db098b3a..fa8c5b67 100644 --- a/examples/hellojs.c +++ b/examples/hellojs.c @@ -10,6 +10,7 @@ #include "libc/calls/calls.h" #include "libc/calls/struct/stat.h" #include "libc/log/check.h" +#include "libc/log/log.h" #include "libc/mem/mem.h" #include "libc/runtime/gc.h" #include "libc/sysv/consts/o.h" @@ -39,6 +40,7 @@ int main(int argc, char *argv[]) { struct stat st; const char *code; duk_context *ctx; + showcrashreports(); ctx = duk_create_heap_default(); duk_push_c_function(ctx, NativePrint, DUK_VARARGS); duk_put_global_string(ctx, "NativePrint"); @@ -47,7 +49,7 @@ int main(int argc, char *argv[]) { CHECK_NE(-1, (fd = open("zip:examples/hello.js", O_RDONLY))); CHECK_NE(-1, fstat(fd, &st)); - CHECK_NOTNULL((code = gc(malloc(st.st_size)))); + CHECK_NOTNULL((code = gc(calloc(1, st.st_size + 1)))); CHECK_EQ(st.st_size, read(fd, code, st.st_size)); CHECK_NE(-1, close(fd)); diff --git a/third_party/duktape/duk_js_compiler.c b/third_party/duktape/duk_js_compiler.c index 3b5d2738..bbe7d9e3 100644 --- a/third_party/duktape/duk_js_compiler.c +++ b/third_party/duktape/duk_js_compiler.c @@ -1278,8 +1278,9 @@ DUK_LOCAL void duk__convert_to_func_template(duk_compiler_ctx *comp_ctx) { (1u << 12) /* slot B is a target (default: source) */ #define DUK__EMIT_FLAG_C_IS_TARGET \ (1u << 13) /* slot C is a target (default: source) */ -#define DUK__EMIT_FLAG_BC_REGCONST (1u << 14) /* slots B and C are reg/const \ - */ +#define DUK__EMIT_FLAG_BC_REGCONST \ + (1u << 14) /* slots B and C are reg/const \ + */ #define DUK__EMIT_FLAG_RESERVE_JUMPSLOT \ (1u << 15) /* reserve a jumpslot after instr before target spilling, used \ for NEXTENUM */