Search code examples
python-3.xpygobjectgobject-introspection

PyGObject GTK+ GLib.Date strftime()


A method call in Poppler returns a GDate object in my Python code. I cannot find a way how to nicely print this object.

Following the Python GI API Reference, I came up with the following:

gdate_object = annot_mapping.annot.get_date()
destination_buffer = '.' * 50
print('Output:', GLib.Date.strftime(destination_buffer, 50, '%c', gdate_object))
print('Buffer:', annot_time)

However, this places nothing in the buffer, while it does output the written buffer size.

How do I get access to the destination buffer?


Solution

  • Looks like nobody documented that API so it will be broken for introspection bindings.

    I made a simple patch but it seems pygobject doesn't like allocating string buffers, I will talk with upstream about it.

    diff --git a/glib/gdate.c b/glib/gdate.c
    index bea2448..bacdb93 100644
    --- a/glib/gdate.c
    +++ b/glib/gdate.c
    @@ -2418,8 +2418,8 @@ win32_strftime_helper (const GDate     *d,
    
     /**
      * g_date_strftime:
    - * @s: destination buffer
    - * @slen: buffer size
    + * @s: (out caller-allocates) (array length=slen): destination buffer
    + * @slen: (in): buffer size
      * @format: format string
      * @date: valid #GDate
      *