1
0
mirror of https://github.com/golang/go synced 2024-11-21 21:54: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:
Jeff R. Allen 2011-01-19 15:30:26 -05:00 committed by Russ Cox
parent f8e9936d87
commit 1558834248
9 changed files with 15 additions and 36 deletions

View File

@ -54,7 +54,6 @@ typedef struct Hist Hist;
#define NSYMB 8192 #define NSYMB 8192
#define BUFSIZ 8192 #define BUFSIZ 8192
#define HISTSZ 20 #define HISTSZ 20
#define NHUNK 10000
#define EOF (-1) #define EOF (-1)
#define IGN (-2) #define IGN (-2)
#define GETC() ((--fi.c < 0)? filbuf(): *fi.p++ & 0xff) #define GETC() ((--fi.c < 0)? filbuf(): *fi.p++ & 0xff)

View File

@ -276,7 +276,6 @@ enum
STRINGSZ = 200, STRINGSZ = 200,
NHASH = 10007, NHASH = 10007,
NHUNK = 100000,
MINSIZ = 64, MINSIZ = 64,
NENT = 100, NENT = 100,
MAXIO = 8192, MAXIO = 8192,

View File

@ -57,7 +57,6 @@ typedef struct Gen2 Gen2;
#define NSYMB 500 #define NSYMB 500
#define BUFSIZ 8192 #define BUFSIZ 8192
#define HISTSZ 20 #define HISTSZ 20
#define NHUNK 10000
#define EOF (-1) #define EOF (-1)
#define IGN (-2) #define IGN (-2)
#define GETC() ((--fi.c < 0)? filbuf(): *fi.p++ & 0xff) #define GETC() ((--fi.c < 0)? filbuf(): *fi.p++ & 0xff)

View File

@ -196,7 +196,6 @@ enum
SSUB = 1<<8, SSUB = 1<<8,
NHASH = 10007, NHASH = 10007,
NHUNK = 100000,
MINSIZ = 8, MINSIZ = 8,
STRINGSZ = 200, STRINGSZ = 200,
MINLC = 1, MINLC = 1,

View File

@ -57,7 +57,6 @@ typedef struct Gen2 Gen2;
#define NSYMB 500 #define NSYMB 500
#define BUFSIZ 8192 #define BUFSIZ 8192
#define HISTSZ 20 #define HISTSZ 20
#define NHUNK 10000
#define EOF (-1) #define EOF (-1)
#define IGN (-2) #define IGN (-2)
#define GETC() ((--fi.c < 0)? filbuf(): *fi.p++ & 0xff) #define GETC() ((--fi.c < 0)? filbuf(): *fi.p++ & 0xff)

View File

@ -190,7 +190,6 @@ enum
SSUB = 1<<8, /* sub-symbol, linked from parent via ->sub list */ SSUB = 1<<8, /* sub-symbol, linked from parent via ->sub list */
NHASH = 10007, NHASH = 10007,
NHUNK = 100000,
MINSIZ = 4, MINSIZ = 4,
STRINGSZ = 200, STRINGSZ = 200,
MINLC = 1, MINLC = 1,

View File

@ -59,7 +59,6 @@ typedef struct Bits Bits;
typedef struct Dynimp Dynimp; typedef struct Dynimp Dynimp;
typedef struct Dynexp Dynexp; typedef struct Dynexp Dynexp;
#define NHUNK 50000L
#define BUFSIZ 8192 #define BUFSIZ 8192
#define NSYMB 500 #define NSYMB 500
#define NHASH 1024 #define NHASH 1024

View File

@ -399,6 +399,7 @@ dpcheck(Node *n)
return; return;
i = l->param; i = l->param;
a = nil;
b = n->right; b = n->right;
a = Z; a = Z;
while(i > 0) { while(i > 0) {

View File

@ -88,47 +88,32 @@ pragincomplete(void)
; ;
} }
void
gethunk(void)
{
hunk = malloc(NHUNK);
memset(hunk, 0, NHUNK);
nhunk = NHUNK;
}
void* void*
alloc(int32 n) alloc(int32 n)
{ {
void *p; void *p;
while((uintptr)hunk & MAXALIGN) { p = malloc(n);
hunk++; if(p == nil) {
nhunk--; print("alloc out of mem\n");
exit(1);
} }
while(nhunk < n) memset(p, 0, n);
gethunk();
p = hunk;
nhunk -= n;
hunk += n;
return p; return p;
} }
void* void*
allocn(void *p, int32 on, int32 n) allocn(void *p, int32 n, int32 d)
{ {
void *q; if(p == nil)
return alloc(n+d);
q = (uchar*)p + on; p = realloc(p, n+d);
if(q != hunk || nhunk < n) { if(p == nil) {
while(nhunk < on+n) print("allocn out of mem\n");
gethunk(); exit(1);
memmove(hunk, p, on);
p = hunk;
hunk += on;
nhunk -= on;
} }
hunk += n; if(d > 0)
nhunk -= n; memset((char*)p+n, 0, d);
return p; return p;
} }