]> Cypherpunks repositories - gostls13.git/commitdiff
5a, 5l, 6a, 6l, 8a, 8l: handle out of memory, large allocations
authorJeff R. Allen <jra@nella.org>
Wed, 19 Jan 2011 20:30:26 +0000 (15:30 -0500)
committerRuss Cox <rsc@golang.org>
Wed, 19 Jan 2011 20:30:26 +0000 (15:30 -0500)
Fixes #392.

R=rsc, r2
CC=golang-dev
https://golang.org/cl/2732042

src/cmd/5a/a.h
src/cmd/5l/l.h
src/cmd/6a/a.h
src/cmd/6l/l.h
src/cmd/8a/a.h
src/cmd/8l/l.h
src/cmd/cc/cc.h
src/cmd/cc/dpchk.c
src/cmd/cc/lexbody

index bc4f433e130454a4491b0ddd9bc91429c69da1f3..550b61dcf361be9fbb72753b9f2057a1966547e5 100644 (file)
@@ -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)
index 4e7ccea887738a0571b1901e37d0d43401d2a145..ceffac86d608c014cf1408a5fd694f005485edc5 100644 (file)
@@ -276,7 +276,6 @@ enum
 
        STRINGSZ        = 200,
        NHASH           = 10007,
-       NHUNK           = 100000,
        MINSIZ          = 64,
        NENT            = 100,
        MAXIO           = 8192,
index 9030081ca048563d28d2e85cf2ff303bb1b96a01..2d42726465e645f942249a28d39372193e76a845 100644 (file)
@@ -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)
index 1c52ea89d2748f00506863e54d3c9bed9b2009e3..d3639d0f2b886226ff5e6cfaae55068c87abf903 100644 (file)
@@ -196,7 +196,6 @@ enum
        SSUB    = 1<<8,
 
        NHASH           = 10007,
-       NHUNK           = 100000,
        MINSIZ          = 8,
        STRINGSZ        = 200,
        MINLC           = 1,
index fe6b172802eeb5890d5258063e8c52d792c27f58..3cb30f4c27a676a49294e973af189ec43d802c00 100644 (file)
@@ -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)
index daede88790b0c08e5aec16caee305014ae80be94..d85453bc3161a18ac00ea3b63386c9d07f3beae5 100644 (file)
@@ -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,
index 3649bf5f6a168cbf406660a389cac8040e24b001..bdb2269214a2328ce7de27ab1db6f3cb0377cd1b 100644 (file)
@@ -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
index 6eb5fb409cc999a8a58bdda255a9e973ae84bf9e..d78a72a2b726d4fcdff0a50b4ccc9e7027e23320 100644 (file)
@@ -399,6 +399,7 @@ dpcheck(Node *n)
                return;
 
        i = l->param;
+       a = nil;
        b = n->right;
        a = Z;
        while(i > 0) {
index 0bccc173358a9cc6ea7596cd2d9bb09a67042e9e..24f9bdc85591c8e76cb695b138b1e6ce2a779d78 100644 (file)
@@ -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;
 }