buffer.c: Publish the internal structure of buffer objects.
[catacomb-python] / catacomb-python.h
index c3b120d..9b60ce4 100644 (file)
@@ -158,6 +158,27 @@ extern PyObject *mexp_common(PyObject *, PyObject *, size_t,
 PyObject *bytestring_pywrap(const void *, size_t);
 PyObject *bytestring_pywrapbuf(buf *);
 
+/*----- Buffers -----------------------------------------------------------*/
+
+typedef struct buf_pyobj {
+  PyObject_HEAD
+  buf b;
+  PyObject *sub;
+  unsigned lk;
+} buf_pyobj;
+
+extern PyTypeObject *rbuf_pytype, *wbuf_pytype;
+#define RBUF_PYCHECK(o) PyObject_TypeCheck((o), rbuf_pytype)
+#define WBUF_PYCHECK(o) PyObject_TypeCheck((o), wbuf_pytype)
+#define BUF_B(o) (&((buf_pyobj *)(o))->b)
+#define BUF_SUB(o) (((buf_pyobj *)(o))->sub)
+#define BUF_LK(o) (((buf_pyobj *)(o))->lk)
+
+extern PyObject *buferr;
+#define BUFERR(str) do { PyErr_SetString(buferr, str); goto end; } while (0)
+
+extern int ensurebuf(PyObject *, size_t);
+
 /*----- Multiprecision arithmetic -----------------------------------------*/
 
 typedef struct mp_pyobj {