aboutsummaryrefslogtreecommitdiff
path: root/libxcb/src
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2012-08-31 15:18:29 +0200
committermarha <marha@users.sourceforge.net>2012-08-31 15:18:29 +0200
commit53192e17e55aa9ed3e3721bf4fdcb2b01a595202 (patch)
tree01d81bc7cfb5dc92584f4b7615d2ac1b09fe5411 /libxcb/src
parent05d67ae9117e5157fd1a5175dde6d7e48caf4653 (diff)
downloadvcxsrv-53192e17e55aa9ed3e3721bf4fdcb2b01a595202.tar.gz
vcxsrv-53192e17e55aa9ed3e3721bf4fdcb2b01a595202.tar.bz2
vcxsrv-53192e17e55aa9ed3e3721bf4fdcb2b01a595202.zip
randrproto xwininfo fontconfig libxcb mesa xkeyboard-config pixman xserver
git update 31 Aug 2012
Diffstat (limited to 'libxcb/src')
-rw-r--r--libxcb/src/c_client.py3
-rw-r--r--libxcb/src/xcb.h4
-rw-r--r--libxcb/src/xcb_conn.c9
-rw-r--r--libxcb/src/xcb_ext.c258
-rw-r--r--libxcb/src/xcb_in.c4
-rw-r--r--libxcb/src/xcb_list.c206
-rw-r--r--libxcb/src/xcb_out.c4
-rw-r--r--libxcb/src/xcb_util.c15
-rw-r--r--libxcb/src/xcb_xid.c198
9 files changed, 375 insertions, 326 deletions
diff --git a/libxcb/src/c_client.py b/libxcb/src/c_client.py
index 31ed3b58d..27a01b193 100644
--- a/libxcb/src/c_client.py
+++ b/libxcb/src/c_client.py
@@ -176,6 +176,9 @@ def c_open(self):
_h('')
_h('#include "xcb.h"')
+ _c('#ifdef HAVE_CONFIG_H')
+ _c('#include "config.h"')
+ _c('#endif')
_c('#include <stdlib.h>')
_c('#include <string.h>')
_c('#include <assert.h>')
diff --git a/libxcb/src/xcb.h b/libxcb/src/xcb.h
index 179af845c..f7dc6afaa 100644
--- a/libxcb/src/xcb.h
+++ b/libxcb/src/xcb.h
@@ -84,6 +84,9 @@ extern "C" {
/** Connection closed, error during parsing display string. */
#define XCB_CONN_CLOSED_PARSE_ERR 5
+/** Connection closed because the server does not have a screen matching the display. */
+#define XCB_CONN_CLOSED_INVALID_SCREEN 6
+
#define XCB_TYPE_PAD(T,I) (-(I) & (sizeof(T) > 4 ? 3 : sizeof(T) - 1))
/* Opaque structures */
@@ -423,6 +426,7 @@ int xcb_get_file_descriptor(xcb_connection_t *c);
* @return XCB_CONN_CLOSED_MEM_INSUFFICIENT, when memory not available.
* @return XCB_CONN_CLOSED_REQ_LEN_EXCEED, exceeding request length that server accepts.
* @return XCB_CONN_CLOSED_PARSE_ERR, error during parsing display string.
+ * @return XCB_CONN_CLOSED_INVALID_SCREEN, because the server does not have a screen matching the display.
*/
int xcb_connection_has_error(xcb_connection_t *c);
diff --git a/libxcb/src/xcb_conn.c b/libxcb/src/xcb_conn.c
index 725502af6..7979491d3 100644
--- a/libxcb/src/xcb_conn.c
+++ b/libxcb/src/xcb_conn.c
@@ -25,6 +25,10 @@
/* Connection management: the core of XCB. */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
#include <assert.h>
#include <string.h>
#include <stdio.h>
@@ -62,6 +66,7 @@ typedef struct {
static const int xcb_con_error = XCB_CONN_ERROR;
static const int xcb_con_closed_mem_er = XCB_CONN_CLOSED_MEM_INSUFFICIENT;
static const int xcb_con_closed_parse_er = XCB_CONN_CLOSED_PARSE_ERR;
+static const int xcb_con_closed_screen_er = XCB_CONN_CLOSED_INVALID_SCREEN;
static int set_fd_flags(const int fd)
{
@@ -345,6 +350,10 @@ xcb_connection_t *_xcb_conn_ret_error(int err)
{
return (xcb_connection_t *) &xcb_con_closed_parse_er;
}
+ case XCB_CONN_CLOSED_INVALID_SCREEN:
+ {
+ return (xcb_connection_t *) &xcb_con_closed_screen_er;
+ }
case XCB_CONN_ERROR:
default:
{
diff --git a/libxcb/src/xcb_ext.c b/libxcb/src/xcb_ext.c
index edad18da3..831f28381 100644
--- a/libxcb/src/xcb_ext.c
+++ b/libxcb/src/xcb_ext.c
@@ -1,127 +1,131 @@
-/* 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.
- */
-
-/* A cache for QueryExtension results. */
-
-#include <stdlib.h>
-#include <string.h>
-
-#include "xcb.h"
-#include "xcbext.h"
-#include "xcbint.h"
-
-typedef struct lazyreply {
- enum lazy_reply_tag tag;
- union {
- xcb_query_extension_cookie_t cookie;
- xcb_query_extension_reply_t *reply;
- } value;
-} lazyreply;
-
-static lazyreply *get_index(xcb_connection_t *c, int idx)
-{
- if(idx > c->ext.extensions_size)
- {
- int new_size = idx << 1;
- lazyreply *new_extensions = realloc(c->ext.extensions, sizeof(lazyreply) * new_size);
- if(!new_extensions)
- return 0;
- memset(new_extensions + c->ext.extensions_size, 0, sizeof(lazyreply) * (new_size - c->ext.extensions_size));
- c->ext.extensions = new_extensions;
- c->ext.extensions_size = new_size;
- }
- return c->ext.extensions + idx - 1;
-}
-
-static lazyreply *get_lazyreply(xcb_connection_t *c, xcb_extension_t *ext)
-{
- static pthread_mutex_t global_lock = PTHREAD_MUTEX_INITIALIZER;
- static int next_global_id;
-
- lazyreply *data;
-
- pthread_mutex_lock(&global_lock);
- if(!ext->global_id)
- ext->global_id = ++next_global_id;
- pthread_mutex_unlock(&global_lock);
-
- data = get_index(c, ext->global_id);
- if(data && data->tag == LAZY_NONE)
- {
- /* cache miss: query the server */
- data->tag = LAZY_COOKIE;
- data->value.cookie = xcb_query_extension(c, strlen(ext->name), ext->name);
- }
- return data;
-}
-
-/* Public interface */
-
-/* Do not free the returned xcb_query_extension_reply_t - on return, it's aliased
- * from the cache. */
-const xcb_query_extension_reply_t *xcb_get_extension_data(xcb_connection_t *c, xcb_extension_t *ext)
-{
- lazyreply *data;
- if(c->has_error)
- return 0;
-
- pthread_mutex_lock(&c->ext.lock);
- data = get_lazyreply(c, ext);
- if(data && data->tag == LAZY_COOKIE)
- {
- data->tag = LAZY_FORCED;
- data->value.reply = xcb_query_extension_reply(c, data->value.cookie, 0);
- }
- pthread_mutex_unlock(&c->ext.lock);
-
- return data ? data->value.reply : 0;
-}
-
-void xcb_prefetch_extension_data(xcb_connection_t *c, xcb_extension_t *ext)
-{
- if(c->has_error)
- return;
- pthread_mutex_lock(&c->ext.lock);
- get_lazyreply(c, ext);
- pthread_mutex_unlock(&c->ext.lock);
-}
-
-/* Private interface */
-
-int _xcb_ext_init(xcb_connection_t *c)
-{
- if(pthread_mutex_init(&c->ext.lock, 0))
- return 0;
- return 1;
-}
-
-void _xcb_ext_destroy(xcb_connection_t *c)
-{
- pthread_mutex_destroy(&c->ext.lock);
- while(c->ext.extensions_size-- > 0)
- if(c->ext.extensions[c->ext.extensions_size].tag == LAZY_FORCED)
- free(c->ext.extensions[c->ext.extensions_size].value.reply);
- free(c->ext.extensions);
-}
+/* 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.
+ */
+
+/* A cache for QueryExtension results. */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "xcb.h"
+#include "xcbext.h"
+#include "xcbint.h"
+
+typedef struct lazyreply {
+ enum lazy_reply_tag tag;
+ union {
+ xcb_query_extension_cookie_t cookie;
+ xcb_query_extension_reply_t *reply;
+ } value;
+} lazyreply;
+
+static lazyreply *get_index(xcb_connection_t *c, int idx)
+{
+ if(idx > c->ext.extensions_size)
+ {
+ int new_size = idx << 1;
+ lazyreply *new_extensions = realloc(c->ext.extensions, sizeof(lazyreply) * new_size);
+ if(!new_extensions)
+ return 0;
+ memset(new_extensions + c->ext.extensions_size, 0, sizeof(lazyreply) * (new_size - c->ext.extensions_size));
+ c->ext.extensions = new_extensions;
+ c->ext.extensions_size = new_size;
+ }
+ return c->ext.extensions + idx - 1;
+}
+
+static lazyreply *get_lazyreply(xcb_connection_t *c, xcb_extension_t *ext)
+{
+ static pthread_mutex_t global_lock = PTHREAD_MUTEX_INITIALIZER;
+ static int next_global_id;
+
+ lazyreply *data;
+
+ pthread_mutex_lock(&global_lock);
+ if(!ext->global_id)
+ ext->global_id = ++next_global_id;
+ pthread_mutex_unlock(&global_lock);
+
+ data = get_index(c, ext->global_id);
+ if(data && data->tag == LAZY_NONE)
+ {
+ /* cache miss: query the server */
+ data->tag = LAZY_COOKIE;
+ data->value.cookie = xcb_query_extension(c, strlen(ext->name), ext->name);
+ }
+ return data;
+}
+
+/* Public interface */
+
+/* Do not free the returned xcb_query_extension_reply_t - on return, it's aliased
+ * from the cache. */
+const xcb_query_extension_reply_t *xcb_get_extension_data(xcb_connection_t *c, xcb_extension_t *ext)
+{
+ lazyreply *data;
+ if(c->has_error)
+ return 0;
+
+ pthread_mutex_lock(&c->ext.lock);
+ data = get_lazyreply(c, ext);
+ if(data && data->tag == LAZY_COOKIE)
+ {
+ data->tag = LAZY_FORCED;
+ data->value.reply = xcb_query_extension_reply(c, data->value.cookie, 0);
+ }
+ pthread_mutex_unlock(&c->ext.lock);
+
+ return data ? data->value.reply : 0;
+}
+
+void xcb_prefetch_extension_data(xcb_connection_t *c, xcb_extension_t *ext)
+{
+ if(c->has_error)
+ return;
+ pthread_mutex_lock(&c->ext.lock);
+ get_lazyreply(c, ext);
+ pthread_mutex_unlock(&c->ext.lock);
+}
+
+/* Private interface */
+
+int _xcb_ext_init(xcb_connection_t *c)
+{
+ if(pthread_mutex_init(&c->ext.lock, 0))
+ return 0;
+ return 1;
+}
+
+void _xcb_ext_destroy(xcb_connection_t *c)
+{
+ pthread_mutex_destroy(&c->ext.lock);
+ while(c->ext.extensions_size-- > 0)
+ if(c->ext.extensions[c->ext.extensions_size].tag == LAZY_FORCED)
+ free(c->ext.extensions[c->ext.extensions_size].value.reply);
+ free(c->ext.extensions);
+}
diff --git a/libxcb/src/xcb_in.c b/libxcb/src/xcb_in.c
index 4998cdda3..b8107834c 100644
--- a/libxcb/src/xcb_in.c
+++ b/libxcb/src/xcb_in.c
@@ -25,6 +25,10 @@
/* Stuff that reads stuff from the server. */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
#include <assert.h>
#include <string.h>
#include <stdlib.h>
diff --git a/libxcb/src/xcb_list.c b/libxcb/src/xcb_list.c
index fc00588b4..6f5c61190 100644
--- a/libxcb/src/xcb_list.c
+++ b/libxcb/src/xcb_list.c
@@ -1,101 +1,105 @@
-/* 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.
- */
-
-/* A generic implementation of a list of void-pointers. */
-
-#include <stdlib.h>
-
-#include "xcb.h"
-#include "xcbint.h"
-
-typedef struct node {
- struct node *next;
- unsigned int key;
- void *data;
-} node;
-
-struct _xcb_map {
- node *head;
- node **tail;
-};
-
-/* Private interface */
-
-_xcb_map *_xcb_map_new()
-{
- _xcb_map *list;
- list = malloc(sizeof(_xcb_map));
- if(!list)
- return 0;
- list->head = 0;
- list->tail = &list->head;
- return list;
-}
-
-void _xcb_map_delete(_xcb_map *list, xcb_list_free_func_t do_free)
-{
- if(!list)
- return;
- while(list->head)
- {
- node *cur = list->head;
- if(do_free)
- do_free(cur->data);
- list->head = cur->next;
- free(cur);
- }
- free(list);
-}
-
-int _xcb_map_put(_xcb_map *list, unsigned int key, void *data)
-{
- node *cur = malloc(sizeof(node));
- if(!cur)
- return 0;
- cur->key = key;
- cur->data = data;
- cur->next = 0;
- *list->tail = cur;
- list->tail = &cur->next;
- return 1;
-}
-
-void *_xcb_map_remove(_xcb_map *list, unsigned int key)
-{
- node **cur;
- for(cur = &list->head; *cur; cur = &(*cur)->next)
- if((*cur)->key == key)
- {
- node *tmp = *cur;
- void *ret = (*cur)->data;
- *cur = (*cur)->next;
- if(!*cur)
- list->tail = cur;
-
- free(tmp);
- return ret;
- }
- return 0;
-}
+/* 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.
+ */
+
+/* A generic implementation of a list of void-pointers. */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+
+#include "xcb.h"
+#include "xcbint.h"
+
+typedef struct node {
+ struct node *next;
+ unsigned int key;
+ void *data;
+} node;
+
+struct _xcb_map {
+ node *head;
+ node **tail;
+};
+
+/* Private interface */
+
+_xcb_map *_xcb_map_new()
+{
+ _xcb_map *list;
+ list = malloc(sizeof(_xcb_map));
+ if(!list)
+ return 0;
+ list->head = 0;
+ list->tail = &list->head;
+ return list;
+}
+
+void _xcb_map_delete(_xcb_map *list, xcb_list_free_func_t do_free)
+{
+ if(!list)
+ return;
+ while(list->head)
+ {
+ node *cur = list->head;
+ if(do_free)
+ do_free(cur->data);
+ list->head = cur->next;
+ free(cur);
+ }
+ free(list);
+}
+
+int _xcb_map_put(_xcb_map *list, unsigned int key, void *data)
+{
+ node *cur = malloc(sizeof(node));
+ if(!cur)
+ return 0;
+ cur->key = key;
+ cur->data = data;
+ cur->next = 0;
+ *list->tail = cur;
+ list->tail = &cur->next;
+ return 1;
+}
+
+void *_xcb_map_remove(_xcb_map *list, unsigned int key)
+{
+ node **cur;
+ for(cur = &list->head; *cur; cur = &(*cur)->next)
+ if((*cur)->key == key)
+ {
+ node *tmp = *cur;
+ void *ret = (*cur)->data;
+ *cur = (*cur)->next;
+ if(!*cur)
+ list->tail = cur;
+
+ free(tmp);
+ return ret;
+ }
+ return 0;
+}
diff --git a/libxcb/src/xcb_out.c b/libxcb/src/xcb_out.c
index c0601f270..405f963de 100644
--- a/libxcb/src/xcb_out.c
+++ b/libxcb/src/xcb_out.c
@@ -25,6 +25,10 @@
/* Stuff that sends stuff to the server. */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
#include <assert.h>
#include <stdlib.h>
#include <unistd.h>
diff --git a/libxcb/src/xcb_util.c b/libxcb/src/xcb_util.c
index 45f66cbfe..463d085f6 100644
--- a/libxcb/src/xcb_util.c
+++ b/libxcb/src/xcb_util.c
@@ -25,6 +25,10 @@
/* Utility functions implementable using only public APIs. */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
#include <assert.h>
#include <sys/types.h>
#include <limits.h>
@@ -51,7 +55,6 @@
#include "xcbext.h"
#include "xcbint.h"
-/* must be after "xcbint.h" to get autoconf #defines */
#if defined(HAVE_TSOL_LABEL_H) && defined(HAVE_IS_SYSTEM_LABELED)
# include <tsol/label.h>
# include <sys/stat.h>
@@ -464,6 +467,16 @@ xcb_connection_t *xcb_connect_to_display_with_auth_info(const char *displayname,
else
c = xcb_connect_to_fd(fd, 0);
+ if(c->has_error)
+ goto out;
+
+ /* Make sure requested screen number is in bounds for this server */
+ if((screenp != NULL) && (*screenp >= (int) c->setup->roots_len)) {
+ xcb_disconnect(c);
+ c = _xcb_conn_ret_error(XCB_CONN_CLOSED_INVALID_SCREEN);
+ goto out;
+ }
+
out:
free(host);
free(protocol);
diff --git a/libxcb/src/xcb_xid.c b/libxcb/src/xcb_xid.c
index 364662bc1..79a9a27de 100644
--- a/libxcb/src/xcb_xid.c
+++ b/libxcb/src/xcb_xid.c
@@ -1,97 +1,101 @@
-/* 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"),
- * 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.
- */
-
-/* XID allocators. */
-
-#include <assert.h>
-#include <stdlib.h>
-#include "xcb.h"
-#include "xcbext.h"
-#include "xcbint.h"
-#include "xc_misc.h"
-
-/* Public interface */
-
-uint32_t xcb_generate_id(xcb_connection_t *c)
-{
- uint32_t ret;
- if(c->has_error)
- return -1;
- pthread_mutex_lock(&c->xid.lock);
- if(c->xid.last >= c->xid.max - c->xid.inc + 1)
- {
- xcb_xc_misc_get_xid_range_reply_t *range;
- 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);
- }
- } else {
- c->xid.last += c->xid.inc;
- }
- ret = c->xid.last | c->xid.base;
- pthread_mutex_unlock(&c->xid.lock);
- return ret;
-}
-
-/* Private interface */
-
-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.inc = c->setup->resource_id_mask & -(c->setup->resource_id_mask);
- return 1;
-}
-
-void _xcb_xid_destroy(xcb_connection_t *c)
-{
- pthread_mutex_destroy(&c->xid.lock);
-}
+/* 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"),
+ * 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.
+ */
+
+/* XID allocators. */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <assert.h>
+#include <stdlib.h>
+#include "xcb.h"
+#include "xcbext.h"
+#include "xcbint.h"
+#include "xc_misc.h"
+
+/* Public interface */
+
+uint32_t xcb_generate_id(xcb_connection_t *c)
+{
+ uint32_t ret;
+ if(c->has_error)
+ return -1;
+ pthread_mutex_lock(&c->xid.lock);
+ if(c->xid.last >= c->xid.max - c->xid.inc + 1)
+ {
+ xcb_xc_misc_get_xid_range_reply_t *range;
+ 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);
+ }
+ } else {
+ c->xid.last += c->xid.inc;
+ }
+ ret = c->xid.last | c->xid.base;
+ pthread_mutex_unlock(&c->xid.lock);
+ return ret;
+}
+
+/* Private interface */
+
+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.inc = c->setup->resource_id_mask & -(c->setup->resource_id_mask);
+ return 1;
+}
+
+void _xcb_xid_destroy(xcb_connection_t *c)
+{
+ pthread_mutex_destroy(&c->xid.lock);
+}