diff options
author | Christoph Reiter <reiter.christoph@gmail.com> | 2018-06-17 12:20:10 +0200 |
---|---|---|
committer | Christoph Reiter <reiter.christoph@gmail.com> | 2018-06-17 12:34:54 +0200 |
commit | 898bbe50005223f5f04994764b3e95f13dffe2d2 (patch) | |
tree | 45bcc5733473eec7bb54534a2bd6c3815ddfe170 /gi | |
parent | 4b92d6d1d92b711f3640238504b9714a7d89ea29 (diff) | |
download | pygobject-898bbe50005223f5f04994764b3e95f13dffe2d2.tar.gz |
Add override for GdkPixbuf.Pixbuf.new_from_data. Fixes #225pixbuf-new-from-data
new_from_data isn't bindable (see https://bugzilla.gnome.org/show_bug.cgi?id=721497)
and will result in use after free. While we could try to move people away from it and
skip it in GI a github code search turns up quite a few users.
This adds an override for it, wrapping GdkPixbuf.Pixbuf.new_from_bytes, and marks any
usage of the callback args as deprecated.
Diffstat (limited to 'gi')
-rw-r--r-- | gi/overrides/GdkPixbuf.py | 53 | ||||
-rw-r--r-- | gi/overrides/meson.build | 1 |
2 files changed, 54 insertions, 0 deletions
diff --git a/gi/overrides/GdkPixbuf.py b/gi/overrides/GdkPixbuf.py new file mode 100644 index 00000000..0f6cd751 --- /dev/null +++ b/gi/overrides/GdkPixbuf.py @@ -0,0 +1,53 @@ +# Copyright 2018 Christoph Reiter <reiter.christoph@gmail.com> +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 +# USA + +import warnings + +from gi import PyGIDeprecationWarning +from gi.repository import GLib + +from ..overrides import override +from ..module import get_introspection_module + + +GdkPixbuf = get_introspection_module('GdkPixbuf') +__all__ = [] + + +@override +class Pixbuf(GdkPixbuf.Pixbuf): + + @classmethod + def new_from_data( + cls, data, colorspace, has_alpha, bits_per_sample, + width, height, rowstride, + destroy_fn=None, *destroy_fn_data): + + if destroy_fn is not None: + w = PyGIDeprecationWarning("destroy_fn argument deprecated") + warnings.warn(w) + if destroy_fn_data: + w = PyGIDeprecationWarning("destroy_fn_data argument deprecated") + warnings.warn(w) + + data = GLib.Bytes.new(data) + return cls.new_from_bytes( + data, colorspace, has_alpha, bits_per_sample, + width, height, rowstride) + + +__all__.append('Pixbuf') diff --git a/gi/overrides/meson.build b/gi/overrides/meson.build index b8ecae95..6ff073ff 100644 --- a/gi/overrides/meson.build +++ b/gi/overrides/meson.build @@ -2,6 +2,7 @@ python_sources = [ 'GLib.py', 'Gtk.py', 'Gdk.py', + 'GdkPixbuf.py', 'GObject.py', 'Gio.py', 'GIMarshallingTests.py', |