[gimp] pdb, libgimp: add a HORRIBLE hack to make sure objects arrays don't leak
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] pdb, libgimp: add a HORRIBLE hack to make sure objects arrays don't leak
- Date: Thu, 5 Sep 2019 13:04:26 +0000 (UTC)
commit 46608393c3abc13fd7d2e79506e44fe88b9da28b
Author: Michael Natterer <mitch gimp org>
Date: Thu Sep 5 14:51:35 2019 +0200
pdb, libgimp: add a HORRIBLE hack to make sure objects arrays don't leak
In the generated libgimp wrappers, we can't return object arrays
from a call to GIMP_VALUES_DUP_OBJECT_ARRAY() because it returns
a deep copy and adds a reference to all objects, which the caller
would have to unref.
But we want a shallow (transfer container) copy because we don't want
libgimp proxy objects to be refed or unrefed by any user code.
Therefore, add a HACK that simply memdup()s and returns the
GimpObjectArray's array memory, and leaves the contained object
pointers alone.
libgimp/gimpfileops_pdb.c | 2 +-
libgimp/gimpimage_pdb.c | 8 ++++----
libgimp/gimpitem_pdb.c | 2 +-
libgimp/gimpvectors_pdb.c | 4 ++--
pdb/pdb.pl | 10 +++++-----
5 files changed, 13 insertions(+), 13 deletions(-)
---
diff --git a/libgimp/gimpfileops_pdb.c b/libgimp/gimpfileops_pdb.c
index aed8abf9c1..c024ba08e3 100644
--- a/libgimp/gimpfileops_pdb.c
+++ b/libgimp/gimpfileops_pdb.c
@@ -171,7 +171,7 @@ gimp_file_load_layers (GimpRunMode run_mode,
if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
{
*num_layers = GIMP_VALUES_GET_INT (return_vals, 1);
- layers = GIMP_VALUES_DUP_OBJECT_ARRAY (return_vals, 2);
+ { GimpObjectArray *a = g_value_get_boxed (gimp_value_array_index (return_vals, 2)); if (a) layers =
g_memdup (a->data, a->length * sizeof (gpointer)); };
}
gimp_value_array_unref (return_vals);
diff --git a/libgimp/gimpimage_pdb.c b/libgimp/gimpimage_pdb.c
index 8eea9989fb..85fb087d3d 100644
--- a/libgimp/gimpimage_pdb.c
+++ b/libgimp/gimpimage_pdb.c
@@ -104,7 +104,7 @@ gimp_get_images (gint *num_images)
if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
{
*num_images = GIMP_VALUES_GET_INT (return_vals, 1);
- images = GIMP_VALUES_DUP_OBJECT_ARRAY (return_vals, 2);
+ { GimpObjectArray *a = g_value_get_boxed (gimp_value_array_index (return_vals, 2)); if (a) images =
g_memdup (a->data, a->length * sizeof (gpointer)); };
}
gimp_value_array_unref (return_vals);
@@ -496,7 +496,7 @@ gimp_image_get_layers (GimpImage *image,
if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
{
*num_layers = GIMP_VALUES_GET_INT (return_vals, 1);
- layers = GIMP_VALUES_DUP_OBJECT_ARRAY (return_vals, 2);
+ { GimpObjectArray *a = g_value_get_boxed (gimp_value_array_index (return_vals, 2)); if (a) layers =
g_memdup (a->data, a->length * sizeof (gpointer)); };
}
gimp_value_array_unref (return_vals);
@@ -543,7 +543,7 @@ gimp_image_get_channels (GimpImage *image,
if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
{
*num_channels = GIMP_VALUES_GET_INT (return_vals, 1);
- channels = GIMP_VALUES_DUP_OBJECT_ARRAY (return_vals, 2);
+ { GimpObjectArray *a = g_value_get_boxed (gimp_value_array_index (return_vals, 2)); if (a) channels =
g_memdup (a->data, a->length * sizeof (gpointer)); };
}
gimp_value_array_unref (return_vals);
@@ -589,7 +589,7 @@ gimp_image_get_vectors (GimpImage *image,
if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
{
*num_vectors = GIMP_VALUES_GET_INT (return_vals, 1);
- vectors = GIMP_VALUES_DUP_OBJECT_ARRAY (return_vals, 2);
+ { GimpObjectArray *a = g_value_get_boxed (gimp_value_array_index (return_vals, 2)); if (a) vectors =
g_memdup (a->data, a->length * sizeof (gpointer)); };
}
gimp_value_array_unref (return_vals);
diff --git a/libgimp/gimpitem_pdb.c b/libgimp/gimpitem_pdb.c
index 7d74e274e0..d7e720c2ae 100644
--- a/libgimp/gimpitem_pdb.c
+++ b/libgimp/gimpitem_pdb.c
@@ -511,7 +511,7 @@ gimp_item_get_children (GimpItem *item,
if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
{
*num_children = GIMP_VALUES_GET_INT (return_vals, 1);
- children = GIMP_VALUES_DUP_OBJECT_ARRAY (return_vals, 2);
+ { GimpObjectArray *a = g_value_get_boxed (gimp_value_array_index (return_vals, 2)); if (a) children =
g_memdup (a->data, a->length * sizeof (gpointer)); };
}
gimp_value_array_unref (return_vals);
diff --git a/libgimp/gimpvectors_pdb.c b/libgimp/gimpvectors_pdb.c
index 6e6d82cca9..fd2cef1368 100644
--- a/libgimp/gimpvectors_pdb.c
+++ b/libgimp/gimpvectors_pdb.c
@@ -1077,7 +1077,7 @@ gimp_vectors_import_from_file (GimpImage *image,
if (success)
{
*num_vectors = GIMP_VALUES_GET_INT (return_vals, 1);
- *vectors = GIMP_VALUES_DUP_OBJECT_ARRAY (return_vals, 2);
+ { GimpObjectArray *a = g_value_get_boxed (gimp_value_array_index (return_vals, 2)); if (a) *vectors =
g_memdup (a->data, a->length * sizeof (gpointer)); };
}
gimp_value_array_unref (return_vals);
@@ -1139,7 +1139,7 @@ gimp_vectors_import_from_string (GimpImage *image,
if (success)
{
*num_vectors = GIMP_VALUES_GET_INT (return_vals, 1);
- *vectors = GIMP_VALUES_DUP_OBJECT_ARRAY (return_vals, 2);
+ { GimpObjectArray *a = g_value_get_boxed (gimp_value_array_index (return_vals, 2)); if (a) *vectors =
g_memdup (a->data, a->length * sizeof (gpointer)); };
}
gimp_value_array_unref (return_vals);
diff --git a/pdb/pdb.pl b/pdb/pdb.pl
index 91b9f6999d..5925809ba4 100644
--- a/pdb/pdb.pl
+++ b/pdb/pdb.pl
@@ -145,7 +145,7 @@ package Gimp::CodeGen::pdb;
in_annotate => '(element-type GimpImage)',
out_annotate => '(element-type GimpImage) (transfer container)',
get_value_func => '$var = gimp_value_get_object_array ($value)',
- dup_value_func => '$var = GIMP_VALUES_DUP_OBJECT_ARRAY ($value)',
+ dup_value_func => '{ GimpObjectArray *a = g_value_get_boxed (gimp_value_array_index
($value)); if (a) $var = g_memdup (a->data, a->length * sizeof (gpointer)); }',
set_value_func => 'gimp_value_set_object_array ($value, GIMP_TYPE_IMAGE, (GObject **)
$var, $var_len)',
take_value_func => 'gimp_value_take_object_array ($value, GIMP_TYPE_IMAGE, (GObject **)
$var, $var_len)' },
@@ -158,7 +158,7 @@ package Gimp::CodeGen::pdb;
in_annotate => '(element-type GimpItem)',
out_annotate => '(element-type GimpItem) (transfer container)',
get_value_func => '$var = gimp_value_get_object_array ($value)',
- dup_value_func => '$var = GIMP_VALUES_DUP_OBJECT_ARRAY ($value)',
+ dup_value_func => '{ GimpObjectArray *a = g_value_get_boxed (gimp_value_array_index
($value)); if (a) $var = g_memdup (a->data, a->length * sizeof (gpointer)); }',
set_value_func => 'gimp_value_set_object_array ($value, GIMP_TYPE_ITEM, (GObject **)
$var, $var_len)',
take_value_func => 'gimp_value_take_object_array ($value, GIMP_TYPE_ITEM, (GObject **)
$var, $var_len)' },
@@ -171,7 +171,7 @@ package Gimp::CodeGen::pdb;
in_annotate => '(element-type GimpLayer)',
out_annotate => '(element-type GimpLayer) (transfer container)',
get_value_func => '$var = gimp_value_get_object_array ($value)',
- dup_value_func => '$var = GIMP_VALUES_DUP_OBJECT_ARRAY ($value)',
+ dup_value_func => '{ GimpObjectArray *a = g_value_get_boxed (gimp_value_array_index
($value)); if (a) $var = g_memdup (a->data, a->length * sizeof (gpointer)); }',
set_value_func => 'gimp_value_set_object_array ($value, GIMP_TYPE_LAYER, (GObject **)
$var, $var_len)',
take_value_func => 'gimp_value_take_object_array ($value, GIMP_TYPE_LAYER, (GObject **)
$var, $var_len)' },
@@ -184,7 +184,7 @@ package Gimp::CodeGen::pdb;
in_annotate => '(element-type GimpChannel)',
out_annotate => '(element-type GimpChannel) (transfer container)',
get_value_func => '$var = gimp_value_get_object_array ($value)',
- dup_value_func => '$var = GIMP_VALUES_DUP_OBJECT_ARRAY ($value)',
+ dup_value_func => '{ GimpObjectArray *a = g_value_get_boxed (gimp_value_array_index
($value)); if (a) $var = g_memdup (a->data, a->length * sizeof (gpointer)); }',
set_value_func => 'gimp_value_set_object_array ($value, GIMP_TYPE_CHANNEL, (GObject **)
$var, $var_len)',
take_value_func => 'gimp_value_take_object_array ($value, GIMP_TYPE_CHANNEL, (GObject
**) $var, $var_len)' },
@@ -197,7 +197,7 @@ package Gimp::CodeGen::pdb;
in_annotate => '(element-type GimpVectors)',
out_annotate => '(element-type GimpVectors) (transfer container)',
get_value_func => '$var = gimp_value_get_object_array ($value)',
- dup_value_func => '$var = GIMP_VALUES_DUP_OBJECT_ARRAY ($value)',
+ dup_value_func => '{ GimpObjectArray *a = g_value_get_boxed (gimp_value_array_index
($value)); if (a) $var = g_memdup (a->data, a->length * sizeof (gpointer)); }',
set_value_func => 'gimp_value_set_object_array ($value, GIMP_TYPE_VECTORS, (GObject **)
$var, $var_len)',
take_value_func => 'gimp_value_take_object_array ($value, GIMP_TYPE_VECTORS, (GObject
**) $var, $var_len)' },
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]