Commit 15588342 authored by Jeff R. Allen's avatar Jeff R. Allen Committed by Russ Cox

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
parent f8e9936d
...@@ -54,7 +54,6 @@ typedef struct Hist Hist; ...@@ -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)
......
...@@ -276,7 +276,6 @@ enum ...@@ -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,
......
...@@ -57,7 +57,6 @@ typedef struct Gen2 Gen2; ...@@ -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)
......
...@@ -196,7 +196,6 @@ enum ...@@ -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,
......
...@@ -57,7 +57,6 @@ typedef struct Gen2 Gen2; ...@@ -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)
......
...@@ -190,7 +190,6 @@ enum ...@@ -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,
......
...@@ -59,7 +59,6 @@ typedef struct Bits Bits; ...@@ -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
......
...@@ -399,6 +399,7 @@ dpcheck(Node *n) ...@@ -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) {
......
...@@ -88,47 +88,32 @@ pragincomplete(void) ...@@ -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; if(d > 0)
hunk += on; memset((char*)p+n, 0, d);
nhunk -= on;
}
hunk += n;
nhunk -= n;
return p; return p;
} }
......
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