[Gnucash-changes] The SCM_xxx_CHARS macros return pointers to
internal scheme data and
David Hampton
hampton at cvs.gnucash.org
Sat Jul 30 13:06:31 EDT 2005
Log Message:
-----------
The SCM_xxx_CHARS macros return pointers to internal scheme data and
should be treated as const. Use the compiler to enforce this
restriction.
Tags:
----
gnucash-gnome2-dev
Modified Files:
--------------
gnucash:
ChangeLog
gnucash/src/app-utils:
option-util.c
gnucash/src/engine:
engine-helpers.c
glib-helpers.c
kvp-scm.c
gnucash/src/gnome-utils:
argv-list-converters.c
dialog-options.c
gnc-menu-extensions.c
Revision Data
-------------
Index: ChangeLog
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/ChangeLog,v
retrieving revision 1.1487.2.257
retrieving revision 1.1487.2.258
diff -LChangeLog -LChangeLog -u -r1.1487.2.257 -r1.1487.2.258
--- ChangeLog
+++ ChangeLog
@@ -1,3 +1,15 @@
+2005-07-30 David Hampton <hampton at employees.org>
+
+ * src/app-utils/option-util.c:
+ * src/engine/engine-helpers.c:
+ * src/engine/glib-helpers.c:
+ * src/engine/kvp-scm.c:
+ * src/gnome-utils/argv-list-converters.c:
+ * src/gnome-utils/dialog-options.c:
+ * src/gnome-utils/gnc-menu-extensions.c: The SCM_xxx_CHARS macros
+ return pointers to internal scheme data and should be treated as
+ const. Use the compiler to enforce this restriction.
+
2005-07-28 David Hampton <hampton at employees.org>
* src/import-export/hbci/Makefile.am:
Index: kvp-scm.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/kvp-scm.c,v
retrieving revision 1.11.4.2
retrieving revision 1.11.4.3
diff -Lsrc/engine/kvp-scm.c -Lsrc/engine/kvp-scm.c -u -r1.11.4.2 -r1.11.4.3
--- src/engine/kvp-scm.c
+++ src/engine/kvp-scm.c
@@ -47,9 +47,8 @@
}
else if(SCM_STRINGP(val))
{
- char *newstr;
+ const gchar *newstr;
KvpValue *ret;
- /* newstr = gh_scm2newstr(val, NULL); */
newstr = SCM_STRING_CHARS (val);
ret = kvp_value_new_string(newstr);
return ret;
Index: glib-helpers.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/glib-helpers.c,v
retrieving revision 1.3.4.2
retrieving revision 1.3.4.3
diff -Lsrc/engine/glib-helpers.c -Lsrc/engine/glib-helpers.c -u -r1.3.4.2 -r1.3.4.3
--- src/engine/glib-helpers.c
+++ src/engine/glib-helpers.c
@@ -155,13 +155,9 @@
while (!SCM_NULLP (list))
{
- /* glist = g_list_prepend (glist, gh_scm2newstr(SCM_CAR(list), NULL)); */
- char * str = SCM_STRING_CHARS (SCM_CAR(list));
+ const gchar * str = SCM_STRING_CHARS (SCM_CAR(list));
if (str)
- {
- str = g_strdup (str);
- glist = g_list_prepend (glist, str);
- }
+ glist = g_list_prepend (glist, g_strdup (str));
list = SCM_CDR (list);
}
Index: engine-helpers.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/engine-helpers.c,v
retrieving revision 1.24.4.4
retrieving revision 1.24.4.5
diff -Lsrc/engine/engine-helpers.c -Lsrc/engine/engine-helpers.c -u -r1.24.4.4 -r1.24.4.5
--- src/engine/engine-helpers.c
+++ src/engine/engine-helpers.c
@@ -37,7 +37,6 @@
#include "gnc-engine.h"
#include "gnc-numeric.h"
#include "gnc-trace.h"
-#include "guile-mappings.h"
#include "qofbook.h"
#include "qofquery.h"
#include "qofquery-p.h"
@@ -134,11 +133,7 @@
gnc_scm2guid(SCM guid_scm)
{
GUID guid;
- char * str;
-
- /* char string[GUID_ENCODING_LENGTH + 1]; */
- /* gh_get_substr(guid_scm, string, 0, GUID_ENCODING_LENGTH); */
- /* string[GUID_ENCODING_LENGTH] = '\0'; */
+ const gchar * str;
if (GUID_ENCODING_LENGTH != SCM_STRING_LENGTH (guid_scm))
{
@@ -153,15 +148,11 @@
gnc_guid_p(SCM guid_scm)
{
GUID guid;
- char * str;
+ const gchar * str;
if (!SCM_STRINGP(guid_scm))
return FALSE;
- /* char string[GUID_ENCODING_LENGTH + 1]; */
- /* gh_get_substr(guid_scm, string, 0, GUID_ENCODING_LENGTH); */
- /* string[GUID_ENCODING_LENGTH] = '\0'; */
-
if (GUID_ENCODING_LENGTH != SCM_STRING_LENGTH (guid_scm))
{
return FALSE;
@@ -329,8 +320,7 @@
gnc_scm2acct_match_how (SCM how_scm)
{
QofGuidMatch res;
- /* char *how = gh_symbol2newstr (how_scm, NULL); */
- char *how = SCM_SYMBOL_CHARS (how_scm);
+ const gchar *how = SCM_SYMBOL_CHARS (how_scm);
if (!safe_strcmp (how, "acct-match-all"))
res = QOF_GUID_MATCH_ALL;
@@ -349,8 +339,7 @@
gnc_scm2amt_match_how (SCM how_scm)
{
QofQueryCompare res;
- /* char *how = gh_symbol2newstr (how_scm, NULL); */
- char *how = SCM_SYMBOL_CHARS (how_scm);
+ const gchar *how = SCM_SYMBOL_CHARS (how_scm);
if (!safe_strcmp (how, "amt-match-atleast"))
res = QOF_COMPARE_GTE;
@@ -370,8 +359,7 @@
gnc_scm2kvp_match_how (SCM how_scm)
{
QofQueryCompare res;
- /* char *how = gh_symbol2newstr (how_scm, NULL); */
- char *how = SCM_SYMBOL_CHARS (how_scm);
+ const gchar *how = SCM_SYMBOL_CHARS (how_scm);
if (!safe_strcmp (how, "kvp-match-lt"))
res = QOF_COMPARE_LT;
@@ -422,7 +410,7 @@
static gboolean
gnc_scm2balance_match_how (SCM how_scm, gboolean *resp)
{
- char *how;
+ const gchar *how;
if (!SCM_LISTP (how_scm))
return FALSE;
@@ -434,7 +422,6 @@
if (!SCM_NULLP (SCM_CDR (how_scm)))
return FALSE;
- /* how = gh_symbol2newstr (SCM_CAR (how_scm), NULL); */
how = SCM_SYMBOL_CHARS (SCM_CAR(how_scm));
if (!safe_strcmp (how, "balance-match-balanced"))
@@ -449,12 +436,11 @@
gnc_scm2kvp_match_where (SCM where_scm)
{
QofIdType res;
- char *where;
+ const gchar *where;
if (!SCM_LISTP (where_scm))
return NULL;
- /* where = gh_symbol2newstr (SCM_CAR (where_scm), NULL); */
where = SCM_SYMBOL_CHARS (SCM_CAR(where_scm));
if (!safe_strcmp (where, "kvp-match-split"))
@@ -576,14 +562,12 @@
while (!SCM_NULLP (path_scm))
{
SCM key_scm = SCM_CAR (path_scm);
- char *key, *tmp;
+ char *key;
if (!SCM_STRINGP (key_scm))
break;
- /* tmp = gh_scm2newstr (key_scm, NULL); */
- tmp = SCM_STRING_CHARS (key_scm);
- key = g_strdup (tmp);
+ key = g_strdup (SCM_STRING_CHARS (key_scm));
path = g_slist_prepend (path, key);
@@ -754,8 +738,7 @@
break;
case KVP_TYPE_STRING: {
- /* char *str = gh_scm2newstr (val_scm, NULL); */
- char * str = SCM_STRING_CHARS (val_scm);
+ const gchar * str = SCM_STRING_CHARS (val_scm);
value = kvp_value_new_string (str);
break;
}
@@ -843,7 +826,7 @@
KvpValue *value;
SCM key_scm;
SCM val_scm;
- char *key;
+ const gchar *key;
if (!SCM_CONSP (pair))
continue;
@@ -854,8 +837,7 @@
if (!SCM_STRINGP (key_scm))
continue;
- /* key = gh_scm2newstr (key_scm, NULL); */
- key = SCM_STRING_CHARS (key_scm);
+ key = SCM_STRING_CHARS (key_scm);
if (!key)
continue;
@@ -948,7 +930,7 @@
QofQuery *q = NULL;
QofQueryPredData *pd = NULL;
SCM scm;
- char *type = NULL;
+ const gchar *type = NULL;
GSList *path = NULL;
gboolean inverted = FALSE;
QofQueryCompare compare_how;
@@ -976,7 +958,6 @@
qt_scm = SCM_CDR (qt_scm);
if (!SCM_SYMBOLP (scm))
break;
- /* type = gh_symbol2newstr (scm, NULL); */
type = SCM_SYMBOL_CHARS (scm);
/* QofCompareFunc */
@@ -992,7 +973,7 @@
{
QofStringMatch options;
gboolean is_regex;
- char *matchstring;
+ const gchar *matchstring;
scm = SCM_CAR (qt_scm);
qt_scm = SCM_CDR (qt_scm);
@@ -1008,8 +989,7 @@
qt_scm = SCM_CDR (qt_scm);
if (!SCM_STRINGP (scm)) break;
- /* matchstring = gh_scm2newstr (scm, NULL); */
- matchstring = SCM_STRING_CHARS (scm);
+ matchstring = SCM_STRING_CHARS (scm);
pd = qof_query_string_predicate (compare_how, matchstring,
options, is_regex);
@@ -1106,7 +1086,7 @@
} else if (!safe_strcmp (type, QOF_TYPE_CHAR)) {
QofCharMatch options;
- char *char_list;
+ const gchar *char_list;
scm = SCM_CAR (qt_scm);
qt_scm = SCM_CDR (qt_scm);
@@ -1118,8 +1098,7 @@
qt_scm = SCM_CDR (qt_scm);
if (!SCM_STRINGP (scm))
break;
- /* char_list = gh_scm2newstr (scm, NULL); */
- char_list = SCM_STRING_CHARS (scm);
+ char_list = SCM_STRING_CHARS (scm);
pd = qof_query_char_predicate (options, char_list);
}
@@ -1172,8 +1151,8 @@
gnc_scm2query_term_query_v1 (SCM query_term_scm)
{
gboolean ok = FALSE;
- char * pd_type = NULL;
- char * pr_type = NULL;
+ const gchar * pd_type = NULL;
+ const gchar * pr_type = NULL;
gboolean sense = FALSE;
QofQuery *q = NULL;
SCM scm;
@@ -1188,7 +1167,6 @@
/* pd_type */
scm = SCM_CAR (query_term_scm);
query_term_scm = SCM_CDR (query_term_scm);
- /* pd_type = gh_symbol2newstr (scm, NULL); */
pd_type = SCM_SYMBOL_CHARS (scm);
/* pr_type */
@@ -1198,7 +1176,6 @@
}
scm = SCM_CAR (query_term_scm);
query_term_scm = SCM_CDR (query_term_scm);
- /* pr_type = gh_symbol2newstr (scm, NULL); */
pr_type = SCM_SYMBOL_CHARS (scm);
/* sense */
@@ -1340,7 +1317,7 @@
} else if (!safe_strcmp (pd_type, "pd-string")) {
gboolean case_sens;
gboolean use_regexp;
- char *matchstring;
+ const gchar *matchstring;
/* case_sens */
if (SCM_NULLP (query_term_scm))
@@ -1364,8 +1341,7 @@
scm = SCM_CAR (query_term_scm);
query_term_scm = SCM_CDR (query_term_scm);
- /* matchstring = gh_scm2newstr (scm, NULL); */
- matchstring = SCM_STRING_CHARS (scm);
+ matchstring = SCM_STRING_CHARS (scm);
if (!safe_strcmp (pr_type, "pr-action")) {
xaccQueryAddActionMatch (q, matchstring, case_sens, use_regexp,
@@ -1423,7 +1399,6 @@
} else if (!safe_strcmp (pd_type, "pd-guid")) {
GUID guid;
QofIdType id_type;
- char *tmp;
/* guid */
if (SCM_NULLP (query_term_scm))
@@ -1436,9 +1411,7 @@
/* id type */
scm = SCM_CAR (query_term_scm);
query_term_scm = SCM_CDR (query_term_scm);
- /* tmp = gh_scm2newstr (scm, NULL); */
- tmp = SCM_STRING_CHARS (scm);
- id_type = g_strdup (tmp);
+ id_type = g_strdup (SCM_STRING_CHARS (scm));
xaccQueryAddGUIDMatch (q, &guid, id_type, QOF_QUERY_OR);
ok = TRUE;
@@ -1755,7 +1728,7 @@
}
static GSList *
-gnc_query_sort_to_list (char * symbol)
+gnc_query_sort_to_list (const gchar * symbol)
{
GSList *path = NULL;
@@ -1823,9 +1796,9 @@
{
Query *q = NULL;
gboolean ok = TRUE;
- char * primary_sort = NULL;
- char * secondary_sort = NULL;
- char * tertiary_sort = NULL;
+ const gchar * primary_sort = NULL;
+ const gchar * secondary_sort = NULL;
+ const gchar * tertiary_sort = NULL;
gboolean primary_increasing = TRUE;
gboolean secondary_increasing = TRUE;
gboolean tertiary_increasing = TRUE;
@@ -1833,7 +1806,7 @@
while (!SCM_NULLP (query_scm))
{
- char *symbol;
+ const gchar *symbol;
SCM sym_scm;
SCM value;
SCM pair;
@@ -1856,7 +1829,6 @@
break;
}
- /* symbol = gh_symbol2newstr (sym_scm, NULL); */
symbol = SCM_SYMBOL_CHARS (sym_scm);
if (!symbol) {
PERR ("No string found");
@@ -1882,7 +1854,6 @@
break;
}
- /* primary_sort = gh_symbol2newstr (value, NULL); */
primary_sort = SCM_SYMBOL_CHARS (value);
} else if (safe_strcmp ("secondary-sort", symbol) == 0) {
@@ -1892,7 +1863,6 @@
break;
}
- /* secondary_sort = gh_symbol2newstr (value, NULL); */
secondary_sort = SCM_SYMBOL_CHARS (value);
} else if (safe_strcmp ("tertiary-sort", symbol) == 0) {
@@ -1902,7 +1872,6 @@
break;
}
- /* tertiary_sort = gh_symbol2newstr (value, NULL); */
tertiary_sort = SCM_SYMBOL_CHARS (value);
} else if (safe_strcmp ("primary-increasing", symbol) == 0) {
@@ -1953,7 +1922,7 @@
{
Query *q = NULL;
gboolean ok = TRUE;
- char * search_for = NULL;
+ const gchar * search_for = NULL;
GSList *sp1 = NULL, *sp2 = NULL, *sp3 = NULL;
gint so1 = 0, so2 = 0, so3 = 0;
gboolean si1 = TRUE, si2 = TRUE, si3 = TRUE;
@@ -1963,7 +1932,7 @@
while (!SCM_NULLP (query_scm))
{
- char *symbol;
+ const gchar *symbol;
SCM sym_scm;
SCM value;
SCM pair;
@@ -1984,7 +1953,6 @@
break;
}
- /* symbol = gh_symbol2newstr (sym_scm, NULL); */
symbol = SCM_SYMBOL_CHARS (sym_scm);
if (!symbol) {
ok = FALSE;
@@ -2006,7 +1974,6 @@
ok = FALSE;
break;
}
- /* search_for = gh_symbol2newstr (value, NULL); */
search_for = SCM_SYMBOL_CHARS (value);
} else if (safe_strcmp ("primary-sort", symbol) == 0) {
@@ -2061,7 +2028,7 @@
gnc_scm2query (SCM query_scm)
{
SCM q_type;
- char *type;
+ const gchar *type;
Query *q = NULL;
/* Not a list or NULL? No need to go further */
@@ -2081,7 +2048,6 @@
}
/* Ok, the LHS is the version and the RHS is the actual query list */
- /* type = gh_symbol2newstr (q_type, NULL); */
type = SCM_SYMBOL_CHARS (q_type);
if (!type)
return NULL;
Index: option-util.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/app-utils/option-util.c,v
retrieving revision 1.19.4.8
retrieving revision 1.19.4.9
diff -Lsrc/app-utils/option-util.c -Lsrc/app-utils/option-util.c -u -r1.19.4.8 -r1.19.4.9
--- src/app-utils/option-util.c
+++ src/app-utils/option-util.c
@@ -2028,7 +2028,7 @@
{
value = scm_call_0(getter);
if (SCM_STRINGP(value))
- return SCM_STRING_CHARS(value);
+ return g_strdup(SCM_STRING_CHARS(value));
}
}
Index: argv-list-converters.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/gnome-utils/argv-list-converters.c,v
retrieving revision 1.1.4.2
retrieving revision 1.1.4.3
diff -Lsrc/gnome-utils/argv-list-converters.c -Lsrc/gnome-utils/argv-list-converters.c -u -r1.1.4.2 -r1.1.4.3
--- src/gnome-utils/argv-list-converters.c
+++ src/gnome-utils/argv-list-converters.c
@@ -25,7 +25,6 @@
#include <glib.h>
#include <libguile.h>
-#include "guile-mappings.h"
#include "argv-list-converters.h"
@@ -61,8 +60,7 @@
next = SCM_CDR(next);
if(SCM_STRINGP(scm_string))
{
- /* char *onestr = gh_scm2newstr(scm_string, 0); */
- char *onestr = SCM_STRING_CHARS(scm_string);
+ const gchar *onestr = SCM_STRING_CHARS(scm_string);
ret[loc] = g_strdup (onestr);
}
else
Index: dialog-options.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/gnome-utils/dialog-options.c,v
retrieving revision 1.22.2.18
retrieving revision 1.22.2.19
diff -Lsrc/gnome-utils/dialog-options.c -Lsrc/gnome-utils/dialog-options.c -u -r1.22.2.18 -r1.22.2.19
--- src/gnome-utils/dialog-options.c
+++ src/gnome-utils/dialog-options.c
@@ -2019,8 +2019,7 @@
{
if (SCM_STRINGP(value))
{
- /* char *string = gh_scm2newstr(value, NULL); */
- char *string = SCM_STRING_CHARS(value);
+ const gchar *string = SCM_STRING_CHARS(value);
gtk_entry_set_text(GTK_ENTRY(widget), string);
return FALSE;
}
@@ -2041,10 +2040,8 @@
if (SCM_STRINGP(value))
{
- /* char *string = gh_scm2newstr(value, NULL); */
- char *string = SCM_STRING_CHARS(value);
+ const gchar *string = SCM_STRING_CHARS(value);
gtk_text_buffer_set_text (buffer, string, strlen (string));
- free(string);
return FALSE;
}
else
@@ -2309,8 +2306,7 @@
{
if (SCM_STRINGP(value))
{
- /* char *string = gh_scm2newstr(value, NULL); */
- char *string = SCM_STRING_CHARS(value);
+ const gchar *string = SCM_STRING_CHARS(value);
if ((string != NULL) && (*string != '\0'))
{
GnomeFontPicker *picker = GNOME_FONT_PICKER(widget);
@@ -2329,8 +2325,7 @@
ENTER("option %p(%s)", option, gnc_option_name(option));
if (SCM_STRINGP(value))
{
- /* char * string = gh_scm2newstr(value, NULL); */
- char *string = SCM_STRING_CHARS(value);
+ const gchar *string = SCM_STRING_CHARS(value);
if (string && *string)
{
Index: gnc-menu-extensions.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/gnome-utils/gnc-menu-extensions.c,v
retrieving revision 1.9.4.7
retrieving revision 1.9.4.8
diff -Lsrc/gnome-utils/gnc-menu-extensions.c -Lsrc/gnome-utils/gnc-menu-extensions.c -u -r1.9.4.7 -r1.9.4.8
--- src/gnome-utils/gnc-menu-extensions.c
+++ src/gnome-utils/gnc-menu-extensions.c
@@ -148,8 +148,7 @@
if (SCM_STRINGP(item))
{
- /* strings[i] = gh_scm2newstr(item, NULL); */
- strings[i] = SCM_STRING_CHARS (item);
+ strings[i] = g_strdup(SCM_STRING_CHARS(item));
}
else
{
More information about the gnucash-changes
mailing list