Skip to content

Commit

Permalink
Fix object_id with padding
Browse files Browse the repository at this point in the history
Forgotten in the padding fix : immutables with haspadding fields.
  • Loading branch information
carnaval committed Aug 3, 2015
1 parent e22233e commit 5ee7acd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -1102,11 +1102,10 @@ static uptrint_t bits_hash(void *b, size_t sz)
}
}

DLLEXPORT uptrint_t jl_object_id(jl_value_t *v)
static uptrint_t jl_object_id_(jl_value_t *tv, jl_value_t *v)
{
if (jl_is_symbol(v))
if (tv == (jl_value_t*)jl_sym_type)
return ((jl_sym_t*)v)->hash;
jl_value_t *tv = (jl_value_t*)jl_typeof(v);
if (tv == (jl_value_t*)jl_simplevector_type) {
uptrint_t h = 0;
size_t l = jl_svec_len(v);
Expand Down Expand Up @@ -1148,13 +1147,23 @@ DLLEXPORT uptrint_t jl_object_id(jl_value_t *v)
u = f==NULL ? 0 : jl_object_id(f);
}
else {
u = bits_hash(vo, dt->fields[f].size);
jl_datatype_t *fieldtype = (jl_datatype_t*)jl_svecref(dt->types, f);
assert(jl_is_datatype(fieldtype) && !fieldtype->abstract && !fieldtype->mutabl);
if (fieldtype->haspadding)
u = jl_object_id_((jl_value_t*)fieldtype, (jl_value_t*)vo);
else
u = bits_hash(vo, dt->fields[f].size);
}
h = bitmix(h, u);
}
return h;
}

DLLEXPORT uptrint_t jl_object_id(jl_value_t *v)
{
return jl_object_id_(jl_typeof(v), v);
}

// init -----------------------------------------------------------------------

static void add_builtin(const char *name, jl_value_t *v)
Expand Down
11 changes: 11 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3173,3 +3173,14 @@ let x = Array(Empty12394,1), y = [Empty12394()]
@test_throws UndefRefError x==y
@test_throws UndefRefError y==x
end

# object_id of haspadding field
immutable HasPadding
x::Bool
y::Int
end
immutable HasHasPadding
x::HasPadding
end
# less than 1k does not reproduce very reliably
@test length(unique([object_id(HasHasPadding(HasPadding(true, 1))) for _=1:1000])) == 1

0 comments on commit 5ee7acd

Please sign in to comment.