Skip to content

Commit

Permalink
alloca!
Browse files Browse the repository at this point in the history
  • Loading branch information
saghul committed Nov 22, 2023
1 parent ef811a4 commit 918ab62
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion libregexp.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include "cutils.h"
#include "libregexp.h"
#include "xalloca.h"

/*
TODO:
Expand Down Expand Up @@ -2529,7 +2530,7 @@ int lre_exec(uint8_t **capture,
for(i = 0; i < s->capture_count * 2; i++)
capture[i] = NULL;
alloca_size = s->stack_size_max * sizeof(stack_buf[0]);
stack_buf = alloca(alloca_size);
stack_buf = xalloca(alloca_size);
ret = lre_exec_backtrack(s, capture, stack_buf, 0, bc_buf + RE_HEADER_LEN,
cbuf + (cindex << cbuf_type), FALSE);
lre_realloc(s->opaque, s->state_stack, 0);
Expand Down
9 changes: 5 additions & 4 deletions quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "quickjs.h"
#include "libregexp.h"
#include "libbf.h"
#include "xalloca.h"

#if defined(EMSCRIPTEN)
#define DIRECT_DISPATCH 0
Expand Down Expand Up @@ -4870,7 +4871,7 @@ static JSValue js_c_function_data_call(JSContext *ctx, JSValueConst func_obj,

/* XXX: could add the function on the stack for debug */
if (unlikely(argc < s->length)) {
arg_buf = alloca(sizeof(arg_buf[0]) * s->length);
arg_buf = xalloca(sizeof(arg_buf[0]) * s->length);
for(i = 0; i < argc; i++)
arg_buf[i] = argv[i];
for(i = argc; i < s->length; i++)
Expand Down Expand Up @@ -13993,7 +13994,7 @@ static JSValue js_call_c_function(JSContext *ctx, JSValueConst func_obj,

if (unlikely(argc < arg_count)) {
/* ensure that at least argc_count arguments are readable */
arg_buf = alloca(sizeof(arg_buf[0]) * arg_count);
arg_buf = xalloca(sizeof(arg_buf[0]) * arg_count);
for(i = 0; i < argc; i++)
arg_buf[i] = argv[i];
for(i = argc; i < arg_count; i++)
Expand Down Expand Up @@ -14104,7 +14105,7 @@ static JSValue js_call_bound_function(JSContext *ctx, JSValueConst func_obj,
arg_count = bf->argc + argc;
if (js_check_stack_overflow(ctx->rt, sizeof(JSValue) * arg_count))
return JS_ThrowStackOverflow(ctx);
arg_buf = alloca(sizeof(JSValue) * arg_count);
arg_buf = xalloca(sizeof(JSValue) * arg_count);
for(i = 0; i < bf->argc; i++) {
arg_buf[i] = bf->argv[i];
}
Expand Down Expand Up @@ -14231,7 +14232,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj,
init_list_head(&sf->var_ref_list);
var_refs = p->u.func.var_refs;

local_buf = alloca(alloca_size);
local_buf = xalloca(alloca_size);
if (unlikely(arg_allocated_size)) {
int n = min_int(argc, b->arg_count);
arg_buf = local_buf;
Expand Down

0 comments on commit 918ab62

Please sign in to comment.