summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEamon Walsh <ewalsh@tycho.nsa.gov>2008-05-28 19:24:46 -0400
committerEamon Walsh <ewalsh@moss-charon.epoch.ncsc.mil>2008-05-28 19:24:46 -0400
commit2de2bb239ad196d33ebbcfd7ad001621d363d09d (patch)
tree59e33a94675244fdc4a54974aa683a16e9325a0a
parent44a1317913bb1e88b87b23488fd8cc59279d77d2 (diff)
Accept simple buffer objects as parents for new protocol objects.
-rw-r--r--src/cookie.c2
-rw-r--r--src/error.c2
-rw-r--r--src/event.c2
-rw-r--r--src/list.c15
-rw-r--r--src/protobj.c34
-rw-r--r--src/protobj.h3
6 files changed, 13 insertions, 45 deletions
diff --git a/src/cookie.c b/src/cookie.c
index f8f2ae6..d69d76b 100644
--- a/src/cookie.c
+++ b/src/cookie.c
@@ -83,7 +83,7 @@ xpybCookie_reply(xpybCookie *self, PyObject *args)
}
/* Create a shim protocol object */
- shim = xpybProtobj_create(&xpybProtobj_type, data, 32 + data->length * 4);
+ shim = PyBuffer_FromMemory(data, 32 + data->length * 4);
if (shim == NULL)
goto err1;
diff --git a/src/error.c b/src/error.c
index 9358e46..c51530b 100644
--- a/src/error.c
+++ b/src/error.c
@@ -23,7 +23,7 @@ xpybError_set(xpybConn *conn, xcb_generic_error_t *e)
except = PyTuple_GET_ITEM(conn->errors[opcode], 1);
}
- shim = xpybProtobj_create(&xpybProtobj_type, e, sizeof(*e));
+ shim = PyBuffer_FromMemory(e, sizeof(*e));
if (shim == NULL)
return 1;
diff --git a/src/event.c b/src/event.c
index 75b75fb..73acf1f 100644
--- a/src/event.c
+++ b/src/event.c
@@ -16,7 +16,7 @@ xpybEvent_create(xpybConn *conn, xcb_generic_event_t *e)
if (opcode < conn->events_len && conn->events[opcode] != NULL)
type = conn->events[opcode];
- shim = xpybProtobj_create(&xpybProtobj_type, e, sizeof(*e));
+ shim = PyBuffer_FromMemory(e, sizeof(*e));
if (shim == NULL)
return NULL;
diff --git a/src/list.c b/src/list.c
index f43bc91..6fe8aa3 100644
--- a/src/list.c
+++ b/src/list.c
@@ -47,12 +47,10 @@ xpybList_init(xpybList *self, PyObject *args, PyObject *kw)
{
static char *kwlist[] = { "parent", "offset", "length", "type", "size", NULL };
Py_ssize_t i, datalen, cur, offset, length, size = -1;
- xpybProtobj *parent, *sobj;
- PyObject *type, *obj, *arglist;
+ PyObject *parent, *type, *obj, *arglist;
const char *data;
- if (!PyArg_ParseTupleAndKeywords(args, kw, "O!iiO|i", kwlist,
- &xpybProtobj_type, &parent,
+ if (!PyArg_ParseTupleAndKeywords(args, kw, "OiiO|i", kwlist, &parent,
&offset, &length, &type, &size))
return -1;
@@ -60,7 +58,7 @@ xpybList_init(xpybList *self, PyObject *args, PyObject *kw)
if (self->list == NULL)
return -1;
- if (PyObject_AsReadBuffer(parent->buf, (const void **)&data, &datalen) < 0)
+ if (PyObject_AsReadBuffer(parent, (const void **)&data, &datalen) < 0)
return -1;
if (length * size - offset > datalen) {
PyErr_SetString(xpybExcept_base, "Protocol object buffer too short.");
@@ -98,12 +96,11 @@ xpybList_init(xpybList *self, PyObject *args, PyObject *kw)
return -1;
}
- sobj = (xpybProtobj *)self;
- sobj->buf = PyBuffer_FromObject(parent->buf, offset, cur);
- if (sobj->buf == NULL)
+ obj = PyBuffer_FromObject(parent, offset, cur);
+ if (obj == NULL)
return -1;
- Py_INCREF(sobj->parent = (PyObject *)parent);
+ ((xpybProtobj *)self)->buf = obj;
return 0;
}
diff --git a/src/protobj.c b/src/protobj.c
index 685d826..a51a440 100644
--- a/src/protobj.c
+++ b/src/protobj.c
@@ -2,29 +2,6 @@
#include "except.h"
#include "protobj.h"
-/*
- * Helpers
- */
-
-PyObject *
-xpybProtobj_create(PyTypeObject *type, void *data, Py_ssize_t size)
-{
- xpybProtobj *obj;
- PyObject *buf;
-
- obj = PyObject_New(xpybProtobj, type);
- if (obj == NULL)
- return NULL;
- buf = PyBuffer_FromMemory(data, size);
- if (buf == NULL)
- return NULL;
-
- obj->parent = NULL;
- obj->buf = buf;
- obj->data = data;
- return (PyObject *)obj;
-}
-
/*
* Infrastructure
@@ -41,18 +18,16 @@ xpybProtobj_init(xpybProtobj *self, PyObject *args, PyObject *kw)
{
static char *kwlist[] = { "parent", "offset", "size", NULL };
Py_ssize_t offset = 0, size = Py_END_OF_BUFFER;
- xpybProtobj *parent;
+ PyObject *parent;
- if (!PyArg_ParseTupleAndKeywords(args, kw, "O!|ii", kwlist,
- &xpybProtobj_type, &parent,
- &offset, &size))
+ if (!PyArg_ParseTupleAndKeywords(args, kw, "O|ii", kwlist,
+ &parent, &offset, &size))
return -1;
- self->buf = PyBuffer_FromObject(parent->buf, offset, size);
+ self->buf = PyBuffer_FromObject(parent, offset, size);
if (self->buf == NULL)
return -1;
- Py_INCREF(self->parent = (PyObject *)parent);
return 0;
}
@@ -60,7 +35,6 @@ static void
xpybProtobj_dealloc(xpybProtobj *self)
{
Py_CLEAR(self->buf);
- Py_CLEAR(self->parent);
free(self->data);
self->ob_type->tp_free((PyObject *)self);
}
diff --git a/src/protobj.h b/src/protobj.h
index 3bba660..2f8a1a8 100644
--- a/src/protobj.h
+++ b/src/protobj.h
@@ -3,15 +3,12 @@
typedef struct {
PyObject_HEAD
- PyObject *parent;
PyObject *buf;
void *data;
} xpybProtobj;
extern PyTypeObject xpybProtobj_type;
-PyObject *xpybProtobj_create(PyTypeObject *type, void *data, Py_ssize_t size);
-
int xpybProtobj_modinit(PyObject *m);
#endif