public inbox for gsl-discuss@sourceware.org
 help / color / mirror / Atom feed
From: Brian Gough <bjg@gnu.org>
To: "Field G. Van Zee" <field@cs.utexas.edu>
Cc: gsl-discuss mailing list <gsl-discuss@sourceware.org>,
	Rhys Ulerich <rhys.ulerich@gmail.com>,
	jungman@lanl.gov
Subject: Re: Feedback from GSL folks on libflame 4.0
Date: Fri, 19 Feb 2010 20:07:00 -0000	[thread overview]
Message-ID: <87wry9ovy6.wl%bjg@network-theory.co.uk> (raw)
In-Reply-To: <4B7D90B5.4020707@cs.utexas.edu>

> It seemed like a better idea to just get our attention so we could
> fix the problem. We agree that using return values would be a more
> standard way of handling errors, but we're also somewhat cynical in
> that we don't trust our users to check return values.

The approach in GSL is to have an abort() by default, for the same
reason.  But the user can turn off the abort() and use the error
return values instead by providing an alternative error handler as a
function pointer.  Here's how it would look with your functions:

=== FLA_macro_defs.h ===

// Error code translation and output macro definition.
#define FLA_Check_error_code( code ) \
  do { \
       if (code != FLA_SUCCESS) {  \
         FLA_Check_error_code_helper( code, __FILE__, __LINE__ ); \
         return code; \    /* see comment below about void functions */
       } \
  } while (0)


=== FLA_main_prototypes.h ===

typedef void FLA_error_handler_t (int code, const char * file, int line);


=== FLA_Check.c ===

static FLA_error_handler_t * FLA_error_handler = NULL;

void FLA_Check_error_code_helper( int code, char* file, int line )
{
  if ( code == FLA_SUCCESS )
    return;

  if (FLA_error_handler) 
    {
      (*FLA_error_handler) (code, file, line);
      return ;
    }

  if ( FLA_ERROR_CODE_MAX <= code && code <= FLA_ERROR_CODE_MIN )
  {
    FLA_Print_message( FLA_Error_string_for_code( code ),
                       file, line );
    FLA_Abort();
  }
  else
  {
    FLA_Print_message( FLA_Error_string_for_code( FLA_UNDEFINED_ERROR_CODE ),
                       file, line );
    FLA_Abort();
  }
}


(We actually have three macro GSL_ERROR, GSL_ERROR_VOID and
GSL_ERROR_VAL to handle different types of return value - error code,
void, and "other".  This is to avoid warnings about "returning a value
from a void function" etc).

  parent reply	other threads:[~2010-02-19 20:07 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <4a00655d1002171047t4e87fb85w88b609245e3f9a8e@mail.gmail.com>
2010-02-19  8:48 ` Field G. Van Zee
2010-02-18 19:51   ` Rhys Ulerich
2010-02-19  0:20     ` Gerard Jungman
2010-02-19 20:22     ` Brian Gough
2010-02-19  0:00   ` Gerard Jungman
2010-02-20  4:30     ` Field G. Van Zee
2010-02-23 13:13       ` Brian Gough
2010-02-24  1:42       ` Gerard Jungman
2010-02-19 18:19   ` Brian Gough
2010-02-19 18:41     ` Robert G. Brown
2010-02-19 20:57       ` Gerard Jungman
2010-02-19 21:46         ` Robert G. Brown
2010-02-19 22:34           ` Gerard Jungman
2010-02-22 23:09         ` Brian Gough
2010-02-23 10:50           ` Theodore Papadopoulo
2010-02-23 14:55             ` Robert G. Brown
2010-02-24  1:50               ` Gerard Jungman
2010-02-24 11:31                 ` Robert G. Brown
2010-02-23 17:39           ` James Amundson
2010-02-19 20:07   ` Brian Gough [this message]
2010-02-19 20:54     ` Gerard Jungman
2010-02-20  4:31     ` Field G. Van Zee

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87wry9ovy6.wl%bjg@network-theory.co.uk \
    --to=bjg@gnu.org \
    --cc=field@cs.utexas.edu \
    --cc=gsl-discuss@sourceware.org \
    --cc=jungman@lanl.gov \
    --cc=rhys.ulerich@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).