aboutsummaryrefslogtreecommitdiff
path: root/libxcb/src
diff options
context:
space:
mode:
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.c262
-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.c202
9 files changed, 379 insertions, 330 deletions
diff --git a/libxcb/src/c_client.py b/libxcb/src/c_client.py
index 9b93a9067..f4df6a425 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 1372f4653..4722a270c 100644
--- a/libxcb/src/xcb.h
+++ b/libxcb/src/xcb.h
@@ -85,6 +85,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 */
@@ -424,6 +427,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 ed6f06bdd..45ada1fb7 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>
@@ -68,6 +72,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)
{
@@ -366,6 +371,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 be7862f41..990c67a96 100644
--- a/libxcb/src/xcb_ext.c
+++ b/libxcb/src/xcb_ext.c
@@ -1,129 +1,133 @@
-/* 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)
-{
- if (!c->ext.lock)
- return; /* mutex is not initialised */
- 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)
+{
+ if (!c->ext.lock)
+ return; /* mutex is not initialised */
+ 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 d7db8235e..da2b7077a 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 c082c98ab..996fedb23 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 065fe1407..5cee9ca2d 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>
@@ -493,6 +496,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 e32306157..7d9fc621b 100644
--- a/libxcb/src/xcb_xid.c
+++ b/libxcb/src/xcb_xid.c
@@ -1,99 +1,103 @@
-/* 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)
-{
- if (!c->xid.lock)
- return; /* mutex was not initialised yet */
- 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)
+{
+ if (!c->xid.lock)
+ return; /* mutex was not initialised yet */
+ pthread_mutex_destroy(&c->xid.lock);
+}