diff options
-rw-r--r-- | libX11/src/OpenDis.c | 20 | ||||
-rw-r--r-- | libX11/src/Xxcbint.h | 2 | ||||
-rw-r--r-- | libX11/src/xcb_disp.c | 18 | ||||
-rw-r--r-- | libxcb/src/xcb_in.c | 1476 | ||||
-rw-r--r-- | pixman/configure.ac | 2 | ||||
-rw-r--r-- | pixman/pixman/pixman-region.c | 42 | ||||
-rw-r--r-- | pixman/pixman/pixman-region16.c | 130 | ||||
-rw-r--r-- | pixman/pixman/pixman-region32.c | 90 | ||||
-rw-r--r-- | pixman/pixman/pixman.c | 17 | ||||
-rw-r--r-- | pixman/test/Makefile.am | 2 | ||||
-rw-r--r-- | pixman/test/region-translate-test.c | 30 |
11 files changed, 929 insertions, 900 deletions
diff --git a/libX11/src/OpenDis.c b/libX11/src/OpenDis.c index b1992a9a2..e5336a847 100644 --- a/libX11/src/OpenDis.c +++ b/libX11/src/OpenDis.c @@ -70,7 +70,6 @@ XOpenDisplay ( int j, k; /* random iterator indexes */
char *display_name; /* pointer to display name */
char *setup = NULL; /* memory allocated at startup */
- char *fullname = NULL; /* expanded name of display */
int iscreen; /* screen number */
xConnSetupPrefix prefix; /* prefix information */
int vendorlen; /* length of vendor string */
@@ -118,13 +117,17 @@ XOpenDisplay ( return(NULL);
}
+ if ((dpy->display_name = strdup(display_name)) == NULL) {
+ OutOfMemory(dpy);
+ return(NULL);
+ }
+
/*
* Call the Connect routine to get the transport connection object.
- * If NULL is returned, the connection failed. The connect routine
- * will set fullname to point to the expanded name.
+ * If NULL is returned, the connection failed.
*/
- if(!_XConnectXCB(dpy, display, &fullname, &iscreen)) {
+ if(!_XConnectXCB(dpy, display, &iscreen)) {
/* Try falling back on other transports if no transport specified */
const char *slash = strrchr(display_name, '/');
if(slash == NULL) {
@@ -136,14 +139,13 @@ XOpenDisplay ( if(buf) {
for(s = protocols; buf && *s; s++) {
snprintf(buf, buf_size, "%s/%s", *s, display_name);
- if(_XConnectXCB(dpy, buf, &fullname, &iscreen))
+ if(_XConnectXCB(dpy, buf, &iscreen))
goto fallback_success;
}
Xfree(buf);
}
}
- dpy->display_name = fullname;
OutOfMemory(dpy);
return NULL;
}
@@ -153,7 +155,6 @@ fallback_success: * Initialize pointers to NULL so that XFreeDisplayStructure will
* work if we run out of memory before we finish initializing.
*/
- dpy->display_name = fullname;
dpy->keysyms = (KeySym *) NULL;
dpy->modifiermap = NULL;
dpy->lock_meaning = NoSymbol;
@@ -315,7 +316,7 @@ fallback_success: if (!mask)
{
fprintf (stderr, "Xlib: connection to \"%s\" invalid setup\n",
- fullname);
+ dpy->display_name);
OutOfMemory(dpy);
return (NULL);
}
@@ -679,8 +680,7 @@ void _XFreeDisplayStructure(Display *dpy) Xfree ((char *)dpy->pixmap_format);
}
- if (dpy->display_name)
- Xfree (dpy->display_name);
+ free(dpy->display_name);
if (dpy->vendor)
Xfree (dpy->vendor);
diff --git a/libX11/src/Xxcbint.h b/libX11/src/Xxcbint.h index 06636ce86..15423c407 100644 --- a/libX11/src/Xxcbint.h +++ b/libX11/src/Xxcbint.h @@ -40,7 +40,7 @@ typedef struct _X11XCBPrivate { /* xcb_disp.c */
-int _XConnectXCB(Display *dpy, _Xconst char *display, char **fullnamep, int *screenp);
+int _XConnectXCB(Display *dpy, _Xconst char *display, int *screenp);
void _XFreeX11XCBStructure(Display *dpy);
#endif /* XXCBINT_H */
diff --git a/libX11/src/xcb_disp.c b/libX11/src/xcb_disp.c index 2def9b014..60d186a5e 100644 --- a/libX11/src/xcb_disp.c +++ b/libX11/src/xcb_disp.c @@ -54,11 +54,10 @@ void XSetAuthorization(char *name, int namelen, char *data, int datalen) _XUnlockMutex(_Xglobal_lock);
}
-int _XConnectXCB(Display *dpy, _Xconst char *display, char **fullnamep, int *screenp)
+int _XConnectXCB(Display *dpy, _Xconst char *display, int *screenp)
{
char *host;
int n = 0;
- int len;
xcb_connection_t *c;
dpy->fd = -1;
@@ -69,20 +68,7 @@ int _XConnectXCB(Display *dpy, _Xconst char *display, char **fullnamep, int *scr if(!xcb_parse_display(display, &host, &n, screenp))
return 0;
-
- len = strlen(host) + (1 + 20 + 1 + 20 + 1);
- *fullnamep = Xmalloc(len);
- if (!*fullnamep) {
- free(host);
- return 0;
- }
-
-#ifdef HAVE_LAUNCHD
- if(strncmp(host, "/tmp/launch", 11) == 0)
- snprintf(*fullnamep, len, "%s:%d", host, n);
- else
-#endif
- snprintf(*fullnamep, len, "%s:%d.%d", host, n, *screenp);
+ /* host and n are unused, but xcb_parse_display requires them */
free(host);
_XLockMutex(_Xglobal_lock);
diff --git a/libxcb/src/xcb_in.c b/libxcb/src/xcb_in.c index b186a6e4a..aaec5c8b4 100644 --- a/libxcb/src/xcb_in.c +++ b/libxcb/src/xcb_in.c @@ -1,738 +1,738 @@ -/* Copyright (C) 2001-2004 Bart Massey and Jamey Sharp. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * Except as contained in this notice, the names of the authors or their - * institutions shall not be used in advertising or otherwise to promote the - * sale, use or other dealings in this Software without prior written - * authorization from the authors. - */ - -/* Stuff that reads stuff from the server. */ - -#include <assert.h> -#include <string.h> -#include <stdlib.h> -#include <unistd.h> -#include <stdio.h> -#ifdef _MSC_VER -#include <X11/Xwinsock.h> -#endif -#include <errno.h> - -#include "xcb.h" -#include "xcbext.h" -#include "xcbint.h" -#if USE_POLL -#include <poll.h> -#else -#include <sys/select.h> -#endif - -#define XCB_ERROR 0 -#define XCB_REPLY 1 -#define XCB_XGE_EVENT 35 - -struct event_list { - xcb_generic_event_t *event; - struct event_list *next; -}; - -struct reply_list { - void *reply; - struct reply_list *next; -}; - -typedef struct pending_reply { - uint64_t first_request; - uint64_t last_request; - enum workarounds workaround; - int flags; - struct pending_reply *next; -} pending_reply; - -typedef struct reader_list { - unsigned int request; - pthread_cond_t *data; - struct reader_list *next; -} reader_list; - -static int read_packet(xcb_connection_t *c) -{ - xcb_generic_reply_t genrep; - int length = 32; - int eventlength = 0; /* length after first 32 bytes for GenericEvents */ - void *buf; - pending_reply *pend = 0; - struct event_list *event; - - /* Wait for there to be enough data for us to read a whole packet */ - if(c->in.queue_len < length) - return 0; - - /* Get the response type, length, and sequence number. */ - memcpy(&genrep, c->in.queue, sizeof(genrep)); - - /* Compute 32-bit sequence number of this packet. */ - if((genrep.response_type & 0x7f) != XCB_KEYMAP_NOTIFY) - { - uint64_t lastread = c->in.request_read; - c->in.request_read = (lastread & UINT64_C(0xffffffffffff0000)) | genrep.sequence; - if(XCB_SEQUENCE_COMPARE(c->in.request_read, <, lastread)) - c->in.request_read += 0x10000; - if(XCB_SEQUENCE_COMPARE(c->in.request_read, >, c->in.request_expected)) - c->in.request_expected = c->in.request_read; - - if(c->in.request_read != lastread) - { - if(c->in.current_reply) - { - _xcb_map_put(c->in.replies, lastread, c->in.current_reply); - c->in.current_reply = 0; - c->in.current_reply_tail = &c->in.current_reply; - } - c->in.request_completed = c->in.request_read - 1; - } - - while(c->in.pending_replies && - c->in.pending_replies->workaround != WORKAROUND_EXTERNAL_SOCKET_OWNER && - XCB_SEQUENCE_COMPARE (c->in.pending_replies->last_request, <=, c->in.request_completed)) - { - pending_reply *oldpend = c->in.pending_replies; - c->in.pending_replies = oldpend->next; - if(!oldpend->next) - c->in.pending_replies_tail = &c->in.pending_replies; - free(oldpend); - } - - if(genrep.response_type == XCB_ERROR) - c->in.request_completed = c->in.request_read; - } - - if(genrep.response_type == XCB_ERROR || genrep.response_type == XCB_REPLY) - { - pend = c->in.pending_replies; - if(pend && - !(XCB_SEQUENCE_COMPARE(pend->first_request, <=, c->in.request_read) && - (pend->workaround == WORKAROUND_EXTERNAL_SOCKET_OWNER || - XCB_SEQUENCE_COMPARE(c->in.request_read, <=, pend->last_request)))) - pend = 0; - } - - /* For reply packets, check that the entire packet is available. */ - if(genrep.response_type == XCB_REPLY) - { - if(pend && pend->workaround == WORKAROUND_GLX_GET_FB_CONFIGS_BUG) - { - uint32_t *p = (uint32_t *) c->in.queue; - genrep.length = p[2] * p[3] * 2; - } - length += genrep.length * 4; - } - - /* XGE events may have sizes > 32 */ - if (genrep.response_type == XCB_XGE_EVENT) - eventlength = genrep.length * 4; - - buf = malloc(length + eventlength + - (genrep.response_type == XCB_REPLY ? 0 : sizeof(uint32_t))); - if(!buf) - { - _xcb_conn_shutdown(c); - return 0; - } - - if(_xcb_in_read_block(c, buf, length) <= 0) - { - free(buf); - return 0; - } - - /* pull in XGE event data if available, append after event struct */ - if (eventlength) - { - if(_xcb_in_read_block(c, &((xcb_generic_event_t*)buf)[1], eventlength) <= 0) - { - free(buf); - return 0; - } - } - - if(pend && (pend->flags & XCB_REQUEST_DISCARD_REPLY)) - { - free(buf); - return 1; - } - - if(genrep.response_type != XCB_REPLY) - ((xcb_generic_event_t *) buf)->full_sequence = c->in.request_read; - - /* reply, or checked error */ - if( genrep.response_type == XCB_REPLY || - (genrep.response_type == XCB_ERROR && pend && (pend->flags & XCB_REQUEST_CHECKED))) - { - reader_list *reader; - struct reply_list *cur = malloc(sizeof(struct reply_list)); - if(!cur) - { - _xcb_conn_shutdown(c); - free(buf); - return 0; - } - cur->reply = buf; - cur->next = 0; - *c->in.current_reply_tail = cur; - c->in.current_reply_tail = &cur->next; - for(reader = c->in.readers; - reader && - XCB_SEQUENCE_COMPARE_32(reader->request, <=, c->in.request_read); - reader = reader->next) - { - if(XCB_SEQUENCE_COMPARE_32(reader->request, ==, c->in.request_read)) - { - pthread_cond_signal(reader->data); - break; - } - } - return 1; - } - - /* event, or unchecked error */ - event = malloc(sizeof(struct event_list)); - if(!event) - { - _xcb_conn_shutdown(c); - free(buf); - return 0; - } - event->event = buf; - event->next = 0; - *c->in.events_tail = event; - c->in.events_tail = &event->next; - pthread_cond_signal(&c->in.event_cond); - return 1; /* I have something for you... */ -} - -static xcb_generic_event_t *get_event(xcb_connection_t *c) -{ - struct event_list *cur = c->in.events; - xcb_generic_event_t *ret; - if(!c->in.events) - return 0; - ret = cur->event; - c->in.events = cur->next; - if(!cur->next) - c->in.events_tail = &c->in.events; - free(cur); - return ret; -} - -static void free_reply_list(struct reply_list *head) -{ - while(head) - { - struct reply_list *cur = head; - head = cur->next; - free(cur->reply); - free(cur); - } -} - -static int read_block(const int fd, void *buf, const ssize_t len) -{ -#ifdef _MSC_VER - int done = 0; - while(done < len) - { - int Err; - int ret = recv(fd, ((char *) buf) + done, len - done,0); - if(ret > 0) - done += ret; - else - Err=WSAGetLastError(); - if(ret < 0 && Err == WSAEWOULDBLOCK) - { - fd_set fds; - FD_ZERO(&fds); - FD_SET(fd, &fds); - do { - ret = select(fd + 1, &fds, 0, 0, 0); - if (ret==SOCKET_ERROR) - { - ret=-1; - errno = WSAGetLastError(); - if (errno == WSAEINTR) - errno=EINTR; - } - } while (ret == -1 && errno == EINTR); - } - if(ret <= 0) - return ret; - } - return len; -#else - int done = 0; - while(done < len) - { - int ret = read(fd, ((char *) buf) + done, len - done); - if(ret > 0) - done += ret; - if(ret < 0 && errno == EAGAIN) - { -#if USE_POLL - struct pollfd pfd; - pfd.fd = fd; - pfd.events = POLLIN; - pfd.revents = 0; - do { - ret = poll(&pfd, 1, -1); - } while (ret == -1 && errno == EINTR); -#else - fd_set fds; - FD_ZERO(&fds); - FD_SET(fd, &fds); - do { - ret = select(fd + 1, &fds, 0, 0, 0); - } while (ret == -1 && errno == EINTR); -#endif - } - if(ret <= 0) - return ret; - } - return len; -#endif -} - -static int poll_for_reply(xcb_connection_t *c, unsigned int request, void **reply, xcb_generic_error_t **error) -{ - struct reply_list *head; - - /* If an error occurred when issuing the request, fail immediately. */ - if(!request) - head = 0; - /* We've read requests past the one we want, so if it has replies we have - * them all and they're in the replies map. */ - else if(XCB_SEQUENCE_COMPARE_32(request, <, c->in.request_read)) - { - head = _xcb_map_remove(c->in.replies, request); - if(head && head->next) - _xcb_map_put(c->in.replies, request, head->next); - } - /* We're currently processing the responses to the request we want, and we - * have a reply ready to return. So just return it without blocking. */ - else if(XCB_SEQUENCE_COMPARE_32(request, ==, c->in.request_read) && c->in.current_reply) - { - head = c->in.current_reply; - c->in.current_reply = head->next; - if(!head->next) - c->in.current_reply_tail = &c->in.current_reply; - } - /* We know this request can't have any more replies, and we've already - * established it doesn't have a reply now. Don't bother blocking. */ - else if(XCB_SEQUENCE_COMPARE_32(request, ==, c->in.request_completed)) - head = 0; - /* We may have more replies on the way for this request: block until we're - * sure. */ - else - return 0; - - if(error) - *error = 0; - *reply = 0; - - if(head) - { - if(((xcb_generic_reply_t *) head->reply)->response_type == XCB_ERROR) - { - if(error) - *error = head->reply; - else - free(head->reply); - } - else - *reply = head->reply; - - free(head); - } - - return 1; -} - -/* Public interface */ - -void *xcb_wait_for_reply(xcb_connection_t *c, unsigned int request, xcb_generic_error_t **e) -{ - uint64_t widened_request; - void *ret = 0; - if(e) - *e = 0; - if(c->has_error) - return 0; - - pthread_mutex_lock(&c->iolock); - - widened_request = (c->out.request & UINT64_C(0xffffffff00000000)) | request; - if(widened_request > c->out.request) - widened_request -= UINT64_C(1) << 32; - - /* If this request has not been written yet, write it. */ - if(c->out.return_socket || _xcb_out_flush_to(c, widened_request)) - { - pthread_cond_t cond = PTHREAD_COND_INITIALIZER; - reader_list reader; - reader_list **prev_reader; - - for(prev_reader = &c->in.readers; - *prev_reader && - XCB_SEQUENCE_COMPARE_32((*prev_reader)->request, <=, request); - prev_reader = &(*prev_reader)->next) - { - /* empty */; - } - reader.request = request; - reader.data = &cond; - reader.next = *prev_reader; - *prev_reader = &reader; - - while(!poll_for_reply(c, request, &ret, e)) - if(!_xcb_conn_wait(c, &cond, 0, 0)) - break; - - for(prev_reader = &c->in.readers; - *prev_reader && - XCB_SEQUENCE_COMPARE_32((*prev_reader)->request, <=, request); - prev_reader = &(*prev_reader)->next) - { - if(*prev_reader == &reader) - { - *prev_reader = (*prev_reader)->next; - break; - } - } - pthread_cond_destroy(&cond); - } - - _xcb_in_wake_up_next_reader(c); - pthread_mutex_unlock(&c->iolock); - return ret; -} - -static void insert_pending_discard(xcb_connection_t *c, pending_reply **prev_next, uint64_t seq) -{ - pending_reply *pend; - pend = malloc(sizeof(*pend)); - if(!pend) - { - _xcb_conn_shutdown(c); - return; - } - - pend->first_request = seq; - pend->last_request = seq; - pend->workaround = 0; - pend->flags = XCB_REQUEST_DISCARD_REPLY; - pend->next = *prev_next; - *prev_next = pend; - - if(!pend->next) - c->in.pending_replies_tail = &pend->next; -} - -static void discard_reply(xcb_connection_t *c, unsigned int request) -{ - pending_reply *pend = 0; - pending_reply **prev_pend; - uint64_t widened_request; - - /* We've read requests past the one we want, so if it has replies we have - * them all and they're in the replies map. */ - if(XCB_SEQUENCE_COMPARE_32(request, <, c->in.request_read)) - { - struct reply_list *head; - head = _xcb_map_remove(c->in.replies, request); - while (head) - { - struct reply_list *next = head->next; - free(head->reply); - free(head); - head = next; - } - return; - } - - /* We're currently processing the responses to the request we want, and we - * have a reply ready to return. Free it, and mark the pend to free any further - * replies. */ - if(XCB_SEQUENCE_COMPARE_32(request, ==, c->in.request_read) && c->in.current_reply) - { - struct reply_list *head; - head = c->in.current_reply; - c->in.current_reply = NULL; - c->in.current_reply_tail = &c->in.current_reply; - while (head) - { - struct reply_list *next = head->next; - free(head->reply); - free(head); - head = next; - } - - pend = c->in.pending_replies; - if(pend && - !(XCB_SEQUENCE_COMPARE(pend->first_request, <=, c->in.request_read) && - (pend->workaround == WORKAROUND_EXTERNAL_SOCKET_OWNER || - XCB_SEQUENCE_COMPARE(c->in.request_read, <=, pend->last_request)))) - pend = 0; - if(pend) - pend->flags |= XCB_REQUEST_DISCARD_REPLY; - else - insert_pending_discard(c, &c->in.pending_replies, c->in.request_read); - - return; - } - - /* Walk the list of pending requests. Mark the first match for deletion. */ - for(prev_pend = &c->in.pending_replies; *prev_pend; prev_pend = &(*prev_pend)->next) - { - if(XCB_SEQUENCE_COMPARE_32((*prev_pend)->first_request, >, request)) - break; - - if(XCB_SEQUENCE_COMPARE_32((*prev_pend)->first_request, ==, request)) - { - /* Pending reply found. Mark for discard: */ - (*prev_pend)->flags |= XCB_REQUEST_DISCARD_REPLY; - return; - } - } - - /* Pending reply not found (likely due to _unchecked request). Create one: */ - widened_request = (c->out.request & UINT64_C(0xffffffff00000000)) | request; - if(widened_request > c->out.request) - widened_request -= UINT64_C(1) << 32; - - insert_pending_discard(c, prev_pend, widened_request); -} - -void xcb_discard_reply(xcb_connection_t *c, unsigned int sequence) -{ - if(c->has_error) - return; - - /* If an error occurred when issuing the request, fail immediately. */ - if(!sequence) - return; - - pthread_mutex_lock(&c->iolock); - discard_reply(c, sequence); - pthread_mutex_unlock(&c->iolock); -} - -int xcb_poll_for_reply(xcb_connection_t *c, unsigned int request, void **reply, xcb_generic_error_t **error) -{ - int ret; - if(c->has_error) - { - *reply = 0; - if(error) - *error = 0; - return 1; /* would not block */ - } - assert(reply != 0); - pthread_mutex_lock(&c->iolock); - ret = poll_for_reply(c, request, reply, error); - pthread_mutex_unlock(&c->iolock); - return ret; -} - -xcb_generic_event_t *xcb_wait_for_event(xcb_connection_t *c) -{ - xcb_generic_event_t *ret; - if(c->has_error) - return 0; - pthread_mutex_lock(&c->iolock); - /* get_event returns 0 on empty list. */ - while(!(ret = get_event(c))) - if(!_xcb_conn_wait(c, &c->in.event_cond, 0, 0)) - break; - - _xcb_in_wake_up_next_reader(c); - pthread_mutex_unlock(&c->iolock); - return ret; -} - -xcb_generic_event_t *xcb_poll_for_event(xcb_connection_t *c) -{ - xcb_generic_event_t *ret = 0; - if(!c->has_error) - { - pthread_mutex_lock(&c->iolock); - /* FIXME: follow X meets Z architecture changes. */ - ret = get_event(c); - if(!ret && _xcb_in_read(c)) /* _xcb_in_read shuts down the connection on error */ - ret = get_event(c); - pthread_mutex_unlock(&c->iolock); - } - return ret; -} - -xcb_generic_error_t *xcb_request_check(xcb_connection_t *c, xcb_void_cookie_t cookie) -{ - /* FIXME: this could hold the lock to avoid syncing unnecessarily, but - * that would require factoring the locking out of xcb_get_input_focus, - * xcb_get_input_focus_reply, and xcb_wait_for_reply. */ - xcb_generic_error_t *ret; - void *reply; - if(c->has_error) - return 0; - if(XCB_SEQUENCE_COMPARE_32(cookie.sequence,>,c->in.request_expected) - && XCB_SEQUENCE_COMPARE_32(cookie.sequence,>,c->in.request_completed)) - { - free(xcb_get_input_focus_reply(c, xcb_get_input_focus(c), &ret)); - assert(!ret); - } - reply = xcb_wait_for_reply(c, cookie.sequence, &ret); - assert(!reply); - return ret; -} - -/* Private interface */ - -int _xcb_in_init(_xcb_in *in) -{ - if(pthread_cond_init(&in->event_cond, 0)) - return 0; - in->reading = 0; - - in->queue_len = 0; - - in->request_read = 0; - in->request_completed = 0; - - in->replies = _xcb_map_new(); - if(!in->replies) - return 0; - - in->current_reply_tail = &in->current_reply; - in->events_tail = &in->events; - in->pending_replies_tail = &in->pending_replies; - - return 1; -} - -void _xcb_in_destroy(_xcb_in *in) -{ - pthread_cond_destroy(&in->event_cond); - free_reply_list(in->current_reply); - _xcb_map_delete(in->replies, (void (*)(void *)) free_reply_list); - while(in->events) - { - struct event_list *e = in->events; - in->events = e->next; - free(e->event); - free(e); - } - while(in->pending_replies) - { - pending_reply *pend = in->pending_replies; - in->pending_replies = pend->next; - free(pend); - } -} - -void _xcb_in_wake_up_next_reader(xcb_connection_t *c) -{ - int pthreadret; - if(c->in.readers) - pthreadret = pthread_cond_signal(c->in.readers->data); - else - pthreadret = pthread_cond_signal(&c->in.event_cond); - assert(pthreadret == 0); -} - -int _xcb_in_expect_reply(xcb_connection_t *c, uint64_t request, enum workarounds workaround, int flags) -{ - pending_reply *pend = malloc(sizeof(pending_reply)); - assert(workaround != WORKAROUND_NONE || flags != 0); - if(!pend) - { - _xcb_conn_shutdown(c); - return 0; - } - pend->first_request = pend->last_request = request; - pend->workaround = workaround; - pend->flags = flags; - pend->next = 0; - *c->in.pending_replies_tail = pend; - c->in.pending_replies_tail = &pend->next; - return 1; -} - -void _xcb_in_replies_done(xcb_connection_t *c) -{ - struct pending_reply *pend; - if (c->in.pending_replies_tail != &c->in.pending_replies) - { - pend = container_of(c->in.pending_replies_tail, struct pending_reply, next); - if(pend->workaround == WORKAROUND_EXTERNAL_SOCKET_OWNER) - { - pend->last_request = c->out.request; - pend->workaround = WORKAROUND_NONE; - } - } -} - -int _xcb_in_read(xcb_connection_t *c) -{ - int n = recv(c->fd, c->in.queue + c->in.queue_len, sizeof(c->in.queue) - c->in.queue_len,0); //MH - if(n > 0) - c->in.queue_len += n; - while(read_packet(c)) - /* empty */; -#ifdef _MSC_VER - errno=WSAGetLastError(); - if (errno==WSAEWOULDBLOCK) - errno=EAGAIN; -#endif - if((n > 0) || (n < 0 && errno == EAGAIN)) - return 1; - _xcb_conn_shutdown(c); - return 0; -} - -int _xcb_in_read_block(xcb_connection_t *c, void *buf, int len) -{ - int done = c->in.queue_len; - if(len < done) - done = len; - - memcpy(buf, c->in.queue, done); - c->in.queue_len -= done; - memmove(c->in.queue, c->in.queue + done, c->in.queue_len); - - if(len > done) - { - int ret = read_block(c->fd, (char *) buf + done, len - done); - if(ret <= 0) - { - _xcb_conn_shutdown(c); - return ret; - } - } - - return len; -} +/* Copyright (C) 2001-2004 Bart Massey and Jamey Sharp.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Except as contained in this notice, the names of the authors or their
+ * institutions shall not be used in advertising or otherwise to promote the
+ * sale, use or other dealings in this Software without prior written
+ * authorization from the authors.
+ */
+
+/* Stuff that reads stuff from the server. */
+
+#include <assert.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+#ifdef _MSC_VER
+#include <X11/Xwinsock.h>
+#endif
+#include <errno.h>
+
+#include "xcb.h"
+#include "xcbext.h"
+#include "xcbint.h"
+#if USE_POLL
+#include <poll.h>
+#else
+#include <sys/select.h>
+#endif
+
+#define XCB_ERROR 0
+#define XCB_REPLY 1
+#define XCB_XGE_EVENT 35
+
+struct event_list {
+ xcb_generic_event_t *event;
+ struct event_list *next;
+};
+
+struct reply_list {
+ void *reply;
+ struct reply_list *next;
+};
+
+typedef struct pending_reply {
+ uint64_t first_request;
+ uint64_t last_request;
+ enum workarounds workaround;
+ int flags;
+ struct pending_reply *next;
+} pending_reply;
+
+typedef struct reader_list {
+ unsigned int request;
+ pthread_cond_t *data;
+ struct reader_list *next;
+} reader_list;
+
+static int read_packet(xcb_connection_t *c)
+{
+ xcb_generic_reply_t genrep;
+ int length = 32;
+ int eventlength = 0; /* length after first 32 bytes for GenericEvents */
+ void *buf;
+ pending_reply *pend = 0;
+ struct event_list *event;
+
+ /* Wait for there to be enough data for us to read a whole packet */
+ if(c->in.queue_len < length)
+ return 0;
+
+ /* Get the response type, length, and sequence number. */
+ memcpy(&genrep, c->in.queue, sizeof(genrep));
+
+ /* Compute 32-bit sequence number of this packet. */
+ if((genrep.response_type & 0x7f) != XCB_KEYMAP_NOTIFY)
+ {
+ uint64_t lastread = c->in.request_read;
+ c->in.request_read = (lastread & UINT64_C(0xffffffffffff0000)) | genrep.sequence;
+ if(XCB_SEQUENCE_COMPARE(c->in.request_read, <, lastread))
+ c->in.request_read += 0x10000;
+ if(XCB_SEQUENCE_COMPARE(c->in.request_read, >, c->in.request_expected))
+ c->in.request_expected = c->in.request_read;
+
+ if(c->in.request_read != lastread)
+ {
+ if(c->in.current_reply)
+ {
+ _xcb_map_put(c->in.replies, lastread, c->in.current_reply);
+ c->in.current_reply = 0;
+ c->in.current_reply_tail = &c->in.current_reply;
+ }
+ c->in.request_completed = c->in.request_read - 1;
+ }
+
+ while(c->in.pending_replies &&
+ c->in.pending_replies->workaround != WORKAROUND_EXTERNAL_SOCKET_OWNER &&
+ XCB_SEQUENCE_COMPARE (c->in.pending_replies->last_request, <=, c->in.request_completed))
+ {
+ pending_reply *oldpend = c->in.pending_replies;
+ c->in.pending_replies = oldpend->next;
+ if(!oldpend->next)
+ c->in.pending_replies_tail = &c->in.pending_replies;
+ free(oldpend);
+ }
+
+ if(genrep.response_type == XCB_ERROR)
+ c->in.request_completed = c->in.request_read;
+ }
+
+ if(genrep.response_type == XCB_ERROR || genrep.response_type == XCB_REPLY)
+ {
+ pend = c->in.pending_replies;
+ if(pend &&
+ !(XCB_SEQUENCE_COMPARE(pend->first_request, <=, c->in.request_read) &&
+ (pend->workaround == WORKAROUND_EXTERNAL_SOCKET_OWNER ||
+ XCB_SEQUENCE_COMPARE(c->in.request_read, <=, pend->last_request))))
+ pend = 0;
+ }
+
+ /* For reply packets, check that the entire packet is available. */
+ if(genrep.response_type == XCB_REPLY)
+ {
+ if(pend && pend->workaround == WORKAROUND_GLX_GET_FB_CONFIGS_BUG)
+ {
+ uint32_t *p = (uint32_t *) c->in.queue;
+ genrep.length = p[2] * p[3] * 2;
+ }
+ length += genrep.length * 4;
+ }
+
+ /* XGE events may have sizes > 32 */
+ if (genrep.response_type == XCB_XGE_EVENT)
+ eventlength = genrep.length * 4;
+
+ buf = malloc(length + eventlength +
+ (genrep.response_type == XCB_REPLY ? 0 : sizeof(uint32_t)));
+ if(!buf)
+ {
+ _xcb_conn_shutdown(c);
+ return 0;
+ }
+
+ if(_xcb_in_read_block(c, buf, length) <= 0)
+ {
+ free(buf);
+ return 0;
+ }
+
+ /* pull in XGE event data if available, append after event struct */
+ if (eventlength)
+ {
+ if(_xcb_in_read_block(c, &((xcb_generic_event_t*)buf)[1], eventlength) <= 0)
+ {
+ free(buf);
+ return 0;
+ }
+ }
+
+ if(pend && (pend->flags & XCB_REQUEST_DISCARD_REPLY))
+ {
+ free(buf);
+ return 1;
+ }
+
+ if(genrep.response_type != XCB_REPLY)
+ ((xcb_generic_event_t *) buf)->full_sequence = c->in.request_read;
+
+ /* reply, or checked error */
+ if( genrep.response_type == XCB_REPLY ||
+ (genrep.response_type == XCB_ERROR && pend && (pend->flags & XCB_REQUEST_CHECKED)))
+ {
+ reader_list *reader;
+ struct reply_list *cur = malloc(sizeof(struct reply_list));
+ if(!cur)
+ {
+ _xcb_conn_shutdown(c);
+ free(buf);
+ return 0;
+ }
+ cur->reply = buf;
+ cur->next = 0;
+ *c->in.current_reply_tail = cur;
+ c->in.current_reply_tail = &cur->next;
+ for(reader = c->in.readers;
+ reader &&
+ XCB_SEQUENCE_COMPARE_32(reader->request, <=, c->in.request_read);
+ reader = reader->next)
+ {
+ if(XCB_SEQUENCE_COMPARE_32(reader->request, ==, c->in.request_read))
+ {
+ pthread_cond_signal(reader->data);
+ break;
+ }
+ }
+ return 1;
+ }
+
+ /* event, or unchecked error */
+ event = malloc(sizeof(struct event_list));
+ if(!event)
+ {
+ _xcb_conn_shutdown(c);
+ free(buf);
+ return 0;
+ }
+ event->event = buf;
+ event->next = 0;
+ *c->in.events_tail = event;
+ c->in.events_tail = &event->next;
+ pthread_cond_signal(&c->in.event_cond);
+ return 1; /* I have something for you... */
+}
+
+static xcb_generic_event_t *get_event(xcb_connection_t *c)
+{
+ struct event_list *cur = c->in.events;
+ xcb_generic_event_t *ret;
+ if(!c->in.events)
+ return 0;
+ ret = cur->event;
+ c->in.events = cur->next;
+ if(!cur->next)
+ c->in.events_tail = &c->in.events;
+ free(cur);
+ return ret;
+}
+
+static void free_reply_list(struct reply_list *head)
+{
+ while(head)
+ {
+ struct reply_list *cur = head;
+ head = cur->next;
+ free(cur->reply);
+ free(cur);
+ }
+}
+
+static int read_block(const int fd, void *buf, const ssize_t len)
+{
+#ifdef _MSC_VER
+ int done = 0;
+ while(done < len)
+ {
+ int Err;
+ int ret = recv(fd, ((char *) buf) + done, len - done,0);
+ if(ret > 0)
+ done += ret;
+ else
+ Err=WSAGetLastError();
+ if(ret < 0 && Err == WSAEWOULDBLOCK)
+ {
+ fd_set fds;
+ FD_ZERO(&fds);
+ FD_SET(fd, &fds);
+ do {
+ ret = select(fd + 1, &fds, 0, 0, 0);
+ if (ret==SOCKET_ERROR)
+ {
+ ret=-1;
+ errno = WSAGetLastError();
+ if (errno == WSAEINTR)
+ errno=EINTR;
+ }
+ } while (ret == -1 && errno == EINTR);
+ }
+ if(ret <= 0)
+ return ret;
+ }
+ return len;
+#else
+ int done = 0;
+ while(done < len)
+ {
+ int ret = read(fd, ((char *) buf) + done, len - done);
+ if(ret > 0)
+ done += ret;
+ if(ret < 0 && errno == EAGAIN)
+ {
+#if USE_POLL
+ struct pollfd pfd;
+ pfd.fd = fd;
+ pfd.events = POLLIN;
+ pfd.revents = 0;
+ do {
+ ret = poll(&pfd, 1, -1);
+ } while (ret == -1 && errno == EINTR);
+#else
+ fd_set fds;
+ FD_ZERO(&fds);
+ FD_SET(fd, &fds);
+ do {
+ ret = select(fd + 1, &fds, 0, 0, 0);
+ } while (ret == -1 && errno == EINTR);
+#endif
+ }
+ if(ret <= 0)
+ return ret;
+ }
+ return len;
+#endif
+}
+
+static int poll_for_reply(xcb_connection_t *c, unsigned int request, void **reply, xcb_generic_error_t **error)
+{
+ struct reply_list *head;
+
+ /* If an error occurred when issuing the request, fail immediately. */
+ if(!request)
+ head = 0;
+ /* We've read requests past the one we want, so if it has replies we have
+ * them all and they're in the replies map. */
+ else if(XCB_SEQUENCE_COMPARE_32(request, <, c->in.request_read))
+ {
+ head = _xcb_map_remove(c->in.replies, request);
+ if(head && head->next)
+ _xcb_map_put(c->in.replies, request, head->next);
+ }
+ /* We're currently processing the responses to the request we want, and we
+ * have a reply ready to return. So just return it without blocking. */
+ else if(XCB_SEQUENCE_COMPARE_32(request, ==, c->in.request_read) && c->in.current_reply)
+ {
+ head = c->in.current_reply;
+ c->in.current_reply = head->next;
+ if(!head->next)
+ c->in.current_reply_tail = &c->in.current_reply;
+ }
+ /* We know this request can't have any more replies, and we've already
+ * established it doesn't have a reply now. Don't bother blocking. */
+ else if(XCB_SEQUENCE_COMPARE_32(request, ==, c->in.request_completed))
+ head = 0;
+ /* We may have more replies on the way for this request: block until we're
+ * sure. */
+ else
+ return 0;
+
+ if(error)
+ *error = 0;
+ *reply = 0;
+
+ if(head)
+ {
+ if(((xcb_generic_reply_t *) head->reply)->response_type == XCB_ERROR)
+ {
+ if(error)
+ *error = head->reply;
+ else
+ free(head->reply);
+ }
+ else
+ *reply = head->reply;
+
+ free(head);
+ }
+
+ return 1;
+}
+
+/* Public interface */
+
+void *xcb_wait_for_reply(xcb_connection_t *c, unsigned int request, xcb_generic_error_t **e)
+{
+ uint64_t widened_request;
+ void *ret = 0;
+ if(e)
+ *e = 0;
+ if(c->has_error)
+ return 0;
+
+ pthread_mutex_lock(&c->iolock);
+
+ widened_request = (c->out.request & UINT64_C(0xffffffff00000000)) | request;
+ if(widened_request > c->out.request)
+ widened_request -= UINT64_C(1) << 32;
+
+ /* If this request has not been written yet, write it. */
+ if(c->out.return_socket || _xcb_out_flush_to(c, widened_request))
+ {
+ pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
+ reader_list reader;
+ reader_list **prev_reader;
+
+ for(prev_reader = &c->in.readers;
+ *prev_reader &&
+ XCB_SEQUENCE_COMPARE_32((*prev_reader)->request, <=, request);
+ prev_reader = &(*prev_reader)->next)
+ {
+ /* empty */;
+ }
+ reader.request = request;
+ reader.data = &cond;
+ reader.next = *prev_reader;
+ *prev_reader = &reader;
+
+ while(!poll_for_reply(c, request, &ret, e))
+ if(!_xcb_conn_wait(c, &cond, 0, 0))
+ break;
+
+ for(prev_reader = &c->in.readers;
+ *prev_reader &&
+ XCB_SEQUENCE_COMPARE_32((*prev_reader)->request, <=, request);
+ prev_reader = &(*prev_reader)->next)
+ {
+ if(*prev_reader == &reader)
+ {
+ *prev_reader = (*prev_reader)->next;
+ break;
+ }
+ }
+ pthread_cond_destroy(&cond);
+ }
+
+ _xcb_in_wake_up_next_reader(c);
+ pthread_mutex_unlock(&c->iolock);
+ return ret;
+}
+
+static void insert_pending_discard(xcb_connection_t *c, pending_reply **prev_next, uint64_t seq)
+{
+ pending_reply *pend;
+ pend = malloc(sizeof(*pend));
+ if(!pend)
+ {
+ _xcb_conn_shutdown(c);
+ return;
+ }
+
+ pend->first_request = seq;
+ pend->last_request = seq;
+ pend->workaround = 0;
+ pend->flags = XCB_REQUEST_DISCARD_REPLY;
+ pend->next = *prev_next;
+ *prev_next = pend;
+
+ if(!pend->next)
+ c->in.pending_replies_tail = &pend->next;
+}
+
+static void discard_reply(xcb_connection_t *c, unsigned int request)
+{
+ pending_reply *pend = 0;
+ pending_reply **prev_pend;
+ uint64_t widened_request;
+
+ /* We've read requests past the one we want, so if it has replies we have
+ * them all and they're in the replies map. */
+ if(XCB_SEQUENCE_COMPARE_32(request, <, c->in.request_read))
+ {
+ struct reply_list *head;
+ head = _xcb_map_remove(c->in.replies, request);
+ while (head)
+ {
+ struct reply_list *next = head->next;
+ free(head->reply);
+ free(head);
+ head = next;
+ }
+ return;
+ }
+
+ /* We're currently processing the responses to the request we want, and we
+ * have a reply ready to return. Free it, and mark the pend to free any further
+ * replies. */
+ if(XCB_SEQUENCE_COMPARE_32(request, ==, c->in.request_read) && c->in.current_reply)
+ {
+ struct reply_list *head;
+ head = c->in.current_reply;
+ c->in.current_reply = NULL;
+ c->in.current_reply_tail = &c->in.current_reply;
+ while (head)
+ {
+ struct reply_list *next = head->next;
+ free(head->reply);
+ free(head);
+ head = next;
+ }
+
+ pend = c->in.pending_replies;
+ if(pend &&
+ !(XCB_SEQUENCE_COMPARE(pend->first_request, <=, c->in.request_read) &&
+ (pend->workaround == WORKAROUND_EXTERNAL_SOCKET_OWNER ||
+ XCB_SEQUENCE_COMPARE(c->in.request_read, <=, pend->last_request))))
+ pend = 0;
+ if(pend)
+ pend->flags |= XCB_REQUEST_DISCARD_REPLY;
+ else
+ insert_pending_discard(c, &c->in.pending_replies, c->in.request_read);
+
+ return;
+ }
+
+ /* Walk the list of pending requests. Mark the first match for deletion. */
+ for(prev_pend = &c->in.pending_replies; *prev_pend; prev_pend = &(*prev_pend)->next)
+ {
+ if(XCB_SEQUENCE_COMPARE_32((*prev_pend)->first_request, >, request))
+ break;
+
+ if(XCB_SEQUENCE_COMPARE_32((*prev_pend)->first_request, ==, request))
+ {
+ /* Pending reply found. Mark for discard: */
+ (*prev_pend)->flags |= XCB_REQUEST_DISCARD_REPLY;
+ return;
+ }
+ }
+
+ /* Pending reply not found (likely due to _unchecked request). Create one: */
+ widened_request = (c->out.request & UINT64_C(0xffffffff00000000)) | request;
+ if(widened_request > c->out.request)
+ widened_request -= UINT64_C(1) << 32;
+
+ insert_pending_discard(c, prev_pend, widened_request);
+}
+
+void xcb_discard_reply(xcb_connection_t *c, unsigned int sequence)
+{
+ if(c->has_error)
+ return;
+
+ /* If an error occurred when issuing the request, fail immediately. */
+ if(!sequence)
+ return;
+
+ pthread_mutex_lock(&c->iolock);
+ discard_reply(c, sequence);
+ pthread_mutex_unlock(&c->iolock);
+}
+
+int xcb_poll_for_reply(xcb_connection_t *c, unsigned int request, void **reply, xcb_generic_error_t **error)
+{
+ int ret;
+ if(c->has_error)
+ {
+ *reply = 0;
+ if(error)
+ *error = 0;
+ return 1; /* would not block */
+ }
+ assert(reply != 0);
+ pthread_mutex_lock(&c->iolock);
+ ret = poll_for_reply(c, request, reply, error);
+ pthread_mutex_unlock(&c->iolock);
+ return ret;
+}
+
+xcb_generic_event_t *xcb_wait_for_event(xcb_connection_t *c)
+{
+ xcb_generic_event_t *ret;
+ if(c->has_error)
+ return 0;
+ pthread_mutex_lock(&c->iolock);
+ /* get_event returns 0 on empty list. */
+ while(!(ret = get_event(c)))
+ if(!_xcb_conn_wait(c, &c->in.event_cond, 0, 0))
+ break;
+
+ _xcb_in_wake_up_next_reader(c);
+ pthread_mutex_unlock(&c->iolock);
+ return ret;
+}
+
+xcb_generic_event_t *xcb_poll_for_event(xcb_connection_t *c)
+{
+ xcb_generic_event_t *ret = 0;
+ if(!c->has_error)
+ {
+ pthread_mutex_lock(&c->iolock);
+ /* FIXME: follow X meets Z architecture changes. */
+ ret = get_event(c);
+ if(!ret && _xcb_in_read(c)) /* _xcb_in_read shuts down the connection on error */
+ ret = get_event(c);
+ pthread_mutex_unlock(&c->iolock);
+ }
+ return ret;
+}
+
+xcb_generic_error_t *xcb_request_check(xcb_connection_t *c, xcb_void_cookie_t cookie)
+{
+ /* FIXME: this could hold the lock to avoid syncing unnecessarily, but
+ * that would require factoring the locking out of xcb_get_input_focus,
+ * xcb_get_input_focus_reply, and xcb_wait_for_reply. */
+ xcb_generic_error_t *ret;
+ void *reply;
+ if(c->has_error)
+ return 0;
+ if(XCB_SEQUENCE_COMPARE_32(cookie.sequence,>=,c->in.request_expected)
+ && XCB_SEQUENCE_COMPARE_32(cookie.sequence,>,c->in.request_completed))
+ {
+ free(xcb_get_input_focus_reply(c, xcb_get_input_focus(c), &ret));
+ assert(!ret);
+ }
+ reply = xcb_wait_for_reply(c, cookie.sequence, &ret);
+ assert(!reply);
+ return ret;
+}
+
+/* Private interface */
+
+int _xcb_in_init(_xcb_in *in)
+{
+ if(pthread_cond_init(&in->event_cond, 0))
+ return 0;
+ in->reading = 0;
+
+ in->queue_len = 0;
+
+ in->request_read = 0;
+ in->request_completed = 0;
+
+ in->replies = _xcb_map_new();
+ if(!in->replies)
+ return 0;
+
+ in->current_reply_tail = &in->current_reply;
+ in->events_tail = &in->events;
+ in->pending_replies_tail = &in->pending_replies;
+
+ return 1;
+}
+
+void _xcb_in_destroy(_xcb_in *in)
+{
+ pthread_cond_destroy(&in->event_cond);
+ free_reply_list(in->current_reply);
+ _xcb_map_delete(in->replies, (void (*)(void *)) free_reply_list);
+ while(in->events)
+ {
+ struct event_list *e = in->events;
+ in->events = e->next;
+ free(e->event);
+ free(e);
+ }
+ while(in->pending_replies)
+ {
+ pending_reply *pend = in->pending_replies;
+ in->pending_replies = pend->next;
+ free(pend);
+ }
+}
+
+void _xcb_in_wake_up_next_reader(xcb_connection_t *c)
+{
+ int pthreadret;
+ if(c->in.readers)
+ pthreadret = pthread_cond_signal(c->in.readers->data);
+ else
+ pthreadret = pthread_cond_signal(&c->in.event_cond);
+ assert(pthreadret == 0);
+}
+
+int _xcb_in_expect_reply(xcb_connection_t *c, uint64_t request, enum workarounds workaround, int flags)
+{
+ pending_reply *pend = malloc(sizeof(pending_reply));
+ assert(workaround != WORKAROUND_NONE || flags != 0);
+ if(!pend)
+ {
+ _xcb_conn_shutdown(c);
+ return 0;
+ }
+ pend->first_request = pend->last_request = request;
+ pend->workaround = workaround;
+ pend->flags = flags;
+ pend->next = 0;
+ *c->in.pending_replies_tail = pend;
+ c->in.pending_replies_tail = &pend->next;
+ return 1;
+}
+
+void _xcb_in_replies_done(xcb_connection_t *c)
+{
+ struct pending_reply *pend;
+ if (c->in.pending_replies_tail != &c->in.pending_replies)
+ {
+ pend = container_of(c->in.pending_replies_tail, struct pending_reply, next);
+ if(pend->workaround == WORKAROUND_EXTERNAL_SOCKET_OWNER)
+ {
+ pend->last_request = c->out.request;
+ pend->workaround = WORKAROUND_NONE;
+ }
+ }
+}
+
+int _xcb_in_read(xcb_connection_t *c)
+{
+ int n = recv(c->fd, c->in.queue + c->in.queue_len, sizeof(c->in.queue) - c->in.queue_len,0); //MH
+ if(n > 0)
+ c->in.queue_len += n;
+ while(read_packet(c))
+ /* empty */;
+#ifdef _MSC_VER
+ errno=WSAGetLastError();
+ if (errno==WSAEWOULDBLOCK)
+ errno=EAGAIN;
+#endif
+ if((n > 0) || (n < 0 && errno == EAGAIN))
+ return 1;
+ _xcb_conn_shutdown(c);
+ return 0;
+}
+
+int _xcb_in_read_block(xcb_connection_t *c, void *buf, int len)
+{
+ int done = c->in.queue_len;
+ if(len < done)
+ done = len;
+
+ memcpy(buf, c->in.queue, done);
+ c->in.queue_len -= done;
+ memmove(c->in.queue, c->in.queue + done, c->in.queue_len);
+
+ if(len > done)
+ {
+ int ret = read_block(c->fd, (char *) buf + done, len - done);
+ if(ret <= 0)
+ {
+ _xcb_conn_shutdown(c);
+ return ret;
+ }
+ }
+
+ return len;
+}
diff --git a/pixman/configure.ac b/pixman/configure.ac index be1690b3b..1b592de14 100644 --- a/pixman/configure.ac +++ b/pixman/configure.ac @@ -54,7 +54,7 @@ AC_PREREQ([2.57]) m4_define([pixman_major], 0)
m4_define([pixman_minor], 19)
-m4_define([pixman_micro], 1)
+m4_define([pixman_micro], 3)
m4_define([pixman_version],[pixman_major.pixman_minor.pixman_micro])
diff --git a/pixman/pixman/pixman-region.c b/pixman/pixman/pixman-region.c index 4f694b63b..52e26dd5c 100644 --- a/pixman/pixman/pixman-region.c +++ b/pixman/pixman/pixman-region.c @@ -2212,7 +2212,7 @@ PIXMAN_EXPORT PREFIX (_contains_rectangle) (region_type_t * region, PIXMAN_EXPORT void
PREFIX (_translate) (region_type_t *region, int x, int y)
{
- int x1, x2, y1, y2;
+ overflow_int_t x1, x2, y1, y2;
int nbox;
box_type_t * pbox;
@@ -2222,7 +2222,7 @@ PREFIX (_translate) (region_type_t *region, int x, int y) region->extents.x2 = x2 = region->extents.x2 + x;
region->extents.y2 = y2 = region->extents.y2 + y;
- if (((x1 - SHRT_MIN) | (y1 - SHRT_MIN) | (SHRT_MAX - x2) | (SHRT_MAX - y2)) >= 0)
+ if (((x1 - PIXMAN_REGION_MIN) | (y1 - PIXMAN_REGION_MIN) | (PIXMAN_REGION_MAX - x2) | (PIXMAN_REGION_MAX - y2)) >= 0)
{
if (region->data && (nbox = region->data->numRects))
{
@@ -2237,7 +2237,7 @@ PREFIX (_translate) (region_type_t *region, int x, int y) return;
}
- if (((x2 - SHRT_MIN) | (y2 - SHRT_MIN) | (SHRT_MAX - x1) | (SHRT_MAX - y1)) <= 0)
+ if (((x2 - PIXMAN_REGION_MIN) | (y2 - PIXMAN_REGION_MIN) | (PIXMAN_REGION_MAX - x1) | (PIXMAN_REGION_MAX - y1)) <= 0)
{
region->extents.x2 = region->extents.x1;
region->extents.y2 = region->extents.y1;
@@ -2246,15 +2246,15 @@ PREFIX (_translate) (region_type_t *region, int x, int y) return;
}
- if (x1 < SHRT_MIN)
- region->extents.x1 = SHRT_MIN;
- else if (x2 > SHRT_MAX)
- region->extents.x2 = SHRT_MAX;
+ if (x1 < PIXMAN_REGION_MIN)
+ region->extents.x1 = PIXMAN_REGION_MIN;
+ else if (x2 > PIXMAN_REGION_MAX)
+ region->extents.x2 = PIXMAN_REGION_MAX;
- if (y1 < SHRT_MIN)
- region->extents.y1 = SHRT_MIN;
- else if (y2 > SHRT_MAX)
- region->extents.y2 = SHRT_MAX;
+ if (y1 < PIXMAN_REGION_MIN)
+ region->extents.y1 = PIXMAN_REGION_MIN;
+ else if (y2 > PIXMAN_REGION_MAX)
+ region->extents.y2 = PIXMAN_REGION_MAX;
if (region->data && (nbox = region->data->numRects))
{
@@ -2267,22 +2267,22 @@ PREFIX (_translate) (region_type_t *region, int x, int y) pbox_out->x2 = x2 = pbox->x2 + x;
pbox_out->y2 = y2 = pbox->y2 + y;
- if (((x2 - SHRT_MIN) | (y2 - SHRT_MIN) |
- (SHRT_MAX - x1) | (SHRT_MAX - y1)) <= 0)
+ if (((x2 - PIXMAN_REGION_MIN) | (y2 - PIXMAN_REGION_MIN) |
+ (PIXMAN_REGION_MAX - x1) | (PIXMAN_REGION_MAX - y1)) <= 0)
{
region->data->numRects--;
continue;
}
- if (x1 < SHRT_MIN)
- pbox_out->x1 = SHRT_MIN;
- else if (x2 > SHRT_MAX)
- pbox_out->x2 = SHRT_MAX;
+ if (x1 < PIXMAN_REGION_MIN)
+ pbox_out->x1 = PIXMAN_REGION_MIN;
+ else if (x2 > PIXMAN_REGION_MAX)
+ pbox_out->x2 = PIXMAN_REGION_MAX;
- if (y1 < SHRT_MIN)
- pbox_out->y1 = SHRT_MIN;
- else if (y2 > SHRT_MAX)
- pbox_out->y2 = SHRT_MAX;
+ if (y1 < PIXMAN_REGION_MIN)
+ pbox_out->y1 = PIXMAN_REGION_MIN;
+ else if (y2 > PIXMAN_REGION_MAX)
+ pbox_out->y2 = PIXMAN_REGION_MAX;
pbox_out++;
}
diff --git a/pixman/pixman/pixman-region16.c b/pixman/pixman/pixman-region16.c index 46f5e26ea..39d122590 100644 --- a/pixman/pixman/pixman-region16.c +++ b/pixman/pixman/pixman-region16.c @@ -1,63 +1,67 @@ -/* - * Copyright © 2008 Red Hat, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software - * and its documentation for any purpose is hereby granted without - * fee, provided that the above copyright notice appear in all copies - * and that both that copyright notice and this permission notice - * appear in supporting documentation, and that the name of - * Red Hat, Inc. not be used in advertising or publicity pertaining to - * distribution of the software without specific, written prior - * permission. Red Hat, Inc. makes no representations about the - * suitability of this software for any purpose. It is provided "as - * is" without express or implied warranty. - * - * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS - * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL, - * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR - * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * Author: Soren Sandmann <sandmann@redhat.com> - */ -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#undef PIXMAN_DISABLE_DEPRECATED - -#include "pixman-private.h" - -#include <stdlib.h> - -typedef pixman_box16_t box_type_t; -typedef pixman_region16_data_t region_data_type_t; -typedef pixman_region16_t region_type_t; - -typedef struct { - int x, y; -} point_type_t; - -#define PREFIX(x) pixman_region##x - -#include "pixman-region.c" - -/* This function exists only to make it possible to preserve the X ABI - - * it should go away at first opportunity. - * - * The problem is that the X ABI exports the three structs and has used - * them through macros. So the X server calls this function with - * the addresses of those structs which makes the existing code continue to - * work. - */ -PIXMAN_EXPORT void -pixman_region_set_static_pointers (pixman_box16_t *empty_box, - pixman_region16_data_t *empty_data, - pixman_region16_data_t *broken_data) -{ - pixman_region_empty_box = empty_box; - pixman_region_empty_data = empty_data; - pixman_broken_data = broken_data; -} +/*
+ * Copyright © 2008 Red Hat, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Red Hat, Inc. not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Red Hat, Inc. makes no representations about the
+ * suitability of this software for any purpose. It is provided "as
+ * is" without express or implied warranty.
+ *
+ * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
+ * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
+ * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Author: Soren Sandmann <sandmann@redhat.com>
+ */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#undef PIXMAN_DISABLE_DEPRECATED
+
+#include "pixman-private.h"
+
+#include <stdlib.h>
+
+typedef pixman_box16_t box_type_t;
+typedef pixman_region16_data_t region_data_type_t;
+typedef pixman_region16_t region_type_t;
+typedef int32_t overflow_int_t;
+
+typedef struct {
+ int x, y;
+} point_type_t;
+
+#define PREFIX(x) pixman_region##x
+
+#define PIXMAN_REGION_MAX INT16_MAX
+#define PIXMAN_REGION_MIN INT16_MIN
+
+#include "pixman-region.c"
+
+/* This function exists only to make it possible to preserve the X ABI -
+ * it should go away at first opportunity.
+ *
+ * The problem is that the X ABI exports the three structs and has used
+ * them through macros. So the X server calls this function with
+ * the addresses of those structs which makes the existing code continue to
+ * work.
+ */
+PIXMAN_EXPORT void
+pixman_region_set_static_pointers (pixman_box16_t *empty_box,
+ pixman_region16_data_t *empty_data,
+ pixman_region16_data_t *broken_data)
+{
+ pixman_region_empty_box = empty_box;
+ pixman_region_empty_data = empty_data;
+ pixman_broken_data = broken_data;
+}
diff --git a/pixman/pixman/pixman-region32.c b/pixman/pixman/pixman-region32.c index aeee86cf9..ccab36050 100644 --- a/pixman/pixman/pixman-region32.c +++ b/pixman/pixman/pixman-region32.c @@ -1,43 +1,47 @@ -/* - * Copyright © 2008 Red Hat, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software - * and its documentation for any purpose is hereby granted without - * fee, provided that the above copyright notice appear in all copies - * and that both that copyright notice and this permission notice - * appear in supporting documentation, and that the name of - * Red Hat, Inc. not be used in advertising or publicity pertaining to - * distribution of the software without specific, written prior - * permission. Red Hat, Inc. makes no representations about the - * suitability of this software for any purpose. It is provided "as - * is" without express or implied warranty. - * - * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS - * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL, - * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR - * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * Author: Soren Sandmann <sandmann@redhat.com> - */ -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "pixman-private.h" - -#include <stdlib.h> - -typedef pixman_box32_t box_type_t; -typedef pixman_region32_data_t region_data_type_t; -typedef pixman_region32_t region_type_t; - -typedef struct { - int x, y; -} point_type_t; - -#define PREFIX(x) pixman_region32##x - -#include "pixman-region.c" +/*
+ * Copyright © 2008 Red Hat, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Red Hat, Inc. not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Red Hat, Inc. makes no representations about the
+ * suitability of this software for any purpose. It is provided "as
+ * is" without express or implied warranty.
+ *
+ * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
+ * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
+ * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Author: Soren Sandmann <sandmann@redhat.com>
+ */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "pixman-private.h"
+
+#include <stdlib.h>
+
+typedef pixman_box32_t box_type_t;
+typedef pixman_region32_data_t region_data_type_t;
+typedef pixman_region32_t region_type_t;
+typedef int64_t overflow_int_t;
+
+typedef struct {
+ int x, y;
+} point_type_t;
+
+#define PREFIX(x) pixman_region32##x
+
+#define PIXMAN_REGION_MAX INT32_MAX
+#define PIXMAN_REGION_MIN INT32_MIN
+
+#include "pixman-region.c"
diff --git a/pixman/pixman/pixman.c b/pixman/pixman/pixman.c index 819bb5146..81cf20a8f 100644 --- a/pixman/pixman/pixman.c +++ b/pixman/pixman/pixman.c @@ -787,14 +787,17 @@ analyze_extent (pixman_image_t *image, int x, int y, if (!compute_sample_extents (transform, &ex, x, y, x_off, y_off, width, height))
return FALSE;
- /* Check whether the non-expanded, transformed extent is entirely within
- * the source image, and set the FAST_PATH_SAMPLES_COVER_CLIP if it is.
- */
- ex = *extents;
- if (compute_sample_extents (transform, &ex, x, y, x_off, y_off, width, height))
+ if (image->type == BITS)
{
- if (ex.x1 >= 0 && ex.y1 >= 0 && ex.x2 <= image->bits.width && ex.y2 <= image->bits.height)
- *flags |= FAST_PATH_SAMPLES_COVER_CLIP;
+ /* Check whether the non-expanded, transformed extent is entirely within
+ * the source image, and set the FAST_PATH_SAMPLES_COVER_CLIP if it is.
+ */
+ ex = *extents;
+ if (compute_sample_extents (transform, &ex, x, y, x_off, y_off, width, height))
+ {
+ if (ex.x1 >= 0 && ex.y1 >= 0 && ex.x2 <= image->bits.width && ex.y2 <= image->bits.height)
+ *flags |= FAST_PATH_SAMPLES_COVER_CLIP;
+ }
}
return TRUE;
diff --git a/pixman/test/Makefile.am b/pixman/test/Makefile.am index d3e9d3fa0..108ae96ee 100644 --- a/pixman/test/Makefile.am +++ b/pixman/test/Makefile.am @@ -7,6 +7,7 @@ INCLUDES = -I$(top_srcdir)/pixman -I$(top_builddir)/pixman TESTPROGRAMS = \
a1-trap-test \
region-test \
+ region-translate-test \
fetch-test \
oob-test \
window-test \
@@ -27,6 +28,7 @@ trap_crasher_LDADD = $(TEST_LDADD) oob_test_LDADD = $(TEST_LDADD)
window_test_LDADD = $(TEST_LDADD)
scaling_crash_test_LDADD = $(TEST_LDADD)
+region_translate_test_LDADD = $(TEST_LDADD)
region_test_LDADD = $(TEST_LDADD)
region_test_SOURCES = region-test.c utils.c utils.h
diff --git a/pixman/test/region-translate-test.c b/pixman/test/region-translate-test.c new file mode 100644 index 000000000..7c63df966 --- /dev/null +++ b/pixman/test/region-translate-test.c @@ -0,0 +1,30 @@ +#include <pixman.h>
+#include <assert.h>
+
+/* Pixman had a bug where 32bit regions where clipped to 16bit sizes when
+ * pixman_region32_translate() was called. This test exercises that bug.
+ */
+
+#define LARGE 32000
+
+int
+main (int argc, char **argv)
+{
+ pixman_box32_t rect = { -LARGE, -LARGE, LARGE, LARGE };
+ pixman_region32_t r1, r2;
+
+ pixman_region32_init_rects (&r1, &rect, 1);
+ pixman_region32_init_rect (&r2, rect.x1, rect.y1, rect.x2 - rect.x1, rect.y2 - rect.y1);
+
+ assert (pixman_region32_equal (&r1, &r2));
+
+ pixman_region32_translate (&r1, -LARGE, LARGE);
+ pixman_region32_translate (&r1, LARGE, -LARGE);
+
+ assert (pixman_region32_equal (&r1, &r2));
+
+ pixman_region32_fini (&r1);
+ pixman_region32_fini (&r2);
+
+ return 0;
+}
|