~tf4/goose/networking-prototype

« back to all changes in this revision

Viewing changes to testservices/hook/service.go

  • Committer: Tarmac
  • Author(s): Michael Hudson-Doyle
  • Date: 2013-11-26 00:37:35 UTC
  • mfrom: (110.1.4 goose)
  • Revision ID: tarmac-20131126003735-kcvbrh3yn9e0xy8h
[r=dave-cheney],[bug=1254564] The currentServiceMethodName changes are foul, but this branch passes all tests with gccgo. You'll need the nil-related changes to have goose work with go 1.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
 
30
30
// currentServiceMethodName returns the method executing on the service when ProcessControlHook was invoked.
31
31
func (s *TestService) currentServiceMethodName() string {
32
 
        pc, _, _, ok := runtime.Caller(2)
 
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
        }
33
49
        if !ok {
34
50
                panic("current method name cannot be found")
35
51
        }
39
55
func unqualifiedMethodName(pc uintptr) string {
40
56
        f := runtime.FuncForPC(pc)
41
57
        fullName := f.Name()
42
 
        nameParts := strings.Split(fullName, ".")
43
 
        return nameParts[len(nameParts)-1]
 
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
        }
44
69
}
45
70
 
46
71
// ProcessControlHook retrieves the ControlProcessor for the specified hook name and runs it, returning any error.