]> granicus.if.org Git - graphviz/commitdiff
fix bug#1317 - we now keep a maximum of 50 image files open
authorellson <devnull@localhost>
Sat, 15 Mar 2008 23:19:30 +0000 (23:19 +0000)
committerellson <devnull@localhost>
Sat, 15 Mar 2008 23:19:30 +0000 (23:19 +0000)
added support for CAIRO_FORMAT_RGB24 format in png:ps:cairo loader  (for -Tps)

lib/gvc/gvusershape.c

index 3585bcae6fb977fa684dab6913953bf54839e705..398622bbe345b00d345111956249abb68385a8ca 100644 (file)
@@ -343,32 +343,62 @@ usershape_t *gvusershape_find(char *name)
     return (dtsearch(ImageDict, &probe));
 }
 
-static usershape_t *gvusershape_open (char *name)
+#define MAX_USERSHAPE_FILES_OPEN 50
+boolean gvusershape_file_access(usershape_t *us)
 {
-    usershape_t *us;
+    static int usershape_files_open_cnt;
     char *fn;
 
-    if (!ImageDict)
-        ImageDict = dtopen(&ImageDictDisc, Dttree);
+    assert(us);
+    assert(us->name);
 
-    if (! (us = gvusershape_find(name))) {
-        if (! (us = zmalloc(sizeof(usershape_t))))
-           return NULL;
-
-       us->name = name;
-       if ((fn = safefile(name))) {
+    if (us->f)
+       fseek(us->f, 0, SEEK_SET);
+    else {
+        if ((fn = safefile(us->name))) {
 #ifndef WIN32
            us->f = fopen(fn, "r");
 #else
            us->f = fopen(fn, "rb");
 #endif
            if (us->f == NULL) {
-               agerr(AGWARN, "%s while opening %s\n",
-                       strerror(errno), fn);
-               free(us);
-               return NULL;
+               agerr(AGWARN, "%s while opening %s\n", strerror(errno), fn);
+               return false;
            }
+           if (usershape_files_open_cnt >= MAX_USERSHAPE_FILES_OPEN)
+               us->nocache = true;
+           else
+               usershape_files_open_cnt++;
+       }
+    }
+    return true;
+}
+
+void gvusershape_file_release(usershape_t *us)
+{
+    if (us->nocache) {
+       if (us->f) {
+           fclose(us->f);
+           us->f = NULL;
        }
+    }
+}
+
+static usershape_t *gvusershape_open (char *name)
+{
+    usershape_t *us;
+
+    if (!ImageDict)
+        ImageDict = dtopen(&ImageDictDisc, Dttree);
+
+    if (! (us = gvusershape_find(name))) {
+        if (! (us = zmalloc(sizeof(usershape_t))))
+           return NULL;
+
+       us->name = name;
+       if (!gvusershape_file_access(us)) 
+           return NULL;
+
         switch(imagetype(us)) {
            case FT_NULL:
                if (!(us->data = (void*)find_user_shape(us->name)))
@@ -402,6 +432,8 @@ static usershape_t *gvusershape_open (char *name)
         dtinsert(ImageDict, us);
     }
 
+    gvusershape_file_release(us);
+
     return us;
 }