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; }