@@ -1521,14 +1521,22 @@ static uint64_t current_root_id(jl_array_t *root_blocks)
15211521}
15221522
15231523// Add a new block of `len` roots with key `modid` (module id)
1524- static void add_root_block (jl_array_t * root_blocks , uint64_t modid , size_t len )
1524+ static int add_root_block (jl_array_t * root_blocks , uint64_t modid , size_t len )
15251525{
15261526 assert (jl_is_array (root_blocks ));
15271527 jl_array_grow_end (root_blocks , 2 );
15281528 uint64_t * blocks = jl_array_data (root_blocks , uint64_t );
15291529 int nx2 = jl_array_nrows (root_blocks );
1530+ int failed = 0 ;
1531+ for (size_t i = 0 ; i < nx2 ; i += 2 ) {
1532+ if (blocks [i ] == modid ) {
1533+ // found duplicate block
1534+ failed = -1 ;
1535+ }
1536+ }
15301537 blocks [nx2 - 2 ] = modid ;
15311538 blocks [nx2 - 1 ] = len ;
1539+ return failed ;
15321540}
15331541
15341542// Allocate storage for roots
@@ -1555,22 +1563,26 @@ JL_DLLEXPORT void jl_add_method_root(jl_method_t *m, jl_module_t *mod, jl_value_
15551563 }
15561564 assert (jl_is_method (m ));
15571565 prepare_method_for_roots (m , modid );
1558- if (current_root_id (m -> root_blocks ) != modid )
1559- add_root_block (m -> root_blocks , modid , jl_array_nrows (m -> roots ));
1566+ if (current_root_id (m -> root_blocks ) != modid ) {
1567+ int failed = add_root_block (m -> root_blocks , modid , jl_array_nrows (m -> roots ));
1568+ assert (failed == 0 );
1569+ (void )failed ;
1570+ }
15601571 jl_array_ptr_1d_push (m -> roots , root );
15611572 JL_GC_POP ();
15621573}
15631574
15641575// Add a list of roots with key `modid` to a method
1565- void jl_append_method_roots (jl_method_t * m , uint64_t modid , jl_array_t * roots )
1576+ int jl_append_method_roots (jl_method_t * m , uint64_t modid , jl_array_t * roots )
15661577{
15671578 JL_GC_PUSH2 (& m , & roots );
15681579 assert (jl_is_method (m ));
15691580 assert (jl_is_array (roots ));
15701581 prepare_method_for_roots (m , modid );
1571- add_root_block (m -> root_blocks , modid , jl_array_nrows (m -> roots ));
1582+ int failed = add_root_block (m -> root_blocks , modid , jl_array_nrows (m -> roots ));
15721583 jl_array_ptr_1d_append (m -> roots , roots );
15731584 JL_GC_POP ();
1585+ return failed ;
15741586}
15751587
15761588// given the absolute index i of a root, retrieve its relocatable reference
0 commit comments