Commit a52fb815 authored by Russ Cox's avatar Russ Cox

386-related fixes and guards

R=r
DELTA=44  (19 added, 1 deleted, 24 changed)
OCL=29912
CL=29915
parent 6739b8d6
...@@ -91,8 +91,8 @@ const ( ...@@ -91,8 +91,8 @@ const (
interfacesize = unsafe.Sizeof(x.xinterface); interfacesize = unsafe.Sizeof(x.xinterface);
) )
var missingString = "$missing$" // syntactic name for undefined type names const missingString = "$missing$" // syntactic name for undefined type names
var dotDotDotString = "..." const dotDotDotString = "..."
// Type is the generic interface to reflection types. Once its Kind is known, // Type is the generic interface to reflection types. Once its Kind is known,
// such as ArrayKind, the Type can be narrowed to the appropriate, more // such as ArrayKind, the Type can be narrowed to the appropriate, more
......
...@@ -61,7 +61,7 @@ func (c *commonValue) Interface() interface {} { ...@@ -61,7 +61,7 @@ func (c *commonValue) Interface() interface {} {
switch { switch {
case c.typ.Kind() == InterfaceKind: case c.typ.Kind() == InterfaceKind:
panic("not reached"); // InterfaceValue overrides this method panic("not reached"); // InterfaceValue overrides this method
case c.typ.Size() > 8: // TODO(rsc): how do we know it is 8? case c.typ.Size() > unsafe.Sizeof(uintptr(0)):
i = unsafe.Unreflect(uint64(uintptr(c.addr)), c.typ.String(), true); i = unsafe.Unreflect(uint64(uintptr(c.addr)), c.typ.String(), true);
default: default:
if uintptr(c.addr) == 0 { if uintptr(c.addr) == 0 {
...@@ -872,7 +872,7 @@ var typecache = make(map[string] Type); ...@@ -872,7 +872,7 @@ var typecache = make(map[string] Type);
func newValueAddr(typ Type, addr Addr) Value { func newValueAddr(typ Type, addr Addr) Value {
c, ok := creator[typ.Kind()]; c, ok := creator[typ.Kind()];
if !ok { if !ok {
panicln("no creator for type" , typ.Kind()); panicln("no creator for type" , typ.String());
} }
return c(typ, addr); return c(typ, addr);
} }
...@@ -945,9 +945,16 @@ func NewValue(e interface {}) Value { ...@@ -945,9 +945,16 @@ func NewValue(e interface {}) Value {
typ, ok := typecache[typestring]; typ, ok := typecache[typestring];
if !ok { if !ok {
typ = ParseTypeString("", typestring); typ = ParseTypeString("", typestring);
if typ.Kind() == MissingKind {
// This can not happen: unsafe.Reflect should only
// ever tell us the names of types that exist.
// Of course it does happen, and when it does
// it is more helpful to catch it in action here than
// to see $missing$ in a later print.
panicln("missing type for", typestring);
}
typecache[typestring] = typ; typecache[typestring] = typ;
} }
var ap Addr; var ap Addr;
if indir { if indir {
// Content of interface is large and didn't // Content of interface is large and didn't
......
...@@ -116,7 +116,7 @@ TEXT gosave(SB), 7, $0 ...@@ -116,7 +116,7 @@ TEXT gosave(SB), 7, $0
// save AX, jmp to lesstack to switch back // save AX, jmp to lesstack to switch back
TEXT retfromnewstack(SB),7,$0 TEXT retfromnewstack(SB),7,$0
MOVL 4(FS), BX // m MOVL 4(FS), BX // m
MOVL AX, 8(BX) // save AX in m->cret MOVL AX, 12(BX) // save AX in m->cret
JMP lessstack(SB) JMP lessstack(SB)
// gogo, returning 2nd arg instead of 1 // gogo, returning 2nd arg instead of 1
......
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
} else { } else {
printf ("not found in table\n"); printf ("not found in table\n");
} }
Example iteration over the elements of *h: Example iteration over the elements of *h:
char **data; char **data;
struct hash_iter it; struct hash_iter it;
...@@ -76,7 +76,7 @@ struct hash; /* opaque */ ...@@ -76,7 +76,7 @@ struct hash; /* opaque */
struct hash_subtable; /* opaque */ struct hash_subtable; /* opaque */
struct hash_entry; /* opaque */ struct hash_entry; /* opaque */
typedef uint64 uintptr_t; typedef uintptr uintptr_t;
typedef uintptr_t hash_hash_t; typedef uintptr_t hash_hash_t;
struct hash_iter { struct hash_iter {
...@@ -96,7 +96,7 @@ struct hash_iter { ...@@ -96,7 +96,7 @@ struct hash_iter {
}; };
/* Return a hashtable h 2**init_power empty entries, each with /* Return a hashtable h 2**init_power empty entries, each with
"datasize" data bytes. "datasize" data bytes.
(*data_hash)(a) should return the hash value of data element *a. (*data_hash)(a) should return the hash value of data element *a.
(*data_eq)(a,b) should return whether the data at "a" and the data at "b" (*data_eq)(a,b) should return whether the data at "a" and the data at "b"
are equal. are equal.
......
...@@ -542,7 +542,7 @@ sys·ifaceE2I2(Sigi *si, Eface e, Iface ret, bool ok) ...@@ -542,7 +542,7 @@ sys·ifaceE2I2(Sigi *si, Eface e, Iface ret, bool ok)
FLUSH(&ok); FLUSH(&ok);
} }
static uint64 static uintptr
ifacehash1(void *data, Sigt *sigt) ifacehash1(void *data, Sigt *sigt)
{ {
int32 alg, wid; int32 alg, wid;
...@@ -565,7 +565,7 @@ ifacehash1(void *data, Sigt *sigt) ...@@ -565,7 +565,7 @@ ifacehash1(void *data, Sigt *sigt)
return algarray[alg].hash(wid, data); return algarray[alg].hash(wid, data);
} }
uint64 uintptr
ifacehash(Iface a) ifacehash(Iface a)
{ {
if(a.type == nil) if(a.type == nil)
...@@ -573,7 +573,7 @@ ifacehash(Iface a) ...@@ -573,7 +573,7 @@ ifacehash(Iface a)
return ifacehash1(a.data, a.type->sigt); return ifacehash1(a.data, a.type->sigt);
} }
uint64 uintptr
efacehash(Eface a) efacehash(Eface a)
{ {
return ifacehash1(a.data, a.type); return ifacehash1(a.data, a.type);
......
...@@ -58,7 +58,10 @@ malloc(uintptr size) ...@@ -58,7 +58,10 @@ malloc(uintptr size)
} }
// setup for mark sweep // setup for mark sweep
mlookup(v, nil, nil, &ref); if(!mlookup(v, nil, nil, &ref)) {
printf("malloc %D; mlookup failed\n", (uint64)size);
throw("malloc mlookup");
}
*ref = RefNone; *ref = RefNone;
m->mallocing = 0; m->mallocing = 0;
...@@ -93,7 +96,8 @@ free(void *v) ...@@ -93,7 +96,8 @@ free(void *v)
throw("malloc/free - deadlock"); throw("malloc/free - deadlock");
m->mallocing = 1; m->mallocing = 1;
mlookup(v, nil, nil, &ref); if(!mlookup(v, nil, nil, &ref))
throw("free mlookup");
*ref = RefFree; *ref = RefFree;
// Find size class for v. // Find size class for v.
...@@ -283,7 +287,8 @@ stackalloc(uint32 n) ...@@ -283,7 +287,8 @@ stackalloc(uint32 n)
return v; return v;
} }
v = malloc(n); v = malloc(n);
mlookup(v, nil, nil, &ref); if(!mlookup(v, nil, nil, &ref))
throw("stackalloc mlookup");
*ref = RefStack; *ref = RefStack;
return v; return v;
} }
......
...@@ -267,16 +267,22 @@ check(void) ...@@ -267,16 +267,22 @@ check(void)
* map and chan helpers for * map and chan helpers for
* dealing with unknown types * dealing with unknown types
*/ */
static uint64 static uintptr
memhash(uint32 s, void *a) memhash(uint32 s, void *a)
{ {
byte *b; byte *b;
uint64 hash; uintptr hash;
b = a; b = a;
hash = 33054211828000289ULL; if(sizeof(hash) == 4)
hash = 2860486313U;
else
hash = 33054211828000289ULL;
while(s > 0) { while(s > 0) {
hash = (hash ^ *b) * 23344194077549503ULL; if(sizeof(hash) == 4)
hash = (hash ^ *b) * 3267000013UL;
else
hash = (hash ^ *b) * 23344194077549503ULL;
b++; b++;
s--; s--;
} }
...@@ -337,7 +343,7 @@ memcopy(uint32 s, void *a, void *b) ...@@ -337,7 +343,7 @@ memcopy(uint32 s, void *a, void *b)
ba[i] = bb[i]; ba[i] = bb[i];
} }
static uint64 static uintptr
strhash(uint32 s, String *a) strhash(uint32 s, String *a)
{ {
USED(s); USED(s);
...@@ -358,7 +364,7 @@ strprint(uint32 s, String *a) ...@@ -358,7 +364,7 @@ strprint(uint32 s, String *a)
sys·printstring(*a); sys·printstring(*a);
} }
static uint64 static uintptr
interhash(uint32 s, Iface *a) interhash(uint32 s, Iface *a)
{ {
USED(s); USED(s);
...@@ -379,7 +385,7 @@ interequal(uint32 s, Iface *a, Iface *b) ...@@ -379,7 +385,7 @@ interequal(uint32 s, Iface *a, Iface *b)
return ifaceeq(*a, *b); return ifaceeq(*a, *b);
} }
static uint64 static uintptr
nilinterhash(uint32 s, Eface *a) nilinterhash(uint32 s, Eface *a)
{ {
USED(s); USED(s);
...@@ -400,7 +406,7 @@ nilinterequal(uint32 s, Eface *a, Eface *b) ...@@ -400,7 +406,7 @@ nilinterequal(uint32 s, Eface *a, Eface *b)
return efaceeq(*a, *b); return efaceeq(*a, *b);
} }
uint64 uintptr
nohash(uint32 s, void *a) nohash(uint32 s, void *a)
{ {
USED(s); USED(s);
......
...@@ -194,7 +194,7 @@ struct Stktop ...@@ -194,7 +194,7 @@ struct Stktop
}; };
struct Alg struct Alg
{ {
uint64 (*hash)(uint32, void*); uintptr (*hash)(uint32, void*);
uint32 (*equal)(uint32, void*, void*); uint32 (*equal)(uint32, void*, void*);
void (*print)(uint32, void*); void (*print)(uint32, void*);
void (*copy)(uint32, void*, void*); void (*copy)(uint32, void*, void*);
...@@ -333,9 +333,9 @@ MCache* allocmcache(void); ...@@ -333,9 +333,9 @@ MCache* allocmcache(void);
void mallocinit(void); void mallocinit(void);
bool ifaceeq(Iface, Iface); bool ifaceeq(Iface, Iface);
bool efaceeq(Eface, Eface); bool efaceeq(Eface, Eface);
uint64 ifacehash(Iface); uintptr ifacehash(Iface);
uint64 efacehash(Eface); uintptr efacehash(Eface);
uint64 nohash(uint32, void*); uintptr nohash(uint32, void*);
uint32 noequal(uint32, void*, void*); uint32 noequal(uint32, void*, void*);
void* malloc(uintptr size); void* malloc(uintptr size);
void* mallocgc(uintptr size); void* mallocgc(uintptr size);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment