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
=== modified file 'testservices/hook/service.go'
--- testservices/hook/service.go 2013-11-25 20:32:40 +0000
+++ testservices/hook/service.go 2013-11-26 01:31:50 +0000
@@ -1,10 +1,5 @@
1package hook1package hook
22
3import (
4 "runtime"
5 "strings"
6)
7
8type TestService struct {3type TestService struct {
9 ServiceControl4 ServiceControl
10 // Hooks to run when specified control points are reached in the service business logic.5 // Hooks to run when specified control points are reached in the service business logic.
@@ -27,47 +22,6 @@
27 RegisterControlPoint(name string, controller ControlProcessor) ControlHookCleanup22 RegisterControlPoint(name string, controller ControlProcessor) ControlHookCleanup
28}23}
2924
30// currentServiceMethodName returns the method executing on the service when ProcessControlHook was invoked.
31func (s *TestService) currentServiceMethodName() string {
32 var pc uintptr
33 var ok bool
34
35 // We have to go deeper into the stack with gccgo because in a situation like:
36 // type Inner { }
37 // func (i *Inner) meth {}
38 // type Outer { Inner }
39 // o = &Outer{}
40 // o.meth()
41 // gccgo generates a method called "meth" on *Outer, and this shows up
42 // on the stack as seen by runtime.Caller (this might be a gccgo bug).
43
44 if runtime.Compiler == "gccgo" {
45 pc, _, _, ok = runtime.Caller(3)
46 } else {
47 pc, _, _, ok = runtime.Caller(2)
48 }
49 if !ok {
50 panic("current method name cannot be found")
51 }
52 return unqualifiedMethodName(pc)
53}
54
55func unqualifiedMethodName(pc uintptr) string {
56 f := runtime.FuncForPC(pc)
57 fullName := f.Name()
58 if runtime.Compiler == "gccgo" {
59 // This is very fragile. fullName will be something like:
60 // launchpad.net_goose_testservices_novaservice.removeServer.pN49_launchpad.net_goose_testservices_novaservice.Nova
61 // so if the number of dots in the full package path changes,
62 // this will need to too...
63 nameParts := strings.Split(fullName, ".")
64 return nameParts[2]
65 } else {
66 nameParts := strings.Split(fullName, ".")
67 return nameParts[len(nameParts)-1]
68 }
69}
70
71// ProcessControlHook retrieves the ControlProcessor for the specified hook name and runs it, returning any error.25// ProcessControlHook retrieves the ControlProcessor for the specified hook name and runs it, returning any error.
72// Use it like this to invoke a hook registered for some arbitrary control point:26// Use it like this to invoke a hook registered for some arbitrary control point:
73// if err := n.ProcessControlHook("foobar", <serviceinstance>, <somearg1>, <somearg2>); err != nil {27// if err := n.ProcessControlHook("foobar", <serviceinstance>, <somearg1>, <somearg2>); err != nil {
7428
=== added file 'testservices/hook/service_gc.go'
--- testservices/hook/service_gc.go 1970-01-01 00:00:00 +0000
+++ testservices/hook/service_gc.go 2013-11-26 01:31:50 +0000
@@ -0,0 +1,24 @@
1// +build !gccgo
2
3package hook
4
5import (
6 "runtime"
7 "strings"
8)
9
10// currentServiceMethodName returns the method executing on the service when ProcessControlHook was invoked.
11func (s *TestService) currentServiceMethodName() string {
12 pc, _, _, ok := runtime.Caller(2)
13 if !ok {
14 panic("current method name cannot be found")
15 }
16 return unqualifiedMethodName(pc)
17}
18
19func unqualifiedMethodName(pc uintptr) string {
20 f := runtime.FuncForPC(pc)
21 fullName := f.Name()
22 nameParts := strings.Split(fullName, ".")
23 return nameParts[len(nameParts)-1]
24}
025
=== added file 'testservices/hook/service_gccgo.go'
--- testservices/hook/service_gccgo.go 1970-01-01 00:00:00 +0000
+++ testservices/hook/service_gccgo.go 2013-11-26 01:31:50 +0000
@@ -0,0 +1,37 @@
1// +build gccgo
2
3package hook
4
5import (
6 "runtime"
7 "strings"
8)
9
10// currentServiceMethodName returns the method executing on the service when ProcessControlHook was invoked.
11func (s *TestService) currentServiceMethodName() string {
12 // We have to go deeper into the stack with gccgo because in a situation like:
13 // type Inner { }
14 // func (i *Inner) meth {}
15 // type Outer { Inner }
16 // o = &Outer{}
17 // o.meth()
18 // gccgo generates a method called "meth" on *Outer, and this shows up
19 // on the stack as seen by runtime.Caller (this might be a gccgo bug).
20
21 pc, _, _, ok := runtime.Caller(3)
22 if !ok {
23 panic("current method name cannot be found")
24 }
25 return unqualifiedMethodName(pc)
26}
27
28func unqualifiedMethodName(pc uintptr) string {
29 f := runtime.FuncForPC(pc)
30 fullName := f.Name()
31 // This is very fragile. fullName will be something like:
32 // launchpad.net_goose_testservices_novaservice.removeServer.pN49_launchpad.net_goose_testservices_novaservice.Nova
33 // so if the number of dots in the full package path changes,
34 // this will need to too...
35 nameParts := strings.Split(fullName, ".")
36 return nameParts[2]
37}

Subscribers

People subscribed via source and target branches