"os"
"reflect"
"strings"
- "unicode"
- "utf8"
)
// state represents the state of an execution. It's not part of the
return s.evalCall(dot, function, name, args, final)
}
-// Is this an exported - upper case - name?
-func isExported(name string) bool {
- rune, _ := utf8.DecodeRuneInString(name)
- return unicode.IsUpper(rune)
-}
-
// evalField evaluates an expression like (.Field) or (.Field arg1 arg2).
// The 'final' argument represents the return value from the preceding
// value of the pipeline, if any.
// It's not a method; is it a field of a struct?
receiver, isNil := indirect(receiver)
if receiver.Kind() == reflect.Struct {
- field := receiver.FieldByName(fieldName)
- if field.IsValid() {
+ tField, ok := receiver.Type().FieldByName(fieldName)
+ if ok {
+ field := receiver.FieldByIndex(tField.Index)
if len(args) > 1 || final.IsValid() {
s.errorf("%s is not a method but has arguments", fieldName)
}
- if isExported(fieldName) { // valid and exported
+ if tField.PkgPath == "" { // field is exported
return field
}
}
return unicode.IsUpper(rune)
}
-// Is this type exported or local to this package?
-func isExportedOrLocalType(t reflect.Type) bool {
+// Is this type exported or a builtin?
+func isExportedOrBuiltinType(t reflect.Type) bool {
for t.Kind() == reflect.Ptr {
t = t.Elem()
}
- return t.PkgPath() == "" || isExported(t.Name())
+ // PkgPath will be non-empty even for an exported type,
+ // so we need to check the type name as well.
+ return isExported(t.Name()) || t.PkgPath() == ""
}
// Register publishes in the server the set of methods of the
if sname == "" {
log.Fatal("rpc: no service name for type", s.typ.String())
}
- if s.typ.PkgPath() != "" && !isExported(sname) && !useName {
+ if !isExported(sname) && !useName {
s := "rpc Register: type " + sname + " is not exported"
log.Print(s)
return os.NewError(s)
method := s.typ.Method(m)
mtype := method.Type
mname := method.Name
- if mtype.PkgPath() != "" || !isExported(mname) {
+ if method.PkgPath != "" {
continue
}
// Method needs three ins: receiver, *args, *reply.
}
// First arg need not be a pointer.
argType := mtype.In(1)
- if !isExportedOrLocalType(argType) {
+ if !isExportedOrBuiltinType(argType) {
log.Println(mname, "argument type not exported or local:", argType)
continue
}
log.Println("method", mname, "reply type not a pointer:", replyType)
continue
}
- if !isExportedOrLocalType(replyType) {
+ if !isExportedOrBuiltinType(replyType) {
log.Println("method", mname, "reply type not exported or local:", replyType)
continue
}
}
args := &Args{7, 8}
reply := new(Reply)
+ runtime.UpdateMemStats()
mallocs := 0 - runtime.MemStats.Mallocs
const count = 100
for i := 0; i < count; i++ {
t.Errorf("Add: expected %d got %d", reply.C, args.A+args.B)
}
}
+ runtime.UpdateMemStats()
mallocs += runtime.MemStats.Mallocs
return mallocs / count
}