]> Cypherpunks.ru repositories - gostls13.git/commitdiff
Move sys.Reflect and sys.Unreflect into unsafe.
authorRob Pike <r@golang.org>
Fri, 8 May 2009 21:57:56 +0000 (14:57 -0700)
committerRob Pike <r@golang.org>
Fri, 8 May 2009 21:57:56 +0000 (14:57 -0700)
R=rsc
DELTA=19  (4 added, 5 deleted, 10 changed)
OCL=28563
CL=28566

src/cmd/gc/builtin.c.boot
src/cmd/gc/sys.go
src/cmd/gc/unsafe.go
src/lib/reflect/all_test.go
src/lib/reflect/value.go
src/runtime/iface.c
test/convert.go

index d935fc564fd633247e7e526ec02371dcdf990794..0f189d36340501b56d00511ad92c8ecc77ec65f7 100644 (file)
@@ -56,8 +56,6 @@ char *sysimport =
        "func sys.arrays2d (old *any, nel int) (ary []any)\n"
        "func sys.closure ()\n"
        "func sys.Breakpoint ()\n"
-       "func sys.Reflect (i interface { }) (? uint64, ? string, ? bool)\n"
-       "func sys.Unreflect (? uint64, ? string, ? bool) (ret interface { })\n"
        "var sys.Args []string\n"
        "var sys.Envs []string\n"
        "func sys.Gosched ()\n"
@@ -72,5 +70,7 @@ char *unsafeimport =
        "func unsafe.Offsetof (? any) (? int)\n"
        "func unsafe.Sizeof (? any) (? int)\n"
        "func unsafe.Alignof (? any) (? int)\n"
+       "func unsafe.Reflect (i interface { }) (? uint64, ? string, ? bool)\n"
+       "func unsafe.Unreflect (? uint64, ? string, ? bool) (ret interface { })\n"
        "\n"
        "$$\n";
index 9c2bc4d04fcf8fbebf78265cd96f0c77b10f1e34..f77771a09dea10b35a42aaf125fe427007bf0bfc 100644 (file)
@@ -77,9 +77,6 @@ func  closure();      // has args, but compiler fills in
 
 func   Breakpoint();
 
-func   Reflect(i interface { }) (uint64, string, bool);
-func   Unreflect(uint64, string, bool) (ret interface { });
-
 var    Args []string;
 var    Envs []string;
 
index d1dcee02a83fbd6376aeb14333eed4b800936a4d..9289a9ca8e7dce5f78889cee66694660aded97a2 100644 (file)
@@ -9,3 +9,5 @@ type    Pointer *any;
 func   Offsetof(any) int;
 func   Sizeof(any) int;
 func   Alignof(any) int;
+func   Reflect(i interface { }) (uint64, string, bool);
+func   Unreflect(uint64, string, bool) (ret interface { });
index d193efde239968c1306756242d802a1148863a8f..cc61bbbf104a778c519029b3b7adce208fe0fecd 100644 (file)
@@ -314,7 +314,7 @@ func TestInterfaceValue(t *testing.T) {
 
        i3 := v2.Interface();
        if f, ok := i3.(float); !ok {
-               a, typ, c := sys.Reflect(i3);
+               a, typ, c := unsafe.Reflect(i3);
                t.Error("v2.Interface() did not return float, got ", typ);
        }
 }
index ac7ed2f84a57453a90ce457fcca2abecadeff381..c3b50ae68b21bd0ad4a2fcc9f58e8864837e1e4e 100644 (file)
@@ -62,12 +62,12 @@ func (c *commonValue) Interface() interface {} {
        case c.typ.Kind() == InterfaceKind:
                i = *(*interface{})(c.addr);
        case c.typ.Size() > 8:  // TODO(rsc): how do we know it is 8?
-               i = sys.Unreflect(uint64(uintptr(c.addr)), c.typ.String(), true);
+               i = unsafe.Unreflect(uint64(uintptr(c.addr)), c.typ.String(), true);
        default:
                if uintptr(c.addr) == 0 {
                        panicln("reflect: address 0 for", c.typ.String());
                }
-               i = sys.Unreflect(uint64(uintptr(*(*Addr)(c.addr))), c.typ.String(), false);
+               i = unsafe.Unreflect(uint64(uintptr(*(*Addr)(c.addr))), c.typ.String(), false);
        }
        return i;
 }
@@ -902,7 +902,7 @@ func copyArray(dst ArrayValue, src ArrayValue, n int) {
 
 // NewValue creates a new Value from the interface{} object provided.
 func NewValue(e interface {}) Value {
-       value, typestring, indir := sys.Reflect(e);
+       value, typestring, indir := unsafe.Reflect(e);
        typ, ok := typecache[typestring];
        if !ok {
                typ = ParseTypeString("", typestring);
index e5de5d16d7e11a33c35e92c8918f4f83e6a2d905..cad7370c5f8493f9b36f8e76c3d566dc15fc754d 100644 (file)
@@ -560,7 +560,7 @@ sys·printinter(Iface i)
 }
 
 void
-sys·Reflect(Iface i, uint64 retit, String rettype, bool retindir)
+unsafe·Reflect(Iface i, uint64 retit, String rettype, bool retindir)
 {
        int32 wid;
 
@@ -602,7 +602,7 @@ extern int32 ngotypesigs;
 // on the fake signature are:
 //
 //     (1) any interface conversion using the signature will fail
-//     (2) calling sys.Reflect() returns the args to unreflect
+//     (2) calling unsafe.Reflect() returns the args to unreflect
 //     (3) the right algorithm type is used, for == and map insertion
 //
 // (1) is ensured by the fact that we allocate a new Sigt,
@@ -757,7 +757,7 @@ findtype(String type, bool indir)
 
 
 void
-sys·Unreflect(uint64 it, String type, bool indir, Iface ret)
+unsafe·Unreflect(uint64 it, String type, bool indir, Iface ret)
 {
        Sigt *sigt;
 
@@ -767,8 +767,8 @@ sys·Unreflect(uint64 it, String type, bool indir, Iface ret)
                goto out;
 
        if(type.len > 10 && mcmp(type.str, (byte*)"interface ", 10) == 0) {
-               printf("sys.Unreflect: cannot put %S in interface\n", type);
-               throw("sys.Unreflect");
+               printf("unsafe.Unreflect: cannot put %S in interface\n", type);
+               throw("unsafe.Unreflect");
        }
 
        // if we think the type should be indirect
index 11369e52111101257b07ef452bed6c54b89e4bdb..4952e01b76c310afaf233b90b25121672a675f45 100644 (file)
@@ -9,7 +9,7 @@ package main
 import "unsafe"
 
 func typeof(x interface{}) string {
-       val, typ, indir := sys.Reflect(x);
+       val, typ, indir := unsafe.Reflect(x);
        return typ;
 }