Better handling of array types in PDB procedures?
Currently array types are handled with a size parameter followed by an array parameter.
When a PDB procedure is called from the core (typically a plug-in called through GIMP GUI), this is pretty transparent to plug-in developers. But when they need to call another procedure using an array parameter, it gets ugly.
Typically:
retvals = gimp_pdb_run_procedure (gimp_get_pdb (),
"proc-name",
GIMP_TYPE_RUN_MODE, GIMP_RUN_NONINTERACTIVE,
GIMP_TYPE_IMAGE, image,
G_TYPE_INT, n_drawables,
GIMP_TYPE_OBJECT_ARRAY, drawables,
G_TYPE_NONE);
must actually be called this way:
GimpValueArray *args;
args = gimp_value_array_new_from_types (NULL,
GIMP_TYPE_RUN_MODE, GIMP_RUN_NONINTERACTIVE,
GIMP_TYPE_IMAGE, image,
G_TYPE_INT, n_drawables,
G_TYPE_NONE);
gimp_value_set_object_array (gimp_value_array_index (args, 3), GIMP_TYPE_ITEM, (GObject **) drawables, n_drawables);
retvals = gimp_pdb_run_procedure_array (gimp_get_pdb (), "proc-name", args);
The reason is that C arrays don't contain their size, so when creating the args, we need to associate the array size as a separate call. Hence we cannot use gimp_pdb_run_procedure()
for procedure using array parameters.
I can see 3 ways forward:
-
Leave it as-is and say it works fine. Plug-in developers just have to special-case calling procedures with arrays. I.e. leave current situation this way. I personally find this extra-ugly but we can consider that actually "it works" (though a bit cumbersome).
-
We make this rule mandatory: array parameters are necessarily accompanied by a size parameter which is the previous one. So it's not just a GIMP-team only style policy but we make this a hard rule of our API. It means we need to add some checks to warn plug-in developers. Then we can also modify the PDB procedure API to use this assumption.
-
We start using NUL-terminated arrays. This means we don't need the size parameter anymore in all these procedures. It also means that we consider that NULL is not a valid value. This is similar to what is proposed in !389 (merged) (only for string arrays in this MR).
Yet this third solution doesn't work with all types of arrays. It would work for string, object and GimpRGB arrays. Not for int, uint and float arrays.
I am leaving this report here because I want this to be discussed and thought out a bit before GIMP 3 release (once this is done, we are stuck to whatever choice we made).