Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.

Commit 103ca87

Browse files
James Prestwoodgrgustaf
authored andcommitted
[callbacks] Fixed broken callbacks after optimization change (#483)
- Also fixed debug build relating to the callback change Signed-off-by: James Prestwood <[email protected]>
1 parent 5844f9f commit 103ca87

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

src/zjs_callbacks.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@
4646
#define SET_TYPE(f, b) f |= (b << TYPE_BIT)
4747
#define SET_JS_TYPE(f, b) f |= (b << JS_TYPE_BIT)
4848
// Macros to get the bits in flags
49-
#define GET_ONCE(f) (f & (1 << ONCE_BIT))
50-
#define GET_TYPE(f) (f & (1 << TYPE_BIT))
51-
#define GET_JS_TYPE(f) (f & (1 << JS_TYPE_BIT))
49+
#define GET_ONCE(f) (f & (1 << ONCE_BIT)) >> ONCE_BIT
50+
#define GET_TYPE(f) (f & (1 << TYPE_BIT)) >> TYPE_BIT
51+
#define GET_JS_TYPE(f) (f & (1 << JS_TYPE_BIT)) >> JS_TYPE_BIT
5252

5353
struct zjs_callback_t {
5454
zjs_callback_id id;
@@ -277,8 +277,8 @@ zjs_callback_id add_callback(jerry_value_t js_func,
277277
cb_size++;
278278
}
279279

280-
DBG_PRINT("adding new callback id %ld, js_func=%lu, once=%u\n",
281-
new_cb->id, new_cb->js->js_func, once);
280+
DBG_PRINT("adding new callback id %d, js_func=%lu, once=%u\n",
281+
new_cb->id, new_cb->js_func, once);
282282

283283
return new_cb->id;
284284
}
@@ -316,13 +316,13 @@ void zjs_remove_callback(zjs_callback_id id)
316316
}
317317
zjs_free(cb_map[id]);
318318
cb_map[id] = NULL;
319-
DBG_PRINT("removing callback id %ld\n", id);
319+
DBG_PRINT("removing callback id %d\n", id);
320320
}
321321
}
322322

