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 754830 - missing constructor annotation on g_volume_monitor_get
missing constructor annotation on g_volume_monitor_get
Status: RESOLVED DUPLICATE of bug 744690
Product: glib
Classification: Platform
Component: gio
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2015-09-10 12:55 UTC by Matěj Cepl
Modified: 2015-09-10 13:14 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Matěj Cepl 2015-09-10 12:55:44 UTC
In order to get working Gio.VolumeMonitor() I would assume that this Python script should do the job:

#!/usr/bin/env python
from gi.repository import Gio
 
gmonitor = Gio.VolumeMonitor()
gmonitor.get_connected_drives()

Unfortunately that leads to crash, because Gio.VolumeMonitor() actually doesn't create new Gio.VolumeMonitor object correctly, one needs to use Gio.VolumeMonitor().get().

It seems to me that the problem is missing (constructor) annotation on 
https://github.com/GNOME/glib/blob/078dbda148a81af1b3a76fbda72f089b963087f1/gio/gunionvolumemonitor.c#L559
Comment 1 Matěj Cepl 2015-09-10 12:56:59 UTC
And yes, another problem is that the calling of method on the object created without .get() leads to crash. It should never crash, just raise an exception.
Comment 2 Emmanuele Bassi (:ebassi) 2015-09-10 13:14:52 UTC
(In reply to Matěj Cepl from comment #0)
> In order to get working Gio.VolumeMonitor() I would assume that this Python
> script should do the job:
> 
> #!/usr/bin/env python
> from gi.repository import Gio
>  
> gmonitor = Gio.VolumeMonitor()
> gmonitor.get_connected_drives()
> 
> Unfortunately that leads to crash, because Gio.VolumeMonitor() actually
> doesn't create new Gio.VolumeMonitor object correctly, one needs to use
> Gio.VolumeMonitor().get().
> 
> It seems to me that the problem is missing (constructor) annotation on 
> https://github.com/GNOME/glib/blob/078dbda148a81af1b3a76fbda72f089b963087f1/
> gio/gunionvolumemonitor.c#L559

See also: bug 744690

The annotation is not the problem, and it would actually be wrong: g_volume_monitor_get() is not a constructor, it's a factory method which always returns the same instance for the whole duration of the application's life time.

You're supposed to use Gio.VolumeMonitor.get(), not the normal Python constructor form. What PyGObject can do is create an override for Gio so that trying to construct Gio.VolumeMonitor using the constructor's normal form will raise an exception.

(In reply to Matěj Cepl from comment #1)
> And yes, another problem is that the calling of method on the object created
> without .get() leads to crash. It should never crash, just raise an
> exception.

While it would be great if all errors at the C level automagically turned into Python exceptions, we cannot really do that. The C layer is binding-agnostic, and will abort() or segfault regardless. The closest thing we could do would be to check for missing methods because you created a GVolumeMonitor instance directly, but you'd still just get critical warnings in the program's output, not exceptions.

*** This bug has been marked as a duplicate of bug 744690 ***