Hi again !

On Thu, Sep 23, 2010 at 07:25:42PM +0200, Axel Simon wrote:
> >/me launch his quickcheck tests with parallel threads and is
> >   happy to see that everything run smoothly ... except for
> >   System.Glib.UTFString.fromUTF which is not as good as the
> >   utf8-string package to process arbitrary strings generated by
> >   QuickCheck2.
> >
> 
> True, fromUTF bails out badly. What kind of behavior does
> utf8-string have that we don't? I don't really want to add yet
> another package to the dependency list of gtk, but I would be happy
> to add some sort of better error handling or recovery.

I've just looked on this problem and it is probably not due to
esoteric unicode numbers. Glib readUTFStringArray0 failed on
arrays of string containing empty strings, a type of data
QuickCheck seems particularly fond of.

So when using readUTFStringArry0 on, say, ["one", "", "three"],
fromUTF8 throws an exception.

When I copy-pasted the module UTFString to implement my own, I
modified glib/System/Glib/UTFString.hs this way:

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
--- a/glib/System/Glib/UTFString.hs     2010-09-06      2010-09-06 
11:24:42.980482243 +0200
+++ b/glib/System/Glib/UTFString.hs     2010-09-24 16:10:21.821860119 +0200
@@ -149,8 +149,9 @@
 readUTFStringArray0 :: Ptr CString -> IO [String]
 readUTFStringArray0 cStrArr = do
   cStrs <- peekArray0 nullPtr cStrArr
+  strings <- mapM peekUTFString cStrs
   g_strfreev cStrArr
-  mapM peekUTFString cStrs
+  return strings
 
 foreign import ccall unsafe "g_strfreev"
   g_strfreev :: Ptr a -> IO ()
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

It's seems wiser to read the array (mapM peekUTFString) *before*
freeing it, laziness considerations apart.

Rebuilding glib-0.11.2 with this modification, my quickcheck
property on string_list run fine with 10,000 samples, which
should be enough to exclude fromUTF8 unicode conversion ability
from the list of suspects.

I can unfortunately not find how to reproduce the original bad
behaviour with raw gtk2hs libraries, since few use
readUTFStringArray0 and even if it's the case, tweaking the
source string list to artificially insert empty string and
trigger the exception is beyond my abilities. (... but it happened
in my project huhu :)


As for gobject count references, construction and memory
consumption, it's another story for another day.

regards,
/John

Attachment: pgpQply2SgfiA.pgp
Description: PGP signature

------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
Gtk2hs-devel mailing list
Gtk2hs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gtk2hs-devel

Reply via email to