Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Unified Diff: go/src/infra/gae/libs/wrapper/unsafe/memcache.go

Issue 1152383003: Simple memory testing for gae/wrapper (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@better_context_lite
Patch Set: add go-slab dependency Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « go/src/infra/gae/libs/wrapper/unsafe/doc.go ('k') | go/src/infra/gae/libs/wrapper/unsafe/memcache_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: go/src/infra/gae/libs/wrapper/unsafe/memcache.go
diff --git a/go/src/infra/gae/libs/wrapper/unsafe/memcache.go b/go/src/infra/gae/libs/wrapper/unsafe/memcache.go
new file mode 100644
index 0000000000000000000000000000000000000000..db7ad3b6f79f82c16e814e311fe9a31334d29865
--- /dev/null
+++ b/go/src/infra/gae/libs/wrapper/unsafe/memcache.go
@@ -0,0 +1,58 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package unsafe
+
+import (
+ "time"
+
+ "unsafe"
+
+ "appengine/memcache"
+)
+
+// Item is duplicated from appengine/memcache.
+type Item struct {
+ Key string
+ Value []byte
+ Object interface{}
+ Flags uint32
+ Expiration time.Duration
+ CasID uint64
+}
+
+func init() {
+ // we can't actually refer to casID by name, but we can refer to everything
+ // else, and ensure that everything lines up. This should catch an api change,
+ // but wouldn't catch something like uint64 -> int64.
+ if unsafe.Sizeof(memcache.Item{}) != unsafe.Sizeof(Item{}) {
+ panic("memcache.Item and Item mismatch sizes")
+ }
+ if unsafe.Offsetof(memcache.Item{}.Key) != unsafe.Offsetof(Item{}.Key) {
+ panic("memcache.Item and Item mismatch Key")
+ }
+ if unsafe.Offsetof(memcache.Item{}.Value) != unsafe.Offsetof(Item{}.Value) {
+ panic("memcache.Item and Item mismatch Value")
+ }
+ if unsafe.Offsetof(memcache.Item{}.Object) != unsafe.Offsetof(Item{}.Object) {
+ panic("memcache.Item and Item mismatch Object")
+ }
+ if unsafe.Offsetof(memcache.Item{}.Flags) != unsafe.Offsetof(Item{}.Flags) {
+ panic("memcache.Item and Item mismatch Flags")
+ }
+ if unsafe.Offsetof(memcache.Item{}.Expiration) != unsafe.Offsetof(Item{}.Expiration) {
+ panic("memcache.Item and Item mismatch Expiration")
+ }
+}
+
+// MCSetCasID sets the private .casID field of memcache.Item.
+func MCSetCasID(i *memcache.Item, val uint64) {
+ mci := (*Item)(unsafe.Pointer(i))
+ mci.CasID = val
+}
+
+// MCGetCasID retrieves the private .casID field of memcache.Item.
+func MCGetCasID(i *memcache.Item) uint64 {
+ return (*Item)(unsafe.Pointer(i)).CasID
+}
« no previous file with comments | « go/src/infra/gae/libs/wrapper/unsafe/doc.go ('k') | go/src/infra/gae/libs/wrapper/unsafe/memcache_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698