return from custom X error handler - Xwindows

This is a discussion on return from custom X error handler - Xwindows ; Can someone tell me what the phrase "Because this condition is not assumed to be fatal, it is acceptable for your error handler to return; the returned value is ignored." means? It' contained in "Xlib − C Language X Interface ...

+ Reply to Thread
Results 1 to 6 of 6

Thread: return from custom X error handler

  1. return from custom X error handler

    Can someone tell me what the phrase
    "Because this condition is not
    assumed to be fatal, it is acceptable for your error handler to
    return; the returned value is ignored."
    means?

    It' contained in
    "Xlib − C Language X Interface
    X Consortium Standard
    X Version 11, Release 6.4" in paragraph
    "11.8.2. Using the Default Error Handlers"

    int myCustomXErrorHandler(Display *, XErrorEvent *)
    {
    ....
    ....
    return 0;
    }

    Have I got to place the "return" statement explicitly in my cistom x
    errror handler like in the previous example?

    If I don't place a "return 0;" statement at the end of my custom x
    error handler, what does it happen? It seems that the connection with
    the x server is shut down; am I right?

    Thank you

    Luca

  2. Re: return from custom X error handler



    Luca wrote:
    >
    > Can someone tell me what the phrase
    > "Because this condition is not
    > assumed to be fatal, it is acceptable for your error handler to
    > return; the returned value is ignored."
    > means?
    >
    > It' contained in
    > "Xlib − C Language X Interface
    > X Consortium Standard
    > X Version 11, Release 6.4" in paragraph
    > "11.8.2. Using the Default Error Handlers"
    >
    > int myCustomXErrorHandler(Display *, XErrorEvent *)
    > {
    > ....
    > ....
    > return 0;
    > }
    >
    > Have I got to place the "return" statement explicitly in my cistom x
    > errror handler like in the previous example?
    >
    > If I don't place a "return 0;" statement at the end of my custom x
    > error handler, what does it happen? It seems that the connection with
    > the x server is shut down; am I right?
    >
    > Thank you
    >
    > Luca


    No.

    The error handler is just another C function. Its return type is 'int".
    So it always returns an int. If you fail to include a return statement,
    your compiler should complain - probably a warning for most compilers,
    fatal for some. If only a warning, the behavior is undefined (most
    compilers probably will return zero.

    The recommended action is for your custom error handler to call exit()
    (after invoking any other actions needed to "clean up" such things as
    open database transactions) instead of returning.

    --
    Fred L. Kleinschmidt
    Boeing Associate Technical Fellow
    Technical Architect, Common User Interface Services
    M/S 2R-94 (206)544-5225

  3. Re: return from custom X error handler

    Luca wrote:
    >Can someone tell me what the phrase
    >"Because this condition is not
    >assumed to be fatal, it is acceptable for your error handler to
    >return; the returned value is ignored."
    >means?


    It means that the return value is ignored, so you can return
    anything you like and it doesn't matter.

    >It' contained in
    >"Xlib − C Language X Interface
    >X Consortium Standard
    >X Version 11, Release 6.4" in paragraph
    >"11.8.2. Using the Default Error Handlers"
    >
    >int myCustomXErrorHandler(Display *, XErrorEvent *)
    >{
    > ....
    > ....
    > return 0;
    >}
    >
    >Have I got to place the "return" statement explicitly in my cistom x
    >errror handler like in the previous example?


    No.

    >If I don't place a "return 0;" statement at the end of my custom x
    >error handler, what does it happen? It seems that the connection with
    >the x server is shut down; am I right?


    No, the connection will never be severed. You can even omit the
    return statement, although doing so might generate a compiler
    diagnostic.

    >Thank you
    >
    >Luca




  4. Re: return from custom X error handler

    Fred L. Kleinschmidt wrote:
    > The error handler is just another C function. Its return type is 'int".
    > So it always returns an int. If you fail to include a return statement,
    > your compiler should complain - probably a warning for most compilers,
    > fatal for some. If only a warning, the behavior is undefined (most
    > compilers probably will return zero.


    I once had the pleasure (?) of making fixes to some code that relied
    on the compiler returning the last-declared local variable.

    --
    Thomas E. Dickey
    http://invisible-island.net
    ftp://invisible-island.net

  5. Re: return from custom X error handler

    kbr@pangea.ca (Kip Rugger) wrote in message news:...
    > Luca wrote:
    > >Can someone tell me what the phrase
    > >"Because this condition is not
    > >assumed to be fatal, it is acceptable for your error handler to
    > >return; the returned value is ignored."
    > >means?

    >
    > It means that the return value is ignored, so you can return
    > anything you like and it doesn't matter.
    >
    > >It' contained in
    > >"Xlib − C Language X Interface
    > >X Consortium Standard
    > >X Version 11, Release 6.4" in paragraph
    > >"11.8.2. Using the Default Error Handlers"
    > >
    > >int myCustomXErrorHandler(Display *, XErrorEvent *)
    > >{
    > > ....
    > > ....
    > > return 0;
    > >}
    > >
    > >Have I got to place the "return" statement explicitly in my cistom x
    > >errror handler like in the previous example?

    >
    > No.
    >
    > >If I don't place a "return 0;" statement at the end of my custom x
    > >error handler, what does it happen? It seems that the connection with
    > >the x server is shut down; am I right?

    >
    > No, the connection will never be severed. You can even omit the
    > return statement, although doing so might generate a compiler
    > diagnostic.
    >
    > >Thank you
    > >
    > >Luca



    In that case, there is something that I don't understand, because in
    my custom error handler I don't issue an exit statement (so the
    application and the connection with the X server should continue to
    run) but when I receive the X error event (in the last case it was a
    BadIDChoice error) the connection with the X server is shut down
    because the screen turns back to the X over a grey screen. Maybe along
    with the protocol error message there is a fatal I/O condition that I
    should catch with XSetIOErrorHandler. With fatal I/O errors, is there
    a way to get some more detailed information about what caused the
    crash?

    Thank you,

    Luca

  6. Re: return from custom X error handler

    Luca wrote:
    >In that case, there is something that I don't understand, because in
    >my custom error handler I don't issue an exit statement (so the
    >application and the connection with the X server should continue to
    >run) but when I receive the X error event (in the last case it was a
    >BadIDChoice error) the connection with the X server is shut down
    >because the screen turns back to the X over a grey screen. Maybe along
    >with the protocol error message there is a fatal I/O condition that I
    >should catch with XSetIOErrorHandler. With fatal I/O errors, is there
    >a way to get some more detailed information about what caused the
    >crash?
    >
    >Thank you,
    >
    >Luca


    I can state fairly that I hate debuggers and seldom use them: the
    design of languages like C/C++ makes them virtually useless because it
    is often impossible to garner useful information from their use, given
    a reasonable expenditure of human effort.

    There is always an exception, and in this case the exception is that a
    debugger can usually provide a stack trace at the entry to 'exit';
    furthermore, that this information is almost always required to
    diagnose an error issued by Xlib.

    [~/X/tests/jpeg] $ gdb testjpeg
    (gdb) b exit
    Breakpoint 1 at 0x8048984
    (gdb) run
    Starting program: /home/rugger/X/tests/jpeg/testjpeg
    Breakpoint 1 at 0x40148085
    X connection to :0.0 broken (explicit kill or server shutdown).

    Breakpoint 1, 0x40148085 in exit () from /lib/libc.so.6
    (gdb) bt
    #0 0x40148085 in exit () from /lib/libc.so.6
    #1 0x400a32a7 in _XDefaultIOError () from /usr/X11R6/lib/libX11.so.6
    #2 0x400a3c30 in _XIOError () from /usr/X11R6/lib/libX11.so.6
    #3 0x400a14c4 in _XRead () from /usr/X11R6/lib/libX11.so.6
    #4 0x400a0ec0 in _XEventsQueued () from /usr/X11R6/lib/libX11.so.6
    #5 0x4009537a in XEventsQueued () from /usr/X11R6/lib/libX11.so.6
    #6 0x4004509e in FindInputs () from /usr/X11R6/lib/libXt.so.6
    #7 0x40045636 in _XtWaitForSomething () from /usr/X11R6/lib/libXt.so.6
    #8 0x400464cd in XtAppNextEvent () from /usr/X11R6/lib/libXt.so.6
    #9 0x4003baac in XtAppMainLoop () from /usr/X11R6/lib/libXt.so.6
    #10 0x08048d92 in main (argc=1, argv=0xbffff6b4) at testjpeg.c:101
    #11 0x401347ce in __libc_start_main () from /lib/libc.so.6
    (gdb)


+ Reply to Thread