From a1b44acabfbca2fd6931699a9407fe8f9d95d253 Mon Sep 17 00:00:00 2001 From: Paul Pogonyshev Date: Sun, 21 Dec 2008 16:08:01 +0000 Subject: Merge from 2.16 branch: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2008-12-21 Paul Pogonyshev Bug 564102 – _wrap_g_output_stream_write_async not adding a reference to the buffer passed * gio/gio.override (pygio_notify_copy_buffer): New function. (pygio_free_notify): Free new `buffer' field if it is set. * gio/goutputstream.override (_wrap_g_output_stream_write_async): Copy the buffer with new pygio_notify_copy_buffer() and use the copy for g_output_stream_write_async() call. * gio/gfile.override (_wrap_g_file_replace_contents_async): Same as for _wrap_g_output_stream_write_async(). svn path=/trunk/; revision=981 --- ChangeLog | 15 +++++++++++++++ gio/gfile.override | 5 +++-- gio/gio.override | 14 ++++++++++++++ gio/goutputstream.override | 5 +++-- 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 38cd16d..b3ec919 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2008-12-21 Paul Pogonyshev + + Bug 564102 – _wrap_g_output_stream_write_async not adding a + reference to the buffer passed + + * gio/gio.override (pygio_notify_copy_buffer): New function. + (pygio_free_notify): Free new `buffer' field if it is set. + + * gio/goutputstream.override (_wrap_g_output_stream_write_async): + Copy the buffer with new pygio_notify_copy_buffer() and use the + copy for g_output_stream_write_async() call. + + * gio/gfile.override (_wrap_g_file_replace_contents_async): Same + as for _wrap_g_output_stream_write_async(). + 2008-12-03 Paul Pogonyshev * glib/pyglib.c (pyglib_error_check): Test if `domain' is not-null diff --git a/gio/gfile.override b/gio/gfile.override index 77dad6f..deb43e8 100644 --- a/gio/gfile.override +++ b/gio/gfile.override @@ -1110,9 +1110,10 @@ _wrap_g_file_replace_contents_async(PyGObject *self, PyObject *args, PyObject *k Py_INCREF(notify->callback); Py_XINCREF(notify->data); + pygio_notify_copy_buffer(notify, contents, length); g_file_replace_contents_async(G_FILE(self->obj), - contents, - length, + notify->buffer, + notify->buffer_size, etag, make_backup, flags, diff --git a/gio/gio.override b/gio/gio.override index e6916a0..0f6ae5f 100644 --- a/gio/gio.override +++ b/gio/gio.override @@ -36,6 +36,8 @@ headers typedef struct { PyObject *callback; PyObject *data; + gpointer buffer; + gsize buffer_size; } PyGIONotify; static void @@ -44,11 +46,23 @@ py_decref_callback (gpointer data) Py_DECREF((PyObject*)data); } +static void +pygio_notify_copy_buffer(PyGIONotify *notify, gpointer buffer, gsize buffer_size) +{ + if (buffer_size > 0) { + notify->buffer = g_slice_copy(buffer_size, buffer); + notify->buffer_size = buffer_size; + } +} + static void pygio_free_notify(PyGIONotify *notify) { Py_XDECREF(notify->callback); Py_XDECREF(notify->data); + if (notify->buffer) + g_slice_free1(notify->buffer_size, notify->buffer); + g_slice_free(PyGIONotify, notify); } diff --git a/gio/goutputstream.override b/gio/goutputstream.override index 3b44632..df9ea94 100644 --- a/gio/goutputstream.override +++ b/gio/goutputstream.override @@ -130,9 +130,10 @@ _wrap_g_output_stream_write_async(PyGObject *self, if (!pygio_check_cancellable(pycancellable, &cancellable)) return NULL; + pygio_notify_copy_buffer(notify, buffer, count); g_output_stream_write_async(G_OUTPUT_STREAM(self->obj), - buffer, - count, + notify->buffer, + notify->buffer_size, io_priority, cancellable, (GAsyncReadyCallback)async_result_callback_marshal, -- cgit