g_return

Neil Williams linux at codehelp.co.uk
Wed Aug 11 13:43:13 EDT 2004


On Wednesday 11 August 2004 5:44, Derek Atkins wrote:
> Uh, show me the code that's failing?
I'm using g_return_if_fail in lots of areas and it used to work - because it's 
all over the source, I put the URL in the message:
> > http://www.codehelp.co.uk/code/source.html

A quick grep for g_return gives some 30 hits.

Just one example:
	g_return_if_fail(rule != NULL);
rule is a pointer to a qof_book_mergeRule struct, naturally if the function is 
passed a null pointer, I want it to report an error and return.

When I deliberately pass a NULL:
		qof_book_mergeUpdateResult(NULL, 0);
instead of
		qof_book_mergeUpdateResult(rule, 0);
(rule being already defined properly)

I get no error message to the terminal AND the function proceeds as normal.

Gnucash Version 1.9.0

                1 conflict needs to be resolved.

5 parameter values for this "Account" object.

The full code snippet in this case is:
	user_reports = rule->mergeParam;
		qof_book_mergeUpdateResult(NULL, 0);
	if(remainder == 1) {
		printf("\n\t\t%i conflict needs to be resolved.\n", remainder);
	}
	else {
		printf("\n\t\t%i conflicits need to be resolved.\n", remainder);
	}

It's adapted from the example-gncBookMerge.c program at:
http://www.codehelp.co.uk/code/gnucash.html

If I force a return using
	g_return_if_fail(rule == NULL);
it just seg faults.

The code runs normally unless a deliberate error is passed.

> I don't THINK you need anything special to get it to print a
> warning...  But honestly I'm not 100% sure.

Is this related?
warning: implicit declaration of function `g_return_if_reached'

During testing, I tried to see if this function would illustrate the problem 
more easily, seeing as I could put it at the end of the function, making a 
seg fault easier to pinpoint.

Have I got an incomplete installation? Where do I start looking?

I've got Debian unstable up to date - must be missing something that autogen 
didn't warn about? I've been building from CVS HEAD fine - and some existing 
GnuCash routines (like the gnc-module loader) DO report critical errors to 
the terminal.

e.g. the test-book-merge.c file above uses two alternatives to launch, 
depending on which is commented out at compile time. Set this way:
//    gnc_module_load("gnucash/engine", 0);
	gnc_engine_init(argc, argv);
I run it directly.
Switch the comment and it runs from make check.
Once compiled for make check, running it directly DOES generate the expected 
error messages.

Would anyone be able to check if qof_book_merge.h, qof_book_merge.c, 
test-book-merge.c and example-gncBookMerge.c compile and make in their CVS 
tree, please? All files available from:
http://www.codehelp.co.uk/code/source.html
except example-gncBookMerge.c which is printed out in full at:
http://www.codehelp.co.uk/code/gnucash.html

If you put:
		qof_book_mergeUpdateResult(NULL, 0);
into test_gnc_rule_loop in the example-gncBookMerge.c file, near the top of 
the function, and execute, does anyone get the warning?

The final zero should cause a warning, let alone the NULL (because of another 
g_return_if_fail that checks the value of the guint as more than zero or 
fail.

Even if I use:
rule = NULL; qof_book_mergeUpdateResult(rule, 0);
I only get (the predictable) seg fault because later functions go ahead and 
try to access the memory that WAS accessible via the rule pointer, before I 
nulled it. g_return_* seem to be completely empty.

I was hoping to put these together as a patch soon - if my system is 
incomplete I'm going to be really miffed.
:-(
It would mean that I'd have to retest almost every stage and make sure that a 
return, if invoked, does what it should.

Anyways, please feel free to play with the qof_book_merge code and let me know 
how the test program and example program look to you all. I've got a few 
other wrinkles to iron out but the framework for the merge is complete and 
operational.

It shouldn't be long before you can merge any QofBook with any other - 
including all QOF objects, business, budget, the lot. (Although I do have an 
issue with KVP at the moment, it's nearly done.)

-- 

Neil Williams
=============
http://www.codehelp.co.uk/
http://www.dclug.org.uk/
http://www.isbn.org.uk/
http://sourceforge.net/projects/isbnsearch/

http://www.biglumber.com/x/web?qs=0x8801094A28BCB3E3
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: signature
Url : http://lists.gnucash.org/pipermail/gnucash-devel/attachments/20040811/9e03adfb/attachment.bin


More information about the gnucash-devel mailing list