Re: Problems using UTF-8



On Tuesday, December 30, 2003, at 03:25 AM, Gustavo Noronha Silva wrote:

Following muppet's tips I ended up with the following xs/GtkMessageDialog.xs
modifications:

that patch isn't recommended for general consumption, actually, as it disables the printf-like signature introduced in 1.020. the point of the exercise was to find out if the problem was in the encoding of the format string without wondering what was happening in sv_vsetpvfn.

i think, but am not sure, that the crux of the problem is the fact that the format string has in C the type guchar* --- unsigned characters, which do not get the special utf8-upgrade treatment from the bindings that gchar* types do.


That is, indeed a bug, and needs to be taken care of, any takers? =)

with a little bit of digging through the perl source to see how sprintf is implemented, i have a new implementation of Gtk2::MessageDialog->new... this one explicitly forces UTF-8 handling on the text. i managed to get the expected text out of your sample with this.

GtkWidget *
gtk_message_dialog_new (class, parent, flags, type, buttons, format, ...)
        GtkWindow_ornull * parent
        GtkDialogFlags flags
        GtkMessageType type
        GtkButtonsType buttons
        SV * format
    PREINIT:
        STRLEN patlen;
        gchar * pat;
        SV * message;
    CODE:
        /* text passed to GTK+ must be UTF-8.  force it. */
        message = newSV (0);
        SvUTF8_on (message);
        sv_utf8_upgrade (format);
        pat = SvPV (format, patlen);
sv_vsetpvfn (message, pat, patlen, NULL, &(ST (6)), items - 6, Null(bool*));
        RETVAL = gtk_message_dialog_new (parent, flags, type, buttons,
                                         "%s", SvPV_nolen (message));
    OUTPUT:
        RETVAL


i will commit this, as it appears to work (i even tried using %s and %d in your example text), but feedback would be greatly appreciated.

--
muppet <scott at asofyet dot org>




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