mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-16 18:25:11 -06:00
Change the KVP string storage type from char* to const char*.
Because we don't want to be able to get a pointer to the KvpValue and change its contents without using KvpValue::set().
This commit is contained in:
parent
831a360122
commit
45a01b0f67
@ -262,7 +262,7 @@ add_kvp_value_node(xmlNodePtr node, const gchar *tag, KvpValue* val)
|
||||
{
|
||||
case KVP_TYPE_STRING:
|
||||
{
|
||||
auto newstr = g_strdup(val->get<char*>());
|
||||
auto newstr = g_strdup(val->get<const char*>());
|
||||
val_node = xmlNewTextChild(node, NULL, BAD_CAST tag,
|
||||
checked_char_cast (newstr));
|
||||
g_free (newstr);
|
||||
|
@ -124,7 +124,7 @@ gchar *gnc_features_test_unknown (QofBook *book)
|
||||
g_list_free(features_list);
|
||||
return msg;
|
||||
}
|
||||
|
||||
g_hash_table_unref (features_used);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -80,7 +80,7 @@ KvpValueImpl::get_type() const noexcept
|
||||
return KvpValueType::KVP_TYPE_DOUBLE;
|
||||
else if (datastore.type() == typeid(gnc_numeric))
|
||||
return KvpValueType::KVP_TYPE_NUMERIC;
|
||||
else if (datastore.type() == typeid(gchar *))
|
||||
else if (datastore.type() == typeid(const gchar *))
|
||||
return KvpValueType::KVP_TYPE_STRING;
|
||||
else if (datastore.type() == typeid(GncGUID *))
|
||||
return KvpValueType::KVP_TYPE_GUID;
|
||||
@ -202,7 +202,7 @@ struct to_string_visitor : boost::static_visitor<void>
|
||||
output << ")";
|
||||
}
|
||||
|
||||
void operator()(char * val)
|
||||
void operator()(const char * val)
|
||||
{
|
||||
output << "KVP_VALUE_STRING(" << val << ")";
|
||||
}
|
||||
@ -243,7 +243,7 @@ struct compare_visitor : boost::static_visitor<int>
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
template <> int compare_visitor::operator()(char * const & one, char * const & two) const
|
||||
template <> int compare_visitor::operator()(const char * const & one, const char * const & two) const
|
||||
{
|
||||
return strcmp(one, two);
|
||||
}
|
||||
@ -337,8 +337,8 @@ KvpValueImpl::~KvpValueImpl() noexcept
|
||||
void
|
||||
KvpValueImpl::duplicate(const KvpValueImpl& other) noexcept
|
||||
{
|
||||
if (other.datastore.type() == typeid(gchar *))
|
||||
this->datastore = g_strdup(other.get<gchar *>());
|
||||
if (other.datastore.type() == typeid(const gchar *))
|
||||
this->datastore = g_strdup(other.get<const gchar *>());
|
||||
else if (other.datastore.type() == typeid(GncGUID*))
|
||||
this->datastore = guid_copy(other.get<GncGUID *>());
|
||||
else if (other.datastore.type() == typeid(GList*))
|
||||
|
@ -108,7 +108,7 @@ struct KvpValueImpl
|
||||
int64_t,
|
||||
double,
|
||||
gnc_numeric,
|
||||
char *,
|
||||
const char*,
|
||||
GncGUID *,
|
||||
Timespec,
|
||||
GList *,
|
||||
|
@ -1050,12 +1050,12 @@ kvp_value_get_numeric(const KvpValue * ovalue)
|
||||
return value->get<gnc_numeric>();
|
||||
}
|
||||
|
||||
char *
|
||||
const char *
|
||||
kvp_value_get_string(const KvpValue * ovalue)
|
||||
{
|
||||
if (!ovalue) return {};
|
||||
const KvpValueImpl * value {static_cast<const KvpValueImpl *>(ovalue)};
|
||||
return value->get<char*>();
|
||||
return value->get<const char*>();
|
||||
}
|
||||
|
||||
GncGUID *
|
||||
|
@ -528,7 +528,7 @@ gnc_numeric kvp_value_get_numeric(const KvpValue * value);
|
||||
|
||||
/** Value accessor. This one is non-copying -- the caller can modify
|
||||
* the value directly. */
|
||||
char * kvp_value_get_string(const KvpValue * value);
|
||||
const char* kvp_value_get_string(const KvpValue * value);
|
||||
|
||||
/** Value accessor. This one is non-copying -- the caller can modify
|
||||
* the value directly. */
|
||||
|
@ -1068,7 +1068,7 @@ static void commit_err (G_GNUC_UNUSED QofInstance *inst, QofBackendError errcode
|
||||
static void
|
||||
add_feature_to_hash (const gchar *key, KvpValue *value, gpointer user_data)
|
||||
{
|
||||
gchar *descr = kvp_value_get_string (value);
|
||||
gchar *descr = g_strdup(kvp_value_get_string (value));
|
||||
g_hash_table_insert (*(GHashTable**)user_data, (gchar*)key, descr);
|
||||
}
|
||||
|
||||
@ -1076,7 +1076,8 @@ GHashTable *
|
||||
qof_book_get_features (QofBook *book)
|
||||
{
|
||||
KvpFrame *frame = qof_instance_get_slots (QOF_INSTANCE (book));
|
||||
GHashTable *features = g_hash_table_new (g_str_hash, g_str_equal);
|
||||
GHashTable *features = g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||
NULL, g_free);
|
||||
|
||||
frame = kvp_frame_get_frame (frame, GNC_FEATURES);
|
||||
kvp_frame_for_each_slot (frame, &add_feature_to_hash, &features);
|
||||
|
Loading…
Reference in New Issue
Block a user