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.
This commit is contained in:
Michael Natterer 2019-09-05 14:51:35 +02:00
parent 3dc354e848
commit 46608393c3
5 changed files with 13 additions and 13 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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)' },