diff --git a/app/pdb/image-cmds.c b/app/pdb/image-cmds.c index 8f582cdad6..59d85b38dc 100644 --- a/app/pdb/image-cmds.c +++ b/app/pdb/image-cmds.c @@ -113,27 +113,20 @@ get_images_invoker (GimpProcedure *procedure, GError **error) { GimpValueArray *return_vals; - gint num_images = 0; GimpImage **images = NULL; GList *list = gimp_get_image_iter (gimp); + gsize num_images; + gint i; num_images = g_list_length (list); + images = g_new0 (GimpImage *, num_images + 1); - if (num_images) - { - gint i; - - images = g_new (GimpImage *, num_images); - - for (i = 0; i < num_images; i++, list = g_list_next (list)) - images[i] = g_object_ref (list->data); - } + for (i = 0; i < num_images; i++, list = g_list_next (list)) + images[i] = list->data; return_vals = gimp_procedure_get_return_values (procedure, TRUE, NULL); - - g_value_set_int (gimp_value_array_index (return_vals, 1), num_images); - gimp_value_take_object_array (gimp_value_array_index (return_vals, 2), GIMP_TYPE_IMAGE, (GObject **) images, num_images); + g_value_take_boxed (gimp_value_array_index (return_vals, 1), images); return return_vals; } @@ -3077,17 +3070,11 @@ register_image_procs (GimpPDB *pdb) "Spencer Kimball & Peter Mattis", "1995-1996"); gimp_procedure_add_return_value (procedure, - g_param_spec_int ("num-images", - "num images", - "The number of images currently open", - 0, G_MAXINT32, 0, - GIMP_PARAM_READWRITE)); - gimp_procedure_add_return_value (procedure, - gimp_param_spec_object_array ("images", - "images", - "The list of images currently open.", - GIMP_TYPE_IMAGE, - GIMP_PARAM_READWRITE)); + gimp_param_spec_core_object_array ("images", + "images", + "The list of images currently open.", + GIMP_TYPE_IMAGE, + GIMP_PARAM_READWRITE)); gimp_pdb_register_procedure (pdb, procedure); g_object_unref (procedure); diff --git a/libgimp/gimpimage.c b/libgimp/gimpimage.c index 0d68d69310..f910ece560 100644 --- a/libgimp/gimpimage.c +++ b/libgimp/gimpimage.c @@ -201,13 +201,12 @@ GList * gimp_list_images (void) { GimpImage **images; - gint num_images; GList *list = NULL; gint i; - images = gimp_get_images (&num_images); + images = gimp_get_images (); - for (i = 0; i < num_images; i++) + for (i = 0; images[i] != NULL; i++) list = g_list_prepend (list, images[i]); g_free (images); diff --git a/libgimp/gimpimage_pdb.c b/libgimp/gimpimage_pdb.c index 7734f3e367..e03c1b969a 100644 --- a/libgimp/gimpimage_pdb.c +++ b/libgimp/gimpimage_pdb.c @@ -76,18 +76,16 @@ gimp_image_id_is_valid (gint image_id) /** * gimp_get_images: - * @num_images: (out): The number of images currently open. * * Returns the list of images currently open. * * This procedure returns the list of images currently open in GIMP. * - * Returns: (array length=num_images) (element-type GimpImage) (transfer container): + * Returns: (element-type GimpImage) (array zero-terminated=1) (transfer container): * The list of images currently open. - * The returned value must be freed with g_free(). **/ GimpImage ** -gimp_get_images (gint *num_images) +gimp_get_images (void) { GimpValueArray *args; GimpValueArray *return_vals; @@ -101,13 +99,8 @@ gimp_get_images (gint *num_images) args); gimp_value_array_unref (args); - *num_images = 0; - if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS) - { - *num_images = GIMP_VALUES_GET_INT (return_vals, 1); - { GimpObjectArray *a = g_value_get_boxed (gimp_value_array_index (return_vals, 2)); if (a) images = g_memdup2 (a->data, a->length * sizeof (gpointer)); }; - } + images = g_value_dup_boxed (gimp_value_array_index (return_vals, 1)); gimp_value_array_unref (return_vals); diff --git a/libgimp/gimpimage_pdb.h b/libgimp/gimpimage_pdb.h index fe5aac23fc..946790e5b8 100644 --- a/libgimp/gimpimage_pdb.h +++ b/libgimp/gimpimage_pdb.h @@ -33,7 +33,7 @@ G_BEGIN_DECLS gboolean gimp_image_id_is_valid (gint image_id); -GimpImage** gimp_get_images (gint *num_images); +GimpImage** gimp_get_images (void); GimpImage* gimp_image_new (gint width, gint height, GimpImageBaseType type); diff --git a/libgimp/tests/test-export-options.c b/libgimp/tests/test-export-options.c index 74a0d40647..467b0223b2 100644 --- a/libgimp/tests/test-export-options.c +++ b/libgimp/tests/test-export-options.c @@ -26,7 +26,6 @@ gimp_c_test_run (GimpProcedure *procedure, GimpLayer *export_layer; GimpExportOptions *options; GimpExportReturn delete; - gint n_images; gboolean identical_buffers; new_image = gimp_image_new (NEW_IMAGE_WIDTH, NEW_IMAGE_HEIGHT, GIMP_RGB); @@ -42,8 +41,8 @@ gimp_c_test_run (GimpProcedure *procedure, NULL); GIMP_TEST_START("Verify start state (1)"); - images = gimp_get_images (&n_images); - GIMP_TEST_END(n_images == 1 && images[0] == new_image); + images = gimp_get_images (); + GIMP_TEST_END(gimp_core_object_array_get_length ((GObject **) images) == 1 && images[0] == new_image); g_free (images); GIMP_TEST_START("Verify start state (2)"); @@ -55,8 +54,8 @@ gimp_c_test_run (GimpProcedure *procedure, GIMP_TEST_START("gimp_export_options_get_image() created a new image"); delete = gimp_export_options_get_image (options, &new_image); - images = gimp_get_images (&n_images); - GIMP_TEST_END(delete == GIMP_EXPORT_EXPORT && n_images == 2 && new_image != original_image); + images = gimp_get_images (); + GIMP_TEST_END(delete == GIMP_EXPORT_EXPORT && gimp_core_object_array_get_length ((GObject **) images) == 2 && new_image != original_image); g_free (images); GIMP_TEST_START("The new image has a single layer"); diff --git a/libgimp/tests/test-image.c b/libgimp/tests/test-image.c index a91ccceb22..2b5d2b7417 100644 --- a/libgimp/tests/test-image.c +++ b/libgimp/tests/test-image.c @@ -16,15 +16,14 @@ gimp_c_test_run (GimpProcedure *procedure, GimpImage **images; GimpImage *new_image; GimpTextLayer *text_layer; - gint n_images; GIMP_TEST_START("gimp_image_new()"); new_image = gimp_image_new (NEW_IMAGE_WIDTH, NEW_IMAGE_HEIGHT, GIMP_RGB); GIMP_TEST_END(GIMP_IS_IMAGE (new_image)); GIMP_TEST_START("gimp_get_images()"); - images = gimp_get_images (&n_images); - GIMP_TEST_END(n_images == 1 && images[0] == new_image); + images = gimp_get_images (); + GIMP_TEST_END(gimp_core_object_array_get_length ((GObject **) images) == 1 && images[0] == new_image); g_free (images); GIMP_TEST_START("gimp_text_layer_new() with point unit"); diff --git a/pdb/app.pl b/pdb/app.pl index 36cb8b9a80..9778cfa5da 100644 --- a/pdb/app.pl +++ b/pdb/app.pl @@ -682,11 +682,11 @@ CODE } elsif ($pdbtype eq 'imagearray') { $pspec = < 'images', type => 'imagearray', - desc => 'The list of images currently open.', - array => { name => 'num_images', - desc => 'The number of images currently open' } } + desc => 'The list of images currently open.' } ); %invoke = ( code => <data); - } + for (i = 0; i < num_images; i++, list = g_list_next (list)) + images[i] = list->data; } CODE ); diff --git a/pdb/pdb.pl b/pdb/pdb.pl index aa2bde4e25..d8da161558 100644 --- a/pdb/pdb.pl +++ b/pdb/pdb.pl @@ -110,17 +110,16 @@ package Gimp::CodeGen::pdb; take_value_func => 'g_value_take_boxed ($value, $var)' }, imagearray => { name => 'IMAGEARRAY', - gtype => 'GIMP_TYPE_OBJECT_ARRAY', + gtype => 'GIMP_TYPE_CORE_OBJECT_ARRAY', type => 'GimpImage **', const_type => 'const GimpImage **', - array => 1, init_value => 'NULL', - in_annotate => '(element-type GimpImage)', - out_annotate => '(element-type GimpImage) (transfer container)', - get_value_func => '$var = (const GimpImage **) gimp_value_get_object_array ($value)', - dup_value_func => '{ GimpObjectArray *a = g_value_get_boxed (gimp_value_array_index ($value)); if (a) $var = g_memdup2 (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)' }, + in_annotate => '(element-type GimpImage) (array zero-terminated=1)', + out_annotate => '(element-type GimpImage) (array zero-terminated=1) (transfer container)', + get_value_func => '$var = g_value_get_boxed ($value)', + dup_value_func => '$var = g_value_dup_boxed (gimp_value_array_index ($value))', + set_value_func => 'g_value_set_boxed ($value, $var)', + take_value_func => 'g_value_take_boxed ($value, $var)' }, itemarray => { name => 'ITEMARRAY', gtype => 'GIMP_TYPE_CORE_OBJECT_ARRAY',