Re: assert.h problems with shared libraries

From: Henning Meier-Geinitz (
Date: Fri Jun 01 2001 - 09:42:46 PDT

  • Next message: Tim Waugh: "Re: [parport] Use of inb/out in backends..."


    On Thu, May 31, 2001 at 10:57:08PM +0100, Nick Lamb wrote:
    > On Thu, May 31, 2001 at 11:39:01PM +0200, Oliver Rauch wrote:
    > > An assert is an emergency stop. I think that most asserts can
    > > be removed without any problems (if not we would have several
    > > known problems).
    > >
    > > I think we should do this:
    > > 1) remove assert() where it is not necessary
    > > 2) replace an assert(a<b) by
    > > if (a<b) {DBG(0, "error..."); + exit or return with error code}
    > So the solution is not to check for error conditions in SANE?

    One possible solution is one line above your question.

    > Poor solution. Let's try to understand what's wrong on AIX and fix it.

    I'm not sure if it's only on AIX. Search with google reveals similar
    problems on other platforms. And I'm also not sure if it happens on
    all versions of AIX with all versions of GCC.

    The problem is: gcc uses an internal header assert.h. assert() is a
    macro that calls __eprintf. __eprintf is in libgcc.a and linked to the
    static binary. In shared case this doesn't seem to work. So a solution
    would be to check if __eprintf is unresolved and disable assert.h in
    this case or use a local implementation. But I don't know an easy way
    to to this.

    Another (more simple) way would be to write a header file "lassert.h"
    and use something like:

    #include <stdio.h>
    #include <stdlib.h>
    #define assert(arg) if (!(arg)) {fprintf(stderr, "error..."; abort();}

    I don't know however, if it's possible to include file names/line
    numbers in the output.

    Another solution would be to implement __eprintf and link to it if
    neccessary. But this looks more complicated because it's only
    necessary for shared libs.


    Source code, list archive, and docs:
    To unsubscribe: echo unsubscribe sane-devel | mail

    This archive was generated by hypermail 2b29 : Fri Jun 01 2001 - 09:42:55 PDT