From dce72553df87382a44c79953cb255a35976e3d0c Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Mon, 1 Feb 2010 19:50:13 +0000 Subject: Binding perl: many improvements * lang.py: use lasso_unref instead of g_object_unref. * lang.py: handle 'optional' annotation for more types, needed by ID-WSF bindings. * lang.py, gobject_handling.c: check object type before making the C call * Makefile.am: improve silent rules, hide all normal output, show errors, and with V=1 shows everything * glist_handling.c, gobject_handling.c: make local functions static * t/Lasso.t: add non regression test for method receiver type checking. * glist_handlind.c; remove unused convertion functions. * lang.py: clear the semi-assigned list and croak if all list elements do not convert to non-NULL values. --- bindings/perl/glist_handling.c | 151 ++++++----------------------------------- 1 file changed, 20 insertions(+), 131 deletions(-) (limited to 'bindings/perl/glist_handling.c') diff --git a/bindings/perl/glist_handling.c b/bindings/perl/glist_handling.c index ec9d93a4..377bf693 100644 --- a/bindings/perl/glist_handling.c +++ b/bindings/perl/glist_handling.c @@ -35,7 +35,7 @@ * * Return value: a newly allocated SV/PV or under. */ -SV* +static SV* xmlnode_to_pv(xmlNode *node, gboolean do_free) { xmlOutputBufferPtr buf; @@ -65,11 +65,15 @@ xmlnode_to_pv(xmlNode *node, gboolean do_free) return pestring; } -xmlNode *pv_to_xmlnode(SV *value) { - char *string = SvPV_nolen(value); +static xmlNode * +pv_to_xmlnode(SV *value) { + char *string; xmlDoc *doc; xmlNode *node = NULL; + if (! SvPOK(value)) + return NULL; + string = SvPV_nolen(value); if (! string) return NULL; @@ -82,37 +86,6 @@ xmlNode *pv_to_xmlnode(SV *value) { return node; } -/** - * glist_string_to_array: - * @list: a GList* of strings - * @do_free: wheter to free the list after the transformation - * - * Convert a #GList of strings to a Perl array of strings. - * - * Return value: a newly created perl array - */ -AV* -glist_string_to_array(GList *list, gboolean do_free) -{ - AV *array; - - array = newAV(); - - while (list) { - SV *sv; - sv = newSVpv((char*)list->data, 0); - if (! sv) - sv = &PL_sv_undef; - av_push(array, sv); - list = list->next; - } - - if (do_free) - lasso_release_list_of_strings(list); - - return array; -} - /** * array_to_glist_string: * @array: a Perl array @@ -121,7 +94,7 @@ glist_string_to_array(GList *list, gboolean do_free) * * Return value: a newly create #GList */ -GList* +static GList* array_to_glist_string(AV *array) { I32 len, i; @@ -140,36 +113,6 @@ array_to_glist_string(AV *array) return result; } -/** - * glist_gobject_to_array: - * @list: a #GList of #GObject objects - * @do_free: wheter to free the list after the conversion - * - * Convert a #GList of #GObject objects to a perl array. - * - * Return value: a newly created perl array - */ -AV* -glist_gobject_to_array(GList *list, gboolean do_free) -{ - AV *array; - - array = newAV(); - while (list) { - SV *sv; - sv = gperl_new_object((GObject*)list->data, FALSE); - if (! sv) - sv = &PL_sv_undef; - av_push(array, sv); - list = list->next; - } - - if (do_free) - lasso_release_list_of_gobjects(list); - - return array; -} - /** * array_to_glist_gobject: * @array: a perl array @@ -178,74 +121,20 @@ glist_gobject_to_array(GList *list, gboolean do_free) * * Return value: a newly created #GList of #GObject objects */ -GList* +static GList* array_to_glist_gobject(AV *array) { - I32 len, i; - GList *result = NULL; - - if (! array) - return NULL; - len = av_len(array); - for (i=len-1; i >= 0; i--) { - SV **sv; + I32 len, i; + GList *result = NULL; - sv = av_fetch(array, i, 0); - lasso_list_add_gobject(result, gperl_get_object(*sv)); - } - - return result; -} - -/** - * glist_xmlnode_to_array: - * @list: a #GList of #xmlNode - * @do_free: whether to free the list after the conversion - * - * Convert a #GList of #xmlNode structures to a perl array of strings. - * - * Return value: a newly created Perl array */ -AV* -glist_xmlnode_to_array(GList *list, gboolean do_free) -{ - AV *array; - - array = newAV(); - while (list) { - SV *sv = xmlnode_to_pv((xmlNode*)list->data, FALSE); - if (! sv) - sv = &PL_sv_undef; - av_push(array, sv); - list = list->next; - } - - if (do_free) - lasso_release_list_of_xml_node(list); + if (! array) + return NULL; + len = av_len(array); + for (i=len-1; i >= 0; i--) { + SV **sv; - return array; -} + sv = av_fetch(array, i, 0); + lasso_list_add_gobject(result, gperl_get_object(*sv)); + } -/** - * array_to_glist_xmlnode: - * @array: a perl array - * - * Convert a perl array of strings to a #GList of #xmlNode structures. - * - * Return value: a newly created #GList of #xmlNode structures. - */ -GList* -array_to_glist_xmlnode(AV *array) { - I32 len, i; - GList *result = NULL; - - if (! array) - return NULL; - len = av_len(array); - for (i=len-1; i >= 0; i--) { - SV **sv; - - sv = av_fetch(array, i, 0); - lasso_list_add_new_xml_node(result, pv_to_xmlnode(*sv)); - } - - return result; + return result; } -- cgit