Skip to content

Commit 8abce49

Browse files
committed
add a uuid to each Module that is stable across serialization
1 parent e3a74ee commit 8abce49

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

src/dump.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,8 @@ static void jl_serialize_module(ios_t *s, jl_module_t *m)
418418
}
419419
}
420420
jl_serialize_value(s, m->constant_table);
421+
write_int32(s, (uint32_t)m->uuid);
422+
write_int32(s, (uint32_t)(m->uuid>>32));
421423
}
422424

423425
static int is_ast_node(jl_value_t *v)
@@ -1088,6 +1090,8 @@ static jl_value_t *jl_deserialize_value_(ios_t *s, int pos, jl_value_t *vtag, jl
10881090
i++;
10891091
}
10901092
m->constant_table = (jl_array_t*)jl_deserialize_value(s, (jl_value_t**)&m->constant_table);
1093+
m->uuid = read_int32(s);
1094+
m->uuid |= ((uint64_t)read_int32(s))<<32;
10911095
return (jl_value_t*)m;
10921096
}
10931097
else if (vtag == (jl_value_t*)SmallInt64_tag) {

src/julia.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ typedef struct _jl_module_t {
255255
htable_t bindings;
256256
arraylist_t usings; // modules with all bindings potentially imported
257257
jl_array_t *constant_table;
258+
uint64_t uuid;
258259
} jl_module_t;
259260

260261
typedef struct _jl_methlist_t {

src/module.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ jl_module_t *jl_new_module(jl_sym_t *name)
2222
assert(jl_is_symbol(name));
2323
m->name = name;
2424
m->constant_table = NULL;
25+
m->uuid = uv_now(uv_default_loop());
2526
htable_new(&m->bindings, 0);
2627
arraylist_new(&m->usings, 0);
2728
if (jl_core_module) {
@@ -425,6 +426,7 @@ DLLEXPORT jl_value_t *jl_module_names(jl_module_t *m, int all, int imported)
425426

426427
DLLEXPORT jl_sym_t *jl_module_name(jl_module_t *m) { return m->name; }
427428
DLLEXPORT jl_module_t *jl_module_parent(jl_module_t *m) { return m->parent; }
429+
DLLEXPORT uint64_t jl_module_uuid(jl_module_t *m) { return m->uuid; }
428430

429431
int jl_module_has_initializer(jl_module_t *m)
430432
{

0 commit comments

Comments
 (0)