mirror of https://github.com/golang/go.git
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
This commit is contained in:
parent
bd0c13e9f8
commit
7a0f4cac03
|
|
@ -41,7 +41,7 @@ char *sysimport =
|
|||
"func sys.efaceeq (i1 any, i2 any) (ret bool)\n"
|
||||
"func sys.ifacethash (i1 any) (ret uint32)\n"
|
||||
"func sys.efacethash (i1 any) (ret uint32)\n"
|
||||
"func sys.makemap (keysize int, valsize int, keyalg int, valalg int, hint int) (hmap map[any] any)\n"
|
||||
"func sys.makemap (key *uint8, val *uint8, hint int) (hmap map[any] any)\n"
|
||||
"func sys.mapaccess1 (hmap map[any] any, key any) (val any)\n"
|
||||
"func sys.mapaccess2 (hmap map[any] any, key any) (val any, pres bool)\n"
|
||||
"func sys.mapassign1 (hmap map[any] any, key any, val any)\n"
|
||||
|
|
@ -50,7 +50,7 @@ char *sysimport =
|
|||
"func sys.mapiternext (hiter *any)\n"
|
||||
"func sys.mapiter1 (hiter *any) (key any)\n"
|
||||
"func sys.mapiter2 (hiter *any) (key any, val any)\n"
|
||||
"func sys.makechan (elemsize int, elemalg int, hint int) (hchan chan any)\n"
|
||||
"func sys.makechan (elem *uint8, hint int) (hchan chan any)\n"
|
||||
"func sys.chanrecv1 (hchan <-chan any) (elem any)\n"
|
||||
"func sys.chanrecv2 (hchan <-chan any) (elem any, pres bool)\n"
|
||||
"func sys.chansend1 (hchan chan<- any, elem any)\n"
|
||||
|
|
|
|||
|
|
@ -51,9 +51,8 @@ func efaceeq(i1 any, i2 any) (ret bool);
|
|||
func ifacethash(i1 any) (ret uint32);
|
||||
func efacethash(i1 any) (ret uint32);
|
||||
|
||||
func makemap(keysize int, valsize int,
|
||||
keyalg int, valalg int,
|
||||
hint int) (hmap map[any]any);
|
||||
// *byte is really *runtime.Type
|
||||
func makemap(key, val *byte, hint int) (hmap map[any]any);
|
||||
func mapaccess1(hmap map[any]any, key any) (val any);
|
||||
func mapaccess2(hmap map[any]any, key any) (val any, pres bool);
|
||||
func mapassign1(hmap map[any]any, key any, val any);
|
||||
|
|
@ -63,7 +62,8 @@ func mapiternext(hiter *any);
|
|||
func mapiter1(hiter *any) (key any);
|
||||
func mapiter2(hiter *any) (key any, val any);
|
||||
|
||||
func makechan(elemsize int, elemalg int, hint int) (hchan chan any);
|
||||
// *byte is really *runtime.Type
|
||||
func makechan(elem *byte, hint int) (hchan chan any);
|
||||
func chanrecv1(hchan <-chan any) (elem any);
|
||||
func chanrecv2(hchan <-chan any) (elem any, pres bool);
|
||||
func chansend1(hchan chan<- any, elem any);
|
||||
|
|
|
|||
|
|
@ -887,8 +887,7 @@ walkexpr(Node **np, NodeList **init)
|
|||
|
||||
case OMAKECHAN:
|
||||
n = mkcall1(chanfn("makechan", 1, n->type), n->type, init,
|
||||
nodintconst(n->type->type->width),
|
||||
nodintconst(algtype(n->type->type)),
|
||||
typename(n->type->type),
|
||||
conv(n->left, types[TINT]));
|
||||
goto ret;
|
||||
|
||||
|
|
@ -900,10 +899,8 @@ walkexpr(Node **np, NodeList **init)
|
|||
argtype(fn, t->type); // any-2
|
||||
|
||||
n = mkcall1(fn, n->type, init,
|
||||
nodintconst(t->down->width), // key width
|
||||
nodintconst(t->type->width), // val width
|
||||
nodintconst(algtype(t->down)), // key algorithm
|
||||
nodintconst(algtype(t->type)), // val algorithm
|
||||
typename(t->down), // key type
|
||||
typename(t->type), // value type
|
||||
conv(n->left, types[TINT]));
|
||||
goto ret;
|
||||
|
||||
|
|
@ -2249,7 +2246,7 @@ maplit(Node *n, Node *var, NodeList **init)
|
|||
walkexpr(&a, init);
|
||||
a->dodata = 2;
|
||||
*init = list(*init, a);
|
||||
|
||||
|
||||
b++;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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*);
|
||||
|
|
|
|||
Loading…
Reference in New Issue