mirror of
https://github.com/golang/go
synced 2024-11-19 15:05:00 -07:00
fix segfault printing errors. add test case and improve messages.
Fixes #338. R=rsc CC=golang-dev https://golang.org/cl/163083
This commit is contained in:
parent
f6c0eba741
commit
114f73f822
@ -214,28 +214,28 @@ func (server *serverType) register(rcvr interface{}) os.Error {
|
|||||||
}
|
}
|
||||||
argType, ok := mtype.In(1).(*reflect.PtrType);
|
argType, ok := mtype.In(1).(*reflect.PtrType);
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Stderr(mname, "arg type not a pointer:", argType.String());
|
log.Stderr(mname, "arg type not a pointer:", mtype.In(1));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if _, ok := argType.Elem().(*reflect.StructType); !ok {
|
if _, ok := argType.Elem().(*reflect.StructType); !ok {
|
||||||
log.Stderr(mname, "arg type not a pointer to a struct:", argType.String());
|
log.Stderr(mname, "arg type not a pointer to a struct:", argType);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
replyType, ok := mtype.In(2).(*reflect.PtrType);
|
replyType, ok := mtype.In(2).(*reflect.PtrType);
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Stderr(mname, "reply type not a pointer:", replyType.String());
|
log.Stderr(mname, "reply type not a pointer:", mtype.In(2));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if _, ok := replyType.Elem().(*reflect.StructType); !ok {
|
if _, ok := replyType.Elem().(*reflect.StructType); !ok {
|
||||||
log.Stderr(mname, "reply type not a pointer to a struct:", replyType.String());
|
log.Stderr(mname, "reply type not a pointer to a struct:", replyType);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if !isPublic(argType.Elem().Name()) {
|
if !isPublic(argType.Elem().Name()) {
|
||||||
log.Stderr(mname, "argument type not public:", argType.String());
|
log.Stderr(mname, "argument type not public:", argType);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if !isPublic(replyType.Elem().Name()) {
|
if !isPublic(replyType.Elem().Name()) {
|
||||||
log.Stderr(mname, "reply type not public:", replyType.String());
|
log.Stderr(mname, "reply type not public:", replyType);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Method needs one out: os.Error.
|
// Method needs one out: os.Error.
|
||||||
|
@ -216,3 +216,38 @@ func TestCheckBadType(t *testing.T) {
|
|||||||
t.Error("expected error about type; got", err)
|
t.Error("expected error about type; got", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Bad int
|
||||||
|
type local struct{}
|
||||||
|
|
||||||
|
func (t *Bad) ArgNotPointer(args Args, reply *Reply) os.Error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Bad) ArgNotPointerToStruct(args *int, reply *Reply) os.Error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Bad) ReplyNotPointer(args *Args, reply Reply) os.Error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Bad) ReplyNotPointerToStruct(args *Args, reply *int) os.Error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Bad) ArgNotPublic(args *local, reply *Reply) os.Error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Bad) ReplyNotPublic(args *Args, reply *local) os.Error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check that registration handles lots of bad methods and a type with no suitable methods.
|
||||||
|
func TestRegistrationError(t *testing.T) {
|
||||||
|
err := Register(new(Bad));
|
||||||
|
if err == nil {
|
||||||
|
t.Errorf("expected error registering bad type")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user