From 6c46fe074d3c7db453bb111fdb422502c33f1b34 Mon Sep 17 00:00:00 2001 From: Adam Jackson Date: Thu, 23 Jun 2011 17:11:00 -0400 Subject: [PATCH] backport some xts fixes from git --- libxcb-1.2-no-nagle.patch | 30 ---- libxcb-1.2-to-git-6e2e87d.patch | 309 -------------------------------- libxcb-1.7-xts-fixes.patch | 79 ++++++++ libxcb.spec | 7 +- 4 files changed, 85 insertions(+), 340 deletions(-) delete mode 100644 libxcb-1.2-no-nagle.patch delete mode 100644 libxcb-1.2-to-git-6e2e87d.patch create mode 100644 libxcb-1.7-xts-fixes.patch diff --git a/libxcb-1.2-no-nagle.patch b/libxcb-1.2-no-nagle.patch deleted file mode 100644 index f7b2e18..0000000 --- a/libxcb-1.2-no-nagle.patch +++ /dev/null @@ -1,30 +0,0 @@ -commit ee89850e68205a7f8961ace0839b5be86040dade -Author: elupus -Date: Tue May 26 16:14:48 2009 +0200 - - Disable Nagle on TCP socket - - Signed-off-by: Julien Danjou - -diff --git a/src/xcb_util.c b/src/xcb_util.c -index adac909..55aadb7 100644 ---- a/src/xcb_util.c -+++ b/src/xcb_util.c -@@ -30,6 +30,7 @@ - #include - #include - #include -+#include - #ifdef DNETCONN - #include - #include -@@ -257,6 +258,9 @@ static int _xcb_open_tcp(char *host, char *protocol, const unsigned short port) - { - fd = socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol); - if(fd >= 0) { -+ int on = 1; -+ setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on)); -+ - if (connect(fd, addr->ai_addr, addr->ai_addrlen) >= 0) - break; - close(fd); diff --git a/libxcb-1.2-to-git-6e2e87d.patch b/libxcb-1.2-to-git-6e2e87d.patch deleted file mode 100644 index f2708e6..0000000 --- a/libxcb-1.2-to-git-6e2e87d.patch +++ /dev/null @@ -1,309 +0,0 @@ -diff --git a/configure.ac b/configure.ac -index 6fe3e57..46c4611 100644 ---- a/configure.ac -+++ b/configure.ac -@@ -116,6 +116,8 @@ AC_PREREQ([2.59c], [], [AC_SUBST([htmldir], [m4_ifset([AC_PACKAGE_TARNAME], - - XCB_CHECK_DOXYGEN() - -+AC_CHECK_FUNC(poll, [AC_DEFINE(USE_POLL, 1, [poll() function is available])], ) -+ - XCB_EXTENSION(Composite, "yes") - XCB_EXTENSION(Damage, "yes") - XCB_EXTENSION(DPMS, "yes") -diff --git a/src/c_client.py b/src/c_client.py -index 73bd064..d86d05e 100755 ---- a/src/c_client.py -+++ b/src/c_client.py -@@ -135,6 +135,9 @@ def c_open(self): - _ns = self.namespace - _ns.c_ext_global_name = _n(_ns.prefix + ('id',)) - -+ # Build the type-name collision avoidance table used by c_enum -+ build_collision_table() -+ - _h_setlevel(0) - _c_setlevel(0) - -@@ -216,13 +219,26 @@ def c_close(self): - cfile.write('\n') - cfile.close() - -+def build_collision_table(): -+ global namecount -+ namecount = {} -+ -+ for v in module.types.values(): -+ name = _t(v[0]) -+ namecount[name] = (namecount.get(name) or 0) + 1 -+ - def c_enum(self, name): - ''' - Exported function that handles enum declarations. - ''' -+ -+ tname = _t(name) -+ if namecount[tname] > 1: -+ tname = _t(name + ('enum',)) -+ - _h_setlevel(0) - _h('') -- _h('typedef enum %s {', _t(name)) -+ _h('typedef enum %s {', tname) - - count = len(self.values) - -@@ -232,7 +248,7 @@ def c_enum(self, name): - comma = ',' if count > 0 else '' - _h(' %s%s%s%s', _n(name + (enam,)).upper(), equals, eval, comma) - -- _h('} %s;', _t(name)) -+ _h('} %s;', tname) - - def _c_type_setup(self, name, postfix): - ''' -diff --git a/src/xcb_auth.c b/src/xcb_auth.c -index b44855e..93a6f68 100644 ---- a/src/xcb_auth.c -+++ b/src/xcb_auth.c -@@ -187,7 +187,7 @@ static int compute_auth(xcb_auth_info_t *info, Xauth *authptr, struct sockaddr * - struct sockaddr_in6 *si6 = (struct sockaddr_in6 *) sockname; - if(IN6_IS_ADDR_V4MAPPED(SIN6_ADDR(sockname))) - { -- APPEND(info->data, j, si6->sin6_addr.s6_addr[12]); -+ do_append(info->data, &j, &si6->sin6_addr.s6_addr[12], 4); - APPEND(info->data, j, si6->sin6_port); - } - else -@@ -243,7 +243,14 @@ int _xcb_get_auth_info(int fd, xcb_auth_info_t *info, int display) - int ret = 1; - - if (getpeername(fd, sockname, &socknamelen) == -1) -- return 0; /* can only authenticate sockets */ -+ { -+ if (getsockname(fd, sockname, &socknamelen) == -1) -+ return 0; /* can only authenticate sockets */ -+ if (sockname->sa_family != AF_UNIX) -+ return 0; -+ /* Some systems like hpux or Hurd do not expose peer names -+ * for UNIX Domain Sockets. We do not need it anyway. */ -+ } - - authptr = get_authptr(sockname, socknamelen, display); - if (authptr == 0) -diff --git a/src/xcb_conn.c b/src/xcb_conn.c -index 5b097f7..251d62e 100644 ---- a/src/xcb_conn.c -+++ b/src/xcb_conn.c -@@ -31,12 +31,16 @@ - #include - #include - #include --#include - #include - #include - - #include "xcb.h" - #include "xcbint.h" -+#if USE_POLL -+#include -+#else -+#include -+#endif - - typedef struct { - uint8_t status; -@@ -258,7 +262,11 @@ void _xcb_conn_shutdown(xcb_connection_t *c) - int _xcb_conn_wait(xcb_connection_t *c, pthread_cond_t *cond, struct iovec **vector, int *count) - { - int ret; -+#if USE_POLL -+ struct pollfd fd; -+#else - fd_set rfds, wfds; -+#endif - - /* If the thing I should be doing is already being done, wait for it. */ - if(count ? c->out.writing : c->in.reading) -@@ -267,20 +275,38 @@ int _xcb_conn_wait(xcb_connection_t *c, pthread_cond_t *cond, struct iovec **vec - return 1; - } - -+#if USE_POLL -+ memset(&fd, 0, sizeof(fd)); -+ fd.fd = c->fd; -+ fd.events = POLLIN; -+#else - FD_ZERO(&rfds); - FD_SET(c->fd, &rfds); -+#endif - ++c->in.reading; - -+#if USE_POLL -+ if(count) -+ { -+ fd.events |= POLLOUT; -+ ++c->out.writing; -+ } -+#else - FD_ZERO(&wfds); - if(count) - { - FD_SET(c->fd, &wfds); - ++c->out.writing; - } -+#endif - - pthread_mutex_unlock(&c->iolock); - do { -+#if USE_POLL -+ ret = poll(&fd, 1, -1); -+#else - ret = select(c->fd + 1, &rfds, &wfds, 0, 0); -+#endif - } while (ret == -1 && errno == EINTR); - if (ret < 0) - { -@@ -291,10 +317,18 @@ int _xcb_conn_wait(xcb_connection_t *c, pthread_cond_t *cond, struct iovec **vec - - if(ret) - { -+#if USE_POLL -+ if((fd.revents & POLLIN) == POLLIN) -+#else - if(FD_ISSET(c->fd, &rfds)) -+#endif - ret = ret && _xcb_in_read(c); - -+#if USE_POLL -+ if((fd.revents & POLLOUT) == POLLOUT) -+#else - if(FD_ISSET(c->fd, &wfds)) -+#endif - ret = ret && write_vec(c, vector, count); - } - -diff --git a/src/xcb_in.c b/src/xcb_in.c -index 212dc9a..26ab358 100644 ---- a/src/xcb_in.c -+++ b/src/xcb_in.c -@@ -30,12 +30,16 @@ - #include - #include - #include --#include - #include - - #include "xcb.h" - #include "xcbext.h" - #include "xcbint.h" -+#if USE_POLL -+#include -+#else -+#include -+#endif - - #define XCB_ERROR 0 - #define XCB_REPLY 1 -@@ -268,12 +272,22 @@ static int read_block(const int fd, void *buf, const ssize_t len) - 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; -diff --git a/src/xcb_xid.c b/src/xcb_xid.c -index 7ff0c5f..3df5dbe 100644 ---- a/src/xcb_xid.c -+++ b/src/xcb_xid.c -@@ -1,4 +1,4 @@ --/* Copyright (C) 2001-2004 Bart Massey and Jamey Sharp. -+/* Copyright (C) 2001-2008 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"), -@@ -25,6 +25,7 @@ - - /* XID allocators. */ - -+#include - #include - #include "xcb.h" - #include "xcbext.h" -@@ -39,21 +40,40 @@ uint32_t xcb_generate_id(xcb_connection_t *c) - if(c->has_error) - return -1; - pthread_mutex_lock(&c->xid.lock); -- if(c->xid.last == c->xid.max) -+ if(c->xid.last >= c->xid.max - c->xid.inc + 1) - { - xcb_xc_misc_get_xid_range_reply_t *range; -- range = xcb_xc_misc_get_xid_range_reply(c, xcb_xc_misc_get_xid_range(c), 0); -- if(!range) -- { -- pthread_mutex_unlock(&c->xid.lock); -- return -1; -+ assert(c->xid.last == c->xid.max); -+ if (c->xid.last == 0) { -+ /* finish setting up initial range */ -+ c->xid.max = c->setup->resource_id_mask; -+ } else { -+ /* check for extension */ -+ const xcb_query_extension_reply_t *xc_misc_reply = -+ xcb_get_extension_data(c, &xcb_xc_misc_id); -+ if (!xc_misc_reply) { -+ pthread_mutex_unlock(&c->xid.lock); -+ return -1; -+ } -+ /* get new range */ -+ range = xcb_xc_misc_get_xid_range_reply(c, -+ xcb_xc_misc_get_xid_range(c), 0); -+ /* XXX The latter disjunct is what the server returns -+ when it is out of XIDs. Sweet. */ -+ if(!range || (range->start_id == 0 && range->count == 1)) -+ { -+ pthread_mutex_unlock(&c->xid.lock); -+ return -1; -+ } -+ assert(range->count > 0 && range->start_id > 0); -+ c->xid.last = range->start_id; -+ c->xid.max = range->start_id + (range->count - 1) * c->xid.inc; -+ free(range); - } -- c->xid.last = range->start_id; -- c->xid.max = range->start_id + (range->count - 1) * c->xid.inc; -- free(range); -+ } else { -+ c->xid.last += c->xid.inc; - } - ret = c->xid.last | c->xid.base; -- c->xid.last += c->xid.inc; - pthread_mutex_unlock(&c->xid.lock); - return ret; - } -@@ -65,8 +85,8 @@ int _xcb_xid_init(xcb_connection_t *c) - if(pthread_mutex_init(&c->xid.lock, 0)) - return 0; - c->xid.last = 0; -+ c->xid.max = 0; - c->xid.base = c->setup->resource_id_base; -- c->xid.max = c->setup->resource_id_mask; - c->xid.inc = c->setup->resource_id_mask & -(c->setup->resource_id_mask); - return 1; - } diff --git a/libxcb-1.7-xts-fixes.patch b/libxcb-1.7-xts-fixes.patch new file mode 100644 index 0000000..8ca2e7e --- /dev/null +++ b/libxcb-1.7-xts-fixes.patch @@ -0,0 +1,79 @@ +diff --git a/src/xcb_conn.c b/src/xcb_conn.c +index 7e18891..e30c5ca 100644 +--- a/src/xcb_conn.c ++++ b/src/xcb_conn.c +@@ -42,13 +42,18 @@ + #include + #endif + ++/* SHUT_RDWR is fairly recent and is not available on all platforms */ ++#if !defined(SHUT_RDWR) ++#define SHUT_RDWR 2 ++#endif ++ + typedef struct { + uint8_t status; + uint8_t pad0[5]; + uint16_t length; + } xcb_setup_generic_t; + +-static const int error_connection = 1; ++const int error_connection = 1; + + static int set_fd_flags(const int fd) + { +@@ -243,10 +248,13 @@ xcb_connection_t *xcb_connect_to_fd(int fd, xcb_auth_info_t *auth_info) + + void xcb_disconnect(xcb_connection_t *c) + { +- if(c->has_error) ++ if(c == (xcb_connection_t *) &error_connection) + return; + + free(c->setup); ++ ++ /* disallow further sends and receives */ ++ shutdown(c->fd, SHUT_RDWR); + close(c->fd); + + pthread_mutex_destroy(&c->iolock); +@@ -311,6 +319,13 @@ int _xcb_conn_wait(xcb_connection_t *c, pthread_cond_t *cond, struct iovec **vec + do { + #if USE_POLL + ret = poll(&fd, 1, -1); ++ /* If poll() returns an event we didn't expect, such as POLLNVAL, treat ++ * it as if it failed. */ ++ if(ret >= 0 && (fd.revents & ~fd.events)) ++ { ++ ret = -1; ++ break; ++ } + #else + ret = select(c->fd + 1, &rfds, &wfds, 0, 0); + #endif +diff --git a/src/xcb_util.c b/src/xcb_util.c +index 5a82ac1..07fa4a3 100644 +--- a/src/xcb_util.c ++++ b/src/xcb_util.c +@@ -49,8 +49,6 @@ + #include "xcbext.h" + #include "xcbint.h" + +-static const int error_connection = 1; +- + int xcb_popcount(uint32_t mask) + { + uint32_t y; +diff --git a/src/xcbint.h b/src/xcbint.h +index f07add8..6991238 100644 +--- a/src/xcbint.h ++++ b/src/xcbint.h +@@ -174,6 +174,8 @@ void _xcb_ext_destroy(xcb_connection_t *c); + + /* xcb_conn.c */ + ++extern const int error_connection; ++ + struct xcb_connection_t { + int has_error; + diff --git a/libxcb.spec b/libxcb.spec index 8754ee0..482910b 100644 --- a/libxcb.spec +++ b/libxcb.spec @@ -1,6 +1,6 @@ Name: libxcb Version: 1.7 -Release: 2%{?dist} +Release: 3%{?dist} Summary: A C binding to the X11 protocol Group: System Environment/Libraries @@ -13,6 +13,7 @@ BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) # we don't need the library because glibc has working pthreads, but we need # the pkgconfig file so libs that link against libxcb know this... Source1: pthread-stubs.pc.in +Patch0: libxcb-1.7-xts-fixes.patch BuildRequires: autoconf automake libtool pkgconfig @@ -49,6 +50,7 @@ The %{name}-doc package contains documentation for the %{name} library. %prep %setup -q +%patch0 -p1 -b .xts %build sed -i 's/pthread-stubs //' configure.ac @@ -110,6 +112,9 @@ rm -rf $RPM_BUILD_ROOT %{_datadir}/doc/%{name}-%{version} %changelog +* Thu Jun 23 2011 Adam Jackson 1.7-3 +- libxcb-1.7-xts-fixes.patch: Backport some XTS5 fixes from git. + * Tue Feb 08 2011 Adam Jackson 1.7-2 - Fix FTBFS.