diff options
author | Russ Cox <rsc@golang.org> | 2009-09-08 13:46:54 -0700 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2009-09-08 13:46:54 -0700 |
commit | 9b77762e7765cf1e5b5357410396ddf2dcc96e59 (patch) | |
tree | 4b7b1227894395359f68eb5d6e0446f9026cd266 /src/pkg/runtime | |
parent | c9b70e10625f65d03013eb3f7141dea370335d8a (diff) | |
download | golang-9b77762e7765cf1e5b5357410396ddf2dcc96e59.tar.gz |
pass Type* to makechan and makemap so that
they can get the official alignment out of there
instead of guessing.
R=ken
OCL=34450
CL=34450
Diffstat (limited to 'src/pkg/runtime')
-rw-r--r-- | src/pkg/runtime/chan.c | 27 | ||||
-rw-r--r-- | src/pkg/runtime/hashmap.c | 32 | ||||
-rw-r--r-- | src/pkg/runtime/reflect.cgo | 4 | ||||
-rw-r--r-- | src/pkg/runtime/runtime.h | 4 |
4 files changed, 36 insertions, 31 deletions
diff --git a/src/pkg/runtime/chan.c b/src/pkg/runtime/chan.c index 46cf18a18..7611023be 100644 --- a/src/pkg/runtime/chan.c +++ b/src/pkg/runtime/chan.c @@ -3,6 +3,7 @@ // license that can be found in the LICENSE file. #include "runtime.h" +#include "type.h" static int32 debug = 0; static Lock chanlock; @@ -43,6 +44,7 @@ struct Hchan uint32 dataqsiz; // size of the circular q uint16 elemsize; uint16 closed; // Wclosed Rclosed errorcount + uint8 elemalign; Alg* elemalg; // interface for element type Link* senddataq; // pointer for sender Link* recvdataq; // pointer for receiver @@ -88,20 +90,21 @@ static uint32 fastrand1(void); static uint32 fastrand2(void); Hchan* -makechan(uint32 elemsize, uint32 elemalg, uint32 hint) +makechan(Type *elem, uint32 hint) { Hchan *c; int32 i; - if(elemalg >= nelem(algarray)) { - printf("chan(alg=%d)\n", elemalg); + if(elem->alg >= nelem(algarray)) { + printf("chan(alg=%d)\n", elem->alg); throw("sys·makechan: unsupported elem type"); } c = mal(sizeof(*c)); - c->elemsize = elemsize; - c->elemalg = &algarray[elemalg]; + c->elemsize = elem->size; + c->elemalg = &algarray[elem->alg]; + c->elemalign = elem->align; if(hint > 0) { Link *d, *b, *e; @@ -127,9 +130,11 @@ makechan(uint32 elemsize, uint32 elemalg, uint32 hint) prints("makechan: chan="); sys·printpointer(c); prints("; elemsize="); - sys·printint(elemsize); + sys·printint(elem->size); prints("; elemalg="); - sys·printint(elemalg); + sys·printint(elem->alg); + prints("; elemalign="); + sys·printint(elem->align); prints("; dataqsiz="); sys·printint(c->dataqsiz); prints("\n"); @@ -140,9 +145,9 @@ makechan(uint32 elemsize, uint32 elemalg, uint32 hint) // makechan(elemsize uint32, elemalg uint32, hint uint32) (hchan *chan any); void -sys·makechan(uint32 elemsize, uint32 elemalg, uint32 hint, Hchan *ret) +sys·makechan(Type *elem, uint32 hint, Hchan *ret) { - ret = makechan(elemsize, elemalg, hint); + ret = makechan(elem, hint); FLUSH(&ret); } @@ -379,7 +384,7 @@ sys·chansend1(Hchan* c, ...) int32 o; byte *ae; - o = rnd(sizeof(c), c->elemsize); + o = rnd(sizeof(c), c->elemalign); ae = (byte*)&c + o; chansend(c, ae, nil); } @@ -391,7 +396,7 @@ sys·chansend2(Hchan* c, ...) int32 o; byte *ae, *ap; - o = rnd(sizeof(c), c->elemsize); + o = rnd(sizeof(c), c->elemalign); ae = (byte*)&c + o; o = rnd(o+c->elemsize, Structrnd); ap = (byte*)&c + o; diff --git a/src/pkg/runtime/hashmap.c b/src/pkg/runtime/hashmap.c index 8c642d9d4..b95941414 100644 --- a/src/pkg/runtime/hashmap.c +++ b/src/pkg/runtime/hashmap.c @@ -4,6 +4,7 @@ #include "runtime.h" #include "hashmap.h" +#include "type.h" /* Return a pointer to the struct/union of type "type" whose "field" field is addressed by pointer "p". */ @@ -664,14 +665,17 @@ donothing(uint32 s, void *a, void *b) static int32 debug = 0; -// makemap(keysize uint32, valsize uint32, -// keyalg uint32, valalg uint32, -// hint uint32) (hmap *map[any]any); +// makemap(key, val *Type, hint uint32) (hmap *map[any]any); Hmap* -makemap(uint32 keysize, uint32 valsize, - uint32 keyalg, uint32 valalg, uint32 hint) +makemap(Type *key, Type *val, uint32 hint) { Hmap *h; + int32 keyalg, valalg, keysize, valsize; + + keyalg = key->alg; + valalg = val->alg; + keysize = key->size; + valsize = val->size; if(keyalg >= nelem(algarray) || algarray[keyalg].hash == nohash) { printf("map(keyalg=%d)\n", keyalg); @@ -707,16 +711,16 @@ makemap(uint32 keysize, uint32 valsize, // func() (key, val) h->ko0 = rnd(sizeof(h), Structrnd); - h->vo0 = rnd(h->ko0+keysize, valsize); + h->vo0 = rnd(h->ko0+keysize, val->align); // func(key) (val[, pres]) - h->ko1 = rnd(sizeof(h), keysize); + h->ko1 = rnd(sizeof(h), key->align); h->vo1 = rnd(h->ko1+keysize, Structrnd); h->po1 = rnd(h->vo1+valsize, 1); // func(key, val[, pres]) - h->ko2 = rnd(sizeof(h), keysize); - h->vo2 = rnd(h->ko2+keysize, valsize); + h->ko2 = rnd(sizeof(h), key->align); + h->vo2 = rnd(h->ko2+keysize, val->align); h->po2 = rnd(h->vo2+valsize, 1); if(debug) { @@ -727,15 +731,11 @@ makemap(uint32 keysize, uint32 valsize, return h; } -// makemap(keysize uint32, valsize uint32, -// keyalg uint32, valalg uint32, -// hint uint32) (hmap *map[any]any); +// makemap(key, val *Type, hint uint32) (hmap *map[any]any); void -sys·makemap(uint32 keysize, uint32 valsize, - uint32 keyalg, uint32 valalg, uint32 hint, - Hmap *ret) +sys·makemap(Type *key, Type *val, uint32 hint, Hmap *ret) { - ret = makemap(keysize, valsize, keyalg, valalg, hint); + ret = makemap(key, val, hint); FLUSH(&ret); } diff --git a/src/pkg/runtime/reflect.cgo b/src/pkg/runtime/reflect.cgo index 7406e9bc3..8bef070c5 100644 --- a/src/pkg/runtime/reflect.cgo +++ b/src/pkg/runtime/reflect.cgo @@ -52,7 +52,7 @@ func makemap(typ *byte) (map *byte) { MapType *t; t = (MapType*)gettype(typ); - map = (byte*)makemap(t->key->size, t->elem->size, t->key->alg, t->elem->alg, 0); + map = (byte*)makemap(t->key, t->elem, 0); } /* @@ -67,7 +67,7 @@ func makechan(typ *byte, size uint32) (ch *byte) { // in front of the raw ChanType. the -2 below backs up // to the interface value header. t = (ChanType*)gettype(typ); - ch = (byte*)makechan(t->elem->size, t->elem->alg, size); + ch = (byte*)makechan(t->elem, size); } func chansend(ch *byte, val *byte, pres *bool) { diff --git a/src/pkg/runtime/runtime.h b/src/pkg/runtime/runtime.h index d4936afa3..58839f97f 100644 --- a/src/pkg/runtime/runtime.h +++ b/src/pkg/runtime/runtime.h @@ -486,9 +486,9 @@ struct hash_iter* mapiterinit(Hmap*); void mapiternext(struct hash_iter*); bool mapiterkey(struct hash_iter*, void*); void mapiterkeyvalue(struct hash_iter*, void*, void*); -Hmap* makemap(uint32, uint32, uint32, uint32, uint32); +Hmap* makemap(Type*, Type*, uint32); -Hchan* makechan(uint32, uint32, uint32); +Hchan* makechan(Type*, uint32); void chansend(Hchan*, void*, bool*); void chanrecv(Hchan*, void*, bool*); void chanclose(Hchan*); |