From b4f040a6ceed6f85a2f53f1b7082050dde6fd25c Mon Sep 17 00:00:00 2001 From: Phil Longstaff Date: Tue, 8 Sep 2009 23:48:42 +0000 Subject: [PATCH] Use SWIG properly to wrap functions to free strings which need to be freed by the caller. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18303 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/engine/Account.c | 2 +- src/engine/Account.h | 2 +- src/engine/engine.i | 6 +++++ src/html/gnc-html.c | 23 +------------------ src/html/gnc-html.h | 2 -- src/html/gnc-html.i | 2 ++ .../report-gnome/gnc-plugin-page-report.c | 2 +- src/report/report-gnome/window-report.c | 2 +- 8 files changed, 13 insertions(+), 28 deletions(-) diff --git a/src/engine/Account.c b/src/engine/Account.c index bcf0b15499..b3ce31c6ad 100644 --- a/src/engine/Account.c +++ b/src/engine/Account.c @@ -2747,7 +2747,7 @@ xaccAccountGetName (const Account *acc) return GET_PRIVATE(acc)->accountName; } -char * +gchar * xaccAccountGetFullName(const Account *account) { AccountPrivate *priv; diff --git a/src/engine/Account.h b/src/engine/Account.h index 5470ff609a..14d3cbb076 100644 --- a/src/engine/Account.h +++ b/src/engine/Account.h @@ -407,7 +407,7 @@ void xaccAccountSortSplits (Account *acc, gboolean force); * 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 diff --git a/src/engine/engine.i b/src/engine/engine.i index 7eae7fd937..88f9bacacd 100644 --- a/src/engine/engine.i +++ b/src/engine/engine.i @@ -33,6 +33,12 @@ GLIST_HELPER_INOUT(CommodityList, SWIGTYPE_p_gnc_commodity); %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 %{ diff --git a/src/html/gnc-html.c b/src/html/gnc-html.c index 227029581e..a8acdaa361 100644 --- a/src/html/gnc-html.c +++ b/src/html/gnc-html.c @@ -564,27 +564,6 @@ gnc_html_initialize( void ) gnc_html_register_urltype (types[i].type, types[i].protocol); } -/** - * 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 *NOT* 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. * @@ -594,7 +573,7 @@ gnc_build_url( URLType type, const gchar* location, const gchar* label ) * @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 ) +gnc_build_url( URLType type, const gchar* location, const gchar* label ) { char * type_name; diff --git a/src/html/gnc-html.h b/src/html/gnc-html.h index a618ed0aff..6136c624a4 100644 --- a/src/html/gnc-html.h +++ b/src/html/gnc-html.h @@ -265,6 +265,4 @@ void gnc_html_unregister_url_handler( URLType url_type ); 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 diff --git a/src/html/gnc-html.i b/src/html/gnc-html.i index b0a484e8ce..468be04e84 100644 --- a/src/html/gnc-html.i +++ b/src/html/gnc-html.i @@ -20,6 +20,8 @@ SCM scm_init_sw_gnc_html_module(void); %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" diff --git a/src/report/report-gnome/gnc-plugin-page-report.c b/src/report/report-gnome/gnc-plugin-page-report.c index 70e3f011ef..87fe6a0ea3 100644 --- a/src/report/report-gnome/gnc-plugin-page-report.c +++ b/src/report/report-gnome/gnc-plugin-page-report.c @@ -353,7 +353,7 @@ gnc_plugin_page_report_create_widget( GncPluginPage *page ) // 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)", diff --git a/src/report/report-gnome/window-report.c b/src/report/report-gnome/window-report.c index 5f8c5d0377..b3ae92f464 100644 --- a/src/report/report-gnome/window-report.c +++ b/src/report/report-gnome/window-report.c @@ -283,7 +283,7 @@ gnc_html_report_url_cb (const char *location, const char *label, { 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);