Lines 13-32
Link Here
|
13 |
{ |
13 |
{ |
14 |
public : |
14 |
public : |
15 |
T **sdata; |
15 |
T **sdata; |
16 |
long son; |
16 |
unsigned int son, _max_size; |
17 |
|
17 |
/* <sigh> the max_size parameter is the number of bytes of the pointerstack |
18 |
grow_stack(int max_size) { sdata=(T **)jmalloc(max_size,"pointer stack"); son=0; } |
18 |
instead of the number of entries which it ofcourse should have been. |
|
|
19 |
This breaks on 64 bit since the caller assumes 4 bytes per pointer and |
20 |
thus on 64 bit allocates not enough memory. Instead of fixing all callers |
21 |
we work around this by multiplying maxsize by 2 on 64 bit. */ |
22 |
grow_stack(unsigned int max_size) |
23 |
{ |
24 |
max_size *= sizeof(void*)/sizeof(int); |
25 |
sdata = (T **)jmalloc(max_size, "pointer stack"); |
26 |
son=0; |
27 |
_max_size=max_size; |
28 |
} |
29 |
|
19 |
void push(T *data) |
30 |
void push(T *data) |
20 |
{ |
31 |
{ |
21 |
sdata[son]=data; |
32 |
sdata[son]=data; |
22 |
son++; |
33 |
son++; |
|
|
34 |
if (son >= (_max_size/sizeof(int))) |
35 |
{ |
36 |
lbreak("stack overflow\n"); |
37 |
exit(0); |
38 |
} |
23 |
} |
39 |
} |
24 |
|
40 |
|
25 |
T *pop(long total) |
41 |
T *pop(unsigned int total) |
26 |
{ if (total>son) { lbreak("stack underflow\n"); exit(0); } |
42 |
{ |
|
|
43 |
if (total>son) { lbreak("stack underflow\n"); exit(0); } |
27 |
son-=total; |
44 |
son-=total; |
28 |
return sdata[son]; |
45 |
return sdata[son]; |
29 |
} |
46 |
} |
|
|
47 |
|
30 |
void clean_up() |
48 |
void clean_up() |
31 |
{ |
49 |
{ |
32 |
if (son!=0) fprintf(stderr,"Warning cleaning up stack and not empty\n"); |
50 |
if (son!=0) fprintf(stderr,"Warning cleaning up stack and not empty\n"); |