mirror of
https://github.com/golang/go
synced 2024-11-21 21:44:40 -07:00
5a, 5l, 6a, 6l, 8a, 8l: handle out of memory, large allocations
Fixes #392. R=rsc, r2 CC=golang-dev https://golang.org/cl/2732042
This commit is contained in:
parent
f8e9936d87
commit
1558834248
@ -54,7 +54,6 @@ typedef struct Hist Hist;
|
||||
#define NSYMB 8192
|
||||
#define BUFSIZ 8192
|
||||
#define HISTSZ 20
|
||||
#define NHUNK 10000
|
||||
#define EOF (-1)
|
||||
#define IGN (-2)
|
||||
#define GETC() ((--fi.c < 0)? filbuf(): *fi.p++ & 0xff)
|
||||
|
@ -276,7 +276,6 @@ enum
|
||||
|
||||
STRINGSZ = 200,
|
||||
NHASH = 10007,
|
||||
NHUNK = 100000,
|
||||
MINSIZ = 64,
|
||||
NENT = 100,
|
||||
MAXIO = 8192,
|
||||
|
@ -57,7 +57,6 @@ typedef struct Gen2 Gen2;
|
||||
#define NSYMB 500
|
||||
#define BUFSIZ 8192
|
||||
#define HISTSZ 20
|
||||
#define NHUNK 10000
|
||||
#define EOF (-1)
|
||||
#define IGN (-2)
|
||||
#define GETC() ((--fi.c < 0)? filbuf(): *fi.p++ & 0xff)
|
||||
|
@ -196,7 +196,6 @@ enum
|
||||
SSUB = 1<<8,
|
||||
|
||||
NHASH = 10007,
|
||||
NHUNK = 100000,
|
||||
MINSIZ = 8,
|
||||
STRINGSZ = 200,
|
||||
MINLC = 1,
|
||||
|
@ -57,7 +57,6 @@ typedef struct Gen2 Gen2;
|
||||
#define NSYMB 500
|
||||
#define BUFSIZ 8192
|
||||
#define HISTSZ 20
|
||||
#define NHUNK 10000
|
||||
#define EOF (-1)
|
||||
#define IGN (-2)
|
||||
#define GETC() ((--fi.c < 0)? filbuf(): *fi.p++ & 0xff)
|
||||
|
@ -190,7 +190,6 @@ enum
|
||||
SSUB = 1<<8, /* sub-symbol, linked from parent via ->sub list */
|
||||
|
||||
NHASH = 10007,
|
||||
NHUNK = 100000,
|
||||
MINSIZ = 4,
|
||||
STRINGSZ = 200,
|
||||
MINLC = 1,
|
||||
|
@ -59,7 +59,6 @@ typedef struct Bits Bits;
|
||||
typedef struct Dynimp Dynimp;
|
||||
typedef struct Dynexp Dynexp;
|
||||
|
||||
#define NHUNK 50000L
|
||||
#define BUFSIZ 8192
|
||||
#define NSYMB 500
|
||||
#define NHASH 1024
|
||||
|
@ -399,6 +399,7 @@ dpcheck(Node *n)
|
||||
return;
|
||||
|
||||
i = l->param;
|
||||
a = nil;
|
||||
b = n->right;
|
||||
a = Z;
|
||||
while(i > 0) {
|
||||
|
@ -88,47 +88,32 @@ pragincomplete(void)
|
||||
;
|
||||
}
|
||||
|
||||
void
|
||||
gethunk(void)
|
||||
{
|
||||
hunk = malloc(NHUNK);
|
||||
memset(hunk, 0, NHUNK);
|
||||
nhunk = NHUNK;
|
||||
}
|
||||
|
||||
void*
|
||||
alloc(int32 n)
|
||||
{
|
||||
void *p;
|
||||
|
||||
while((uintptr)hunk & MAXALIGN) {
|
||||
hunk++;
|
||||
nhunk--;
|
||||
p = malloc(n);
|
||||
if(p == nil) {
|
||||
print("alloc out of mem\n");
|
||||
exit(1);
|
||||
}
|
||||
while(nhunk < n)
|
||||
gethunk();
|
||||
p = hunk;
|
||||
nhunk -= n;
|
||||
hunk += n;
|
||||
memset(p, 0, n);
|
||||
return p;
|
||||
}
|
||||
|
||||
void*
|
||||
allocn(void *p, int32 on, int32 n)
|
||||
allocn(void *p, int32 n, int32 d)
|
||||
{
|
||||
void *q;
|
||||
|
||||
q = (uchar*)p + on;
|
||||
if(q != hunk || nhunk < n) {
|
||||
while(nhunk < on+n)
|
||||
gethunk();
|
||||
memmove(hunk, p, on);
|
||||
p = hunk;
|
||||
hunk += on;
|
||||
nhunk -= on;
|
||||
if(p == nil)
|
||||
return alloc(n+d);
|
||||
p = realloc(p, n+d);
|
||||
if(p == nil) {
|
||||
print("allocn out of mem\n");
|
||||
exit(1);
|
||||
}
|
||||
hunk += n;
|
||||
nhunk -= n;
|
||||
if(d > 0)
|
||||
memset((char*)p+n, 0, d);
|
||||
return p;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user