r18303 - gnucash/trunk/src - Use SWIG properly to wrap functions to free strings which need to be freed by the caller.

Phil Longstaff plongstaff at code.gnucash.org
Tue Sep 8 19:48:42 EDT 2009


Author: plongstaff
Date: 2009-09-08 19:48:42 -0400 (Tue, 08 Sep 2009)
New Revision: 18303
Trac: http://svn.gnucash.org/trac/changeset/18303

Modified:
   gnucash/trunk/src/engine/Account.c
   gnucash/trunk/src/engine/Account.h
   gnucash/trunk/src/engine/engine.i
   gnucash/trunk/src/html/gnc-html.c
   gnucash/trunk/src/html/gnc-html.h
   gnucash/trunk/src/html/gnc-html.i
   gnucash/trunk/src/report/report-gnome/gnc-plugin-page-report.c
   gnucash/trunk/src/report/report-gnome/window-report.c
Log:
Use SWIG properly to wrap functions to free strings which need to be freed by the caller.


Modified: gnucash/trunk/src/engine/Account.c
===================================================================
--- gnucash/trunk/src/engine/Account.c	2009-09-07 20:16:35 UTC (rev 18302)
+++ gnucash/trunk/src/engine/Account.c	2009-09-08 23:48:42 UTC (rev 18303)
@@ -2747,7 +2747,7 @@
     return GET_PRIVATE(acc)->accountName;
 }
 
-char *
+gchar *
 xaccAccountGetFullName(const Account *account)
 {
   AccountPrivate *priv;

Modified: gnucash/trunk/src/engine/Account.h
===================================================================
--- gnucash/trunk/src/engine/Account.h	2009-09-07 20:16:35 UTC (rev 18302)
+++ gnucash/trunk/src/engine/Account.h	2009-09-08 23:48:42 UTC (rev 18303)
@@ -407,7 +407,7 @@
  * hack alert -- since it breaks the rule of string allocation, maybe this
  * routine should not be in this library, but some utility library?
  */
-char * xaccAccountGetFullName (const Account *account);
+gchar * xaccAccountGetFullName (const Account *account);
 
 /** Set a string that identifies the Finance::Quote backend that
  *  should be used to retrieve online prices.  See price-quotes.scm

Modified: gnucash/trunk/src/engine/engine.i
===================================================================
--- gnucash/trunk/src/engine/engine.i	2009-09-07 20:16:35 UTC (rev 18302)
+++ gnucash/trunk/src/engine/engine.i	2009-09-08 23:48:42 UTC (rev 18303)
@@ -33,6 +33,12 @@
 
 %typemap(newfree) gchar * "g_free($1);"
 
+/* These need to be here so that they are *before* the function
+declarations in the header files, some of which are included by
+engine-common.i */
+
+%newobject xaccAccountGetFullName;
+
 %include "engine-common.i"
 
 %inline %{

Modified: gnucash/trunk/src/html/gnc-html.c
===================================================================
--- gnucash/trunk/src/html/gnc-html.c	2009-09-07 20:16:35 UTC (rev 18302)
+++ gnucash/trunk/src/html/gnc-html.c	2009-09-08 23:48:42 UTC (rev 18303)
@@ -570,32 +570,11 @@
  * @param type URL type
  * @param location URL location
  * @param label URL label (optional)
- * @return Newly created URL.  This string must be *NOT* freed by the caller.
+ * @return Newly created URL.  This string must be freed by the caller.
  */
 gchar*
 gnc_build_url( URLType type, const gchar* location, const gchar* label )
 {
-    static gchar buf[1000];
-	gchar* url;
-
-	url = gnc_html_build_url( type, location, label );
-	strncpy( buf, url, sizeof(buf) );
-	g_free( url );
-
-	return buf;
-}
-
-/**
- * Creates a new HMTL url.
- *
- * @param type URL type
- * @param location URL location
- * @param label URL label (optional)
- * @return Newly created URL.  This string must be freed by the caller.
- */
-gchar*
-gnc_html_build_url( URLType type, const gchar* location, const gchar* label )
-{
   char * type_name;
 
   DEBUG(" ");

Modified: gnucash/trunk/src/html/gnc-html.h
===================================================================
--- gnucash/trunk/src/html/gnc-html.h	2009-09-07 20:16:35 UTC (rev 18302)
+++ gnucash/trunk/src/html/gnc-html.h	2009-09-08 23:48:42 UTC (rev 18303)
@@ -265,6 +265,4 @@
 
 const gchar* gnc_html_get_embedded_param( gpointer eb, const gchar* param_name );
 
-gchar* gnc_html_build_url( URLType type, const gchar* location, const gchar* label );
-
 #endif

Modified: gnucash/trunk/src/html/gnc-html.i
===================================================================
--- gnucash/trunk/src/html/gnc-html.i	2009-09-07 20:16:35 UTC (rev 18302)
+++ gnucash/trunk/src/html/gnc-html.i	2009-09-08 23:48:42 UTC (rev 18303)
@@ -20,6 +20,8 @@
 %import "base-typemaps.i"
 
 /* Parse the header file to generate wrappers */
+%newobject gnc_build_url;
+
 %include "gnc-html-extras.h"
 %include "gnc-html-graph-gog-extras.h"
 

Modified: gnucash/trunk/src/report/report-gnome/gnc-plugin-page-report.c
===================================================================
--- gnucash/trunk/src/report/report-gnome/gnc-plugin-page-report.c	2009-09-07 20:16:35 UTC (rev 18302)
+++ gnucash/trunk/src/report/report-gnome/gnc-plugin-page-report.c	2009-09-08 23:48:42 UTC (rev 18303)
@@ -353,7 +353,7 @@
         // FIXME.  This is f^-1(f(x)), isn't it?
         DEBUG( "id=%d", priv->reportId );
         id_name = g_strdup_printf("id=%d", priv->reportId );
-        child_name = gnc_html_build_url( URL_TYPE_REPORT, id_name, NULL );
+        child_name = gnc_build_url( URL_TYPE_REPORT, id_name, NULL );
         type = gnc_html_parse_url( priv->html, child_name, &url_location, &url_label);
         DEBUG( "passing id_name=[%s] child_name=[%s] type=[%s], location=[%s], label=[%s]",
                id_name, child_name ? child_name : "(null)",

Modified: gnucash/trunk/src/report/report-gnome/window-report.c
===================================================================
--- gnucash/trunk/src/report/report-gnome/window-report.c	2009-09-07 20:16:35 UTC (rev 18302)
+++ gnucash/trunk/src/report/report-gnome/window-report.c	2009-09-08 23:48:42 UTC (rev 18303)
@@ -283,7 +283,7 @@
   {
     char *url;
 
-    url = gnc_html_build_url (URL_TYPE_REPORT, location, label);
+    url = gnc_build_url (URL_TYPE_REPORT, location, label);
     gnc_main_window_open_report_url (url, NULL);
     g_free (url);
 



More information about the gnucash-changes mailing list