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

Unified Diff: impl/memory/context.go

Issue 2492053003: Fix 'impl/memory' context key. (Closed)
Patch Set: Created 4 years, 1 month 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 | « no previous file | impl/memory/datastore.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: impl/memory/context.go
diff --git a/impl/memory/context.go b/impl/memory/context.go
index 7fc489d4e27b8fb58ebcd3ca925c75f474dfa263..feddfda29bd9a3485ac4c86d9dbe2449c78f09e2 100644
--- a/impl/memory/context.go
+++ b/impl/memory/context.go
@@ -117,7 +117,7 @@ func Use(c context.Context) context.Context {
//
// Using this more than once per context.Context will cause a panic.
func UseWithAppID(c context.Context, aid string) context.Context {
- if c.Value(memContextKey) != nil {
+ if c.Value(&memContextKey) != nil {
panic(errors.New("memory.Use: called twice on the same Context"))
}
c = memlogger.Use(c)
@@ -128,7 +128,7 @@ func UseWithAppID(c context.Context, aid string) context.Context {
}
memctx := newMemContext(fqAppID)
- c = context.WithValue(c, memContextKey, memctx)
+ c = context.WithValue(c, &memContextKey, memctx)
c = useGID(c, func(mod *globalInfoData) {
mod.appID = aid
mod.fqAppID = fqAppID
@@ -137,18 +137,16 @@ func UseWithAppID(c context.Context, aid string) context.Context {
}
func cur(c context.Context) (*memContext, bool) {
- if txn := c.Value(currentTxnKey); txn != nil {
+ if txn := c.Value(&currentTxnKey); txn != nil {
// We are in a Transaction.
return txn.(*memContext), true
}
- return c.Value(memContextKey).(*memContext), false
+ return c.Value(&memContextKey).(*memContext), false
}
-type memContextKeyType int
-
var (
- memContextKey memContextKeyType
- currentTxnKey = 1
+ memContextKey = "gae:memory:context"
+ currentTxnKey = "gae:memory:currentTxn"
)
// weird stuff
@@ -186,7 +184,7 @@ func (d *dsImpl) RunInTransaction(f func(context.Context) error, o *ds.Transacti
txnMC.endTxn()
}()
- if err := f(context.WithValue(d, currentTxnKey, txnMC)); err != nil {
+ if err := f(context.WithValue(d, &currentTxnKey, txnMC)); err != nil {
return err
}
« no previous file with comments | « no previous file | impl/memory/datastore.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698