GNOME Bugzilla – Bug 385841
Handle gchar** (GStrv) arguments
Last modified: 2007-07-09 19:49:29 UTC
Function gst_type_find_factory_get_extensions returns a list of strings as gchar**, so this definition: (define-method get_extensions (of-object "GstTypeFindFactory") (c-name "gst_type_find_factory_get_extensions") (return-type "gchar**") ) doesn't work: Could not write method GstTypeFindFactory.get_extensions: No ArgType for 'gchar**' I guess it will need a simple C function to build a Python list out of it, but I'm not familiar with the wrapper system pygst uses, so I can't implement it myself.
Created attachment 78406 [details] [review] Add codegen support for gchar** return type With this patch, the code generator becomes capable of additionally binding gst.ElementFactory.get_uri_protocols and gst.TypeFindFactory.get_extensions. List of changes: * gst/arg-types.py: (StringArrayArg, StringArrayArg.write_return): Add support for gchar** return type. * gst/gst.defs: Comment out definition for get_protocols virtual method of GstURIHandler objects. The code generator now attempts to bind this method, which breaks compilation since the C function takes no arguments.
Although the patch is nicely done (using the codegenerator and an argtype), the problem is that saying that 'gchar**' is always a string array is wrong, it could also be a pointer to a string (so that a method could return the location of a string at that adress). I would prefer a patch with an override, please :)
Sure, but are there functions that use it like this? Obviously there are none in the .defs (that aren't overridden already). If there are some that should be added, maybe we should consider to override _them_ instead. Using overrides here is wrong in any case. Instead, one might consider changing the ptype from gchar** to gchar-array or something. The types used in the .defs do not have to match the C types, they already differ since the C definition does not communicate that the caller does not own the return value (seems like all the functions lack G_CONST_RETURN?).
I'm more in favour of changing the type in .defs to gchar-array. Makes it more readable. If that is in the patch, it goes in :)
Created attachment 78529 [details] [review] Add codegen support for gchar*-array return type Oops, gchar-array is just gchar*. What we need is gchararray-array, gchar*-array, gcharpointer-array, str-array or strv or something. Pick your favorite. I picked gchar*-array for this updated patch, but feel free to object. This patch is nicer: I found that we can get rid of an override. This also returns tuples instead of lists, which is consistent with what pygtk does in its overrides. Furthermore, I don't need to comment out the get_protocols virtual definition since we no longer claim to be able to handle gchar** returns. Updated list of changes: * gst/arg-types.py: (StringArrayArg, StringArrayArg.write_return): Add support for gchar*-array return type (which occurs in the C API as gchar**). * gst/gst.defs: Change return type from gchar** to gchar*-array for GstElementFactory.get_uri_protocols, GstTypeFindFactory.get_extensions and GstURIHandler.get_protocols method definitions. * gst/gst.override: (_wrap_gst_uri_handler_get_protocols): Remove the now unneeded override for gst_uri_handler_get_protocols.
Created attachment 78530 [details] [review] Add codegen support for gchar*-array return type (attached correct file this time)
Created attachment 82277 [details] [review] Add codegen support for GStrv return type Looks like GStrv is the correct type to use actually. Updated list of changes: * gst/arg-types.py: (StringArrayArg, StringArrayArg.write_return): Add support for GStrv return type (which occurs in the C API as gchar**). * gst/gst.defs: Change return type from gchar** to GStrv for GstElementFactory.get_uri_protocols, GstTypeFindFactory.get_extensions and GstURIHandler.get_protocols method definitions. * gst/gst.override: (_wrap_gst_uri_handler_get_protocols): Remove the now unneeded override for gst_uri_handler_get_protocols.
2007-07-05 Edward Hervey <bilboed@bilboed.com> Patch by: Rene Stadler <mail@renestadler.de> * gst/arg-types.py: * gst/gst.defs: * gst/gst.override: Handle 'gchar**' (GStrv) arguments in a uniform way. Fixes #385841