[Gnucash-changes] QOF/CashUtil Sync: Engine

Derek Atkins warlord at MIT.EDU
Wed Aug 17 07:57:36 EDT 2005

More comments.  

First, QofBackend *was* originally designed to be part of the
semi-public API -- so you could have a third-party Backend

Anyways, some more comments..  When you create a public API,
you cannot assume the arguments will be valid.  In particular:

Neil Williams <codehelp at cvs.gnucash.org> writes:

> +void
> +qof_backend_run_begin(QofBackend *be, QofInstance *inst)
> +{
> +	(be->begin) (be, inst);
> +}

This function should check that be != NULL AND be->begin != NULL...

> +gboolean
> +qof_backend_begin_exists(QofBackend *be)
> +{
> +	if(be->begin) { return TRUE; }
> +	else { return FALSE; }
> +}

This function should check that be != NULL...

> +void
> +qof_backend_run_commit(QofBackend *be, QofInstance *inst)
> +{
> +	(be->commit) (be, inst);
> +}

This should check both be and be->commit...

> +gboolean
> +qof_backend_commit_exists(QofBackend *be)
> +{
> +	if(be->commit) { return TRUE; }
> +	else { return FALSE; }
> +}

and this should check be...

Yes, I know that elsewhere you call these functions only in places
where you check the value..  BUT these are part of the public API now
so you don't know who will call it!  That means you should check,
because someone else could call it incorrectly.

Rule of thumb: if it's a public function, always check your arguments.
If it's a *static* function then you can sometimes get away with not
checking them, but you should still check them anyways.


       Derek Atkins, SB '93 MIT EE, SM '95 MIT Media Laboratory
       Member, MIT Student Information Processing Board  (SIPB)
       URL: http://web.mit.edu/warlord/    PP-ASEL-IA     N1NWH
       warlord at MIT.EDU                        PGP key available

More information about the gnucash-changes mailing list