classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] FYI: Correctly close gdk_pixbuf_loader


From: Mark Wielaard
Subject: [cp-patches] FYI: Correctly close gdk_pixbuf_loader
Date: Mon, 04 Jul 2005 20:07:52 +0200

Hi,

This adds the bookkeeping needed to correctly close the
gdk_pixbuf_loader as pointed out by my glib_log patch last week.

2005-07-04  Mark Wielaard  <address@hidden>

       * gnu/java/awt/peer/gtk/GdkPixbufDecoder.java (initialized):
       Remove unused field.
       (needsClose): New private field.
       (finish): Take needsClose boolean argument.
       (finalize): Call finish with needsClose.
       (produce): Set needsClose.
       * include/gnu_java_awt_peer_gtk_GdkPixbufDecoder.h: Regenerated.
       * native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkPixbufDecoder.c
       (Java_gnu_java_awt_peer_gtk_GdkPixbufDecoder_finish): Only close
       when needed.

This gets rid of the CRITICAL errors:

(.:25063): GdkPixbuf-CRITICAL **: gdk_pixbuf_loader_close: assertion 
`priv->closed == FALSE' failed
java.lang.InternalError: GdkPixbuf: gdk_pixbuf_loader_close: assertion 
`priv->closed == FALSE' failed
   at gnu.java.awt.peer.gtk.GdkPixbufDecoder.finish (Native Method)
   at gnu.java.awt.peer.gtk.GdkPixbufDecoder.finalize 
(GdkPixbufDecoder.java:182)

Committed,

Mark
Index: gnu/java/awt/peer/gtk/GdkPixbufDecoder.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/gnu/java/awt/peer/gtk/GdkPixbufDecoder.java,v
retrieving revision 1.14
diff -u -r1.14 GdkPixbufDecoder.java
--- gnu/java/awt/peer/gtk/GdkPixbufDecoder.java 2 Jul 2005 20:32:11 -0000       
1.14
+++ gnu/java/awt/peer/gtk/GdkPixbufDecoder.java 4 Jul 2005 18:03:40 -0000
@@ -83,7 +83,9 @@
   
   static native void initStaticState();
   private final int native_state = GtkGenericPeer.getUniqueInteger ();
-  private boolean initialized = false;
+
+  // initState() has been called, but pumpDone() has not yet been called.
+  private boolean needsClose = false;
 
   // the current set of ImageConsumers for this decoder
   Vector curr;
@@ -92,7 +94,7 @@
   native void initState ();
   native void pumpBytes (byte[] bytes, int len) throws IOException;
   native void pumpDone () throws IOException;
-  native void finish ();
+  native void finish (boolean needsClose);
   static native void streamImage(int[] bytes, String format, int width, int 
height, boolean hasAlpha, DataOutput sink);
   
   // gdk-pixbuf provids data in RGBA format
@@ -164,9 +166,11 @@
     byte bytes[] = new byte[4096];
     int len = 0;
     initState();
+    needsClose = true;
     while ((len = is.read (bytes)) != -1)
       pumpBytes (bytes, len);
     pumpDone();
+    needsClose = false;
     
     for (int i = 0; i < curr.size (); i++)
       {
@@ -179,7 +183,7 @@
 
   public void finalize()
   {
-    finish();
+    finish(needsClose);
   }
 
 
Index: include/gnu_java_awt_peer_gtk_GdkPixbufDecoder.h
===================================================================
RCS file: 
/cvsroot/classpath/classpath/include/gnu_java_awt_peer_gtk_GdkPixbufDecoder.h,v
retrieving revision 1.6
diff -u -r1.6 gnu_java_awt_peer_gtk_GdkPixbufDecoder.h
--- include/gnu_java_awt_peer_gtk_GdkPixbufDecoder.h    22 Jun 2005 23:31:49 
-0000      1.6
+++ include/gnu_java_awt_peer_gtk_GdkPixbufDecoder.h    4 Jul 2005 18:03:41 
-0000
@@ -14,7 +14,7 @@
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkPixbufDecoder_initState 
(JNIEnv *env, jobject);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkPixbufDecoder_pumpBytes 
(JNIEnv *env, jobject, jbyteArray, jint);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkPixbufDecoder_pumpDone 
(JNIEnv *env, jobject);
-JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkPixbufDecoder_finish 
(JNIEnv *env, jobject);
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkPixbufDecoder_finish 
(JNIEnv *env, jobject, jboolean);
 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkPixbufDecoder_streamImage 
(JNIEnv *env, jclass, jintArray, jstring, jint, jint, jboolean, jobject);
 
 #ifdef __cplusplus
Index: native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkPixbufDecoder.c
===================================================================
RCS file: 
/cvsroot/classpath/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkPixbufDecoder.c,v
retrieving revision 1.15
diff -u -r1.15 gnu_java_awt_peer_gtk_GdkPixbufDecoder.c
--- native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkPixbufDecoder.c        2 Jul 
2005 20:32:53 -0000       1.15
+++ native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkPixbufDecoder.c        4 Jul 
2005 18:03:42 -0000
@@ -299,7 +299,7 @@
 
 JNIEXPORT void JNICALL
 Java_gnu_java_awt_peer_gtk_GdkPixbufDecoder_finish
-  (JNIEnv *env, jobject obj)
+(JNIEnv *env, jobject obj, jboolean needs_close)
 {
   GdkPixbufLoader *loader = NULL;
 
@@ -308,7 +308,8 @@
     return;
 
   gdk_threads_enter ();
-  gdk_pixbuf_loader_close (loader, NULL);
+  if (needs_close)
+    gdk_pixbuf_loader_close (loader, NULL);
   g_object_unref (loader);
   gdk_threads_leave (); 
 

Attachment: signature.asc
Description: This is a digitally signed message part


reply via email to

[Prev in Thread] Current Thread [Next in Thread]