Module Name:    src
Committed By:   jmcneill
Date:           Fri Jan 20 23:13:47 UTC 2012

Modified Files:
        src/sys/dev/stbi: stb_image.c

Log Message:
reduce stack usage of stbi_gif_load_from_memory when STBI_SMALL_STACK is
defined


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/stbi/stb_image.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/stbi/stb_image.c
diff -u src/sys/dev/stbi/stb_image.c:1.1 src/sys/dev/stbi/stb_image.c:1.2
--- src/sys/dev/stbi/stb_image.c:1.1	Sun Feb  6 23:13:04 2011
+++ src/sys/dev/stbi/stb_image.c	Fri Jan 20 23:13:47 2012
@@ -430,7 +430,7 @@ extern int      stbi_gif_info_from_file 
 #endif
 #ifdef _KERNEL
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: stb_image.c,v 1.1 2011/02/06 23:13:04 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: stb_image.c,v 1.2 2012/01/20 23:13:47 jmcneill Exp $");
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/kernel.h>
@@ -4601,16 +4601,30 @@ stbi_uc *stbi_gif_load_from_memory (stbi
 {
    uint8 *u = 0;
    stbi s;
+   stbi_gif *pg;
+
+   #ifdef STBI_SMALL_STACK
+   pg = (stbi_gif *) MALLOC(sizeof(*pg));
+   if (pg == NULL)
+      return NULL;
+   #else
    stbi_gif g;
+   pg = &g;
+   #endif
 
-   memset(&g, 0, sizeof(g));
+   memset(pg, 0, sizeof(*pg));
    start_mem(&s, buffer, len);
-   u = stbi_gif_load_next(&s, &g, comp, req_comp);
+   u = stbi_gif_load_next(&s, pg, comp, req_comp);
    if (u == (void *) 1) u = 0;  // end of animated gif marker
    if (u) {
-      *x = g.w;
-      *y = g.h;
+      *x = pg->w;
+      *y = pg->h;
    }
+
+   #ifdef STBI_SMALL_STACK
+   FREE(pg);
+   #endif
+
    return u;
 }
 

Reply via email to