简体   繁体   中英

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?

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
  *

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM