Merge lp:~dave-cheney/goose/001-move-gccgo-specific-code-to-individual into lp:goose

Proposed by Dave Cheney
Status: Merged
Approved by: Dave Cheney
Approved revision: 112
Merged at revision: 113
Proposed branch: lp:~dave-cheney/goose/001-move-gccgo-specific-code-to-individual
Merge into: lp:goose
Prerequisite: lp:~dave-cheney/goose/goose
Diff against target: 133 lines (+61/-46)
3 files modified
testservices/hook/service.go (+0/-46)
testservices/hook/service_gc.go (+24/-0)
testservices/hook/service_gccgo.go (+37/-0)
To merge this branch: bzr merge lp:~dave-cheney/goose/001-move-gccgo-specific-code-to-individual
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+196643@code.launchpad.net

Commit message

Split out implementation specific behaviour

Use conditional compilation rather than switching on runtime.Compiler. When the upstream bugs are resolved, we can remove these hacks.

Description of the change

Split out implementation specific behaviour

Use conditional compilation rather than switching on runtime.Compiler. When the upstream bugs are resolved, we can remove these hacks.

https://codereview.appspot.com/32550043/

To post a comment you must log in.
Revision history for this message
Andrew Wilkins (axwalk) wrote :

On 2013/11/26 01:32:05, dfc wrote:
> Please take a look.

LGTM

https://codereview.appspot.com/32550043/

Revision history for this message
Go Bot (go-bot) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'testservices/hook/service.go'
2--- testservices/hook/service.go 2013-11-25 20:32:40 +0000
3+++ testservices/hook/service.go 2013-11-26 01:31:50 +0000
4@@ -1,10 +1,5 @@
5 package hook
6
7-import (
8- "runtime"
9- "strings"
10-)
11-
12 type TestService struct {
13 ServiceControl
14 // Hooks to run when specified control points are reached in the service business logic.
15@@ -27,47 +22,6 @@
16 RegisterControlPoint(name string, controller ControlProcessor) ControlHookCleanup
17 }
18
19-// currentServiceMethodName returns the method executing on the service when ProcessControlHook was invoked.
20-func (s *TestService) currentServiceMethodName() string {
21- var pc uintptr
22- var ok bool
23-
24- // We have to go deeper into the stack with gccgo because in a situation like:
25- // type Inner { }
26- // func (i *Inner) meth {}
27- // type Outer { Inner }
28- // o = &Outer{}
29- // o.meth()
30- // gccgo generates a method called "meth" on *Outer, and this shows up
31- // on the stack as seen by runtime.Caller (this might be a gccgo bug).
32-
33- if runtime.Compiler == "gccgo" {
34- pc, _, _, ok = runtime.Caller(3)
35- } else {
36- pc, _, _, ok = runtime.Caller(2)
37- }
38- if !ok {
39- panic("current method name cannot be found")
40- }
41- return unqualifiedMethodName(pc)
42-}
43-
44-func unqualifiedMethodName(pc uintptr) string {
45- f := runtime.FuncForPC(pc)
46- fullName := f.Name()
47- if runtime.Compiler == "gccgo" {
48- // This is very fragile. fullName will be something like:
49- // launchpad.net_goose_testservices_novaservice.removeServer.pN49_launchpad.net_goose_testservices_novaservice.Nova
50- // so if the number of dots in the full package path changes,
51- // this will need to too...
52- nameParts := strings.Split(fullName, ".")
53- return nameParts[2]
54- } else {
55- nameParts := strings.Split(fullName, ".")
56- return nameParts[len(nameParts)-1]
57- }
58-}
59-
60 // ProcessControlHook retrieves the ControlProcessor for the specified hook name and runs it, returning any error.
61 // Use it like this to invoke a hook registered for some arbitrary control point:
62 // if err := n.ProcessControlHook("foobar", <serviceinstance>, <somearg1>, <somearg2>); err != nil {
63
64=== added file 'testservices/hook/service_gc.go'
65--- testservices/hook/service_gc.go 1970-01-01 00:00:00 +0000
66+++ testservices/hook/service_gc.go 2013-11-26 01:31:50 +0000
67@@ -0,0 +1,24 @@
68+// +build !gccgo
69+
70+package hook
71+
72+import (
73+ "runtime"
74+ "strings"
75+)
76+
77+// currentServiceMethodName returns the method executing on the service when ProcessControlHook was invoked.
78+func (s *TestService) currentServiceMethodName() string {
79+ pc, _, _, ok := runtime.Caller(2)
80+ if !ok {
81+ panic("current method name cannot be found")
82+ }
83+ return unqualifiedMethodName(pc)
84+}
85+
86+func unqualifiedMethodName(pc uintptr) string {
87+ f := runtime.FuncForPC(pc)
88+ fullName := f.Name()
89+ nameParts := strings.Split(fullName, ".")
90+ return nameParts[len(nameParts)-1]
91+}
92
93=== added file 'testservices/hook/service_gccgo.go'
94--- testservices/hook/service_gccgo.go 1970-01-01 00:00:00 +0000
95+++ testservices/hook/service_gccgo.go 2013-11-26 01:31:50 +0000
96@@ -0,0 +1,37 @@
97+// +build gccgo
98+
99+package hook
100+
101+import (
102+ "runtime"
103+ "strings"
104+)
105+
106+// currentServiceMethodName returns the method executing on the service when ProcessControlHook was invoked.
107+func (s *TestService) currentServiceMethodName() string {
108+ // We have to go deeper into the stack with gccgo because in a situation like:
109+ // type Inner { }
110+ // func (i *Inner) meth {}
111+ // type Outer { Inner }
112+ // o = &Outer{}
113+ // o.meth()
114+ // gccgo generates a method called "meth" on *Outer, and this shows up
115+ // on the stack as seen by runtime.Caller (this might be a gccgo bug).
116+
117+ pc, _, _, ok := runtime.Caller(3)
118+ if !ok {
119+ panic("current method name cannot be found")
120+ }
121+ return unqualifiedMethodName(pc)
122+}
123+
124+func unqualifiedMethodName(pc uintptr) string {
125+ f := runtime.FuncForPC(pc)
126+ fullName := f.Name()
127+ // This is very fragile. fullName will be something like:
128+ // launchpad.net_goose_testservices_novaservice.removeServer.pN49_launchpad.net_goose_testservices_novaservice.Nova
129+ // so if the number of dots in the full package path changes,
130+ // this will need to too...
131+ nameParts := strings.Split(fullName, ".")
132+ return nameParts[2]
133+}

Subscribers

People subscribed via source and target branches