Skip to content

Commit

Permalink
Change ccallable handling for entrypoints
Browse files Browse the repository at this point in the history
  • Loading branch information
gbaraldi committed Jan 22, 2025
1 parent a93b084 commit 69eee92
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/gf.c
Original file line number Diff line number Diff line change
Expand Up @@ -3378,7 +3378,7 @@ JL_DLLEXPORT int jl_add_entrypoint(jl_tupletype_t *types)
return 0;
JL_GC_PROMISE_ROOTED(mi);
if (jl_generating_output() && jl_options.trim) {
arraylist_push(jl_entrypoint_mis, mi);
arraylist_push(jl_entrypoint_list, mi);
}
return 1;
}
Expand Down
6 changes: 3 additions & 3 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ extern BOOL (WINAPI *hSymRefreshModuleList)(HANDLE);

// list of modules being deserialized with __init__ methods
jl_array_t *jl_module_init_order;
arraylist_t *jl_entrypoint_mis;
arraylist_t *jl_entrypoint_list;

JL_DLLEXPORT size_t jl_page_size;

Expand Down Expand Up @@ -931,8 +931,8 @@ static NOINLINE void _finish_julia_init(JL_IMAGE_SEARCH rel, jl_ptls_t ptls, jl_
}

if (jl_options.trim) {
jl_entrypoint_mis = (arraylist_t *)malloc_s(sizeof(arraylist_t));
arraylist_new(jl_entrypoint_mis, 0);
jl_entrypoint_list = (arraylist_t *)malloc_s(sizeof(arraylist_t));
arraylist_new(jl_entrypoint_list, 0);
}

if (jl_options.handle_signals == JL_OPTIONS_HANDLE_SIGNALS_ON)
Expand Down
2 changes: 1 addition & 1 deletion src/julia_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ extern htable_t jl_current_modules JL_GLOBALLY_ROOTED;
extern JL_DLLEXPORT jl_module_t *jl_precompile_toplevel_module JL_GLOBALLY_ROOTED;
extern jl_genericmemory_t *jl_global_roots_list JL_GLOBALLY_ROOTED;
extern jl_genericmemory_t *jl_global_roots_keyset JL_GLOBALLY_ROOTED;
extern arraylist_t *jl_entrypoint_mis;
extern arraylist_t *jl_entrypoint_list;
JL_DLLEXPORT int jl_is_globally_rooted(jl_value_t *val JL_MAYBE_UNROOTED) JL_NOTSAFEPOINT;
JL_DLLEXPORT jl_value_t *jl_as_global_root(jl_value_t *val, int insert) JL_GLOBALLY_ROOTED;
extern jl_svec_t *precompile_field_replace JL_GLOBALLY_ROOTED;
Expand Down
15 changes: 4 additions & 11 deletions src/precompile_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ static int enq_ccallable_entrypoints_(jl_typemap_entry_t *def, void *closure)
if (m->external_mt)
return 1;
if (m->ccallable)
jl_add_entrypoint((jl_tupletype_t*)jl_svecref(m->ccallable, 1));
arraylist_push(jl_entrypoint_list, m->ccallable);
return 1;
}

Expand All @@ -367,16 +367,9 @@ static void *jl_precompile_trimmed(size_t world)
{
// array of MethodInstances and ccallable aliases to include in the output
jl_array_t *m = jl_alloc_vec_any(0);
jl_value_t *ccallable = NULL;
JL_GC_PUSH2(&m, &ccallable);
jl_method_instance_t *mi;
for (size_t i = 0; i < jl_entrypoint_mis->len ; i++) {
mi = (jl_method_instance_t*)jl_entrypoint_mis->items[i];
assert(jl_is_method_instance(mi));
jl_array_ptr_1d_push(m, (jl_value_t*)mi);
ccallable = (jl_value_t *)mi->def.method->ccallable;
if (ccallable)
jl_array_ptr_1d_push(m, ccallable);
JL_GC_PUSH(&m);
for (size_t i = 0; i < jl_entrypoint_list->len ; i++) {
jl_array_ptr_1d_push(m, (jl_value_t*)(jl_entrypoint_list->items[i]));
}

void *native_code = jl_create_native(m, NULL, jl_options.trim, 0, world);
Expand Down
8 changes: 3 additions & 5 deletions src/staticdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -1790,11 +1790,9 @@ static void jl_write_values(jl_serializer_state *s) JL_GC_DISABLED
}
if (m->ccallable) {
int should_push = !jl_options.trim;
for (size_t i = 0; !should_push && i < jl_entrypoint_mis->len ; i++) {
jl_method_instance_t* mi = (jl_method_instance_t*)jl_entrypoint_mis->items[i];
assert(jl_is_method_instance(mi));
jl_method_t *ccallable = mi->def.method;
if (ccallable == m) {
for (size_t i = 0; !should_push && i < jl_entrypoint_list->len ; i++) {
jl_value_t* val = jl_entrypoint_list->items[i];
if ((jl_value_t *)m->ccallable == val) {
should_push = 1;
break;
}
Expand Down

0 comments on commit 69eee92

Please sign in to comment.