Skip to content

Commit

Permalink
Merge pull request #12442 from JuliaLang/ob/fixoid
Browse files Browse the repository at this point in the history
Fix object_id with padding
  • Loading branch information
carnaval committed Aug 4, 2015
2 parents a6c78b6 + bb0a405 commit e66175b
Show file tree
Hide file tree
Showing 2 changed files with 27 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 @@ -1119,11 +1119,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 @@ -1165,13 +1164,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)

0 comments on commit e66175b

Please sign in to comment.