XCreateGC can generate BadAlloc, BadDrawable, BadFont, BadMatch, BadPixmap, and BadValue errors.

Michal Srb msrb at suse.com
Thu Jan 3 09:46:24 UTC 2019


On úterý 1. ledna 2019 23:05:31 CET Dennis Clarke wrote:
> Dumb question I am sure but as I see at :
> 
>    https://www.x.org/releases/X11R7.7/doc/man/man3/XCreateGC.3.xhtml
> 
> Where it says :
> 
>      XCreateGC can generate BadAlloc, BadDrawable, BadFont,
>                      BadMatch, BadPixmap, and BadValue errors.
> 
> 
> Yes but where exactly are these errors returned?  I see the
> "DIAGNOSTICS" section at the bottom of that page but where does
> one fetch the error state?
> 
> One may do :
> 
>      gc = XCreateGC(dsp, win, valuemask, &values);
>      /* note that a 32-bit system will throw a warning about
>       * cast from pointer to integer of different size with
>       * (int64_t) type used on a pointer comparison. */
>      if ((int64_t)gc < 0) { /* just taser me */
>          fprintf(stderr, "XCreateGC failed\n");
>          exit(EXIT_FAILURE); /* clumsy */
>      }
> 
> 
> However that just can't be right.
> 
> Where is the error state returned ?

Most libX11 functions are asynchronous. What you get from XCreateGC is a local 
handle. When the function finished, the request was not even sent to X server 
yet. It will be sent once XFlush/XSync is called, or when the send buffer 
fills up or when some other synchronous function causes flush.

If there is an error, libX11 will call error handler. Either the default one 
or your own:

https://tronche.com/gui/x/xlib/event-handling/protocol-errors/
XSetErrorHandler.html

The only thing you can check after calling XCreateGC is if you did not receive 
NULL. It could happen if your program run out of memory.

Michal




More information about the xorg-devel mailing list