Skip to content

Commit a992d84

Browse files
authored
Fix Base.summarysize crash for instances of foreign types (#61517)
Instances of foreign types are opaque to Julia and we can't traverse them. Teach `get_nth_pointer` about this. This in turn prevents `summarysize` from crashing when invoked on a foreign object. Fixes oscar-system/GAP.jl#1366
1 parent 1b3fb0e commit a992d84

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/datatype.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2366,6 +2366,11 @@ jl_value_t *get_nth_pointer(jl_value_t *v, size_t i)
23662366
uint32_t npointers = ly->npointers;
23672367
if (i >= npointers)
23682368
jl_bounds_error_int(v, i);
2369+
if (ly->flags.fielddesc_type == 3) {
2370+
// Foreign types can report that they contain pointers for GC purposes,
2371+
// but they do not expose an inline pointer-offset table to enumerate.
2372+
return NULL;
2373+
}
23692374
const uint8_t *ptrs8 = (const uint8_t *)jl_dt_layout_ptrs(ly);
23702375
const uint16_t *ptrs16 = (const uint16_t *)jl_dt_layout_ptrs(ly);
23712376
const uint32_t *ptrs32 = (const uint32_t*)jl_dt_layout_ptrs(ly);

test/gcext/gcext-test.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ end
6666
GC.gc(true)
6767
end
6868
@test Base.invokelatest(Foreign.get_nmark) > 0
69+
# Bugfix: the following used to crash
70+
summarysize = Base.summarysize(Foreign.FObj())
71+
@test summarysize >= sizeof(Ptr)
6972
@time Base.invokelatest(Foreign.test, 10)
7073
GC.gc(true)
7174
@test Base.invokelatest(Foreign.get_nsweep) > 0

0 commit comments

Comments
 (0)