Skip to content

Commit 918ab62

Browse files
committed
alloca!
1 parent ef811a4 commit 918ab62

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

libregexp.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include "cutils.h"
3232
#include "libregexp.h"
33+
#include "xalloca.h"
3334

3435
/*
3536
TODO:
@@ -2529,7 +2530,7 @@ int lre_exec(uint8_t **capture,
25292530
for(i = 0; i < s->capture_count * 2; i++)
25302531
capture[i] = NULL;
25312532
alloca_size = s->stack_size_max * sizeof(stack_buf[0]);
2532-
stack_buf = alloca(alloca_size);
2533+
stack_buf = xalloca(alloca_size);
25332534
ret = lre_exec_backtrack(s, capture, stack_buf, 0, bc_buf + RE_HEADER_LEN,
25342535
cbuf + (cindex << cbuf_type), FALSE);
25352536
lre_realloc(s->opaque, s->state_stack, 0);

quickjs.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include "quickjs.h"
4848
#include "libregexp.h"
4949
#include "libbf.h"
50+
#include "xalloca.h"
5051

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

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

1399413995
if (unlikely(argc < arg_count)) {
1399513996
/* ensure that at least argc_count arguments are readable */
13996-
arg_buf = alloca(sizeof(arg_buf[0]) * arg_count);
13997+
arg_buf = xalloca(sizeof(arg_buf[0]) * arg_count);
1399713998
for(i = 0; i < argc; i++)
1399813999
arg_buf[i] = argv[i];
1399914000
for(i = argc; i < arg_count; i++)
@@ -14104,7 +14105,7 @@ static JSValue js_call_bound_function(JSContext *ctx, JSValueConst func_obj,
1410414105
arg_count = bf->argc + argc;
1410514106
if (js_check_stack_overflow(ctx->rt, sizeof(JSValue) * arg_count))
1410614107
return JS_ThrowStackOverflow(ctx);
14107-
arg_buf = alloca(sizeof(JSValue) * arg_count);
14108+
arg_buf = xalloca(sizeof(JSValue) * arg_count);
1410814109
for(i = 0; i < bf->argc; i++) {
1410914110
arg_buf[i] = bf->argv[i];
1411014111
}
@@ -14231,7 +14232,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj,
1423114232
init_list_head(&sf->var_ref_list);
1423214233
var_refs = p->u.func.var_refs;
1423314234

14234-
local_buf = alloca(alloca_size);
14235+
local_buf = xalloca(alloca_size);
1423514236
if (unlikely(arg_allocated_size)) {
1423614237
int n = min_int(argc, b->arg_count);
1423714238
arg_buf = local_buf;

0 commit comments

Comments
 (0)