Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix object_id with padding #12442

Merged
merged 1 commit into from
Aug 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
14 changes: 14 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3173,3 +3173,17 @@ 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
hashaspadding = HasHasPadding(HasPadding(true,1))
hashaspadding2 = HasHasPadding(HasPadding(true,1))
unsafe_store!(convert(Ptr{UInt8},pointer_from_objref(hashaspadding)), 0x12, 2)
unsafe_store!(convert(Ptr{UInt8},pointer_from_objref(hashaspadding2)), 0x21, 2)
@test object_id(hashaspadding) == object_id(hashaspadding2)