octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Common gripe for unavailable functions when library does not exist


From: John W. Eaton
Subject: Re: Common gripe for unavailable functions when library does not exist
Date: Fri, 15 Jan 2016 16:07:11 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.7.0

On 01/15/2016 02:42 PM, Rik wrote:
1/15/16

jwe,

How should we handle functions, principally dynamically linked ones, that
may not exist for a given installation of Octave?

Currently we have at least three strategies.

Strategy 1) #ifdef/code/#else/error (...)/#endif.

See dldfcn/amd.cc for example.

Strategy 2) #ifdef/code/#else/gripe/#endif.

See __glpk__.cc which uses gripe_not_supported.
See __magick_read__.cc which uses gripe_disabled_feature

Strategy 3) Declare macro that expands to error message and use that in
place of error or gripe.

See audiodevinfo.cc which has

#define NO_PORTAUDIO_MSG \
   error ("portaudio not found on your system and thus audio functionality
is not present"); \
   (void) args;  /* silence compiler warning "unused parameter" */

It seems like there should be a common response to the same situation which
says to me that a single gripe_XXX function should be made to handle all of
these cases.

I agree, using a gripe function to make the error message uniform would be good. I think gripe_disabled_feature is a better attempt than gripe_not_supported, at least for these features that rely on external >libraries and that might be disabled.

A second issue is whether we want to suppress the warning messages about
the unused variable "args" when the DEFUN_DLD macro is used and the library
is not supported.  It is annoying to see these messages.  On the other
hand, the obvious way to suppress them leads to code bloat.

#ifdef HAVE_AMD
DEFUN_DLD (amd, args, nargout,
#else
DEFUN_DLD (amd, /* args */, nargout,
#endif

Or we could have something like what Mike did with a compiler trick to
silence the warning

(void) args;

but I have to say that even with the comment I was sort of confused as to
what was going on here.

This is a case where a macro might help.  Then you could just write

  OCTAVE_UNUSED (args);

I already defined an OCTAVE_UNUSED macro (for the unused __attribute__) but that could be redefined to work this way instead.

If we do this, could we use a C++-style cast instead?

The GNU coding standards (http://www.gnu.org/prep/standards/standards.html)
suggest not going to great lengths:

"Don’t make the program ugly just to placate static analysis tools such as
lint, clang, and GCC with extra warnings options such as -Wconversion and
-Wundef. These tools can help find bugs and unclear code, but they can also
generate so many false alarms that it hurts readability to silence them
with unnecessary casts, wrappers, and other complications. For example,
please don’t insert casts to void or calls to do-nothing functions merely
to pacify a lint checker."

So is the extra #ifdef around the DEFUN_DLD worth it or not?

The warnings are kind of annoying, but I wouldn't work too hard to eliminate them. It's more important to me that Octave compiles without warnings when all of the features are available and enabled. It doesn't bother me too much if there are warnings when some features are disabled.

jwe




reply via email to

[Prev in Thread] Current Thread [Next in Thread]