Skip to content
Browse files

Merge remote branch 'freedesktop/master' into restructure

Conflicts:
	.gitignore
	Makefile.am
	autogen.sh
	configure.ac
	src/Makefile.am
  • Loading branch information...
2 parents 8dfb397 + 6801531 commit 1e08103bf15a5904d95f2040dd9c9041c317e431 @dequis dequis committed Nov 22, 2010
Showing with 143 additions and 180 deletions.
  1. +3 −0 .gitignore
  2. +29 −0 src/xpyb.h
  3. +4 −1 tools/py_client.py
  4. +78 −17 xcb/conn.c
  5. +4 −14 xcb/conn.h
  6. +0 −71 xcb/constant.c
  7. +0 −3 xcb/constant.h
  8. +5 −2 xcb/cookie.c
  9. +1 −1 xcb/cookie.h
  10. +1 −1 xcb/ext.c
  11. +17 −69 xcb/module.c
  12. +1 −1 xcb/response.c
View
3 .gitignore
@@ -28,6 +28,9 @@ stamp-h1
*.pc
*.tar.bz2
*.tar.gz
+*.xml
+*~
+py-compile
*.so
*.swp
*.pyc
View
29 src/xpyb.h
@@ -0,0 +1,29 @@
+#ifndef XPYB_H
+#define XPYB_H
+
+#include <Python.h>
+#include <xcb/xcb.h>
+
+typedef struct {
+ PyObject_HEAD
+ xcb_connection_t *conn;
+ int wrapped;
+ PyObject *dict;
+ int pref_screen;
+ PyObject *core;
+ PyObject *setup;
+ PyObject *extcache;
+ PyObject **events;
+ int events_len;
+ PyObject **errors;
+ int errors_len;
+} xpybConn;
+
+typedef struct {
+ PyTypeObject *xpybConn_type;
+} xpyb_CAPI_t;
+
+#define xpyb_IMPORT \
+ xpyb_CAPI = (xpyb_CAPI_t *) PyCObject_Import("xcb", "CAPI")
+
+#endif
View
5 tools/py_client.py
@@ -169,7 +169,10 @@ def py_enum(self, name):
for (enam, eval) in self.values:
_py(' %s = %s', _n(enam), eval if eval != '' else count)
- count += 1
+ if eval != '':
+ count = int(eval) + 1
+ else:
+ count += 1
def _py_type_setup(self, name, postfix=''):
'''
View
95 xcb/conn.c
@@ -25,38 +25,96 @@ xpybConn_invalid(xpybConn *self)
return 0;
}
-xpybConn *
-xpybConn_create(PyObject *core_type)
+static int
+xpyb_parse_auth(const char *authstr, int authlen, xcb_auth_info_t *auth)
{
- xpybConn *self;
+ int i = 0;
- self = PyObject_New(xpybConn, &xpybConn_type);
- if (self == NULL)
- return NULL;
+ while (i < authlen && authstr[i] != ':')
+ i++;
+
+ if (i >= authlen) {
+ PyErr_SetString(xpybExcept_base, "Auth string must take the form '<name>:<data>'.");
+ return -1;
+ }
+ auth->name = (char *)authstr;
+ auth->namelen = i++;
+ auth->data = (char *)authstr + i;
+ auth->datalen = authlen - i;
+ return 0;
+}
+
+int
+xpybConn_init_struct(xpybConn *self, PyObject *core_type)
+{
self->core = PyObject_CallFunctionObjArgs(core_type, self, NULL);
if (self->core == NULL)
- goto err;
+ return -1;
self->dict = PyDict_New();
if (self->dict == NULL)
- goto err;
+ return -1;
- self->extcache = PyDict_New();
+ self->extcache = PyDict_New();
if (self->extcache == NULL)
- goto err;
+ return -1;
self->wrapped = 0;
self->setup = NULL;
self->events = NULL;
self->events_len = 0;
self->errors = NULL;
self->errors_len = 0;
- return self;
+ return 0;
+}
-err:
- Py_DECREF(self);
- return NULL;
+int
+xpybConn_init(xpybConn *self, PyObject *args, PyObject *kw)
+{
+ static char *kwlist[] = { "display", "fd", "auth", NULL };
+ const char *displayname = NULL, *authstr = NULL;
+ xcb_auth_info_t auth, *authptr = NULL;
+ int authlen, fd = -1;
+
+ /* Make sure core was set. */
+ if (xpybModule_core == NULL) {
+ PyErr_SetString(xpybExcept_base, "No core protocol object has been set. Did you import xcb.xproto?");
+ return -1;
+ }
+
+ /* Parse arguments and allocate new connection object */
+ if (!PyArg_ParseTupleAndKeywords(args, kw, "|ziz#", kwlist, &displayname,
+ &fd, &authstr, &authlen))
+ return -1;
+
+ /* Set up authorization */
+ if (authstr != NULL) {
+ if (xpyb_parse_auth(authstr, authlen, &auth) < 0)
+ return -1;
+ authptr = &auth;
+ }
+
+ /* Connect to display */
+ if (fd >= 0)
+ self->conn = xcb_connect_to_fd(fd, authptr);
+ else if (authptr)
+ self->conn = xcb_connect_to_display_with_auth_info(displayname, authptr, &self->pref_screen);
+ else
+ self->conn = xcb_connect(displayname, &self->pref_screen);
+
+ if (xcb_connection_has_error(self->conn)) {
+ PyErr_SetString(xpybExcept_conn, "Failed to connect to X server.");
+ return -1;
+ }
+
+ xpybConn_init_struct(self, (PyObject *)xpybModule_core);
+
+ /* Load extensions */
+ if (xpybConn_setup(self) < 0)
+ return -1;
+
+ return 0;
}
static xpybExt *
@@ -398,8 +456,10 @@ xpybConn_poll_for_event(xpybConn *self, PyObject *args)
data = xcb_poll_for_event(self->conn);
if (data == NULL) {
- PyErr_SetString(PyExc_IOError, "I/O error on X server connection.");
- return NULL;
+ if (xpybConn_invalid(self))
+ return NULL;
+ else
+ Py_RETURN_NONE;
}
if (data->response_type == 0) {
@@ -511,7 +571,8 @@ PyTypeObject xpybConn_type = {
.tp_basicsize = sizeof(xpybConn),
.tp_new = xpybConn_new,
.tp_dealloc = (destructor)xpybConn_dealloc,
- .tp_flags = Py_TPFLAGS_DEFAULT,
+ .tp_init = (initproc)xpybConn_init,
+ .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
.tp_doc = "XCB connection object",
.tp_methods = xpybConn_methods,
.tp_members = xpybConn_members,
View
18 xcb/conn.h
@@ -1,20 +1,7 @@
#ifndef XPYB_CONN_H
#define XPYB_CONN_H
-typedef struct {
- PyObject_HEAD
- xcb_connection_t *conn;
- int wrapped;
- PyObject *dict;
- int pref_screen;
- PyObject *core;
- PyObject *setup;
- PyObject *extcache;
- PyObject **events;
- int events_len;
- PyObject **errors;
- int errors_len;
-} xpybConn;
+#include "xpyb.h"
extern PyTypeObject xpybConn_type;
@@ -24,4 +11,7 @@ int xpybConn_setup(xpybConn *self);
int xpybConn_modinit(PyObject *m);
+int xpybConn_init_struct(xpybConn *self, PyObject *core_type);
+int xpybConn_init(xpybConn *self, PyObject *args, PyObject *kw);
+
#endif
View
71 xcb/constant.c
@@ -13,76 +13,5 @@ int xpybConstant_modinit(PyObject *m)
PyModule_AddIntConstant(m, "CurrentTime", XCB_CURRENT_TIME);
PyModule_AddIntConstant(m, "NoSymbol", XCB_NO_SYMBOL);
- /* Pre-defined atoms */
- PyModule_AddIntConstant(m, "XA_PRIMARY", XA_PRIMARY);
- PyModule_AddIntConstant(m, "XA_SECONDARY", XA_SECONDARY);
- PyModule_AddIntConstant(m, "XA_ARC", XA_ARC);
- PyModule_AddIntConstant(m, "XA_ATOM", XA_ATOM);
- PyModule_AddIntConstant(m, "XA_BITMAP", XA_BITMAP);
- PyModule_AddIntConstant(m, "XA_CARDINAL", XA_CARDINAL);
- PyModule_AddIntConstant(m, "XA_COLORMAP", XA_COLORMAP);
- PyModule_AddIntConstant(m, "XA_CURSOR", XA_CURSOR);
- PyModule_AddIntConstant(m, "XA_CUT_BUFFER0", XA_CUT_BUFFER0);
- PyModule_AddIntConstant(m, "XA_CUT_BUFFER1", XA_CUT_BUFFER1);
- PyModule_AddIntConstant(m, "XA_CUT_BUFFER2", XA_CUT_BUFFER2);
- PyModule_AddIntConstant(m, "XA_CUT_BUFFER3", XA_CUT_BUFFER3);
- PyModule_AddIntConstant(m, "XA_CUT_BUFFER4", XA_CUT_BUFFER4);
- PyModule_AddIntConstant(m, "XA_CUT_BUFFER5", XA_CUT_BUFFER5);
- PyModule_AddIntConstant(m, "XA_CUT_BUFFER6", XA_CUT_BUFFER6);
- PyModule_AddIntConstant(m, "XA_CUT_BUFFER7", XA_CUT_BUFFER7);
- PyModule_AddIntConstant(m, "XA_DRAWABLE", XA_DRAWABLE);
- PyModule_AddIntConstant(m, "XA_FONT", XA_FONT);
- PyModule_AddIntConstant(m, "XA_INTEGER", XA_INTEGER);
- PyModule_AddIntConstant(m, "XA_PIXMAP", XA_PIXMAP);
- PyModule_AddIntConstant(m, "XA_POINT", XA_POINT);
- PyModule_AddIntConstant(m, "XA_RECTANGLE", XA_RECTANGLE);
- PyModule_AddIntConstant(m, "XA_RESOURCE_MANAGER", XA_RESOURCE_MANAGER);
- PyModule_AddIntConstant(m, "XA_RGB_COLOR_MAP", XA_RGB_COLOR_MAP);
- PyModule_AddIntConstant(m, "XA_RGB_BEST_MAP", XA_RGB_BEST_MAP);
- PyModule_AddIntConstant(m, "XA_RGB_BLUE_MAP", XA_RGB_BLUE_MAP);
- PyModule_AddIntConstant(m, "XA_RGB_DEFAULT_MAP", XA_RGB_DEFAULT_MAP);
- PyModule_AddIntConstant(m, "XA_RGB_GRAY_MAP", XA_RGB_GRAY_MAP);
- PyModule_AddIntConstant(m, "XA_RGB_GREEN_MAP", XA_RGB_GREEN_MAP);
- PyModule_AddIntConstant(m, "XA_RGB_RED_MAP", XA_RGB_RED_MAP);
- PyModule_AddIntConstant(m, "XA_STRING", XA_STRING);
- PyModule_AddIntConstant(m, "XA_VISUALID", XA_VISUALID);
- PyModule_AddIntConstant(m, "XA_WINDOW", XA_WINDOW);
- PyModule_AddIntConstant(m, "XA_WM_COMMAND", XA_WM_COMMAND);
- PyModule_AddIntConstant(m, "XA_WM_HINTS", XA_WM_HINTS);
- PyModule_AddIntConstant(m, "XA_WM_CLIENT_MACHINE", XA_WM_CLIENT_MACHINE);
- PyModule_AddIntConstant(m, "XA_WM_ICON_NAME", XA_WM_ICON_NAME);
- PyModule_AddIntConstant(m, "XA_WM_ICON_SIZE", XA_WM_ICON_SIZE);
- PyModule_AddIntConstant(m, "XA_WM_NAME", XA_WM_NAME);
- PyModule_AddIntConstant(m, "XA_WM_NORMAL_HINTS", XA_WM_NORMAL_HINTS);
- PyModule_AddIntConstant(m, "XA_WM_SIZE_HINTS", XA_WM_SIZE_HINTS);
- PyModule_AddIntConstant(m, "XA_WM_ZOOM_HINTS", XA_WM_ZOOM_HINTS);
- PyModule_AddIntConstant(m, "XA_MIN_SPACE", XA_MIN_SPACE);
- PyModule_AddIntConstant(m, "XA_NORM_SPACE", XA_NORM_SPACE);
- PyModule_AddIntConstant(m, "XA_MAX_SPACE", XA_MAX_SPACE);
- PyModule_AddIntConstant(m, "XA_END_SPACE", XA_END_SPACE);
- PyModule_AddIntConstant(m, "XA_SUPERSCRIPT_X", XA_SUPERSCRIPT_X);
- PyModule_AddIntConstant(m, "XA_SUPERSCRIPT_Y", XA_SUPERSCRIPT_Y);
- PyModule_AddIntConstant(m, "XA_SUBSCRIPT_X", XA_SUBSCRIPT_X);
- PyModule_AddIntConstant(m, "XA_SUBSCRIPT_Y", XA_SUBSCRIPT_Y);
- PyModule_AddIntConstant(m, "XA_UNDERLINE_POSITION", XA_UNDERLINE_POSITION);
- PyModule_AddIntConstant(m, "XA_UNDERLINE_THICKNESS", XA_UNDERLINE_THICKNESS);
- PyModule_AddIntConstant(m, "XA_STRIKEOUT_ASCENT", XA_STRIKEOUT_ASCENT);
- PyModule_AddIntConstant(m, "XA_STRIKEOUT_DESCENT", XA_STRIKEOUT_DESCENT);
- PyModule_AddIntConstant(m, "XA_ITALIC_ANGLE", XA_ITALIC_ANGLE);
- PyModule_AddIntConstant(m, "XA_X_HEIGHT", XA_X_HEIGHT);
- PyModule_AddIntConstant(m, "XA_QUAD_WIDTH", XA_QUAD_WIDTH);
- PyModule_AddIntConstant(m, "XA_WEIGHT", XA_WEIGHT);
- PyModule_AddIntConstant(m, "XA_POINT_SIZE", XA_POINT_SIZE);
- PyModule_AddIntConstant(m, "XA_RESOLUTION", XA_RESOLUTION);
- PyModule_AddIntConstant(m, "XA_COPYRIGHT", XA_COPYRIGHT);
- PyModule_AddIntConstant(m, "XA_NOTICE", XA_NOTICE);
- PyModule_AddIntConstant(m, "XA_FONT_NAME", XA_FONT_NAME);
- PyModule_AddIntConstant(m, "XA_FAMILY_NAME", XA_FAMILY_NAME);
- PyModule_AddIntConstant(m, "XA_FULL_NAME", XA_FULL_NAME);
- PyModule_AddIntConstant(m, "XA_CAP_HEIGHT", XA_CAP_HEIGHT);
- PyModule_AddIntConstant(m, "XA_WM_CLASS", XA_WM_CLASS);
- PyModule_AddIntConstant(m, "XA_WM_TRANSIENT_FOR", XA_WM_TRANSIENT_FOR);
- PyModule_AddIntConstant(m, "XA_LAST_PREDEFINED", XA_LAST_PREDEFINED);
-
return 0;
}
View
3 xcb/constant.h
@@ -1,9 +1,6 @@
#ifndef XPYB_CONSTANT_H
#define XPYB_CONSTANT_H
-#include <X11/X.h>
-#include <X11/Xatom.h>
-
int xpybConstant_modinit(PyObject *m);
#endif
View
7 xcb/cookie.c
@@ -23,7 +23,10 @@ xpybCookie_new(PyTypeObject *self, PyObject *args, PyObject *kw)
static void
xpybCookie_dealloc(xpybCookie *self)
{
- Py_CLEAR(self->reply);
+ if (self->conn->conn)
+ xcb_discard_reply(self->conn->conn, self->cookie.sequence);
+
+ Py_CLEAR(self->reply_type);
Py_CLEAR(self->request);
Py_CLEAR(self->conn);
self->ob_type->tp_free((PyObject *)self);
@@ -88,7 +91,7 @@ xpybCookie_reply(xpybCookie *self, PyObject *args)
goto err1;
/* Call the reply type object to get a new xcb.Reply instance */
- reply = PyObject_CallFunctionObjArgs((PyObject *)self->reply, shim, NULL);
+ reply = PyObject_CallFunctionObjArgs((PyObject *)self->reply_type, shim, NULL);
Py_DECREF(shim);
return reply;
err1:
View
2 xcb/cookie.h
@@ -9,7 +9,7 @@ typedef struct {
PyObject_HEAD
xpybConn *conn;
xpybRequest *request;
- PyTypeObject *reply;
+ PyTypeObject *reply_type;
xcb_void_cookie_t cookie;
} xpybCookie;
View
2 xcb/ext.c
@@ -134,7 +134,7 @@ xpybExt_send_request(xpybExt *self, PyObject *args, PyObject *kw)
/* Set up cookie */
Py_INCREF(cookie->conn = self->conn);
Py_INCREF((PyObject *)(cookie->request = request));
- Py_XINCREF(cookie->reply = reply);
+ Py_XINCREF(cookie->reply_type = reply);
cookie->cookie.sequence = seq;
Py_INCREF(cookie);
View
86 xcb/module.c
@@ -1,3 +1,4 @@
+#include "xpyb.h"
#include "module.h"
#include "except.h"
#include "constant.h"
@@ -32,85 +33,21 @@ PyObject *xpybModule_ext_errors;
/*
- * Helpers
- */
-
-static int
-xpyb_parse_auth(const char *authstr, int authlen, xcb_auth_info_t *auth)
-{
- int i = 0;
-
- while (i < authlen && authstr[i] != ':')
- i++;
-
- if (i >= authlen) {
- PyErr_SetString(xpybExcept_base, "Auth string must take the form '<name>:<data>'.");
- return -1;
- }
-
- auth->name = (char *)authstr;
- auth->namelen = i++;
- auth->data = (char *)authstr + i;
- auth->datalen = authlen - i;
- return 0;
-}
-
-/*
* Module functions
*/
static PyObject *
xpyb_connect(PyObject *self, PyObject *args, PyObject *kw)
{
- static char *kwlist[] = { "display", "fd", "auth", NULL };
- const char *displayname = NULL, *authstr = NULL;
- xcb_auth_info_t auth, *authptr = NULL;
- xpybConn *conn;
- int authlen, fd = -1;
-
- /* Make sure core was set. */
- if (xpybModule_core == NULL) {
- PyErr_SetString(xpybExcept_base, "No core protocol object has been set. Did you import xcb.xproto?");
- return NULL;
- }
-
- /* Parse arguments and allocate new connection object */
- if (!PyArg_ParseTupleAndKeywords(args, kw, "|ziz#", kwlist, &displayname,
- &fd, &authstr, &authlen))
- return NULL;
+ xpybConn *conn = PyObject_New(xpybConn, &xpybConn_type);
- conn = xpybConn_create((PyObject *)xpybModule_core);
if (conn == NULL)
return NULL;
- /* Set up authorization */
- if (authstr != NULL) {
- if (xpyb_parse_auth(authstr, authlen, &auth) < 0)
- goto err;
- authptr = &auth;
- }
-
- /* Connect to display */
- if (fd >= 0)
- conn->conn = xcb_connect_to_fd(fd, authptr);
- else if (authptr)
- conn->conn = xcb_connect_to_display_with_auth_info(displayname, authptr, &conn->pref_screen);
- else
- conn->conn = xcb_connect(displayname, &conn->pref_screen);
-
- if (xcb_connection_has_error(conn->conn)) {
- PyErr_SetString(xpybExcept_conn, "Failed to connect to X server.");
- goto err;
- }
-
- /* Load extensions */
- if (xpybConn_setup(conn) < 0)
- goto err;
+ if(xpybConn_init(conn, args, kw) < 0)
+ return NULL;
- return (PyObject *)conn;
-err:
- Py_DECREF(conn);
- return NULL;
+ return (PyObject *) conn;
}
static PyObject *
@@ -130,10 +67,15 @@ xpyb_wrap(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "O", &obj))
return NULL;
- conn = xpybConn_create((PyObject *)xpybModule_core);
+ /* Create Python object */
+ conn = PyObject_New(xpybConn, &xpybConn_type);
if (conn == NULL)
return NULL;
+ /* Init struct of that Python object */
+ if (xpybConn_init_struct(conn, (PyObject *)xpybModule_core) < 0)
+ return NULL;
+
/* Get our pointer */
raw = PyLong_AsVoidPtr(obj);
if (!raw || PyErr_Occurred()) {
@@ -289,6 +231,9 @@ static PyMethodDef XCBMethods[] = {
{ NULL } /* terminator */
};
+static xpyb_CAPI_t CAPI = {
+ &xpybConn_type,
+};
/*
* Module init
@@ -349,4 +294,7 @@ initxcb(void)
if (xpybVoid_modinit(m) < 0)
return;
+
+ /* Export C API for other modules */
+ PyModule_AddObject(m, "CAPI", PyCObject_FromVoidPtr(&CAPI, NULL));
}
View
2 xcb/response.c
@@ -26,7 +26,7 @@ xpybResponse_getattro(PyObject *self, PyObject *obj)
if (PyObject_AsReadBuffer(self, (const void **)&data, &size) < 0)
return NULL;
- if (strcmp(name, "type") == 0)
+ if (strcmp(name, "response_type") == 0)
return Py_BuildValue("B", data->response_type);
if (strcmp(name, "sequence") == 0)
return Py_BuildValue("H", data->sequence);

0 comments on commit 1e08103

Please sign in to comment.
Something went wrong with that request. Please try again.