Gentoo Archives: gentoo-commits

From: "Fabian Groffen (grobian)" <grobian@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo commit in src/patchsets/windowmaker/0.92.0: WindowMaker-0.92.0-alt-alloca.patch
Date: Wed, 01 Dec 2010 17:49:58
Message-Id: 20101201174947.F1FA920054@flycatcher.gentoo.org
1 grobian 10/12/01 17:49:47
2
3 Added: WindowMaker-0.92.0-alt-alloca.patch
4 Log:
5 windowmaker-0.92.0-patchset-4
6
7 Revision Changes Path
8 1.1 src/patchsets/windowmaker/0.92.0/WindowMaker-0.92.0-alt-alloca.patch
9
10 file : http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/windowmaker/0.92.0/WindowMaker-0.92.0-alt-alloca.patch?rev=1.1&view=markup
11 plain: http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/windowmaker/0.92.0/WindowMaker-0.92.0-alt-alloca.patch?rev=1.1&content-type=text/plain
12
13 Index: WindowMaker-0.92.0-alt-alloca.patch
14 ===================================================================
15 configure.ac | 1 -
16 wrlib/Makefile.am | 2 +-
17 wrlib/alloca.c | 504 ----------------------------------------------------
18 wrlib/configure.in | 1 -
19 wrlib/nxpm.c | 171 ++++++++++++------
20 wrlib/png.c | 39 +---
21 6 files changed, 128 insertions(+), 590 deletions(-)
22
23 diff --git a/configure.ac b/configure.ac
24 index b49cad5..1c7c4dc 100644
25 --- a/configure.ac
26 +++ b/configure.ac
27 @@ -85,7 +85,6 @@ dnl ============================
28 dnl not used anywhere
29 dnl AC_FUNC_MEMCMP
30 AC_FUNC_VPRINTF
31 -AC_FUNC_ALLOCA
32 AC_CHECK_FUNCS(gethostname select poll strerror strcasecmp strncasecmp \
33 setsid atexit mallinfo mkstemp snprintf vsnprintf asprintf \
34 vasprintf)
35 diff --git a/wrlib/Makefile.am b/wrlib/Makefile.am
36 index f7a3428..659d40c 100644
37 --- a/wrlib/Makefile.am
38 +++ b/wrlib/Makefile.am
39 @@ -56,7 +56,7 @@ x86_specific.o: x86_specific.c
40
41 INCLUDES = $(DFLAGS) @HEADER_SEARCH_PATH@
42
43 -libwraster_la_LIBADD = @ALLOCA@ @LIBRARY_SEARCH_PATH@ @GFXLIBS@ @XLIBS@ -lm
44 +libwraster_la_LIBADD = @LIBRARY_SEARCH_PATH@ @GFXLIBS@ @XLIBS@ -lm
45
46 DISTCLEANFILES = wrlib.pc
47
48 diff --git a/wrlib/alloca.c b/wrlib/alloca.c
49 deleted file mode 100644
50 index 7598aea..0000000
51 --- a/wrlib/alloca.c
52 +++ /dev/null
53 @@ -1,504 +0,0 @@
54 -/* alloca.c -- allocate automatically reclaimed memory
55 - (Mostly) portable public-domain implementation -- D A Gwyn
56 -
57 - This implementation of the PWB library alloca function,
58 - which is used to allocate space off the run-time stack so
59 - that it is automatically reclaimed upon procedure exit,
60 - was inspired by discussions with J. Q. Johnson of Cornell.
61 - J.Otto Tennant <jot@××××.com> contributed the Cray support.
62 -
63 - There are some preprocessor constants that can
64 - be defined when compiling for your specific system, for
65 - improved efficiency; however, the defaults should be okay.
66 -
67 - The general concept of this implementation is to keep
68 - track of all alloca-allocated blocks, and reclaim any
69 - that are found to be deeper in the stack than the current
70 - invocation. This heuristic does not reclaim storage as
71 - soon as it becomes invalid, but it will do so eventually.
72 -
73 - As a special case, alloca(0) reclaims storage without
74 - allocating any. It is a good idea to use alloca(0) in
75 - your main control loop, etc. to force garbage collection. */
76 -
77 -#ifdef HAVE_CONFIG_H
78 -#include <config.h>
79 -#endif
80 -
81 -#ifdef HAVE_STRING_H
82 -#include <string.h>
83 -#endif
84 -#ifdef HAVE_STDLIB_H
85 -#include <stdlib.h>
86 -#endif
87 -
88 -#ifdef emacs
89 -#include "blockinput.h"
90 -#endif
91 -
92 -/* If compiling with GCC 2, this file's not needed. */
93 -#if !defined (__GNUC__) || __GNUC__ < 2
94 -
95 -/* If someone has defined alloca as a macro,
96 - there must be some other way alloca is supposed to work. */
97 -#ifndef alloca
98 -
99 -#ifdef emacs
100 -#ifdef static
101 -/* actually, only want this if static is defined as ""
102 - -- this is for usg, in which emacs must undefine static
103 - in order to make unexec workable
104 - */
105 -#ifndef STACK_DIRECTION
106 -you
107 -lose
108 --- must know STACK_DIRECTION at compile-time
109 -#endif /* STACK_DIRECTION undefined */
110 -#endif /* static */
111 -#endif /* emacs */
112 -
113 -/* If your stack is a linked list of frames, you have to
114 - provide an "address metric" ADDRESS_FUNCTION macro. */
115 -
116 -#if defined (CRAY) && defined (CRAY_STACKSEG_END)
117 -long i00afunc ();
118 -#define ADDRESS_FUNCTION(arg) (char *) i00afunc (&(arg))
119 -#else
120 -#define ADDRESS_FUNCTION(arg) &(arg)
121 -#endif
122 -
123 -#if __STDC__
124 -typedef void *pointer;
125 -#else
126 -typedef char *pointer;
127 -#endif
128 -
129 -#ifndef NULL
130 -#define NULL 0
131 -#endif
132 -
133 -/* Different portions of Emacs need to call different versions of
134 - malloc. The Emacs executable needs alloca to call xmalloc, because
135 - ordinary malloc isn't protected from input signals. On the other
136 - hand, the utilities in lib-src need alloca to call malloc; some of
137 - them are very simple, and don't have an xmalloc routine.
138 -
139 - Non-Emacs programs expect this to call use xmalloc.
140 -
141 - Callers below should use malloc. */
142 -
143 -#ifndef emacs
144 -#define malloc xmalloc
145 -#endif
146 -extern pointer malloc ();
147 -
148 -/* Define STACK_DIRECTION if you know the direction of stack
149 - growth for your system; otherwise it will be automatically
150 - deduced at run-time.
151 -
152 - STACK_DIRECTION > 0 => grows toward higher addresses
153 - STACK_DIRECTION < 0 => grows toward lower addresses
154 - STACK_DIRECTION = 0 => direction of growth unknown */
155 -
156 -#ifndef STACK_DIRECTION
157 -#define STACK_DIRECTION 0 /* Direction unknown. */
158 -#endif
159 -
160 -#if STACK_DIRECTION != 0
161 -
162 -#define STACK_DIR STACK_DIRECTION /* Known at compile-time. */
163 -
164 -#else /* STACK_DIRECTION == 0; need run-time code. */
165 -
166 -static int stack_dir; /* 1 or -1 once known. */
167 -#define STACK_DIR stack_dir
168 -
169 -static void
170 -find_stack_direction ()
171 -{
172 - static char *addr = NULL; /* Address of first `dummy', once known. */
173 - auto char dummy; /* To get stack address. */
174 -
175 - if (addr == NULL)
176 - { /* Initial entry. */
177 - addr = ADDRESS_FUNCTION (dummy);
178 -
179 - find_stack_direction (); /* Recurse once. */
180 - }
181 - else
182 - {
183 - /* Second entry. */
184 - if (ADDRESS_FUNCTION (dummy) > addr)
185 - stack_dir = 1; /* Stack grew upward. */
186 - else
187 - stack_dir = -1; /* Stack grew downward. */
188 - }
189 -}
190 -
191 -#endif /* STACK_DIRECTION == 0 */
192 -
193 -/* An "alloca header" is used to:
194 - (a) chain together all alloca'ed blocks;
195 - (b) keep track of stack depth.
196 -
197 - It is very important that sizeof(header) agree with malloc
198 - alignment chunk size. The following default should work okay. */
199 -
200 -#ifndef ALIGN_SIZE
201 -#define ALIGN_SIZE sizeof(double)
202 -#endif
203 -
204 -typedef union hdr
205 -{
206 - char align[ALIGN_SIZE]; /* To force sizeof(header). */
207 - struct
208 - {
209 - union hdr *next; /* For chaining headers. */
210 - char *deep; /* For stack depth measure. */
211 - } h;
212 -} header;
213 -
214 -static header *last_alloca_header = NULL; /* -> last alloca header. */
215 -
216 -/* Return a pointer to at least SIZE bytes of storage,
217 - which will be automatically reclaimed upon exit from
218 - the procedure that called alloca. Originally, this space
219 - was supposed to be taken from the current stack frame of the
220 - caller, but that method cannot be made to work for some
221 - implementations of C, for example under Gould's UTX/32. */
222 -
223 -pointer
224 -alloca (size)
225 - unsigned size;
226 -{
227 - auto char probe; /* Probes stack depth: */
228 - register char *depth = ADDRESS_FUNCTION (probe);
229 -
230 -#if STACK_DIRECTION == 0
231 - if (STACK_DIR == 0) /* Unknown growth direction. */
232 - find_stack_direction ();
233 -#endif
234 -
235 - /* Reclaim garbage, defined as all alloca'd storage that
236 - was allocated from deeper in the stack than currently. */
237 -
238 - {
239 - register header *hp; /* Traverses linked list. */
240 -
241 -#ifdef emacs
242 - BLOCK_INPUT;
243 -#endif
244 -
245 - for (hp = last_alloca_header; hp != NULL;)
246 - if ((STACK_DIR > 0 && hp->h.deep > depth)
247 - || (STACK_DIR < 0 && hp->h.deep < depth))
248 - {
249 - register header *np = hp->h.next;
250 -
251 - free ((pointer) hp); /* Collect garbage. */
252 -
253 - hp = np; /* -> next header. */
254 - }
255 - else
256 - break; /* Rest are not deeper. */
257 -
258 - last_alloca_header = hp; /* -> last valid storage. */
259 -
260 -#ifdef emacs
261 - UNBLOCK_INPUT;
262 -#endif
263 - }
264 -
265 - if (size == 0)
266 - return NULL; /* No allocation required. */
267 -
268 - /* Allocate combined header + user data storage. */
269 -
270 - {
271 - register pointer new = malloc (sizeof (header) + size);
272 - /* Address of header. */
273 -
274 - if (new == 0)
275 - abort();
276 -
277 - ((header *) new)->h.next = last_alloca_header;
278 - ((header *) new)->h.deep = depth;
279 -
280 - last_alloca_header = (header *) new;
281 -
282 - /* User storage begins just after header. */
283 -
284 - return (pointer) ((char *) new + sizeof (header));
285 - }
286 -}
287 -
288 -#if defined (CRAY) && defined (CRAY_STACKSEG_END)
289 -
290 -#ifdef DEBUG_I00AFUNC
291 -#include <stdio.h>
292 -#endif
293 -
294 -#ifndef CRAY_STACK
295 -#define CRAY_STACK
296 -#ifndef CRAY2
297 -/* Stack structures for CRAY-1, CRAY X-MP, and CRAY Y-MP */
298 -struct stack_control_header
299 -{
300 - long shgrow:32; /* Number of times stack has grown. */
301 - long shaseg:32; /* Size of increments to stack. */
302 - long shhwm:32; /* High water mark of stack. */
303 - long shsize:32; /* Current size of stack (all segments). */
304 -};
305 -
306 -/* The stack segment linkage control information occurs at
307 - the high-address end of a stack segment. (The stack
308 - grows from low addresses to high addresses.) The initial
309 - part of the stack segment linkage control information is
310 - 0200 (octal) words. This provides for register storage
311 - for the routine which overflows the stack. */
312 -
313 -struct stack_segment_linkage
314 -{
315 - long ss[0200]; /* 0200 overflow words. */
316 - long sssize:32; /* Number of words in this segment. */
317 - long ssbase:32; /* Offset to stack base. */
318 - long:32;
319 - long sspseg:32; /* Offset to linkage control of previous
320 - segment of stack. */
321 - long:32;
322 - long sstcpt:32; /* Pointer to task common address block. */
323 - long sscsnm; /* Private control structure number for
324 - microtasking. */
325 - long ssusr1; /* Reserved for user. */
326 - long ssusr2; /* Reserved for user. */
327 - long sstpid; /* Process ID for pid based multi-tasking. */
328 - long ssgvup; /* Pointer to multitasking thread giveup. */
329 - long sscray[7]; /* Reserved for Cray Research. */
330 - long ssa0;
331 - long ssa1;
332 - long ssa2;
333 - long ssa3;
334 - long ssa4;
335 - long ssa5;
336 - long ssa6;
337 - long ssa7;
338 - long sss0;
339 - long sss1;
340 - long sss2;
341 - long sss3;
342 - long sss4;
343 - long sss5;
344 - long sss6;
345 - long sss7;
346 -};
347 -
348 -#else /* CRAY2 */
349 -/* The following structure defines the vector of words
350 - returned by the STKSTAT library routine. */
351 -struct stk_stat
352 -{
353 - long now; /* Current total stack size. */
354 - long maxc; /* Amount of contiguous space which would
355 - be required to satisfy the maximum
356 - stack demand to date. */
357 - long high_water; /* Stack high-water mark. */
358 - long overflows; /* Number of stack overflow ($STKOFEN) calls. */
359 - long hits; /* Number of internal buffer hits. */
360 - long extends; /* Number of block extensions. */
361 - long stko_mallocs; /* Block allocations by $STKOFEN. */
362 - long underflows; /* Number of stack underflow calls ($STKRETN). */
363 - long stko_free; /* Number of deallocations by $STKRETN. */
364 - long stkm_free; /* Number of deallocations by $STKMRET. */
365 - long segments; /* Current number of stack segments. */
366 - long maxs; /* Maximum number of stack segments so far. */
367 - long pad_size; /* Stack pad size. */
368 - long current_address; /* Current stack segment address. */
369 - long current_size; /* Current stack segment size. This
370 - number is actually corrupted by STKSTAT to
371 - include the fifteen word trailer area. */
372 - long initial_address; /* Address of initial segment. */
373 - long initial_size; /* Size of initial segment. */
374 -};
375 -
376 -/* The following structure describes the data structure which trails
377 - any stack segment. I think that the description in 'asdef' is
378 - out of date. I only describe the parts that I am sure about. */
379 -
380 -struct stk_trailer
381 -{
382 - long this_address; /* Address of this block. */
383 - long this_size; /* Size of this block (does not include
384 - this trailer). */
385 - long unknown2;
386 - long unknown3;
387 - long link; /* Address of trailer block of previous
388 - segment. */
389 - long unknown5;
390 - long unknown6;
391 - long unknown7;
392 - long unknown8;
393 - long unknown9;
394 - long unknown10;
395 - long unknown11;
396 - long unknown12;
397 - long unknown13;
398 - long unknown14;
399 -};
400 -
401 -#endif /* CRAY2 */
402 -#endif /* not CRAY_STACK */
403 -
404 -#ifdef CRAY2
405 -/* Determine a "stack measure" for an arbitrary ADDRESS.
406 - I doubt that "lint" will like this much. */
407 -
408 -static long
409 -i00afunc (long *address)
410 -{
411 - struct stk_stat status;
412 - struct stk_trailer *trailer;
413 - long *block, size;
414 - long result = 0;
415 -
416 - /* We want to iterate through all of the segments. The first
417 - step is to get the stack status structure. We could do this
418 - more quickly and more directly, perhaps, by referencing the
419 - $LM00 common block, but I know that this works. */
420 -
421 - STKSTAT (&status);
422 -
423 - /* Set up the iteration. */
424 -
425 - trailer = (struct stk_trailer *) (status.current_address
426 - + status.current_size
427 - - 15);
428 -
429 - /* There must be at least one stack segment. Therefore it is
430 - a fatal error if "trailer" is null. */
431 -
432 - if (trailer == 0)
433 - abort ();
434 -
435 - /* Discard segments that do not contain our argument address. */
436 -
437 - while (trailer != 0)
438 - {
439 - block = (long *) trailer->this_address;
440 - size = trailer->this_size;
441 - if (block == 0 || size == 0)
442 - abort ();
443 - trailer = (struct stk_trailer *) trailer->link;
444 - if ((block <= address) && (address < (block + size)))
445 - break;
446 - }
447 -
448 - /* Set the result to the offset in this segment and add the sizes
449 - of all predecessor segments. */
450 -
451 - result = address - block;
452 -
453 - if (trailer == 0)
454 - {
455 - return result;
456 - }
457 -
458 - do
459 - {
460 - if (trailer->this_size <= 0)
461 - abort ();
462 - result += trailer->this_size;
463 - trailer = (struct stk_trailer *) trailer->link;
464 - }
465 - while (trailer != 0);
466 -
467 - /* We are done. Note that if you present a bogus address (one
468 - not in any segment), you will get a different number back, formed
469 - from subtracting the address of the first block. This is probably
470 - not what you want. */
471 -
472 - return (result);
473 -}
474 -
475 -#else /* not CRAY2 */
476 -/* Stack address function for a CRAY-1, CRAY X-MP, or CRAY Y-MP.
477 - Determine the number of the cell within the stack,
478 - given the address of the cell. The purpose of this
479 - routine is to linearize, in some sense, stack addresses
480 - for alloca. */
481 -
482 -static long
483 -i00afunc (long address)
484 -{
485 - long stkl = 0;
486 -
487 - long size, pseg, this_segment, stack;
488 - long result = 0;
489 -
490 - struct stack_segment_linkage *ssptr;
491 -
492 - /* Register B67 contains the address of the end of the
493 - current stack segment. If you (as a subprogram) store
494 - your registers on the stack and find that you are past
495 - the contents of B67, you have overflowed the segment.
496 -
497 - B67 also points to the stack segment linkage control
498 - area, which is what we are really interested in. */
499 -
500 - stkl = CRAY_STACKSEG_END ();
501 - ssptr = (struct stack_segment_linkage *) stkl;
502 -
503 - /* If one subtracts 'size' from the end of the segment,
504 - one has the address of the first word of the segment.
505 -
506 - If this is not the first segment, 'pseg' will be
507 - nonzero. */
508 -
509 - pseg = ssptr->sspseg;
510 - size = ssptr->sssize;
511 -
512 - this_segment = stkl - size;
513 -
514 - /* It is possible that calling this routine itself caused
515 - a stack overflow. Discard stack segments which do not
516 - contain the target address. */
517 -
518 - while (!(this_segment <= address && address <= stkl))
519 - {
520 -#ifdef DEBUG_I00AFUNC
521 - fprintf (stderr, "%011o %011o %011o\n", this_segment, address, stkl);
522 -#endif
523 - if (pseg == 0)
524 - break;
525 - stkl = stkl - pseg;
526 - ssptr = (struct stack_segment_linkage *) stkl;
527 - size = ssptr->sssize;
528 - pseg = ssptr->sspseg;
529 - this_segment = stkl - size;
530 - }
531 -
532 - result = address - this_segment;
533 -
534 - /* If you subtract pseg from the current end of the stack,
535 - you get the address of the previous stack segment's end.
536 - This seems a little convoluted to me, but I'll bet you save
537 - a cycle somewhere. */
538 -
539 - while (pseg != 0)
540 - {
541 -#ifdef DEBUG_I00AFUNC
542 - fprintf (stderr, "%011o %011o\n", pseg, size);
543 -#endif
544 - stkl = stkl - pseg;
545 - ssptr = (struct stack_segment_linkage *) stkl;
546 - size = ssptr->sssize;
547 - pseg = ssptr->sspseg;
548 - result += size;
549 - }
550 - return (result);
551 -}
552 -
553 -#endif /* not CRAY2 */
554 -#endif /* CRAY */
555 -
556 -#endif /* no alloca */
557 -#endif /* not GCC version 2 */
558 diff --git a/wrlib/configure.in b/wrlib/configure.in
559 index a1ecd05..471d9a3 100644
560 --- a/wrlib/configure.in
561 +++ b/wrlib/configure.in
562 @@ -20,7 +20,6 @@ dnl Checks for library functions.
563 dnl ============================
564 AC_PROG_GCC_TRADITIONAL
565 AC_FUNC_MEMCMP
566 -AC_FUNC_ALLOCA
567 AC_TYPE_SIGNAL
568 AC_FUNC_VPRINTF
569
570 diff --git a/wrlib/nxpm.c b/wrlib/nxpm.c
571 index 33b8806..639dd9c 100644
572 --- a/wrlib/nxpm.c
573 +++ b/wrlib/nxpm.c
574 @@ -21,24 +21,6 @@
575
576 #include <config.h>
577
578 -/* AIX requires this to be the first thing in the file. */
579 -#ifdef __GNUC__
580 -# define alloca __builtin_alloca
581 -#else
582 -# if HAVE_ALLOCA_H
583 -# include <alloca.h>
584 -# else
585 -# ifdef _AIX
586 -# pragma alloca
587 -# else
588 -# ifndef alloca /* predefined by HP cc +Olibcalls */
589 -char *alloca ();
590 -# endif
591 -# endif
592 -# endif
593 -#endif
594 -
595 -
596 #include <stdlib.h>
597 #include <stdio.h>
598 #include <string.h>
599 @@ -76,8 +58,8 @@ RImage*
600 RGetImageFromXPMData(RContext *context, char **data)
601 {
602 RImage *image = NULL;
603 - unsigned char *color_table[4];
604 - unsigned short *symbol_table;
605 + unsigned char *color_table[4] = {NULL, NULL, NULL, NULL};
606 + unsigned short *symbol_table = NULL;
607 unsigned char *r, *g, *b, *a;
608 int i, j, k, line = 0;
609 int transp;
610 @@ -92,18 +74,27 @@ RGetImageFromXPMData(RContext *context, char **data)
611 if (csize!=1 && csize!=2)
612 goto bad_format;
613
614 - color_table[0] = alloca(ccount);
615 - color_table[1] = alloca(ccount);
616 - color_table[2] = alloca(ccount);
617 - color_table[3] = alloca(ccount);
618 - symbol_table = alloca(ccount * sizeof(unsigned short));
619 + color_table[0] = malloc(ccount);
620 + color_table[1] = malloc(ccount);
621 + color_table[2] = malloc(ccount);
622 + color_table[3] = malloc(ccount);
623 + symbol_table = malloc(ccount * sizeof(unsigned short));
624
625 bsize = csize * w + 16;
626
627 if (!color_table[0] || !color_table[1] || !color_table[2] ||
628 !color_table[3] || !symbol_table || !bsize) {
629 RErrorCode = RERR_NOMEMORY;
630 - alloca(0);
631 + if (color_table[0])
632 + free(color_table[0]);
633 + if (color_table[1])
634 + free(color_table[1]);
635 + if (color_table[2])
636 + free(color_table[2]);
637 + if (color_table[3])
638 + free(color_table[3]);
639 + if (symbol_table)
640 + free(symbol_table);
641 return NULL;
642 }
643
644 @@ -152,7 +143,16 @@ RGetImageFromXPMData(RContext *context, char **data)
645
646 image = RCreateImage(w, h, transp);
647 if (!image) {
648 - alloca(0);
649 + if (color_table[0])
650 + free(color_table[0]);
651 + if (color_table[1])
652 + free(color_table[1]);
653 + if (color_table[2])
654 + free(color_table[2]);
655 + if (color_table[3])
656 + free(color_table[3]);
657 + if (symbol_table)
658 + free(symbol_table);
659 return NULL;
660 }
661
662 @@ -212,16 +212,30 @@ RGetImageFromXPMData(RContext *context, char **data)
663 line++;
664 }
665
666 -#ifdef C_ALLOCA
667 - alloca(0);
668 -#endif
669 + if (color_table[0])
670 + free(color_table[0]);
671 + if (color_table[1])
672 + free(color_table[1]);
673 + if (color_table[2])
674 + free(color_table[2]);
675 + if (color_table[3])
676 + free(color_table[3]);
677 + if (symbol_table)
678 + free(symbol_table);
679 return image;
680
681 bad_format:
682 RErrorCode = RERR_BADIMAGEFILE;
683 -#ifdef C_ALLOCA
684 - alloca(0);
685 -#endif
686 + if (color_table[0])
687 + free(color_table[0]);
688 + if (color_table[1])
689 + free(color_table[1]);
690 + if (color_table[2])
691 + free(color_table[2]);
692 + if (color_table[3])
693 + free(color_table[3]);
694 + if (symbol_table)
695 + free(symbol_table);
696 if (image)
697 RReleaseImage(image);
698 return NULL;
699 @@ -234,9 +248,9 @@ RLoadXPM(RContext *context, char *file, int index)
700 {
701 RImage *image = NULL;
702 char line[LINEWIDTH+1];
703 - char *buffer;
704 - unsigned char *color_table[4];
705 - unsigned short *symbol_table;
706 + char *buffer = NULL;
707 + unsigned char *color_table[4] = {NULL, NULL, NULL, NULL};
708 + unsigned short *symbol_table = NULL;
709 unsigned char *r, *g, *b, *a;
710 int i, j, k;
711 int transp;
712 @@ -272,20 +286,31 @@ RLoadXPM(RContext *context, char *file, int index)
713 if (csize!=1 && csize!=2)
714 goto bad_format;
715
716 - color_table[0] = alloca(ccount);
717 - color_table[1] = alloca(ccount);
718 - color_table[2] = alloca(ccount);
719 - color_table[3] = alloca(ccount);
720 - symbol_table = alloca(ccount * sizeof(unsigned short));
721 + color_table[0] = malloc(ccount);
722 + color_table[1] = malloc(ccount);
723 + color_table[2] = malloc(ccount);
724 + color_table[3] = malloc(ccount);
725 + symbol_table = malloc(ccount * sizeof(unsigned short));
726
727 bsize = csize * w + 16;
728 - buffer = alloca(bsize);
729 + buffer = malloc(bsize);
730
731 if (!color_table[0] || !color_table[1] || !color_table[2] ||
732 - !color_table[3] || !symbol_table || !bsize) {
733 + !color_table[3] || !symbol_table || !bsize || !buffer) {
734 RErrorCode = RERR_NOMEMORY;
735 fclose(f);
736 - alloca(0);
737 + if (color_table[0])
738 + free(color_table[0]);
739 + if (color_table[1])
740 + free(color_table[1]);
741 + if (color_table[2])
742 + free(color_table[2]);
743 + if (color_table[3])
744 + free(color_table[3]);
745 + if (symbol_table)
746 + free(symbol_table);
747 + if (buffer)
748 + free(buffer);
749 return NULL;
750 }
751
752 @@ -339,7 +364,18 @@ RLoadXPM(RContext *context, char *file, int index)
753 image = RCreateImage(w, h, transp);
754 if (!image) {
755 fclose(f);
756 - alloca(0);
757 + if (color_table[0])
758 + free(color_table[0]);
759 + if (color_table[1])
760 + free(color_table[1]);
761 + if (color_table[2])
762 + free(color_table[2]);
763 + if (color_table[3])
764 + free(color_table[3]);
765 + if (symbol_table)
766 + free(symbol_table);
767 + if (buffer)
768 + free(buffer);
769 return NULL;
770 }
771
772 @@ -406,17 +442,35 @@ RLoadXPM(RContext *context, char *file, int index)
773 }
774
775 fclose(f);
776 -#ifdef C_ALLOCA
777 - alloca(0);
778 -#endif
779 + if (color_table[0])
780 + free(color_table[0]);
781 + if (color_table[1])
782 + free(color_table[1]);
783 + if (color_table[2])
784 + free(color_table[2]);
785 + if (color_table[3])
786 + free(color_table[3]);
787 + if (symbol_table)
788 + free(symbol_table);
789 + if (buffer)
790 + free(buffer);
791 return image;
792
793 bad_format:
794 RErrorCode = RERR_BADIMAGEFILE;
795 fclose(f);
796 -#ifdef C_ALLOCA
797 - alloca(0);
798 -#endif
799 + if (color_table[0])
800 + free(color_table[0]);
801 + if (color_table[1])
802 + free(color_table[1]);
803 + if (color_table[2])
804 + free(color_table[2]);
805 + if (color_table[3])
806 + free(color_table[3]);
807 + if (symbol_table)
808 + free(symbol_table);
809 + if (buffer)
810 + free(buffer);
811 if (image)
812 RReleaseImage(image);
813 return NULL;
814 @@ -424,9 +478,18 @@ bad_format:
815 bad_file:
816 RErrorCode = RERR_BADIMAGEFILE;
817 fclose(f);
818 -#ifdef C_ALLOCA
819 - alloca(0);
820 -#endif
821 + if (color_table[0])
822 + free(color_table[0]);
823 + if (color_table[1])
824 + free(color_table[1]);
825 + if (color_table[2])
826 + free(color_table[2]);
827 + if (color_table[3])
828 + free(color_table[3]);
829 + if (symbol_table)
830 + free(symbol_table);
831 + if (buffer)
832 + free(buffer);
833 if (image)
834 RReleaseImage(image);
835 return NULL;
836 diff --git a/wrlib/png.c b/wrlib/png.c
837 index ee04a1c..b79060e 100644
838 --- a/wrlib/png.c
839 +++ b/wrlib/png.c
840 @@ -21,24 +21,6 @@
841
842 #include <config.h>
843
844 -/* AIX requires this to be the first thing in the file. */
845 -#ifdef __GNUC__
846 -# define alloca __builtin_alloca
847 -#else
848 -# if HAVE_ALLOCA_H
849 -# include <alloca.h>
850 -# else
851 -# ifdef _AIX
852 -# pragma alloca
853 -# else
854 -# ifndef alloca /* predefined by HP cc +Olibcalls */
855 -char *alloca ();
856 -# endif
857 -# endif
858 -# endif
859 -#endif
860 -
861 -
862 #ifdef USE_PNG
863
864 #include <stdlib.h>
865 @@ -182,27 +164,25 @@ RLoadPNG(RContext *context, char *file, int index)
866 image->background.blue = bkcolor->blue >> 8;
867 }
868
869 - png_rows = alloca(sizeof(char*)*height);
870 + png_rows = calloc(height, sizeof(char*));
871 if (!png_rows) {
872 RErrorCode = RERR_NOMEMORY;
873 fclose(f);
874 RReleaseImage(image);
875 png_destroy_read_struct(&png, &pinfo, &einfo);
876 -#ifdef C_ALLOCA
877 - alloca(0);
878 -#endif
879 return NULL;
880 }
881 for (y=0; y<height; y++) {
882 - png_rows[y] = alloca(png_get_rowbytes(png, pinfo));
883 + png_rows[y] = malloc(png_get_rowbytes(png, pinfo));
884 if (!png_rows[y]) {
885 RErrorCode = RERR_NOMEMORY;
886 fclose(f);
887 RReleaseImage(image);
888 png_destroy_read_struct(&png, &pinfo, &einfo);
889 -#ifdef C_ALLOCA
890 - alloca(0);
891 -#endif
892 + while (y-- > 0)
893 + if (png_rows[y])
894 + free(png_rows[y]);
895 + free(png_rows);
896 return NULL;
897 }
898 }
899 @@ -231,9 +211,10 @@ RLoadPNG(RContext *context, char *file, int index)
900 }
901 }
902 }
903 -#ifdef C_ALLOCA
904 - alloca(0);
905 -#endif
906 + for (y=0; y<height; y++)
907 + if (png_rows[y])
908 + free(png_rows[y]);
909 + free(png_rows);
910 return image;
911 }