mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
[Transaction.c] use is_unset static to denote uncached readonly_reason
tests in 128c8d6f88
This commit is contained in:
@@ -274,8 +274,7 @@ gnc_transaction_init(Transaction* trans)
|
|||||||
trans->date_posted = 0;
|
trans->date_posted = 0;
|
||||||
trans->marker = 0;
|
trans->marker = 0;
|
||||||
trans->orig = NULL;
|
trans->orig = NULL;
|
||||||
trans->readonly_reason = NULL;
|
trans->readonly_reason = (char*) is_unset;
|
||||||
trans->reason_cache_valid = FALSE;
|
|
||||||
trans->isClosingTxn_cached = -1;
|
trans->isClosingTxn_cached = -1;
|
||||||
trans->notes = (char*) is_unset;
|
trans->notes = (char*) is_unset;
|
||||||
trans->doclink = (char*) is_unset;
|
trans->doclink = (char*) is_unset;
|
||||||
@@ -818,6 +817,7 @@ xaccFreeTransaction (Transaction *trans)
|
|||||||
/* free up transaction strings */
|
/* free up transaction strings */
|
||||||
CACHE_REMOVE(trans->num);
|
CACHE_REMOVE(trans->num);
|
||||||
CACHE_REMOVE(trans->description);
|
CACHE_REMOVE(trans->description);
|
||||||
|
if (trans->readonly_reason != is_unset)
|
||||||
g_free (trans->readonly_reason);
|
g_free (trans->readonly_reason);
|
||||||
if (trans->doclink != is_unset)
|
if (trans->doclink != is_unset)
|
||||||
g_free (trans->doclink);
|
g_free (trans->doclink);
|
||||||
@@ -832,7 +832,6 @@ xaccFreeTransaction (Transaction *trans)
|
|||||||
trans->date_entered = 0;
|
trans->date_entered = 0;
|
||||||
trans->date_posted = 0;
|
trans->date_posted = 0;
|
||||||
trans->readonly_reason = NULL;
|
trans->readonly_reason = NULL;
|
||||||
trans->reason_cache_valid = FALSE;
|
|
||||||
trans->doclink = NULL;
|
trans->doclink = NULL;
|
||||||
trans->notes = NULL;
|
trans->notes = NULL;
|
||||||
trans->void_reason = NULL;
|
trans->void_reason = NULL;
|
||||||
@@ -2130,9 +2129,9 @@ void xaccTransClearReadOnly (Transaction *trans)
|
|||||||
qof_instance_set_dirty(QOF_INSTANCE(trans));
|
qof_instance_set_dirty(QOF_INSTANCE(trans));
|
||||||
xaccTransCommitEdit(trans);
|
xaccTransCommitEdit(trans);
|
||||||
|
|
||||||
|
if (trans->readonly_reason != is_unset)
|
||||||
g_free (trans->readonly_reason);
|
g_free (trans->readonly_reason);
|
||||||
trans->readonly_reason = NULL;
|
trans->readonly_reason = NULL;
|
||||||
trans->reason_cache_valid = TRUE;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2150,9 +2149,9 @@ xaccTransSetReadOnly (Transaction *trans, const char *reason)
|
|||||||
g_value_unset (&v);
|
g_value_unset (&v);
|
||||||
xaccTransCommitEdit(trans);
|
xaccTransCommitEdit(trans);
|
||||||
|
|
||||||
|
if (trans->readonly_reason != is_unset)
|
||||||
g_free (trans->readonly_reason);
|
g_free (trans->readonly_reason);
|
||||||
trans->readonly_reason = g_strdup (reason);
|
trans->readonly_reason = g_strdup (reason);
|
||||||
trans->reason_cache_valid = TRUE;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2570,23 +2569,14 @@ xaccTransGetReadOnly (Transaction *trans)
|
|||||||
if (!trans)
|
if (!trans)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (!trans->reason_cache_valid)
|
if (trans->readonly_reason == is_unset)
|
||||||
{
|
{
|
||||||
GValue v = G_VALUE_INIT;
|
GValue v = G_VALUE_INIT;
|
||||||
qof_instance_get_kvp (QOF_INSTANCE(trans), &v, 1, TRANS_READ_ONLY_REASON);
|
qof_instance_get_kvp (QOF_INSTANCE(trans), &v, 1, TRANS_READ_ONLY_REASON);
|
||||||
|
trans->readonly_reason = G_VALUE_HOLDS_STRING (&v) ?
|
||||||
/* Clear possible old cache value first */
|
g_value_dup_string (&v) : NULL;
|
||||||
g_free (trans->readonly_reason);
|
|
||||||
trans->readonly_reason = NULL;
|
|
||||||
|
|
||||||
/* Then set the new one */
|
|
||||||
if (G_VALUE_HOLDS_STRING (&v))
|
|
||||||
{
|
|
||||||
trans->readonly_reason = g_value_dup_string (&v);
|
|
||||||
g_value_unset (&v);
|
g_value_unset (&v);
|
||||||
}
|
}
|
||||||
trans->reason_cache_valid = TRUE;
|
|
||||||
}
|
|
||||||
return trans->readonly_reason;
|
return trans->readonly_reason;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -114,11 +114,9 @@ struct transaction_s
|
|||||||
/* The readonly_reason is a string that indicates why a transaction
|
/* The readonly_reason is a string that indicates why a transaction
|
||||||
* is marked as read-only. If NULL, the transaction is read-write.
|
* is marked as read-only. If NULL, the transaction is read-write.
|
||||||
* This value is stored in kvp, but we cache a copy here for
|
* This value is stored in kvp, but we cache a copy here for
|
||||||
* performance reasons. reason_cache_valid indicates whether the
|
* performance reasons.
|
||||||
* cached value is valid.
|
|
||||||
*/
|
*/
|
||||||
char * readonly_reason;
|
char * readonly_reason;
|
||||||
gboolean reason_cache_valid;
|
|
||||||
|
|
||||||
char * doclink;
|
char * doclink;
|
||||||
char * void_reason;
|
char * void_reason;
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ public:
|
|||||||
marker = 0;
|
marker = 0;
|
||||||
orig = nullptr;
|
orig = nullptr;
|
||||||
readonly_reason = nullptr;
|
readonly_reason = nullptr;
|
||||||
reason_cache_valid = FALSE;
|
|
||||||
isClosingTxn_cached = -1;
|
isClosingTxn_cached = -1;
|
||||||
}
|
}
|
||||||
void* operator new(size_t size)
|
void* operator new(size_t size)
|
||||||
|
|||||||
Reference in New Issue
Block a user