aboutsummaryrefslogtreecommitdiff
path: root/libX11/src/XlibInt.c
diff options
context:
space:
mode:
Diffstat (limited to 'libX11/src/XlibInt.c')
-rw-r--r--libX11/src/XlibInt.c220
1 files changed, 115 insertions, 105 deletions
diff --git a/libX11/src/XlibInt.c b/libX11/src/XlibInt.c
index f90f85112..320e80800 100644
--- a/libX11/src/XlibInt.c
+++ b/libX11/src/XlibInt.c
@@ -42,11 +42,13 @@ from The Open Group.
#include <config.h>
#endif
#include "Xlibint.h"
+#include "Xprivate.h"
#include <X11/Xpoll.h>
#if !USE_XCB
#include <X11/Xtrans/Xtrans.h>
#include <X11/extensions/xcmiscstr.h>
#endif /* !USE_XCB */
+#include <assert.h>
#include <stdio.h>
#ifdef WIN32
#include <direct.h>
@@ -99,12 +101,12 @@ xthread_t (*_Xthread_self_fn)(void) = NULL;
#else /* XTHREADS else */
#if !USE_XCB
-#define UnlockNextReplyReader(d)
+#define UnlockNextReplyReader(d)
#define UnlockNextEventReader(d)
#define InternalLockDisplay(d,wskip)
#endif /* !USE_XCB */
-#endif /* XTHREADS else */
+#endif /* XTHREADS else */
/* check for both EAGAIN and EWOULDBLOCK, because some supposedly POSIX
* systems are broken and return EWOULDBLOCK when they should return EAGAIN
@@ -135,11 +137,7 @@ xthread_t (*_Xthread_self_fn)(void) = NULL;
#define ECHECK(err) (errno == err)
#define ESET(val)
#else
-#ifdef ISC
-#define ECHECK(err) ((errno == err) || ETEST())
-#else
#define ECHECK(err) (errno == err)
-#endif
#define ESET(val) errno = val
#endif
#endif
@@ -214,7 +212,7 @@ static char *_XAsyncReply(
* perform any operations (directly or indirectly) on the DISPLAY.
*
* Routines declared with a return type of 'Status' return 0 on failure,
- * and non 0 on success. Routines with no declared return type don't
+ * and non 0 on success. Routines with no declared return type don't
* return anything. Whenever possible routines that create objects return
* the object they have created.
*/
@@ -275,7 +273,7 @@ _XWaitForWritable(
XXX - what if cv is NULL and someone else comes along after
us while we are waiting?
*/
-
+
if (!dpy->lock ||
(!dpy->lock->event_awaiters &&
(!dpy->lock->reply_awaiters ||
@@ -297,7 +295,7 @@ _XWaitForWritable(
nfound = Select (dpy->fd + 1, &r_mask, &w_mask, NULL, NULL);
#endif
InternalLockDisplay(dpy, cv != NULL);
- if (nfound < 0 && !ECHECK(EINTR))
+ if (nfound < 0 && !(ECHECK(EINTR) || ETEST()))
_XIOError(dpy);
} while (nfound <= 0);
@@ -327,7 +325,7 @@ _XWaitForWritable(
#endif
)
len = SIZEOF(xReply);
-
+
/* but we won't read more than the max buffer size */
if (len > BUFSIZE) len = BUFSIZE;
@@ -460,7 +458,7 @@ _XWaitForReadable(
{
int result;
int fd = dpy->fd;
- struct _XConnectionInfo *ilist;
+ struct _XConnectionInfo *ilist;
register int saved_event_serial = 0;
int in_read_events = 0;
register Bool did_proc_conni = False;
@@ -509,7 +507,7 @@ _XWaitForReadable(
result = Select(highest_fd + 1, &r_mask, NULL, NULL, NULL);
#endif
InternalLockDisplay(dpy, dpy->flags & XlibDisplayReply);
- if (result == -1 && !ECHECK(EINTR)) _XIOError(dpy);
+ if (result == -1 && !(ECHECK(EINTR) || ETEST())) _XIOError(dpy);
if (result <= 0)
continue;
#ifdef USE_POLL
@@ -583,28 +581,42 @@ int _XSeqSyncFunction(
GetEmptyReq(GetInputFocus, req);
(void) _XReply (dpy, (xReply *)&rep, 0, xTrue);
sent_sync = 1;
- }
- /* could get XID handler while waiting for reply in MT env */
- if (dpy->synchandler == _XSeqSyncFunction && !sync_hazard(dpy)) {
- dpy->synchandler = dpy->savedsynchandler;
- dpy->flags &= ~XlibDisplayPrivSync;
- }
+ } else if (sync_hazard(dpy))
+ _XSetPrivSyncFunction(dpy);
UnlockDisplay(dpy);
if (sent_sync)
SyncHandle();
return 0;
}
-void _XSetSeqSyncFunction(
- register Display *dpy)
+static int
+_XPrivSyncFunction (Display *dpy)
+{
+ assert(dpy->synchandler == _XPrivSyncFunction);
+ assert((dpy->flags & XlibDisplayPrivSync) != 0);
+ dpy->synchandler = dpy->savedsynchandler;
+ dpy->savedsynchandler = NULL;
+ dpy->flags &= ~XlibDisplayPrivSync;
+ _XIDHandler(dpy);
+ _XSeqSyncFunction(dpy);
+ return 0;
+}
+
+void _XSetPrivSyncFunction(Display *dpy)
{
- if (!(dpy->flags & XlibDisplayPrivSync) && sync_hazard(dpy)) {
+ if (!(dpy->flags & XlibDisplayPrivSync)) {
dpy->savedsynchandler = dpy->synchandler;
- dpy->synchandler = _XSeqSyncFunction;
+ dpy->synchandler = _XPrivSyncFunction;
dpy->flags |= XlibDisplayPrivSync;
}
}
+void _XSetSeqSyncFunction(Display *dpy)
+{
+ if (sync_hazard(dpy))
+ _XSetPrivSyncFunction (dpy);
+}
+
#if !USE_XCB
#ifdef XTHREADS
static void _XFlushInt(
@@ -643,7 +655,7 @@ static void _XFlushInt(
/* This fix resets the bufptr to the front of the buffer so
* additional appends to the bufptr will not corrupt memory. Since
- * the server is down, these appends are no-op's anyway but
+ * the server is down, these appends are no-op's anyway but
* callers of _XFlush() are not verifying this before they call it.
*/
if (dpy->flags & XlibDisplayIOError)
@@ -701,7 +713,7 @@ static void _XFlushInt(
#endif
#ifdef ESZTEST
} else if (ESZTEST()) {
- if (todo > 1)
+ if (todo > 1)
todo >>= 1;
else {
_XWaitForWritable(dpy
@@ -826,7 +838,7 @@ _XEventsQueued(
if (!pend)
pend = SIZEOF(xReply);
}
- else if (result < 0 && !ECHECK(EINTR))
+ else if (result < 0 && !(ECHECK(EINTR) || ETEST()))
_XIOError(dpy);
}
}
@@ -854,7 +866,7 @@ _XEventsQueued(
#endif /* XTHREADS*/
{
read_buf = buf.buf;
-
+
if (len < SIZEOF(xReply)
#ifdef XTHREADS
|| dpy->async_handlers
@@ -870,7 +882,7 @@ _XEventsQueued(
#endif
(void) _XRead (dpy, read_buf, (long) len);
-
+
#ifdef XTHREADS
/* what did we actually read: reply or event? */
if (dpy->lock && dpy->lock->reply_awaiters) {
@@ -1061,12 +1073,22 @@ void _XReadEvents(
RESETITERPTR(rep,xReply,
_XAsyncReply (dpy, rep,
ITERPTR(rep), &len, True));
- pend = len;
+ pend = len;
} else {
if (rep->generic.type == X_Error)
_XError (dpy, (xError *) rep);
else /* must be an event packet */
- _XEnq (dpy, (xEvent *)rep);
+ {
+ if (rep->generic.type == GenericEvent)
+ {
+ int evlen;
+ evlen = (rep->generic.length << 2);
+ if (_XRead(dpy, &read_buf[len], evlen) == -2)
+ goto got_event; /* XXX: aargh! */
+ }
+
+ _XEnq (dpy, (xEvent *)rep);
+ }
INCITERPTR(rep,xReply);
len -= SIZEOF(xReply);
}
@@ -1076,7 +1098,7 @@ void _XReadEvents(
UnlockNextEventReader(dpy);
}
-/*
+/*
* _XRead - Read bytes from the socket taking into account incomplete
* reads. This routine may have to be reworked if int < long.
*/
@@ -1170,7 +1192,7 @@ void _XRead32(
/*
* _XRead32 - Read bytes from the socket unpacking each 32 bits
* into a long (64 bits on a CRAY computer).
- *
+ *
*/
static void _doXRead32(
register Display *dpy,
@@ -1298,7 +1320,7 @@ void _XReadPad(
if ((dpy->flags & XlibDisplayIOError) || size == 0) return;
iov[0].iov_len = (int)size;
iov[0].iov_base = data;
- /*
+ /*
* The following hack is used to provide 32 bit long-word
* aligned padding. The [1] vector is of length 0, 1, 2, or 3,
* whatever is needed.
@@ -1341,7 +1363,7 @@ void _XReadPad(
ESET(EPIPE);
_XIOError(dpy);
}
-
+
else /* bytes_read is less than 0; presumably -1 */ {
/* If it's a system call interrupt, it's not an error. */
if (!ECHECK(EINTR))
@@ -1441,7 +1463,7 @@ _XSend (
InsertIOV (dpy->buffer, dbufsize)
InsertIOV ((char *)data, size)
InsertIOV ((char *)pad, padsize)
-
+
ESET(0);
if ((len = _X11TransWritev(dpy->trans_conn, iov, i)) >= 0) {
skip += len;
@@ -1463,7 +1485,7 @@ _XSend (
#endif
#ifdef ESZTEST
} else if (ESZTEST()) {
- if (todo > 1)
+ if (todo > 1)
todo >>= 1;
else {
_XWaitForWritable(dpy
@@ -1516,34 +1538,35 @@ _XGetMiscCode(
}
}
-static int
+int
_XIDHandler(
register Display *dpy)
{
xXCMiscGetXIDRangeReply grep;
register xXCMiscGetXIDRangeReq *greq;
+ int sent_req = 0;
LockDisplay(dpy);
- _XGetMiscCode(dpy);
- if (dpy->xcmisc_opcode > 0) {
- GetReq(XCMiscGetXIDRange, greq);
- greq->reqType = dpy->xcmisc_opcode;
- greq->miscReqType = X_XCMiscGetXIDRange;
- if (_XReply (dpy, (xReply *)&grep, 0, xTrue) && grep.count) {
- dpy->resource_id = ((grep.start_id - dpy->resource_base) >>
- dpy->resource_shift);
- dpy->resource_max = dpy->resource_id;
- if (grep.count > 5)
- dpy->resource_max += grep.count - 6;
- dpy->resource_max <<= dpy->resource_shift;
+ if (dpy->resource_max == dpy->resource_mask + 1) {
+ _XGetMiscCode(dpy);
+ if (dpy->xcmisc_opcode > 0) {
+ GetReq(XCMiscGetXIDRange, greq);
+ greq->reqType = dpy->xcmisc_opcode;
+ greq->miscReqType = X_XCMiscGetXIDRange;
+ if (_XReply (dpy, (xReply *)&grep, 0, xTrue) && grep.count) {
+ dpy->resource_id = ((grep.start_id - dpy->resource_base) >>
+ dpy->resource_shift);
+ dpy->resource_max = dpy->resource_id;
+ if (grep.count > 5)
+ dpy->resource_max += grep.count - 6;
+ dpy->resource_max <<= dpy->resource_shift;
+ }
+ sent_req = 1;
}
}
- if (dpy->flags & XlibDisplayPrivSync) {
- dpy->synchandler = dpy->savedsynchandler;
- dpy->flags &= ~XlibDisplayPrivSync;
- }
UnlockDisplay(dpy);
- SyncHandle();
+ if (sent_req)
+ SyncHandle();
return 0;
}
@@ -1557,11 +1580,7 @@ XID _XAllocID(
id = dpy->resource_id << dpy->resource_shift;
if (id >= dpy->resource_max) {
- if (!(dpy->flags & XlibDisplayPrivSync)) {
- dpy->savedsynchandler = dpy->synchandler;
- dpy->flags |= XlibDisplayPrivSync;
- }
- dpy->synchandler = _XIDHandler;
+ _XSetPrivSyncFunction(dpy);
dpy->resource_max = dpy->resource_mask + 1;
}
if (id <= dpy->resource_mask) {
@@ -1617,11 +1636,7 @@ void _XAllocIDs(
dpy->resource_id = id;
}
if (id >= dpy->resource_max) {
- if (!(dpy->flags & XlibDisplayPrivSync)) {
- dpy->savedsynchandler = dpy->synchandler;
- dpy->flags |= XlibDisplayPrivSync;
- }
- dpy->synchandler = _XIDHandler;
+ _XSetPrivSyncFunction(dpy);
dpy->resource_max = dpy->resource_mask + 1;
}
}
@@ -1662,9 +1677,9 @@ _XSetLastRequestRead(
if (newseq < lastseq) {
newseq += 0x10000;
if (newseq > dpy->request) {
- (void) fprintf (stderr,
+ (void) fprintf (stderr,
"Xlib: sequence lost (0x%lx > 0x%lx) in reply type 0x%x!\n",
- newseq, dpy->request,
+ newseq, dpy->request,
(unsigned int) rep->type);
newseq -= 0x10000;
}
@@ -1754,9 +1769,9 @@ _XReply (
}
if (extra <= rep->generic.length) {
if (extra > 0)
- /*
+ /*
* Read the extra data into storage immediately
- * following the GenericReply structure.
+ * following the GenericReply structure.
*/
(void) _XRead (dpy, (char *) (NEXTPTR(rep,xReply)),
((long)extra) << 2);
@@ -1781,9 +1796,9 @@ _XReply (
#endif
return 1;
}
- /*
+ /*
*if we get here, then extra > rep->generic.length--meaning we
- * read a reply that's shorter than we expected. This is an
+ * read a reply that's shorter than we expected. This is an
* error, but we still need to figure out how to handle it...
*/
(void) _XRead (dpy, (char *) (NEXTPTR(rep,xReply)),
@@ -1826,12 +1841,12 @@ _XReply (
UnlockNextReplyReader(dpy);
return (0);
}
- /*
+ /*
* we better see if there is an extension who may
* want to suppress the error.
*/
for (ext = dpy->ext_procs; !ret && ext; ext = ext->next) {
- if (ext->error)
+ if (ext->error)
ret = (*ext->error)(dpy, err, &ext->codes, &ret_code);
}
if (!ret) {
@@ -1854,7 +1869,7 @@ _XReply (
break;
}
}
-}
+}
static char *
_XAsyncReply(
@@ -1877,7 +1892,7 @@ _XAsyncReply(
*lenp = 0;
return buf;
}
-
+
for (async = dpy->async_handlers; async; async = next) {
next = async->next;
if ((consumed = (*async->handler)(dpy, rep, buf, *lenp, async->data)))
@@ -1886,7 +1901,7 @@ _XAsyncReply(
if (!consumed) {
if (!discard)
return buf;
- (void) fprintf(stderr,
+ (void) fprintf(stderr,
"Xlib: unexpected async reply (sequence 0x%lx)!\n",
dpy->last_request_read);
#ifdef XTHREADS
@@ -2183,7 +2198,7 @@ XAddConnectionWatch(
* Unregister a callback registered by XAddConnectionWatch.
* Both callback and client_data must match what was passed to
* XAddConnectionWatch.
- */
+ */
void
XRemoveConnectionWatch(
Display* dpy,
@@ -2259,7 +2274,7 @@ void _XEnq(
/* If dpy->qfree is non-NULL do this, else malloc a new one. */
dpy->qfree = qelt->next;
}
- else if ((qelt =
+ else if ((qelt =
(_XQEvent *) Xmalloc((unsigned)sizeof(_XQEvent))) == NULL) {
/* Malloc call failed! */
ESET(ENOMEM);
@@ -2271,7 +2286,7 @@ void _XEnq(
qelt->qserial_num = dpy->next_event_serial_num++;
if (dpy->tail) dpy->tail->next = qelt;
else dpy->head = qelt;
-
+
dpy->tail = qelt;
dpy->qlen++;
} else {
@@ -2315,7 +2330,7 @@ _XUnknownWireEvent(
register xEvent *event) /* wire protocol event */
{
#ifdef notdef
- (void) fprintf(stderr,
+ (void) fprintf(stderr,
"Xlib: unhandled wire event! event number = %d, display = %x\n.",
event->u.u.type, dpy);
#endif
@@ -2330,7 +2345,7 @@ _XUnknownNativeEvent(
register xEvent *event) /* wire protocol event */
{
#ifdef notdef
- (void) fprintf(stderr,
+ (void) fprintf(stderr,
"Xlib: unhandled native event! event number = %d, display = %x\n.",
re->type, dpy);
#endif
@@ -2351,7 +2366,7 @@ _XWireToEvent(
(xGenericReply *)event);
((XAnyEvent *)re)->send_event = ((event->u.u.type & 0x80) != 0);
((XAnyEvent *)re)->display = dpy;
-
+
/* Ignore the leading bit of the event type since it is set when a
client sends an event rather than the server. */
@@ -2420,7 +2435,7 @@ _XWireToEvent(
ev->y_root = cvtINT16toInt(event->u.enterLeave.rootY);
ev->state = event->u.enterLeave.state;
ev->mode = event->u.enterLeave.mode;
- ev->same_screen = (event->u.enterLeave.flags &
+ ev->same_screen = (event->u.enterLeave.flags &
ELFlagSameScreen) && True;
ev->focus = (event->u.enterLeave.flags &
ELFlagFocus) && True;
@@ -2658,14 +2673,14 @@ _XWireToEvent(
case ClientMessage:
{
register int i;
- register XClientMessageEvent *ev
+ register XClientMessageEvent *ev
= (XClientMessageEvent *) re;
ev->window = event->u.clientMessage.window;
ev->format = event->u.u.detail;
switch (ev->format) {
- case 8:
+ case 8:
ev->message_type = event->u.clientMessage.u.b.type;
- for (i = 0; i < 20; i++)
+ for (i = 0; i < 20; i++)
ev->data.b[i] = event->u.clientMessage.u.b.bytes[i];
break;
case 16:
@@ -2711,7 +2726,7 @@ _XWireToEvent(
/*
- * _XDefaultIOError - Default fatal system error reporting routine. Called
+ * _XDefaultIOError - Default fatal system error reporting routine. Called
* when an X internal system error is encountered.
*/
int _XDefaultIOError(
@@ -2722,7 +2737,7 @@ int _XDefaultIOError(
"X connection to %s broken (explicit kill or server shutdown).\r\n",
DisplayString (dpy));
} else {
- (void) fprintf (stderr,
+ (void) fprintf (stderr,
"XIO: fatal IO error %d (%s) on X server \"%s\"\r\n",
#ifdef WIN32
WSAGetLastError(), strerror(WSAGetLastError()),
@@ -2730,7 +2745,7 @@ int _XDefaultIOError(
errno, strerror (errno),
#endif
DisplayString (dpy));
- (void) fprintf (stderr,
+ (void) fprintf (stderr,
" after %lu requests (%lu known processed) with %d events remaining.\r\n",
NextRequest(dpy) - 1, LastKnownRequestProcessed(dpy),
QLength(dpy));
@@ -2755,7 +2770,7 @@ static int _XPrintDefaultError(
XGetErrorText(dpy, event->error_code, buffer, BUFSIZ);
XGetErrorDatabaseText(dpy, mtype, "XError", "X Error", mesg, BUFSIZ);
(void) fprintf(fp, "%s: %s\n ", mesg, buffer);
- XGetErrorDatabaseText(dpy, mtype, "MajorCode", "Request Major code %d",
+ XGetErrorDatabaseText(dpy, mtype, "MajorCode", "Request Major code %d",
mesg, BUFSIZ);
(void) fprintf(fp, mesg, event->request_code);
if (event->request_code < 128) {
@@ -2788,7 +2803,7 @@ static int _XPrintDefaultError(
/* kludge, try to find the extension that caused it */
buffer[0] = '\0';
for (ext = dpy->ext_procs; ext; ext = ext->next) {
- if (ext->error_string)
+ if (ext->error_string)
(*ext->error_string)(dpy, event->error_code, &ext->codes,
buffer, BUFSIZ);
if (buffer[0]) {
@@ -2799,7 +2814,7 @@ static int _XPrintDefaultError(
ext->codes.first_error < (int)event->error_code &&
(!bext || ext->codes.first_error > bext->codes.first_error))
bext = ext;
- }
+ }
if (bext)
sprintf(buffer, "%s.%d", bext->name,
event->error_code - bext->codes.first_error);
@@ -2839,7 +2854,7 @@ static int _XPrintDefaultError(
(void) fprintf(fp, mesg, event->resourceid);
fputs("\n", fp);
}
- XGetErrorDatabaseText(dpy, mtype, "ErrorSerial", "Error Serial #%d",
+ XGetErrorDatabaseText(dpy, mtype, "ErrorSerial", "Error Serial #%d",
mesg, BUFSIZ);
fputs(" ", fp);
(void) fprintf(fp, mesg, event->serial);
@@ -2862,10 +2877,7 @@ int _XDefaultError(
}
/*ARGSUSED*/
-Bool _XDefaultWireError(display, he, we)
- Display *display;
- XErrorEvent *he;
- xError *we;
+Bool _XDefaultWireError(Display *display, XErrorEvent *he, xError *we)
{
return True;
}
@@ -2877,7 +2889,7 @@ int _XError (
Display *dpy,
register xError *rep)
{
- /*
+ /*
* X_Error packet encountered! We need to unpack the error before
* giving it to the user.
*/
@@ -2920,7 +2932,7 @@ int _XError (
return _XDefaultError(dpy, (XErrorEvent *)&event);
}
}
-
+
/*
* _XIOError - call user connection error handler and exit
*/
@@ -3096,7 +3108,7 @@ _XData32(
#ifdef WORD64
/*
- * XXX This is a *really* stupid way of doing this. It should just use
+ * XXX This is a *really* stupid way of doing this. It should just use
* dpy->bufptr directly, taking into account where in the word it is.
*/
@@ -3197,7 +3209,7 @@ static doData32(
void _XData32(
Display *dpy,
long *data,
- unsigned len,
+ unsigned len)
{
char packbuffer[PACKBUFFERSIZE];
unsigned nunits = PACKBUFFERSIZE >> 2;
@@ -3219,7 +3231,7 @@ void _XData32(
* and so, you may be better off using gethostname (if it exists).
*/
-#if (defined(_POSIX_SOURCE) && !defined(AIXV3) && !defined(__QNX__)) || defined(hpux) || defined(USG) || defined(SVR4)
+#if (defined(_POSIX_SOURCE) && !defined(AIXV3) && !defined(__QNX__)) || defined(hpux) || defined(SVR4)
#define NEED_UTSNAME
#include <sys/utsname.h>
#endif
@@ -3261,9 +3273,7 @@ int _XGetHostname (
* _XScreenOfWindow - get the Screen of a given window
*/
-Screen *_XScreenOfWindow (dpy, w)
- Display *dpy;
- Window w;
+Screen *_XScreenOfWindow(Display *dpy, Window w)
{
register int i;
Window root;
@@ -3272,7 +3282,7 @@ Screen *_XScreenOfWindow (dpy, w)
if (XGetGeometry (dpy, w, &root, &x, &y, &width, &height,
&bw, &depth) == False) {
- return None;
+ return NULL;
}
for (i = 0; i < ScreenCount (dpy); i++) { /* find root from list */
if (root == RootWindow (dpy, i)) {
@@ -3347,7 +3357,7 @@ static int AccessFile (path, pathbuf, len_pathbuf, pathret)
return 1;
}
-#ifndef __UNIXOS2__
+#ifndef __UNIXOS2__
/* one last place to look */
drive = getenv ("HOMEDRIVE");
if (drive) {