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
This commit is contained in:
Phil Longstaff
2009-09-08 23:48:42 +00:00
parent 294390b54e
commit b4f040a6ce
8 changed files with 13 additions and 28 deletions

View File

@@ -2747,7 +2747,7 @@ xaccAccountGetName (const Account *acc)
return GET_PRIVATE(acc)->accountName;
}
char *
gchar *
xaccAccountGetFullName(const Account *account)
{
AccountPrivate *priv;

View File

@@ -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

View File

@@ -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 %{

View File

@@ -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;

View File

@@ -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

View File

@@ -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"

View File

@@ -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)",

View File

@@ -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);