|
From: Allin C. <cot...@wf...> - 2015-03-06 16:25:47
|
On Fri, 6 Mar 2015, Tatsuro MATSUOKA wrote: > I have executed a short test using nmh > https://github.com/shnya/nmh > > Perhaps it is better to use ICU - International Components for Unicode but > I used nmh for rough test. > > Applied changes: > > --- gp_cairo.orig.c2014-12-14 08:42:38.000000000 +0900 > +++ gp_cairo.c2015-03-06 10:04:45.142151900 +0900 > @@ -76,6 +76,7 @@ > > #include <pango/pangocairo.h> > #include <glib.h> > +#include <nmh.h> > > #ifdef _MSC_VER > #define rint(x) floor((x)+0.5L) > @@ -732,14 +733,21 @@ > gsize bytes_read; > GError *error = NULL; > const char *charset = NULL; > +const unsigned char *ucharset = NULL; > gchar * string_utf8; > > -if (g_utf8_validate(string, -1, NULL)) { > - string_utf8 = g_strdup(string); > -} else { > - charset = gp_cairo_get_encoding(plot); > - string_utf8 = g_convert(string, -1, "UTF-8", charset, &bytes_read, NULL, &error); > -} > +charset = gp_cairo_get_encoding(plot); > +ucharset = charset; > +fprintf(stderr, "%f\n", nmh_is_utf8(ucharset, strlen(ucharset))); > + if (nmh_is_utf8(ucharset, strlen(ucharset))) { > +fprintf(stderr, "%f\n", nmh_is_utf8(ucharset, strlen(ucharset))); > + string_utf8 = g_convert(string, -1, "UTF-8", charset, &bytes_read, NULL, &error); Bug right there: according to the documentation for g_convert, it's OK to pass NULL in place of the "bytes_read" pointer argument, but _not_ in place of the "bytes_written" (second to last) argument. So it's to be expected that you get a segfault here. (BTW, I don't see the point of the nmh test on the "ucharset" string: surely that's just the identifier of an encoding and will always be ASCII -- and hence also UTF-8.) Allin Cottrell |