diff options
Diffstat (limited to 'src/pkg')
| -rw-r--r-- | src/pkg/reflect/value.go | 12 | ||||
| -rw-r--r-- | src/pkg/runtime/debug.go | 11 | ||||
| -rw-r--r-- | src/pkg/runtime/hashmap.h | 1 | ||||
| -rw-r--r-- | src/pkg/runtime/malloc.goc | 2 | ||||
| -rw-r--r-- | src/pkg/runtime/runtime.c | 11 | ||||
| -rw-r--r-- | src/pkg/runtime/runtime.h | 1 |
6 files changed, 29 insertions, 9 deletions
diff --git a/src/pkg/reflect/value.go b/src/pkg/reflect/value.go index a80112d342..8b2c1a9530 100644 --- a/src/pkg/reflect/value.go +++ b/src/pkg/reflect/value.go @@ -730,8 +730,6 @@ type tiny struct { // Call calls the function fv with input parameters in. // It returns the function's output parameters as Values. func (fv *FuncValue) Call(in []Value) []Value { - var structAlign = Typeof((*tiny)(nil)).(*PtrType).Elem().Size() - t := fv.Type().(*FuncType) nin := len(in) if fv.first != nil && !fv.isInterface { @@ -757,7 +755,7 @@ func (fv *FuncValue) Call(in []Value) []Value { size = (size + a - 1) &^ (a - 1) size += tv.Size() } - size = (size + structAlign - 1) &^ (structAlign - 1) + size = (size + ptrSize - 1) &^ (ptrSize - 1) for i := 0; i < nout; i++ { tv := t.Out(i) a := uintptr(tv.Align()) @@ -767,9 +765,9 @@ func (fv *FuncValue) Call(in []Value) []Value { // size must be > 0 in order for &args[0] to be valid. // the argument copying is going to round it up to - // a multiple of 8 anyway, so make it 8 to begin with. - if size < 8 { - size = 8 + // a multiple of ptrSize anyway, so make it ptrSize to begin with. + if size < ptrSize { + size = ptrSize } // round to pointer size @@ -811,7 +809,7 @@ func (fv *FuncValue) Call(in []Value) []Value { memmove(addr(ptr+off), v.getAddr(), n) off += n } - off = (off + structAlign - 1) &^ (structAlign - 1) + off = (off + ptrSize - 1) &^ (ptrSize - 1) // Call call(*(**byte)(fv.addr), (*byte)(addr(ptr)), uint32(size)) diff --git a/src/pkg/runtime/debug.go b/src/pkg/runtime/debug.go index 3cc5472f6b..3ce35cc5ba 100644 --- a/src/pkg/runtime/debug.go +++ b/src/pkg/runtime/debug.go @@ -4,6 +4,8 @@ package runtime +import "unsafe" + // Breakpoint() executes a breakpoint trap. func Breakpoint() @@ -73,6 +75,15 @@ type MemStatsType struct { } } +var sizeof_C_MStats int // filled in by malloc.goc + +func init() { + if sizeof_C_MStats != unsafe.Sizeof(MemStats) { + println(sizeof_C_MStats, unsafe.Sizeof(MemStats)) + panic("MStats vs MemStatsType size mismatch") + } +} + // MemStats holds statistics about the memory system. // The statistics are only approximate, as they are not interlocked on update. var MemStats MemStatsType diff --git a/src/pkg/runtime/hashmap.h b/src/pkg/runtime/hashmap.h index 40dac6e9bd..0737535b55 100644 --- a/src/pkg/runtime/hashmap.h +++ b/src/pkg/runtime/hashmap.h @@ -64,7 +64,6 @@ */ #define malloc runtime·mal -#define offsetof(s,m) (uint32)(&(((s*)0)->m)) #define memset(a,b,c) runtime·memclr((byte*)(a), (uint32)(c)) #define memcpy(a,b,c) runtime·mcpy((byte*)(a),(byte*)(b),(uint32)(c)) #define assert(a) if(!(a)) runtime·throw("assert") diff --git a/src/pkg/runtime/malloc.goc b/src/pkg/runtime/malloc.goc index 405b05ee96..f5ca9f9183 100644 --- a/src/pkg/runtime/malloc.goc +++ b/src/pkg/runtime/malloc.goc @@ -244,6 +244,8 @@ runtime·allocmcache(void) return c; } +int32 runtime·sizeof_C_MStats = sizeof(MStats); + void runtime·mallocinit(void) { diff --git a/src/pkg/runtime/runtime.c b/src/pkg/runtime/runtime.c index f2b6c587e9..a2e31d806f 100644 --- a/src/pkg/runtime/runtime.c +++ b/src/pkg/runtime/runtime.c @@ -258,6 +258,13 @@ runtime·check(void) float64 j; void* k; uint16* l; + struct x1 { + byte x; + }; + struct y1 { + struct x1 x1; + byte y; + }; if(sizeof(a) != 1) runtime·throw("bad a"); if(sizeof(b) != 1) runtime·throw("bad b"); @@ -271,7 +278,9 @@ runtime·check(void) if(sizeof(j) != 8) runtime·throw("bad j"); if(sizeof(k) != sizeof(uintptr)) runtime·throw("bad k"); if(sizeof(l) != sizeof(uintptr)) runtime·throw("bad l"); -// prints(1"check ok\n"); + if(sizeof(struct x1) != 1) runtime·throw("bad sizeof x1"); + if(offsetof(struct y1, y) != 1) runtime·throw("bad offsetof y1.y"); + if(sizeof(struct y1) != 2) runtime·throw("bad sizeof y1"); uint32 z; z = 1; diff --git a/src/pkg/runtime/runtime.h b/src/pkg/runtime/runtime.h index b0fa3891e6..37c8103f34 100644 --- a/src/pkg/runtime/runtime.h +++ b/src/pkg/runtime/runtime.h @@ -306,6 +306,7 @@ enum { */ #define nelem(x) (sizeof(x)/sizeof((x)[0])) #define nil ((void*)0) +#define offsetof(s,m) (uint32)(&(((s*)0)->m)) /* * known to compiler |
