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 b882f9b23..04935ab39 100644
--- a/libX11/src/XlibInt.c
+++ b/libX11/src/XlibInt.c
@@ -43,11 +43,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>
@@ -100,12 +102,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
@@ -136,11 +138,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
@@ -215,7 +213,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.
*/
@@ -276,7 +274,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 ||
@@ -298,7 +296,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);
@@ -328,7 +326,7 @@ _XWaitForWritable(
#endif
)
len = SIZEOF(xReply);
-
+
/* but we won't read more than the max buffer size */
if (len > BUFSIZE) len = BUFSIZE;
@@ -461,7 +459,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;
@@ -510,7 +508,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
@@ -589,28 +587,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(
@@ -649,7 +661,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)
@@ -707,7 +719,7 @@ static void _XFlushInt(
#endif
#ifdef ESZTEST
} else if (ESZTEST()) {
- if (todo > 1)
+ if (todo > 1)
todo >>= 1;
else {
_XWaitForWritable(dpy
@@ -832,7 +844,7 @@ _XEventsQueued(
if (!pend)
pend = SIZEOF(xReply);
}
- else if (result < 0 && !ECHECK(EINTR))
+ else if (result < 0 && !(ECHECK(EINTR) || ETEST()))
_XIOError(dpy);
}
}
@@ -860,7 +872,7 @@ _XEventsQueued(
#endif /* XTHREADS*/
{
read_buf = buf.buf;
-
+
if (len < SIZEOF(xReply)
#ifdef XTHREADS
|| dpy->async_handlers
@@ -876,7 +888,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) {
@@ -1067,12 +1079,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);
}
@@ -1082,7 +1104,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.
*/
@@ -1176,7 +1198,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,
@@ -1304,7 +1326,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.
@@ -1347,7 +1369,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))
@@ -1447,7 +1469,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;
@@ -1469,7 +1491,7 @@ _XSend (
#endif
#ifdef ESZTEST
} else if (ESZTEST()) {
- if (todo > 1)
+ if (todo > 1)
todo >>= 1;
else {
_XWaitForWritable(dpy
@@ -1522,34 +1544,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;
}
@@ -1563,11 +1586,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) {
@@ -1623,11 +1642,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;
}
}
@@ -1668,9 +1683,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;
}
@@ -1760,9 +1775,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);
@@ -1787,9 +1802,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)),
@@ -1832,12 +1847,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) {
@@ -1860,7 +1875,7 @@ _XReply (
break;
}
}
-}
+}
static char *
_XAsyncReply(
@@ -1883,7 +1898,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)))
@@ -1892,7 +1907,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
@@ -2189,7 +2204,7 @@ XAddConnectionWatch(
* Unregister a callback registered by XAddConnectionWatch.
* Both callback and client_data must match what was passed to
* XAddConnectionWatch.
- */
+ */
void
XRemoveConnectionWatch(
Display* dpy,
@@ -2265,7 +2280,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);
@@ -2277,7 +2292,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 {
@@ -2321,7 +2336,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
@@ -2336,7 +2351,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
@@ -2357,7 +2372,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. */
@@ -2426,7 +2441,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;
@@ -2664,14 +2679,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:
@@ -2717,7 +2732,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(
@@ -2728,7 +2743,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()),
@@ -2736,7 +2751,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));
@@ -2761,7 +2776,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) {
@@ -2794,7 +2809,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]) {
@@ -2805,7 +2820,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);
@@ -2845,7 +2860,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);
@@ -2868,10 +2883,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;
}
@@ -2883,7 +2895,7 @@ int _XError (
Display *dpy,
register xError *rep)
{
- /*
+ /*
* X_Error packet encountered! We need to unpack the error before
* giving it to the user.
*/
@@ -2926,7 +2938,7 @@ int _XError (
return _XDefaultError(dpy, (XErrorEvent *)&event);
}
}
-
+
/*
* _XIOError - call user connection error handler and exit
*/
@@ -3102,7 +3114,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.
*/
@@ -3203,7 +3215,7 @@ static doData32(
void _XData32(
Display *dpy,
long *data,
- unsigned len,
+ unsigned len)
{
char packbuffer[PACKBUFFERSIZE];
unsigned nunits = PACKBUFFERSIZE >> 2;
@@ -3225,7 +3237,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
@@ -3267,9 +3279,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;
@@ -3278,7 +3288,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)) {
@@ -3353,7 +3363,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) {