mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Rename guid_new to guid_replace
`new` implies some allocation. Since guid_new was actually constructing a guid in place rather than allocating it, it makes much more sense to call it guid_replace (or guid_construct). We went with guid_replace.
This commit is contained in:
parent
26a49f9644
commit
9c82a1e9bc
@ -353,7 +353,7 @@ entities such as Accounts and Transactions.
|
||||
Generate a new guid. This function is guaranteed to return a guid that
|
||||
is unique within the scope of all GnuCash entities being managed by the
|
||||
the current invocation of GnuCash. GnuCash routines should always use
|
||||
this function and not @code{guid_new}!
|
||||
this function and not @code{guid_replace}!
|
||||
@end deftypefun
|
||||
|
||||
@deftypefun {void *} xaccLookupEntity (const GUID * @var{guid}, GNCIdType @var{entity_type})
|
||||
@ -394,7 +394,7 @@ binary data. This provides a way to reliably obtain a given sequence of
|
||||
GUIDs.
|
||||
@end deftypefun
|
||||
|
||||
@deftypefun void guid_new (GUID * @var{guid})
|
||||
@deftypefun void guid_replace (GUID * @var{guid})
|
||||
Create a new GUID and store it in @var{guid}. This is a low-level function!
|
||||
GnuCash code should use @code{xaccGUIDNew}.
|
||||
@end deftypefun
|
||||
|
@ -243,7 +243,7 @@ get_random_guid(void)
|
||||
GncGUID *ret;
|
||||
|
||||
ret = g_new(GncGUID, 1);
|
||||
guid_new(ret);
|
||||
guid_replace(ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ test_customer (void)
|
||||
do_test (gncCustomerGetAddr (customer) != NULL, "Addr");
|
||||
do_test (gncCustomerGetShipAddr (customer) != NULL, "ShipAddr");
|
||||
|
||||
guid_new (&guid);
|
||||
guid_replace (&guid);
|
||||
customer = gncCustomerCreate (book);
|
||||
count++;
|
||||
gncCustomerSetGUID (customer, &guid);
|
||||
|
@ -96,7 +96,7 @@ test_employee (void)
|
||||
|
||||
do_test (gncEmployeeGetAddr (employee) != NULL, "Addr");
|
||||
|
||||
guid_new (&guid);
|
||||
guid_replace (&guid);
|
||||
employee = gncEmployeeCreate (book);
|
||||
count++;
|
||||
gncEmployeeSetGUID (employee, &guid);
|
||||
|
@ -43,7 +43,7 @@ static void test_null_guid(void)
|
||||
|
||||
g = guid_new_return();
|
||||
gp = guid_malloc();
|
||||
guid_new(gp);
|
||||
guid_replace(gp);
|
||||
|
||||
do_test(guid_equal(guid_null(), guid_null()), "null guids equal");
|
||||
do_test(!guid_equal(&g, gp), "two guids equal");
|
||||
@ -70,7 +70,7 @@ run_test (void)
|
||||
for (i = 0; i < NENT; i++)
|
||||
{
|
||||
ent = g_object_new(QOF_TYPE_INSTANCE, NULL);
|
||||
guid_new(&guid);
|
||||
guid_replace(&guid);
|
||||
ent = g_object_new(QOF_TYPE_INSTANCE, "guid", &guid, NULL);
|
||||
do_test ((NULL == qof_collection_lookup_entity (col, &guid)),
|
||||
"duplicate guid");
|
||||
|
@ -91,7 +91,7 @@ test_job (void)
|
||||
|
||||
test_bool_fcn (book, "Active", gncJobSetActive, gncJobGetActive);
|
||||
|
||||
guid_new (&guid);
|
||||
guid_replace (&guid);
|
||||
job = gncJobCreate (book);
|
||||
count++;
|
||||
gncJobSetGUID (job, &guid);
|
||||
|
@ -96,7 +96,7 @@ test_vendor (void)
|
||||
|
||||
do_test (gncVendorGetAddr (vendor) != NULL, "Addr");
|
||||
|
||||
guid_new (&guid);
|
||||
guid_replace (&guid);
|
||||
vendor = gncVendorCreate (book);
|
||||
count++;
|
||||
gncVendorSetGUID (vendor, &guid);
|
||||
|
@ -116,7 +116,7 @@ auth_user (const char * name, const char *passwd)
|
||||
if (!name || !passwd) return NULL;
|
||||
|
||||
guid = g_new (GncGUID, 1);
|
||||
guid_new (guid);
|
||||
guid_replace (guid);
|
||||
logged_in_users = g_list_prepend (logged_in_users, guid);
|
||||
session_auth_string = guid_to_string (guid); /* THREAD UNSAFE */
|
||||
return session_auth_string;
|
||||
|
@ -767,7 +767,7 @@ pcd_save_custom_data(PrintCheckDialog *pcd, const gchar *title)
|
||||
multip = pcd_get_custom_multip(pcd);
|
||||
|
||||
key_file = g_key_file_new();
|
||||
guid_new(&guid);
|
||||
guid_replace(&guid);
|
||||
guid_to_string_buff(&guid, buf);
|
||||
g_key_file_set_string(key_file, KF_GROUP_TOP, KF_KEY_GUID, buf);
|
||||
g_key_file_set_string(key_file, KF_GROUP_TOP, KF_KEY_TITLE, title);
|
||||
|
@ -767,7 +767,7 @@ pcd_save_custom_data(PrintCheckDialog *pcd, const gchar *title)
|
||||
multip = pcd_get_custom_multip(pcd);
|
||||
|
||||
key_file = g_key_file_new();
|
||||
guid_new(&guid);
|
||||
guid_replace(&guid);
|
||||
guid_to_string_buff(&guid, buf);
|
||||
g_key_file_set_string(key_file, KF_GROUP_TOP, KF_KEY_GUID, buf);
|
||||
g_key_file_set_string(key_file, KF_GROUP_TOP, KF_KEY_TITLE, title);
|
||||
|
@ -99,7 +99,7 @@ GncGUID *
|
||||
guid_malloc (void)
|
||||
{
|
||||
/*We need to actually construct here (not just ::operator new (size_t) -- allocate)
|
||||
because in guid_new, we assume that the object has already been constructed.
|
||||
because in guid_replace, we assume that the object has already been constructed.
|
||||
Note the boost UUID is a POD, so its constructor is trivial.*/
|
||||
return reinterpret_cast<GncGUID*> (new boost::uuids::uuid);
|
||||
}
|
||||
@ -146,9 +146,9 @@ guid_shutdown (void)
|
||||
{
|
||||
}
|
||||
|
||||
/*Takes an already-constructed guid pointer and re-constructs it in place*/
|
||||
/*Takes an allocated guid pointer and constructs it in place*/
|
||||
void
|
||||
guid_new(GncGUID *guid)
|
||||
guid_replace(GncGUID *guid)
|
||||
{
|
||||
static boost::uuids::random_generator gen;
|
||||
boost::uuids::uuid * val {reinterpret_cast<boost::uuids::uuid*> (guid)};
|
||||
@ -160,10 +160,10 @@ GncGUID
|
||||
guid_new_return(void)
|
||||
{
|
||||
/*we need to construct our value as a boost guid so that
|
||||
it can be deconstructed (in place) in guid_new*/
|
||||
it can be deconstructed (in place) in guid_replace*/
|
||||
boost::uuids::uuid guid;
|
||||
GncGUID * ret {reinterpret_cast<GncGUID*> (&guid)};
|
||||
guid_new (ret);
|
||||
guid_replace (ret);
|
||||
/*return a copy*/
|
||||
return *ret;
|
||||
}
|
||||
|
@ -87,21 +87,12 @@ void guid_init(void);
|
||||
* GUIDs at once. */
|
||||
void guid_shutdown (void);
|
||||
|
||||
/** Generate a new id. If no initialization function has been called,
|
||||
* guid_init() will be called before the id is created.
|
||||
/** Generate a new guid.
|
||||
*
|
||||
* @param guid A pointer to an existing guid data structure. The
|
||||
* @param guid A pointer to an allocated guid data structure. The
|
||||
* existing value will be replaced with a new value.
|
||||
*
|
||||
* This routine uses the md5 algorithm to build strong random guids.
|
||||
* Note that while guid's are generated randomly, the odds of this
|
||||
* routine returning a non-unique id are astronomically small.
|
||||
* (Literally astronomically: If you had Cray's on every solar
|
||||
* system in the universe running for the entire age of the universe,
|
||||
* you'd still have less than a one-in-a-million chance of coming up
|
||||
* with a duplicate id. 2^128 == 10^38 is a really really big number.)
|
||||
*/
|
||||
void guid_new (GncGUID *guid);
|
||||
void guid_replace (GncGUID *guid);
|
||||
|
||||
/** Generate a new id. If no initialization function has been called,
|
||||
* guid_init() will be called before the id is created.
|
||||
|
@ -303,7 +303,7 @@ qof_instance_init_data (QofInstance *inst, QofIdType type, QofBook *book)
|
||||
|
||||
do
|
||||
{
|
||||
guid_new(&priv->guid);
|
||||
guid_replace(&priv->guid);
|
||||
|
||||
if (NULL == qof_collection_lookup_entity (col, &priv->guid))
|
||||
break;
|
||||
|
@ -47,7 +47,7 @@ static const gchar * suitename {"/qof/gnc-guid"};
|
||||
static void test_create_gnc_guid (void){
|
||||
GncGUID * guid {guid_malloc ()};
|
||||
g_assert (guid != nullptr);
|
||||
guid_new (guid);
|
||||
guid_replace (guid);
|
||||
/*We apparently don't need to free guid_null (based on its being const)*/
|
||||
const GncGUID * guidnull {guid_null ()};
|
||||
g_assert (!guid_equal (guid, guidnull));
|
||||
@ -58,7 +58,7 @@ static void test_create_gnc_guid (void){
|
||||
static void test_gnc_guid_copy (void) {
|
||||
GncGUID * guid {guid_malloc ()};
|
||||
g_assert (guid != nullptr);
|
||||
guid_new (guid);
|
||||
guid_replace (guid);
|
||||
GncGUID * cp {guid_copy (guid)};
|
||||
g_assert (guid_equal (guid, cp));
|
||||
guid_free (cp);
|
||||
@ -70,7 +70,7 @@ defined in the guid api. We then compare them.*/
|
||||
static void test_gnc_guid_to_string (void) {
|
||||
GncGUID * guid {guid_malloc()};
|
||||
g_assert (guid != nullptr);
|
||||
guid_new (guid);
|
||||
guid_replace (guid);
|
||||
string message {" using guid_to_string (deprecated): "};
|
||||
/*don't free the return value of guid_to_string!*/
|
||||
string guidstr {guid_to_string (guid)};
|
||||
@ -135,7 +135,7 @@ static void test_gnc_guid_roundtrip (void) {
|
||||
g_assert (guid1 != nullptr);
|
||||
GncGUID * guid2 {guid_malloc ()};
|
||||
g_assert (guid2 != nullptr);
|
||||
guid_new (guid1);
|
||||
guid_replace (guid1);
|
||||
|
||||
gchar guidstrp [GUID_ENCODING_LENGTH+1];
|
||||
gchar * temp {guid_to_string_buff (guid1, guidstrp)};
|
||||
|
@ -102,7 +102,7 @@ populate_frame (KvpFrame *frame)
|
||||
ts.tv_sec = 1;
|
||||
ts.tv_nsec = 1;
|
||||
guid = guid_malloc ();
|
||||
guid_new (guid);
|
||||
guid_replace (guid);
|
||||
g_date_set_dmy (&gdate, 26, 1, 1957);
|
||||
|
||||
kvp_frame_set_gint64( frame, "gint64-type", 100 );
|
||||
@ -164,7 +164,7 @@ test_kvp_frame_copy( Fixture *fixture, gconstpointer pData )
|
||||
test_ts.tv_nsec = 1;
|
||||
test_str = "abcdefghijklmnop";
|
||||
test_guid = guid_malloc();
|
||||
guid_new( test_guid );
|
||||
guid_replace( test_guid );
|
||||
test_frame = kvp_frame_new();
|
||||
|
||||
g_assert( fixture->frame );
|
||||
@ -224,7 +224,7 @@ test_kvp_frame_set_foo( Fixture *fixture, gconstpointer pData )
|
||||
test_ts.tv_sec = 1;
|
||||
test_ts.tv_nsec = 1;
|
||||
test_guid = guid_malloc();
|
||||
guid_new( test_guid );
|
||||
guid_replace( test_guid );
|
||||
|
||||
g_assert( fixture->frame );
|
||||
g_assert( kvp_frame_is_empty( fixture->frame ) );
|
||||
@ -513,7 +513,7 @@ test_kvp_value_copy( void )
|
||||
|
||||
gnc_numeric_orig = gnc_numeric_zero();
|
||||
guid_orig = guid_malloc();
|
||||
guid_new( guid_orig );
|
||||
guid_replace( guid_orig );
|
||||
ts_orig.tv_sec = 1;
|
||||
ts_orig.tv_nsec = 1;
|
||||
list_orig = NULL;
|
||||
@ -632,7 +632,7 @@ test_kvp_glist_copy( void )
|
||||
|
||||
gnc_numeric_orig = gnc_numeric_zero();
|
||||
guid_orig = guid_malloc();
|
||||
guid_new( guid_orig );
|
||||
guid_replace( guid_orig );
|
||||
ts_orig.tv_sec = 1;
|
||||
ts_orig.tv_nsec = 1;
|
||||
list_orig = NULL;
|
||||
@ -704,7 +704,7 @@ test_kvp_glist_compare( void )
|
||||
|
||||
gnc_numeric_orig = gnc_numeric_zero();
|
||||
guid_orig = guid_malloc();
|
||||
guid_new( guid_orig );
|
||||
guid_replace( guid_orig );
|
||||
ts_orig.tv_sec = 1;
|
||||
ts_orig.tv_nsec = 1;
|
||||
list_orig = NULL;
|
||||
@ -798,9 +798,9 @@ test_kvp_value_compare( void )
|
||||
gnc_numeric_orig = gnc_numeric_zero();
|
||||
gnc_numeric_copy = gnc_numeric_zero();
|
||||
guid_orig = guid_malloc();
|
||||
guid_new( guid_orig );
|
||||
guid_replace( guid_orig );
|
||||
guid_copy = guid_malloc();
|
||||
guid_new( guid_copy );
|
||||
guid_replace( guid_copy );
|
||||
ts_orig.tv_sec = 1;
|
||||
ts_orig.tv_nsec = 1;
|
||||
ts_copy.tv_sec = 2;
|
||||
@ -1008,7 +1008,7 @@ test_kvp_value_to_string( void )
|
||||
|
||||
gnc_numeric_orig = gnc_numeric_zero();
|
||||
guid_orig = guid_malloc();
|
||||
guid_new( guid_orig );
|
||||
guid_replace( guid_orig );
|
||||
ts_orig.tv_sec = 1;
|
||||
ts_orig.tv_nsec = 1;
|
||||
list_orig = NULL;
|
||||
@ -1094,7 +1094,7 @@ test_kvp_frame_to_string( Fixture *fixture, gconstpointer pData )
|
||||
|
||||
test_gnc_numeric = gnc_numeric_zero();
|
||||
test_guid = guid_malloc();
|
||||
guid_new( test_guid );
|
||||
guid_replace( test_guid );
|
||||
test_ts.tv_sec = 1;
|
||||
test_ts.tv_nsec = 1;
|
||||
test_frame = kvp_frame_new();
|
||||
|
@ -98,7 +98,7 @@ test_instance_set_get_guid( Fixture *fixture, gconstpointer pData )
|
||||
|
||||
/* set up */
|
||||
gncGuid = guid_malloc();
|
||||
guid_new( gncGuid );
|
||||
guid_replace( gncGuid );
|
||||
g_assert( QOF_IS_INSTANCE( fixture->inst ) );
|
||||
g_assert( gncGuid );
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user