Commit 1adb5bd3 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Fix int64 handlemap.

parent 92ccb1ff
...@@ -285,6 +285,7 @@ func (m *int64HandleMap) Register(obj *Handled) (handle uint64) { ...@@ -285,6 +285,7 @@ func (m *int64HandleMap) Register(obj *Handled) (handle uint64) {
panic(_ALREADY_MSG) panic(_ALREADY_MSG)
} }
obj.check = check obj.check = check
obj.handle = handle
m.handles[handle] = obj m.handles[handle] = obj
} else { } else {
handle = m.Handle(obj) handle = m.Handle(obj)
......
...@@ -20,22 +20,6 @@ func markSeen(t *testing.T, substr string) { ...@@ -20,22 +20,6 @@ func markSeen(t *testing.T, substr string) {
} }
} }
func TestHandleMapDoubleRegister(t *testing.T) {
if unsafe.Sizeof(t) < 8 {
t.Log("skipping test for 32 bits")
return
}
t.Log("TestDoubleRegister")
defer markSeen(t, "already has a handle")
hm := NewHandleMap(false)
obj := &Handled{}
hm.Register(obj)
v := &Handled{}
hm.Register(v)
hm.Register(v)
t.Error("Double register did not panic")
}
func TestHandleMapUnaligned(t *testing.T) { func TestHandleMapUnaligned(t *testing.T) {
if unsafe.Sizeof(t) < 8 { if unsafe.Sizeof(t) < 8 {
t.Log("skipping test for 32 bits") t.Log("skipping test for 32 bits")
...@@ -51,19 +35,46 @@ func TestHandleMapUnaligned(t *testing.T) { ...@@ -51,19 +35,46 @@ func TestHandleMapUnaligned(t *testing.T) {
t.Error("Unaligned register did not panic") t.Error("Unaligned register did not panic")
} }
func TestHandleMapPointerLayout(t *testing.T) { func TestHandleMapLookupCount(t *testing.T) {
if unsafe.Sizeof(t) < 8 { for _, portable := range []bool{true, false} {
t.Log("skipping test for 32 bits") t.Log("portable:", portable)
return v := new(Handled)
hm := NewHandleMap(portable)
h1 := hm.Register(v)
h2 := hm.Register(v)
if h1 != h2 {
t.Fatalf("double register should reuse handle: got %d want %d.", h2, h1)
} }
hm := NewHandleMap(false)
bogus := uint64(1) << uint32((8 * (unsafe.Sizeof(t) - 1)))
p := uintptr(bogus)
v := (*Handled)(unsafe.Pointer(p))
defer markSeen(t, "48")
hm.Register(v) hm.Register(v)
t.Error("bogus register did not panic")
forgotten, obj := hm.Forget(h1, 1)
if forgotten {
t.Fatalf("single forget unref forget object.")
}
if obj != v {
t.Fatalf("should return input object.")
}
if !hm.Has(h1) {
t.Fatalf("handlemap.Has() returned false for live object.")
}
forgotten, obj = hm.Forget(h1, 2)
if !forgotten {
t.Fatalf("unref did not forget object.")
}
if obj != v {
t.Fatalf("should return input object.")
}
if hm.Has(h1) {
t.Fatalf("handlemap.Has() returned false for live object.")
}
}
} }
func TestHandleMapBasic(t *testing.T) { func TestHandleMapBasic(t *testing.T) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment