github.com/tencent/goom@v1.0.1/internal/patch/signature.go (about) 1 package patch 2 3 import ( 4 "fmt" 5 "reflect" 6 ) 7 8 // SignatureEquals 检测两个函数类型的参数的内存区段是否一致 9 func SignatureEquals(typeA reflect.Type, typeB reflect.Type) bool { 10 // 检测参数对齐 11 if typeA.NumIn() != typeB.NumIn() { 12 panic(fmt.Sprintf("func signature mismatch, args len must:%d, actual:%d", 13 typeA.NumIn(), typeB.NumIn())) 14 } 15 if typeA.NumOut() != typeB.NumOut() { 16 panic(fmt.Sprintf("func signature mismatch, returns len must:%d, actual:%d", 17 typeA.NumOut(), typeB.NumOut())) 18 } 19 for i := 0; i < typeA.NumIn(); i++ { 20 if typeA.In(i).Size() != typeB.In(i).Size() { 21 panic(fmt.Sprintf("func signature mismatch, args %d's size must:%d, actual:%d", 22 i, typeA.In(i).Size(), typeB.In(i).Size())) 23 } 24 } 25 for i := 0; i < typeA.NumOut(); i++ { 26 if typeA.Out(i).Size() != typeB.Out(i).Size() { 27 panic(fmt.Sprintf("func signature mismatch, returns %d's size must:%d, actual:%d", 28 i, typeA.Out(i).Size(), typeB.Out(i).Size())) 29 } 30 } 31 return true 32 }