|
@ -39,12 +39,10 @@ static duk_ret_t test_1(duk_context *ctx, void *udata) { |
|
|
/* demonstrate how using one large duk_check_stack_top() before such
|
|
|
/* demonstrate how using one large duk_check_stack_top() before such
|
|
|
* a loop works. |
|
|
* a loop works. |
|
|
*/ |
|
|
*/ |
|
|
static duk_ret_t check_1(duk_context *ctx, void *udata) { |
|
|
static duk_ret_t check_1_inner(duk_context *ctx) { |
|
|
int i; |
|
|
int i; |
|
|
duk_ret_t rc; |
|
|
duk_ret_t rc; |
|
|
|
|
|
|
|
|
(void) udata; |
|
|
|
|
|
|
|
|
|
|
|
rc = duk_check_stack_top(ctx, 1000); |
|
|
rc = duk_check_stack_top(ctx, 1000); |
|
|
printf("rc=%d\n", (int) rc); |
|
|
printf("rc=%d\n", (int) rc); |
|
|
|
|
|
|
|
@ -55,6 +53,22 @@ static duk_ret_t check_1(duk_context *ctx, void *udata) { |
|
|
printf("final top: %ld\n", (long) duk_get_top(ctx)); |
|
|
printf("final top: %ld\n", (long) duk_get_top(ctx)); |
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
|
|
|
static duk_ret_t check_1(duk_context *ctx, void *udata) { |
|
|
|
|
|
int i; |
|
|
|
|
|
|
|
|
|
|
|
(void) udata; |
|
|
|
|
|
|
|
|
|
|
|
/* dummy filler */ |
|
|
|
|
|
for (i = 0; i < 10000; i++) { |
|
|
|
|
|
duk_require_stack(ctx, 1); |
|
|
|
|
|
duk_push_uint(ctx, 123); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
duk_push_c_function(ctx, check_1_inner, 0); |
|
|
|
|
|
duk_call(ctx, 0); |
|
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/* same test but with one element checks, once per loop */ |
|
|
/* same test but with one element checks, once per loop */ |
|
|
static duk_ret_t check_2(duk_context *ctx, void *udata) { |
|
|
static duk_ret_t check_2(duk_context *ctx, void *udata) { |
|
@ -89,11 +103,9 @@ static duk_ret_t check_3(duk_context *ctx, void *udata) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/* same as check_1 but with duk_require_stack_top() */ |
|
|
/* same as check_1 but with duk_require_stack_top() */ |
|
|
static duk_ret_t require_1(duk_context *ctx, void *udata) { |
|
|
static duk_ret_t require_1_inner(duk_context *ctx) { |
|
|
int i; |
|
|
int i; |
|
|
|
|
|
|
|
|
(void) udata; |
|
|
|
|
|
|
|
|
|
|
|
duk_require_stack_top(ctx, 1000); |
|
|
duk_require_stack_top(ctx, 1000); |
|
|
|
|
|
|
|
|
for (i = 0; i < 1000; i++) { |
|
|
for (i = 0; i < 1000; i++) { |
|
@ -103,6 +115,23 @@ static duk_ret_t require_1(duk_context *ctx, void *udata) { |
|
|
printf("final top: %ld\n", (long) duk_get_top(ctx)); |
|
|
printf("final top: %ld\n", (long) duk_get_top(ctx)); |
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
|
|
|
static duk_ret_t require_1(duk_context *ctx, void *udata) { |
|
|
|
|
|
int i; |
|
|
|
|
|
duk_ret_t rc; |
|
|
|
|
|
|
|
|
|
|
|
(void) udata; |
|
|
|
|
|
|
|
|
|
|
|
/* dummy filler */ |
|
|
|
|
|
for (i = 0; i < 10000; i++) { |
|
|
|
|
|
duk_require_stack(ctx, 1); |
|
|
|
|
|
duk_push_uint(ctx, 123); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
duk_push_c_function(ctx, require_1_inner, 0); |
|
|
|
|
|
duk_call(ctx, 0); |
|
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/* same as check_2 but with duk_require_stack_top() */ |
|
|
/* same as check_2 but with duk_require_stack_top() */ |
|
|
static duk_ret_t require_2(duk_context *ctx, void *udata) { |
|
|
static duk_ret_t require_2(duk_context *ctx, void *udata) { |
|
|