Re: yap - Gnome2::About



Memory leak! bad Chas, no cookie for you!

The code needs 
       if (d) free(d);
at the end.  Sigh.

On Thu, 2003-04-17 at 17:58, Chas Owens wrote:
I have stolen some code from Gtk-Perl, cleaned it up (NULL instead of 0,
const gchar** instead of char**, etc.), and modified it to match the new
arguments for Gnome2::About.

<patch>
--- Gnome2/xs/GnomeAbout.xs.orig        2003-04-17 17:30:45.000000000 -0400
+++ Gnome2/xs/GnomeAbout.xs     2003-04-17 17:50:31.000000000 -0400
@@ -4,25 +4,58 @@


 GtkWidget *
-gnome_about_new (class, name, version, copyright, comments, authors_ref, documenters_ref, 
translator_credits, logo_pixbuf)
-       SV * class
-       const gchar * name
-       const gchar * version
-       const gchar * copyright
-       const gchar * comments
-       SV * authors_ref
-       SV * documenters_ref
-       const gchar * translator_credits
+gnome_about_new (class, name=NULL, version=NULL, copyright=NULL, comments=NULL, authors=NULL, 
documenters=NULL, translator_credits=NULL, logo_pixbuf=NULL)
+       SV               * class
+       const gchar      * name
+       const gchar      * version
+       const gchar      * copyright
+       const gchar      * comments
+       SV               * authors
+       SV               * documenters
+       const gchar      * translator_credits
        GdkPixbuf_ornull * logo_pixbuf
-    PREINIT:
-       const gchar **authors = NULL;
-       const gchar **documenters = NULL;
     CODE:
-       /* FIXME pull authors and documentors out of the SVs, which may be
-        *       either plain strings or refs to arrays of strings */
+       const gchar ** a = NULL;
+       if (authors && SvOK(authors)) {
+               if (SvRV(authors) && (SvTYPE(SvRV(authors)) == SVt_PVAV)) {
+                       AV * av = (AV*)SvRV(authors);
+                       int  i;
+                       a = (const gchar**)malloc(
+                               sizeof(const gchar*) * (av_len(av)+2)
+                       );
+
+                       for(i=0;i<=av_len(av);i++) {
+                               a[i] = SvPV(*av_fetch(av, i, 0), PL_na);
+                       }
+                       a[i] = NULL;
+               } else {
+                       a = (const gchar**)malloc(sizeof(const gchar*) * 2);
+                       a[0] = SvPV(authors, PL_na);
+                       a[1] = NULL;
+               }
+       }
+       const gchar ** d = NULL;
+       if (documenters && SvOK(documenters)) {
+               if (SvRV(documenters) && (SvTYPE(SvRV(documenters)) == SVt_PVAV)) {
+                       AV * av = (AV*)SvRV(documenters);
+                       int  i;
+                       d = (const gchar**)malloc(
+                               sizeof(const gchar*) * (av_len(av)+2)
+                       );
+
+                       for(i=0;i<=av_len(av);i++) {
+                               d[i] = SvPV(*av_fetch(av, i, 0), PL_na);
+                       }
+                       d[i] = NULL;
+               } else {
+                       d = (const gchar**)malloc(sizeof(const gchar*) * 2);
+                       d[0] = SvPV(documenters, PL_na);
+                       d[1] = NULL;
+               }
+       }
        RETVAL = gnome_about_new (name, version, copyright, comments,
-                                 authors, documenters, translator_credits,
-                                 logo_pixbuf);
+                                 a, d, translator_credits, logo_pixbuf);
+       if (a) free(a);
     OUTPUT:
        RETVAL
</patch>

_______________________________________________
gtk-perl-list mailing list
gtk-perl-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list
-- 
Chas Owens <alas widomaker com>




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]