0

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?

timothymctim
  • 205
  • 1
  • 9

1 Answers1

1

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
  *
TingPing
  • 2,129
  • 1
  • 12
  • 15
  • Wow, thanks for digging in! I'm curious what ‘they’ will say upstream. If one needs to file bug report, please let me know. – timothymctim Apr 21 '16 at 17:07
  • So from what I gather that function will probably just never be usable from an introspected language. lgi only supports fixed size arrays (which makes sense) and pygobject does not support them at all. Somebody did suggest trying to convert it to a GDateTime and use `g_date_time_format()` if possible. The API was just poorly designed for GI usage. – TingPing Apr 22 '16 at 10:01