fix-gnome40-build.patch 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. From 7cf6268e54620bbbe5e6e61800c50fb0cb4bea57 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Corentin=20No=C3=ABl?= <corentin@elementary.io>
  3. Date: Fri, 16 Oct 2020 19:56:26 +0200
  4. Subject: [PATCH] Change GLib.PtrArray into GLib.GenericArray
  5. This is the vala-friendly way of handling GPtrArray.
  6. Fix several memory leaks on the go and unnecessary reference increase.
  7. ---
  8. src/cheese-preferences.vala | 26 ++++++++++++--------------
  9. src/cheese-window.vala | 22 +++++++++++-----------
  10. src/vapi/cheese-common.vapi | 2 +-
  11. 3 files changed, 24 insertions(+), 26 deletions(-)
  12. diff --git a/src/cheese-preferences.vala b/src/cheese-preferences.vala
  13. index f56af7e0..80a92431 100644
  14. --- a/src/cheese-preferences.vala
  15. +++ b/src/cheese-preferences.vala
  16. @@ -100,7 +100,7 @@ public PreferencesDialog (Cheese.Camera camera)
  17. */
  18. private void initialize_camera_devices ()
  19. {
  20. - unowned GLib.PtrArray devices = camera.get_camera_devices ();
  21. + GLib.GenericArray<unowned Cheese.CameraDevice> devices = camera.get_camera_devices ();
  22. camera_model = new Gtk.ListStore (2, typeof (string), typeof (Cheese.CameraDevice));
  23. source_combo.model = camera_model;
  24. @@ -357,13 +357,13 @@ public PreferencesDialog (Cheese.Camera camera)
  25. */
  26. private void on_camera_update_num_camera_devices ()
  27. {
  28. - unowned GLib.PtrArray devices = camera.get_camera_devices ();
  29. - Cheese.CameraDevice dev;
  30. + GLib.GenericArray<unowned Cheese.CameraDevice> devices = camera.get_camera_devices ();
  31. + unowned Cheese.CameraDevice dev;
  32. // Add (if) / Remove (else) a camera device.
  33. - if (devices.len > camera_model.iter_n_children (null))
  34. + if (devices.length > camera_model.iter_n_children (null))
  35. {
  36. - dev = (Cheese.CameraDevice) devices.index (devices.len - 1);
  37. + dev = devices.get (devices.length - 1);
  38. add_camera_device(dev);
  39. }
  40. else
  41. @@ -382,12 +382,11 @@ public PreferencesDialog (Cheese.Camera camera)
  42. bool device_removed = false;
  43. devices.foreach ((device) =>
  44. {
  45. - var old_device = (Cheese.CameraDevice) device;
  46. Cheese.CameraDevice new_device;
  47. camera_model.get (iter, 1, out new_device, -1);
  48. // Found the device that was removed.
  49. - if (old_device != new_device)
  50. + if (device != new_device)
  51. {
  52. remove_camera_device (iter, new_device, active_device);
  53. device_removed = true;
  54. @@ -418,17 +417,16 @@ public PreferencesDialog (Cheese.Camera camera)
  55. *
  56. * @param device a Cheese.CameraDevice to add to the device combo box model
  57. */
  58. - private void add_camera_device (void *device)
  59. + private void add_camera_device (Cheese.CameraDevice device)
  60. {
  61. TreeIter iter;
  62. - Cheese.CameraDevice dev = (Cheese.CameraDevice) device;
  63. camera_model.append (out iter);
  64. camera_model.set (iter,
  65. - 0, dev.get_name (),
  66. - 1, dev);
  67. + 0, device.get_name (),
  68. + 1, device);
  69. - if (camera.get_selected_device () == dev)
  70. + if (camera.get_selected_device () == device)
  71. source_combo.set_active_iter (iter);
  72. if (camera_model.iter_n_children (null) > 1)
  73. @@ -445,12 +443,12 @@ public PreferencesDialog (Cheese.Camera camera)
  74. private void remove_camera_device (TreeIter iter, Cheese.CameraDevice device_node,
  75. Cheese.CameraDevice active_device_node)
  76. {
  77. - unowned GLib.PtrArray devices = camera.get_camera_devices ();
  78. + GLib.GenericArray<unowned Cheese.CameraDevice> devices = camera.get_camera_devices ();
  79. // Check if the camera that we want to remove, is the active one
  80. if (device_node == active_device_node)
  81. {
  82. - if (devices.len > 0)
  83. + if (devices.length > 0)
  84. set_new_available_camera_device (iter);
  85. else
  86. this.hide ();
  87. diff --git a/src/cheese-window.vala b/src/cheese-window.vala
  88. index ff069808..cc119b68 100644
  89. --- a/src/cheese-window.vala
  90. +++ b/src/cheese-window.vala
  91. @@ -1216,9 +1216,9 @@ public class Cheese.MainWindow : Gtk.ApplicationWindow
  92. */
  93. public void on_switch_camera_clicked ()
  94. {
  95. - Cheese.CameraDevice selected;
  96. - Cheese.CameraDevice next = null;
  97. - GLib.PtrArray cameras;
  98. + unowned Cheese.CameraDevice selected;
  99. + unowned Cheese.CameraDevice next = null;
  100. + GLib.GenericArray<unowned Cheese.CameraDevice> cameras;
  101. uint i;
  102. if (camera == null)
  103. @@ -1235,9 +1235,9 @@ public class Cheese.MainWindow : Gtk.ApplicationWindow
  104. cameras = camera.get_camera_devices ();
  105. - for (i = 0; i < cameras.len; i++)
  106. + for (i = 0; i < cameras.length; i++)
  107. {
  108. - next = (Cheese.CameraDevice )cameras.index (i);
  109. + next = cameras.get (i);
  110. if (next == selected)
  111. {
  112. @@ -1245,13 +1245,13 @@ public class Cheese.MainWindow : Gtk.ApplicationWindow
  113. }
  114. }
  115. - if (i + 1 < cameras.len)
  116. + if (i + 1 < cameras.length)
  117. {
  118. - next = (Cheese.CameraDevice )cameras.index (i + 1);
  119. + next = cameras.get (i + 1);
  120. }
  121. else
  122. {
  123. - next = (Cheese.CameraDevice )cameras.index (0);
  124. + next = cameras.get (0);
  125. }
  126. if (next == selected)
  127. @@ -1269,8 +1269,8 @@ public class Cheese.MainWindow : Gtk.ApplicationWindow
  128. */
  129. public void set_switch_camera_button_state ()
  130. {
  131. - Cheese.CameraDevice selected;
  132. - GLib.PtrArray cameras;
  133. + unowned Cheese.CameraDevice selected;
  134. + GLib.GenericArray<unowned Cheese.CameraDevice> cameras;
  135. if (camera == null)
  136. {
  137. @@ -1288,7 +1288,7 @@ public class Cheese.MainWindow : Gtk.ApplicationWindow
  138. cameras = camera.get_camera_devices ();
  139. - if (cameras.len > 1)
  140. + if (cameras.length > 1)
  141. {
  142. switch_camera_button.set_visible (true);
  143. return;
  144. diff --git a/src/vapi/cheese-common.vapi b/src/vapi/cheese-common.vapi
  145. index 6517cdfc..e4ae7ad3 100644
  146. --- a/src/vapi/cheese-common.vapi
  147. +++ b/src/vapi/cheese-common.vapi
  148. @@ -35,7 +35,7 @@ namespace Cheese
  149. [CCode (has_construct_function = false)]
  150. public Camera (Clutter.Actor video_texture, string camera_device_node, int x_resolution, int y_resolution);
  151. public bool get_balance_property_range (string property, double min, double max, double def);
  152. - public unowned GLib.PtrArray get_camera_devices ();
  153. + public GLib.GenericArray<unowned Cheese.CameraDevice> get_camera_devices ();
  154. public unowned Cheese.VideoFormat get_current_video_format ();
  155. public int get_num_camera_devices ();
  156. public unowned Cheese.CameraDevice get_selected_device ();
  157. --
  158. GitLab