323323
void zjs_signal_callback(zjs_callback_id id, void* args, uint32_t size)
324324
{
325-
DBG_PRINT("pushing item to ring buffer. id=%li, args=%p, size=%lu\n", id, args, size);
325+
DBG_PRINT("pushing item to ring buffer. id=%d, args=%p, size=%lu\n", id, args, size);
326326
int ret = zjs_port_ring_buf_put(&ring_buffer,
327327
(uint16_t)id,
328328
0,
@@ -353,7 +353,7 @@ zjs_callback_id zjs_add_c_callback(void* handle, zjs_c_callback_func callback)
353353
if (new_cb->id >= cb_size - 1) {
354354
cb_size++;
355355
}
356-
DBG_PRINT("adding new C callback id %ld\n", new_cb->id);
356+
DBG_PRINT("adding new C callback id %d\n", new_cb->id);
357357

358358
return new_cb->id;
359359
}
@@ -364,17 +364,17 @@ void print_callbacks(void)
364364
int i;
365365
for (i = 0; i < cb_size; i++) {
366366
if (cb_map[i]) {
367-
if (cb_map[i]->type == CALLBACK_TYPE_JS) {
367+
if (GET_TYPE(cb_map[i]->flags) == CALLBACK_TYPE_JS) {
368368
ZJS_PRINT("[%u] JS Callback:\n\tType: ", i);
369-
if (cb_map[i]->js->func_list == NULL &&
370-
jerry_value_is_function(cb_map[i]->js->js_func)) {
369+
if (cb_map[i]->func_list == NULL &&
370+
jerry_value_is_function(cb_map[i]->js_func)) {
371371
ZJS_PRINT("Single Function\n");
372-
ZJS_PRINT("\tjs_func: %lu\n", cb_map[i]->js->js_func);
373-
ZJS_PRINT("\tonce: %u\n", cb_map[i]->js->once);
372+
ZJS_PRINT("\tjs_func: %lu\n", cb_map[i]->js_func);
373+
ZJS_PRINT("\tonce: %u\n", GET_ONCE(cb_map[i]->flags));
374374
} else {
375375
ZJS_PRINT("List\n");
376-
ZJS_PRINT("\tmax_funcs: %u\n", cb_map[i]->js->max_funcs);
377-
ZJS_PRINT("\tmax_funcs: %u\n", cb_map[i]->js->num_funcs);
376+
ZJS_PRINT("\tmax_funcs: %u\n", cb_map[i]->max_funcs);
377+
ZJS_PRINT("\tmax_funcs: %u\n", cb_map[i]->num_funcs);
378378
}
379379
}
380380
} else {
@@ -396,13 +396,13 @@ void zjs_call_callback(zjs_callback_id id, void* data, uint32_t sz)
396396
if (GET_JS_TYPE(cb_map[id]->flags) == JS_TYPE_SINGLE) {
397397
ret_val = jerry_call_function(cb_map[id]->js_func, cb_map[id]->this, data, sz);
398398
if (jerry_value_has_error_flag(ret_val)) {
399-
DBG_PRINT("callback %ld returned an error for function\n", id);
399+
DBG_PRINT("callback %d returned an error for function\n", id);
400400
}
401401
} else if (GET_JS_TYPE(cb_map[id]->flags) == JS_TYPE_LIST) {
402402
for (i = 0; i < cb_map[id]->num_funcs; ++i) {
403403
ret_val = jerry_call_function(cb_map[id]->func_list[i], cb_map[id]->this, data, sz);
404404
if (jerry_value_has_error_flag(ret_val)) {
405-
DBG_PRINT("callback %ld returned an error for function[%i]\n", id, i);
405+
DBG_PRINT("callback %d returned an error for function[%i]\n", id, i);
406406
}
407407
}
408408
}

src/zjs_promise.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ void zjs_fulfill_promise(jerry_value_t obj, jerry_value_t argv[], uint32_t argc)
154154

155155
zjs_signal_callback(handle->then_id, argv, argc * sizeof(jerry_value_t));
156156

157-
DBG_PRINT("fulfilling promise, obj=%lu, then_id=%lu, argv=%p, nargs=%lu\n",
157+
DBG_PRINT("fulfilling promise, obj=%lu, then_id=%d, argv=%p, nargs=%lu\n",
158158
obj, handle->then_id, argv, argc);
159159
} else {
160160
ERR_PRINT("native handle not found\n");
@@ -188,7 +188,7 @@ void zjs_reject_promise(jerry_value_t obj, jerry_value_t argv[], uint32_t argc)
188188

189189
zjs_signal_callback(handle->catch_id, argv, argc * sizeof(jerry_value_t));
190190

191-
DBG_PRINT("rejecting promise, obj=%lu, catch_id=%ld, argv=%p, nargs=%lu\n",
191+
DBG_PRINT("rejecting promise, obj=%lu, catch_id=%d, argv=%p, nargs=%lu\n",
192192
obj, handle->catch_id, argv, argc);
193193
} else {
194194
ERR_PRINT("native handle not found\n");

src/zjs_timers.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ static zjs_timer_t* add_timer(uint32_t interval,
8181

8282
zjs_timers = tm;
8383

84-
DBG_PRINT("adding timer. id=%li, interval=%lu, repeat=%u, argv=%p, argc=%lu\n",
84+
DBG_PRINT("adding timer. id=%d, interval=%lu, repeat=%u, argv=%p, argc=%lu\n",
8585
tm->callback_id, interval, repeat, argv, argc);
8686
zjs_port_timer_start(&tm->timer, interval);
8787
return tm;
@@ -99,7 +99,7 @@ static bool delete_timer(int32_t id)
9999
for (zjs_timer_t **ptm = &zjs_timers; *ptm; ptm = &(*ptm)->next) {
100100
zjs_timer_t *tm = *ptm;
101101
if (id == tm->callback_id) {
102-
DBG_PRINT("removing timer. id=%li\n", tm->callback_id);
102+
DBG_PRINT("removing timer. id=%d\n", tm->callback_id);
103103
zjs_port_timer_stop(&tm->timer);
104104
*ptm = tm->next;
105105
for (int i = 0; i < tm->argc; ++i) {
@@ -216,7 +216,7 @@ void zjs_timers_process_events()
216216
}
217217
else if (zjs_port_timer_test(&tm->timer, ZJS_TICKS_NONE)) {
218218
// timer has expired, signal the callback
219-
DBG_PRINT("signaling timer. id=%li, argv=%p, argc=%lu\n",
219+
DBG_PRINT("signaling timer. id=%d, argv=%p, argc=%lu\n",
220220
tm->callback_id, tm->argv, tm->argc);
221221
zjs_signal_callback(tm->callback_id, tm->argv, tm->argc * sizeof(jerry_value_t));
222222

0 commit comments

Comments
 (0)