After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 572471 - Giomm streams cannot be inherited from (add vfuncs at ABI break)
Giomm streams cannot be inherited from (add vfuncs at ABI break)
Status: RESOLVED FIXED
Product: glibmm
Classification: Bindings
Component: giomm
unspecified
Other All
: Normal enhancement
: ---
Assigned To: gtkmm-forge
gtkmm-forge
: 642111 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2009-02-19 18:43 UTC by Krzysztof Kosiński
Modified: 2016-11-21 15:32 UTC
See Also:
GNOME target: ---
GNOME version: Unversioned Enhancement


Attachments
Wrap stream vfuncs (43.64 KB, patch)
2009-12-30 01:36 UTC, Krzysztof Kosiński
none Details | Review
patch: Wrap some vfuncs in giomm streams (4.46 KB, patch)
2016-06-02 09:00 UTC, Kjell Ahlstedt
committed Details | Review
patch: Add tests/giomm_stream_vfuncs (6.83 KB, patch)
2016-06-02 09:01 UTC, Kjell Ahlstedt
committed Details | Review

Description Krzysztof Kosiński 2009-02-19 18:43:13 UTC
It's impossible to define new types of streams in giomm. Firstly, it's impossible to inherit from InputStream and FilterInputStream, and secondly even if I inherit from a constructible type, the stream is not polymorphic (i.e. it simply doesn't work in the situations that matter).

This could be solved by giving Gio::InputStream an Gio::OutputStream a couple of vfuncs that correspond to the virtual methods of GInputStream and GOutputStream GObjects, in a matter similar to e.g. Gtk::CellRenderer.
Comment 1 Murray Cumming 2009-02-20 19:24:18 UTC
Yes, we chose not to wrap the vfuncs (via _WRAP_VFUNC()) in giomm, because we thought that almost nobody would want to do this and we were worried about the bugs it could introduce in the short term.

But if you have a real-world test case, and a real use for them, we could add these in a future ABI break. That's likely to happen in the nearish future, if the glib/gtk+ 3.0 ABI break really happens. So a patch would be welcome. 
Comment 2 Krzysztof Kosiński 2009-02-20 20:45:15 UTC
A real-world use case would be a base64-encoded stream, or streams that write compressed files. This way if I have a function in an image processing app like this:

void Document::save_png_image(Glib::RefPtr<Gio::OutputStream>)

and I want to create an SVG document which embeds this PNG as a base64-encoded data: URI, I can pass it a Base64OutputStream, which is derived from Gio::FilterOutputStream and writes the base64-encoded data directly into the output file. I could do this in a roundabout way by base64-encoding data written to a MemoryOutputStream, but then I would need to save the entire file into memory, increasing the memory footprint of my application.
Comment 3 Murray Cumming 2009-12-29 12:37:21 UTC
Could you please try to add the vfuncs in the gtkmm3-maybe branch, along with a test/example to show that the idea works.
Comment 4 Krzysztof Kosiński 2009-12-29 14:11:26 UTC
OK, working on a patch, though I'm not very familiar with the gtkmm binding tools and it might take a while.
Comment 5 Krzysztof Kosiński 2009-12-29 14:20:00 UTC
I noticed that there is no 3.0 branch for glibmm yet. Should I work from glibmm master instead?
Comment 6 Murray Cumming 2009-12-29 20:22:49 UTC
Sorry, yes, just use master for now please. We'll branch when we have something to commit there.
Comment 7 Krzysztof Kosiński 2009-12-30 01:36:42 UTC
Created attachment 150564 [details] [review]
Wrap stream vfuncs

Initial version of a patch to allow creating custom streams. I had to create hand-coded wrappers, because the vfuncs are different if exceptions are disabled. For now only synchronous operations are wrapped.

The patch includes a new test, which defines a filter output stream class that base64 encodes the data that passes through it.

I had to fix a bug with MemoryOutputStream that made it completely unusable: GMemoryOutputStream does not use construction properties, so we cannot use the vanilla constructor wrapper. I added a workaround that just calls g_memory_output_stream_new. I will report this as a separate issue, because it doesn't break ABI to fix this.
Comment 8 Krzysztof Kosiński 2009-12-30 01:45:57 UTC
MemoryOutputStream issue reported here:
https://bugzilla.gnome.org/show_bug.cgi?id=605710
Comment 9 Murray Cumming 2011-02-21 11:12:34 UTC
*** Bug 642111 has been marked as a duplicate of this bug. ***
Comment 10 Murray Cumming 2011-02-21 11:54:58 UTC
Note that the patch can now be simplified because we no longer use the no-exceptions ifdefs.
Comment 11 Kjell Ahlstedt 2016-06-02 08:59:33 UTC
I have updated Krzysztof's patch and split it into several smaller patches.
I have also pushed those parts that don't break ABI.
New vfuncs and the new test case must wait until we can break ABI.

Gio::FilterOutputStream::property_base_stream() was declared with the wrong
return type. I have pushed Krzysztof's fix.
  Was Glib::PropertyProxy_ReadOnly< Glib::RefPtr<InputStream> >
  Is Glib::PropertyProxy_ReadOnly< Glib::RefPtr<OutputStream> >
This fix breaks API, but it does not break ABI. The return type is not part
of the mangled name, and only the type of a pointer differs. I guess that
the property with the wrong return type has been useless. The API break should
be acceptable. Unfortunately gmmproc does not detect such an error. In the .defs
file, the type is specified as GParamObject, which can be any kind of GObject.
Comment 12 Kjell Ahlstedt 2016-06-02 09:00:58 UTC
Created attachment 328926 [details] [review]
patch: Wrap some vfuncs in giomm streams

This patch adds vfuncs in BufferedInputStream, InputStream and OutputStream.
No vfunc is hand-coded now.
Comment 13 Kjell Ahlstedt 2016-06-02 09:01:59 UTC
Created attachment 328927 [details] [review]
patch: Add tests/giomm_stream_vfuncs

This is an updated version of Krzysztof's test case. It requires the vfuncs.
Comment 14 Kjell Ahlstedt 2016-11-21 15:32:41 UTC
The remaining two pathces have been pushed to the git master branch.
They will be included in the ABI-breaking glibmm 2.52 release.