Skip to content

Commit a21fbdc

Browse files
authored
Crash when timeout finishes (#999)
1 parent 2bc6188 commit a21fbdc

3 files changed

Lines changed: 9 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ All notable changes to this project will be documented in this file. This change
3131
- `tty?` spec refers to `planck.core/IWriter` ([#928](https://github.com/planck-repl/planck/issues/928))
3232
- HTTP binary response includes trailing buffer ([#949](https://github.com/planck-repl/planck/issues/949))
3333
- IO encoding should default to UTF-8 if unspecified ([#960](https://github.com/planck-repl/planck/issues/960))
34+
- Crash when timeout finishes ([#998](https://github.com/planck-repl/planck/issues/998))
3435

3536
## [2.23.0] - 2019-05-19
3637
### Added

planck-c/engine.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ void evaluate_source(char *type, char *source, bool expression, bool print_nil,
197197
}
198198
}
199199

200+
acquire_eval_lock();
200201
JSValueRef args[6];
201202
size_t num_args = 6;
202203

@@ -226,7 +227,6 @@ void evaluate_source(char *type, char *source, bool expression, bool print_nil,
226227
}
227228
JSObjectRef global_obj = JSContextGetGlobalObject(ctx);
228229

229-
acquire_eval_lock();
230230
JSObjectCallAsFunction(ctx, execute_fn, global_obj, num_args, args, NULL);
231231
release_eval_lock();
232232
}
@@ -330,9 +330,9 @@ void run_main_cli_fn() {
330330
return;
331331
}
332332

333+
acquire_eval_lock();
333334
JSObjectRef global_obj = JSContextGetGlobalObject(ctx);
334335
JSObjectRef run_main_cli_fn = get_function("planck.repl", "run-main-cli-fn");
335-
acquire_eval_lock();
336336
JSObjectCallAsFunction(ctx, run_main_cli_fn, global_obj, 0, NULL, NULL);
337337
release_eval_lock();
338338
}

planck-c/functions.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,6 +1260,7 @@ void do_run_timeout(void *data) {
12601260

12611261
unsigned long *timeout_data = data;
12621262

1263+
acquire_eval_lock();
12631264
JSValueRef args[1];
12641265
args[0] = JSValueMakeNumber(ctx, (double)*timeout_data);
12651266
free(timeout_data);
@@ -1269,7 +1270,6 @@ void do_run_timeout(void *data) {
12691270
run_timeout_fn = get_function("global", "PLANCK_RUN_TIMEOUT");
12701271
JSValueProtect(ctx, run_timeout_fn);
12711272
}
1272-
acquire_eval_lock();
12731273
JSObjectCallAsFunction(ctx, run_timeout_fn, NULL, 1, args, NULL);
12741274
release_eval_lock();
12751275
}
@@ -1310,6 +1310,7 @@ void do_run_interval(void *data) {
13101310

13111311
unsigned long *interval_data = data;
13121312

1313+
acquire_eval_lock();
13131314
JSValueRef args[1];
13141315
args[0] = JSValueMakeNumber(ctx, (double)*interval_data);
13151316
free(interval_data);
@@ -1319,7 +1320,7 @@ void do_run_interval(void *data) {
13191320
run_interval_fn = get_function("global", "PLANCK_RUN_INTERVAL");
13201321
JSValueProtect(ctx, run_interval_fn);
13211322
}
1322-
acquire_eval_lock();
1323+
13231324
JSObjectCallAsFunction(ctx, run_interval_fn, NULL, 1, args, NULL);
13241325
release_eval_lock();
13251326
}
@@ -1378,6 +1379,7 @@ conn_data_cb_ret_t *socket_conn_data_arrived(char *data, int sock, void *info) {
13781379

13791380
data_arrived_info_t *data_arrived_info = info;
13801381

1382+
acquire_eval_lock();
13811383
JSValueRef args[2];
13821384
args[0] = JSValueMakeNumber(ctx, sock);
13831385

@@ -1388,7 +1390,6 @@ conn_data_cb_ret_t *socket_conn_data_arrived(char *data, int sock, void *info) {
13881390
args[1] = JSValueMakeNull(ctx);
13891391
}
13901392

1391-
acquire_eval_lock();
13921393
JSObjectCallAsFunction(ctx, data_arrived_info->data_arrived_cb, NULL, 2, args, NULL);
13931394
release_eval_lock();
13941395

@@ -1408,16 +1409,16 @@ accepted_conn_cb_ret_t *accepted_socket_connection(int sock, void *info) {
14081409

14091410
accept_info_t *accept_info = info;
14101411

1412+
acquire_eval_lock();
14111413
JSValueRef args[1];
14121414
args[0] = JSValueMakeNumber(ctx, sock);
14131415

1414-
acquire_eval_lock();
14151416
JSValueRef data_arrived_cb_ref = JSObjectCallAsFunction(ctx, accept_info->accept_cb, NULL, 1, args, NULL);
1416-
release_eval_lock();
14171417

14181418
data_arrived_info_t *data_arrived_info = malloc(sizeof(data_arrived_info_t));
14191419
data_arrived_info->data_arrived_cb = JSValueToObject(ctx, data_arrived_cb_ref, NULL);
14201420
JSValueProtect(ctx, data_arrived_cb_ref);
1421+
release_eval_lock();
14211422

14221423
accepted_conn_cb_ret_t *accepted_conn_cb_ret = malloc(sizeof(accepted_conn_cb_ret_t));
14231424

0 commit comments

Comments
 (0)