Fix bugs with new book pointers.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@6053 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Dave Peticolas 2001-11-25 09:05:23 +00:00
parent 8168a283b2
commit fed69ff72c
13 changed files with 59 additions and 46 deletions

View File

@ -230,7 +230,9 @@ pricedb_start_handler(GSList* sibling_data,
const gchar *tag,
gchar **attrs)
{
GNCPriceDB *db = gnc_pricedb_create();
gxpf_data *gdata = global_data;
GNCBook *book = gdata->bookdata;
GNCPriceDB *db = gnc_pricedb_create(book);
g_return_val_if_fail(db, FALSE);
*result = db;
return(TRUE);

View File

@ -202,7 +202,7 @@ cvt_potential_prices_to_pricedb_and_cleanup(GNCPriceDB **prices,
{
GSList *item = potential_quotes;
*prices = gnc_pricedb_create();
*prices = gnc_pricedb_create(book);
if (!*prices) return FALSE;
while(item)

View File

@ -404,7 +404,7 @@ gnc_session_load_from_xml_file(GNCSession *session)
{
GNCPriceDB *db = gnc_book_get_pricedb(book);
gnc_book_set_pricedb(book, gnc_pricedb_create());
gnc_book_set_pricedb(book, gnc_pricedb_create(book));
if(db) gnc_pricedb_destroy(db);
}
@ -3711,7 +3711,8 @@ pricedb_start_handler(GSList* sibling_data,
const gchar *tag,
gchar **attrs)
{
GNCPriceDB *db = gnc_pricedb_create();
GNCParseStatus *pstatus = (GNCParseStatus *) global_data;
GNCPriceDB *db = gnc_pricedb_create(pstatus->book);
g_return_val_if_fail(db, FALSE);
*result = db;
return(TRUE);

View File

@ -46,7 +46,6 @@
#include "io-utils.h"
#define GNC_V2_STRING "gnc-v2"
static void
@ -533,7 +532,7 @@ gnc_session_load_from_xml_file_v2(
* then the file had no pricedb section. However,
* this routine is expected to put one in the book. */
if (!gnc_book_get_pricedb (book))
gnc_book_set_pricedb (book, gnc_pricedb_create ());
gnc_book_set_pricedb (book, gnc_pricedb_create (book));
/* mark the newly read group as saved, since the act of putting
* it together will have caused it to be marked up as not-saved.

View File

@ -300,7 +300,7 @@ pgendGetAllPrices (PGBackend *be, GNCPriceDB *prdb)
ENTER ("be=%p, conn=%p", be, be->connection);
if (!prdb) {
prdb = gnc_pricedb_create();
prdb = gnc_pricedb_create(be->book);
}
/* first, make sure commodities table is up to date */

View File

@ -662,10 +662,7 @@ xaccAccountInsertSubAccount (Account *adult, Account *child)
/* if a container for the children doesn't yet exist, add it */
if (adult->children == NULL)
{
GNCBook *book = xaccGroupGetBook (adult->parent);
adult->children = xaccMallocAccountGroup (book);
}
adult->children = xaccMallocAccountGroup (adult->book);
/* set back-pointer to parent */
adult->children->parent = adult;

View File

@ -78,7 +78,7 @@ gnc_book_init (GNCBook *book)
book->kvp_data = kvp_frame_new ();
book->topgroup = xaccMallocAccountGroup(book);
book->pricedb = gnc_pricedb_create();
book->pricedb = gnc_pricedb_create(book);
book->sched_xactions = NULL;
book->sx_notsaved = FALSE;
@ -238,6 +238,7 @@ gnc_book_set_pricedb(GNCBook *book, GNCPriceDB *db)
{
if(!book) return;
book->pricedb = db;
if (db) db->book = book;
}
/* ---------------------------------------------------------------------- */

View File

@ -35,8 +35,6 @@ struct gnc_price_s
{
/* 'public' data fields */
GUID guid; /* globally unique price id */
GNCEntityTable *entity_table; /* table in which price is stored */
GNCBook *book; /* book to which this price belongs to */
GNCPriceDB *db;
gnc_commodity *commodity;
@ -49,6 +47,8 @@ struct gnc_price_s
guint32 version_check; /* data aging timestamp */
/* 'private' object management fields */
GNCBook *book; /* book to which this price belongs to */
GNCEntityTable *entity_table; /* table in which price is stored */
guint32 refcount; /* garbage collection reference count */
gint32 editlevel; /* nesting level of begin/end edit calls */
gboolean not_saved; /* price edit saved flag */

View File

@ -612,10 +612,14 @@ commodity_equal (gconstpointer a, gconstpointer b)
}
GNCPriceDB *
gnc_pricedb_create(void)
gnc_pricedb_create(GNCBook * book)
{
GNCPriceDB * result = g_new0(GNCPriceDB, 1);
result->book = NULL;
GNCPriceDB * result;
g_return_val_if_fail (book, NULL);
result = g_new0(GNCPriceDB, 1);
result->book = book;
result->commodity_hash = g_hash_table_new(commodity_hash, commodity_equal);
g_return_val_if_fail (result->commodity_hash, NULL);
return result;

View File

@ -219,7 +219,7 @@ typedef struct gnc_price_db_s GNCPriceDB;
/* gnc_pricedb_create - create a new pricedb. Normally you won't need
this; you will get the pricedb via gnc_book_get_pricedb. */
GNCPriceDB * gnc_pricedb_create(void);
GNCPriceDB * gnc_pricedb_create(GNCBook *book);
/* gnc_pricedb_destroy - destroy the given pricedb and unref all of
the prices it contains. This may not deallocate all of those

View File

@ -12,7 +12,6 @@
#include "date.h"
#include "Group.h"
#include "gnc-book-p.h"
#include "gnc-engine.h"
#include "gnc-engine-util.h"
#include "test-engine-stuff.h"
@ -226,7 +225,7 @@ get_random_pricedb(GNCBook *book)
{
GNCPriceDB *db;
db = gnc_pricedb_create ();
db = gnc_pricedb_create (book);
make_random_pricedb (book, db);
return db;
@ -546,16 +545,16 @@ account_add_subaccounts (GNCBook *book, Account *account, int depth)
}
}
static AccountGroup *
get_random_group_depth(GNCBook *book, int depth)
static void
make_random_group_depth (GNCBook *book, AccountGroup *group, int depth)
{
AccountGroup *group;
int num_accounts;
if (depth <= 0)
return NULL;
g_return_if_fail (book);
g_return_if_fail (group);
group = xaccMallocAccountGroup (book);
if (depth <= 0)
return;
num_accounts = get_random_int_in_range (1, max_group_accounts);
@ -567,18 +566,33 @@ get_random_group_depth(GNCBook *book, int depth)
account_add_subaccounts (book, account, depth - 1);
}
}
return group;
static void
make_random_group (GNCBook *book, AccountGroup * group)
{
int depth;
g_return_if_fail (book);
g_return_if_fail (group);
depth = get_random_int_in_range (1, max_group_depth);
make_random_group_depth (book, group, depth);
}
AccountGroup *
get_random_group (GNCBook *book)
{
int depth;
AccountGroup * group;
depth = get_random_int_in_range (1, max_group_depth);
g_return_val_if_fail (book, NULL);
return get_random_group_depth (book, depth);
group = xaccMallocAccountGroup (book);
make_random_group (book, group);
return group;
}
typedef struct
@ -1443,11 +1457,7 @@ get_random_book (void)
book = gnc_book_new ();
/* XXX fixme -- gnc_book_set_group is a private engine function,
* it should not be invoked in ordinary test cases. Its should
* be more like make_random_pricedb below... */
gnc_book_set_group (book, get_random_group (book));
make_random_group (book, gnc_book_get_group (book));
make_random_pricedb (book, gnc_book_get_pricedb (book));
return book;
@ -1463,11 +1473,7 @@ get_random_session (void)
book = gnc_session_get_book (session);
/* XXX fixme -- gnc_book_set_group is a private engine function,
* it should not be invoked in ordinary test cases. Its should
* be more like make_random_pricedb below... */
gnc_book_set_group (book, get_random_group (book));
make_random_group (book, gnc_book_get_group (book));
make_random_pricedb (book, gnc_book_get_pricedb (book));
return session;

View File

@ -62,15 +62,18 @@ run_test (void)
exit(get_rv());
}
if (!group_has_book (group1, NULL))
if (!group_has_book (group1, book))
{
failure("new group has non-null book");
failure("new group has wrong book");
exit(get_rv());
}
/* ???????? this test seems to be testing routines that
* are private to the engine, not sure why. book_set_group
* should not be called publically. */
/* this test is testing routines that are private
* to the engine. these tests are intended to test
* the engine as a whole, not just the public
* interface. the maintenance of the correct
* book pointers is important for correct
* engine operation. */
gnc_book_set_group (book, group1);
if (!group_has_book (group1, book))
{

View File

@ -48,7 +48,7 @@ run_tests (void)
test_query (q);
xaccFreeQuery (q);
for (i = 0; i < 10; i++)
for (i = 0; i < 50; i++)
{
q = get_random_query ();
test_query (q);