OLD | NEW |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 #include "runtime.h" | 5 #include "runtime.h" |
6 #include "arch_GOARCH.h" | 6 #include "arch_GOARCH.h" |
7 #include "type.h" | 7 #include "type.h" |
8 #include "typekind.h" | 8 #include "typekind.h" |
9 #include "malloc.h" | 9 #include "malloc.h" |
10 | 10 |
(...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
679 if(e.type == nil) { | 679 if(e.type == nil) { |
680 ret.type = nil; | 680 ret.type = nil; |
681 ret.data = nil; | 681 ret.data = nil; |
682 } else { | 682 } else { |
683 ret = *(Eface*)(e.type); | 683 ret = *(Eface*)(e.type); |
684 } | 684 } |
685 FLUSH(&ret); | 685 FLUSH(&ret); |
686 } | 686 } |
687 | 687 |
688 void | 688 void |
689 reflect·unsafe_New(Eface typ, void *ret) | 689 reflect·unsafe_New(Type *t, void *ret) |
690 { | 690 { |
691 Type *t; | |
692 uint32 flag; | 691 uint32 flag; |
693 | 692 |
694 // Reflect library has reinterpreted typ | |
695 // as its own kind of type structure. | |
696 // We know that the pointer to the original | |
697 // type structure sits before the data pointer. | |
698 t = (Type*)((Eface*)typ.data-1); | |
699 | |
700 flag = t->kind&KindNoPointers ? FlagNoPointers : 0; | 693 flag = t->kind&KindNoPointers ? FlagNoPointers : 0; |
701 ret = runtime·mallocgc(t->size, flag, 1, 1); | 694 ret = runtime·mallocgc(t->size, flag, 1, 1); |
702 | 695 |
703 if(UseSpanType && !flag) { | 696 if(UseSpanType && !flag) { |
704 if(false) { | 697 if(false) { |
705 runtime·printf("unsafe_New %S: %p\n", *t->string, ret); | 698 runtime·printf("unsafe_New %S: %p\n", *t->string, ret); |
706 } | 699 } |
707 runtime·settype(ret, (uintptr)t | TypeInfo_SingleObject); | 700 runtime·settype(ret, (uintptr)t | TypeInfo_SingleObject); |
708 } | 701 } |
709 | 702 |
710 FLUSH(&ret); | 703 FLUSH(&ret); |
711 } | 704 } |
712 | 705 |
713 void | 706 void |
714 reflect·unsafe_NewArray(Eface typ, intgo n, void *ret) | 707 reflect·unsafe_NewArray(Type *t, intgo n, void *ret) |
715 { | 708 { |
716 uint64 size; | 709 uint64 size; |
717 Type *t; | |
718 | |
719 // Reflect library has reinterpreted typ | |
720 // as its own kind of type structure. | |
721 // We know that the pointer to the original | |
722 // type structure sits before the data pointer. | |
723 t = (Type*)((Eface*)typ.data-1); | |
724 | 710 |
725 size = n*t->size; | 711 size = n*t->size; |
726 if(size == 0) | 712 if(size == 0) |
727 ret = (byte*)&runtime·zerobase; | 713 ret = (byte*)&runtime·zerobase; |
728 else if(t->kind&KindNoPointers) | 714 else if(t->kind&KindNoPointers) |
729 ret = runtime·mallocgc(size, FlagNoPointers, 1, 1); | 715 ret = runtime·mallocgc(size, FlagNoPointers, 1, 1); |
730 else { | 716 else { |
731 ret = runtime·mallocgc(size, 0, 1, 1); | 717 ret = runtime·mallocgc(size, 0, 1, 1); |
732 | 718 |
733 if(UseSpanType) { | 719 if(UseSpanType) { |
734 if(false) { | 720 if(false) { |
735 runtime·printf("unsafe_NewArray [%D]%S: %p\n", (
int64)n, *t->string, ret); | 721 runtime·printf("unsafe_NewArray [%D]%S: %p\n", (
int64)n, *t->string, ret); |
736 } | 722 } |
737 runtime·settype(ret, (uintptr)t | TypeInfo_Array); | 723 runtime·settype(ret, (uintptr)t | TypeInfo_Array); |
738 } | 724 } |
739 } | 725 } |
740 | 726 |
741 FLUSH(&ret); | 727 FLUSH(&ret); |
742 } | 728 } |
| 729 |
| 730 void |
| 731 reflect·typelinks(Slice ret) |
| 732 { |
| 733 extern Type *typelink[], *etypelink[]; |
| 734 static int32 first = 1; |
| 735 ret.array = (byte*)typelink; |
| 736 ret.len = etypelink - typelink; |
| 737 ret.cap = ret.len; |
| 738 FLUSH(&ret); |
| 739 } |
OLD | NEW |