Merge branch '1.3.x' into HEAD
[catacomb-python] / buffer.c
CommitLineData
46e6ad89 1/* -*-c-*-
2 *
46e6ad89 3 * Reading and writing buffers of stuff
4 *
5 * (c) 2005 Straylight/Edgeware
6 */
7
b2687a0a 8/*----- Licensing notice --------------------------------------------------*
46e6ad89 9 *
10 * This file is part of the Python interface to Catacomb.
11 *
12 * Catacomb/Python is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
b2687a0a 16 *
46e6ad89 17 * Catacomb/Python is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
b2687a0a 21 *
46e6ad89 22 * You should have received a copy of the GNU General Public License
23 * along with Catacomb/Python; if not, write to the Free Software Foundation,
24 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 */
26
27/*----- Header files ------------------------------------------------------*/
28
29#include "catacomb-python.h"
30
31/*----- Data structures ---------------------------------------------------*/
32
33typedef struct buf_pyobj {
34 PyObject_HEAD
35 buf b;
0463996f 36 PyObject *sub;
46e6ad89 37} buf_pyobj;
38
39static PyTypeObject *rbuf_pytype, *wbuf_pytype;
40#define RBUF_PYCHECK(o) PyObject_TypeCheck((o), rbuf_pytype)
41#define WBUF_PYCHECK(o) PyObject_TypeCheck((o), wbuf_pytype)
42#define BUF_B(o) (&((buf_pyobj *)(o))->b)
0463996f 43#define BUF_SUB(o) (((buf_pyobj *)(o))->sub)
46e6ad89 44
45/*----- Exceptions --------------------------------------------------------*/
46
47static PyObject *buferr;
48
49#define BUFERR() do { PyErr_SetNone(buferr); goto end; } while (0)
50
51/*----- Read buffers ------------------------------------------------------*/
52
53static PyObject *rbuf_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw)
54{
55 char *p, *q;
6b54260d 56 Py_ssize_t n;
46e6ad89 57 buf_pyobj *me = 0;
827f89d7 58 static const char *const kwlist[] = { "data", 0 };
46e6ad89 59
827f89d7 60 if (!PyArg_ParseTupleAndKeywords(arg, kw, "s#:new", KWLIST, &p, &n))
46e6ad89 61 goto end;
46e6ad89 62 q = xmalloc(n);
63 memcpy(q, p, n);
0463996f 64 me = (buf_pyobj *)ty->tp_alloc(ty, 0);
65 me->sub = 0;
46e6ad89 66 buf_init(&me->b, q, n);
67end:
68 return ((PyObject *)me);
69}
70
71static void buf_pydealloc(PyObject *me)
0463996f 72{
73 if (BUF_SUB(me))
74 Py_DECREF(BUF_SUB(me));
75 else
76 xfree(BBASE(BUF_B(me)));
77 FREEOBJ(me);
78}
46e6ad89 79
3d8f5f7c 80static Py_ssize_t rbuf_pysegcount(PyObject *me, Py_ssize_t *nn)
46e6ad89 81 { if (nn) *nn = BSZ(BUF_B(me)); return (1); }
82
3d8f5f7c 83static Py_ssize_t rbuf_pyreadbuf(PyObject *me, Py_ssize_t seg, void **q)
f368b46e 84 { assert(seg == 0); *q = BCUR(BUF_B(me)); return (BLEFT(BUF_B(me))); }
46e6ad89 85
86static PyObject *rbmeth_skip(PyObject *me, PyObject *arg)
87{
88 size_t n;
89
90 if (!PyArg_ParseTuple(arg, "O&:skip", convszt, &n)) goto end;
91 if (!buf_get(BUF_B(me), n)) BUFERR();
92 RETURN_ME;
93end:
94 return (0);
95}
96
97static PyObject *rbmeth_get(PyObject *me, PyObject *arg)
98{
99 void *p;
100 size_t n;
101
102 if (!PyArg_ParseTuple(arg, "O&:get", convszt, &n)) goto end;
103 if ((p = buf_get(BUF_B(me), n)) == 0) BUFERR();
104 return (bytestring_pywrap(p, n));
105end:
106 return (0);
107}
108
109#define RBMETH_GETU_(n, W, w) \
110 static PyObject *rbmeth_getu##w(PyObject *me, PyObject *arg) \
111 { \
112 uint##n x; \
113 if (!PyArg_ParseTuple(arg, ":getu" #w)) goto end; \
114 if (buf_getu##w(BUF_B(me), &x)) BUFERR(); \
2da7a9c0
MW
115 if (MASK##W <= ULONG_MAX) return (getulong(x)); \
116 else { kludge64 y; ASSIGN64(y, x); return (getk64(y)); } \
46e6ad89 117 end: \
118 return (0); \
119 }
120DOUINTCONV(RBMETH_GETU_)
121
122#define RBMETH_GETBLK_(n, W, w) \
123 static PyObject *rbmeth_getblk##w(PyObject *me, PyObject *arg) \
124 { \
125 size_t sz; \
126 char *q; \
127 if (!PyArg_ParseTuple(arg, ":getblk" #w)) goto end; \
128 if ((q = buf_getmem##w(BUF_B(me), &sz)) == 0) BUFERR(); \
129 return (bytestring_pywrap(q, sz)); \
130 end: \
131 return (0); \
132 }
133BUF_DOSUFFIXES(RBMETH_GETBLK_)
134
0463996f 135#define RBMETH_GETBUF_(n, W, w) \
136 static PyObject *rbmeth_getbuf##w(PyObject *me, PyObject *arg) \
137 { \
138 buf_pyobj *b; \
139 buf bb; \
140 if (!PyArg_ParseTuple(arg, ":getbuf" #w)) goto end; \
141 if (buf_getbuf##w(BUF_B(me), &bb)) BUFERR(); \
142 b = PyObject_NEW(buf_pyobj, rbuf_pytype); \
143 b->b = bb; \
144 b->sub = me; \
145 Py_INCREF(me); \
146 return ((PyObject *)b); \
147 end: \
148 return (0); \
149 }
150BUF_DOSUFFIXES(RBMETH_GETBUF_)
151
46e6ad89 152static PyObject *rbmeth_getmp(PyObject *me, PyObject *arg)
153{
154 mp *x;
155 if (!PyArg_ParseTuple(arg, ":getmp")) goto end;
156 if ((x = buf_getmp(BUF_B(me))) == 0) BUFERR();
157 return (mp_pywrap(x));
158end:
159 return (0);
160}
161
162static PyObject *rbmeth_getgf(PyObject *me, PyObject *arg)
163{
164 mp *x;
165 if (!PyArg_ParseTuple(arg, ":getgf")) goto end;
166 if ((x = buf_getmp(BUF_B(me))) == 0) BUFERR();
167 return (gf_pywrap(x));
168end:
169 return (0);
170}
171
172static PyObject *rbmeth_getecpt(PyObject *me, PyObject *arg, PyObject *kw)
173{
174 PyObject *cobj = Py_None;
827f89d7 175 static const char *const kwlist[] = { "curve", 0 };
46e6ad89 176 ec pt = EC_INIT;
827f89d7 177 if (!PyArg_ParseTupleAndKeywords(arg, kw, "|O:getecpt", KWLIST, &cobj))
46e6ad89 178 goto end;
179 if (cobj == Py_None) cobj = (PyObject *)ecpt_pytype;
180 if (!PyType_Check(cobj) ||
181 !PyType_IsSubtype((PyTypeObject *)cobj, ecpt_pytype))
182 TYERR("expected elliptic curve type");
183 if (buf_getec(BUF_B(me), &pt)) BUFERR();
184 return (ecpt_pywrapout(cobj, &pt));
185end:
186 return (0);
187}
b2687a0a 188
46e6ad89 189static PyObject *rbmeth_getecptraw(PyObject *me, PyObject *arg)
190{
191 PyTypeObject *cobj = ecpt_pytype;
192 ec pt = EC_INIT;
193 if (!PyArg_ParseTuple(arg, "O!:getecptraw", eccurve_pytype, &cobj))
194 goto end;
195 if (ec_getraw(ECCURVE_C(cobj), BUF_B(me), &pt)) BUFERR();
196 return (ecpt_pywrapout(cobj, &pt));
197end:
198 return (0);
199}
200
201static PyObject *rbmeth_getge(PyObject *me, PyObject *arg)
202{
203 PyObject *gobj;
204 ge *x = 0;
205 if (!PyArg_ParseTuple(arg, "O!:getge", group_pytype, &gobj)) goto end;
206 x = G_CREATE(GROUP_G(gobj));
207 if (G_FROMBUF(GROUP_G(gobj), BUF_B(me), x)) BUFERR();
208 return (ge_pywrap(gobj, x));
209end:
210 if (x) G_DESTROY(GROUP_G(gobj), x);
211 return (0);
212}
213
214static PyObject *rbmeth_getgeraw(PyObject *me, PyObject *arg)
215{
216 PyObject *gobj;
217 ge *x = 0;
218 if (!PyArg_ParseTuple(arg, "O!:getgeraw", group_pytype, &gobj)) goto end;
219 x = G_CREATE(GROUP_G(gobj));
220 if (G_FROMRAW(GROUP_G(gobj), BUF_B(me), x)) BUFERR();
221 return (ge_pywrap(gobj, x));
222end:
223 if (x) G_DESTROY(GROUP_G(gobj), x);
224 return (0);
225}
226
227static PyObject *rbget_size(PyObject *me, void *hunoz)
228 { return (PyInt_FromLong(BSZ(BUF_B(me)))); }
229static PyObject *rbget_left(PyObject *me, void *hunoz)
230 { return (PyInt_FromLong(BLEFT(BUF_B(me)))); }
231static PyObject *rbget_endp(PyObject *me, void *hunoz)
232 { return (getbool(!BLEFT(BUF_B(me)))); }
0463996f 233static PyObject *rbget_offset(PyObject *me, void *hunoz)
234 { return (PyInt_FromLong(BLEN(BUF_B(me)))); }
235static int rbset_offset(PyObject *me, PyObject *x, void *hunoz)
236{
237 size_t n;
f368b46e 238 if (!x) NIERR("__del__");
0463996f 239 if (!convszt(x, &n)) goto end;
240 if (n > BSZ(BUF_B(me))) VALERR("out of range");
241 BCUR(BUF_B(me)) = BBASE(BUF_B(me)) + n;
242 return (0);
243end:
244 return (-1);
245}
46e6ad89 246
247static PyGetSetDef rbuf_pygetset[] = {
248#define GETSETNAME(op, name) rb##op##_##name
249 GET (size, "RBUF.size -> SIZE")
250 GET (left, "RBUF.left -> REMAINDER")
251 GET (endp, "RBUF.endp -> BOOL")
0463996f 252 GETSET(offset, "RBUF.offset -> OFFSET")
46e6ad89 253#undef GETSETNAME
254 { 0 }
255};
256
257static PyMethodDef rbuf_pymethods[] = {
258#define METHNAME(func) rbmeth_##func
259 METH (skip, "RBUF.skip(N)")
260 METH (get, "RBUF.get(N) -> BYTES")
261#define RBMETH_DECL_GETU_(n, W, w) \
262 METH(getu##w, "RBUF.getu" #w "() -> INT")
263 DOUINTCONV(RBMETH_DECL_GETU_)
264#define RBMETH_DECL_GETBLK_(n, W, w) \
b56be758 265 METH(getblk##w, "RBUF.getblk" #w "() -> BYTES")
46e6ad89 266 BUF_DOSUFFIXES(RBMETH_DECL_GETBLK_)
0463996f 267#define RBMETH_DECL_GETBUF_(n, W, w) \
b56be758 268 METH(getbuf##w, "RBUF.getbuf" #w "() -> RBUF'")
0463996f 269 BUF_DOSUFFIXES(RBMETH_DECL_GETBUF_)
46e6ad89 270 METH (getmp, "RBUF.getmp() -> X")
271 METH (getgf, "RBUF.getgf() -> X")
1df8d5fe 272 KWMETH(getecpt, "RBUF.getecpt([curve = None]) -> P")
46e6ad89 273 METH (getecptraw, "RBUF.getecptraw(CURVE) -> P")
274 METH (getge, "RBUF.getge(GROUP) -> X")
275 METH (getgeraw, "RBUF.getgeraw(GROUP) -> X")
276#undef METHNAME
277 { 0 }
278};
279
280static PyBufferProcs rbuf_pybuffer = {
281 rbuf_pyreadbuf, /* @bf_getreadbuffer@ */
282 0, /* @bf_getwritebuffer@ */
283 rbuf_pysegcount, /* @bf_getsegcount@ */
284 0 /* @bf_getcharbuffer@ */
285};
286
287static PyTypeObject rbuf_pytype_skel = {
288 PyObject_HEAD_INIT(0) 0, /* Header */
c461c9b3 289 "ReadBuffer", /* @tp_name@ */
46e6ad89 290 sizeof(buf_pyobj), /* @tp_basicsize@ */
291 0, /* @tp_itemsize@ */
292
293 buf_pydealloc, /* @tp_dealloc@ */
294 0, /* @tp_print@ */
295 0, /* @tp_getattr@ */
296 0, /* @tp_setattr@ */
297 0, /* @tp_compare@ */
298 0, /* @tp_repr@ */
299 0, /* @tp_as_number@ */
300 0, /* @tp_as_sequence@ */
301 0, /* @tp_as_mapping@ */
302 0, /* @tp_hash@ */
303 0, /* @tp_call@ */
304 0, /* @tp_str@ */
305 0, /* @tp_getattro@ */
306 0, /* @tp_setattro@ */
307 &rbuf_pybuffer, /* @tp_as_buffer@ */
308 Py_TPFLAGS_DEFAULT | /* @tp_flags@ */
309 Py_TPFLAGS_BASETYPE,
310
311 /* @tp_doc@ */
06cd26e8 312"ReadBuffer(STR): a read buffer.",
46e6ad89 313
314 0, /* @tp_traverse@ */
315 0, /* @tp_clear@ */
316 0, /* @tp_richcompare@ */
317 0, /* @tp_weaklistoffset@ */
318 0, /* @tp_iter@ */
963a6148 319 0, /* @tp_iternext@ */
46e6ad89 320 rbuf_pymethods, /* @tp_methods@ */
321 0, /* @tp_members@ */
322 rbuf_pygetset, /* @tp_getset@ */
323 0, /* @tp_base@ */
324 0, /* @tp_dict@ */
325 0, /* @tp_descr_get@ */
326 0, /* @tp_descr_set@ */
327 0, /* @tp_dictoffset@ */
328 0, /* @tp_init@ */
329 PyType_GenericAlloc, /* @tp_alloc@ */
330 rbuf_pynew, /* @tp_new@ */
331 0, /* @tp_free@ */
332 0 /* @tp_is_gc@ */
333};
334
335/*----- Write buffers -----------------------------------------------------*/
336
337static void ensure(PyObject *me, size_t n)
338{
339 buf *b = BUF_B(me);
340
341 if (BLEFT(b) < n) {
342 size_t nn = BSZ(b);
343 octet *p;
c4ca600f 344 size_t want = BLEN(b) + n;
46e6ad89 345 while (nn < want) nn <<= 1;
346 p = xrealloc(BBASE(b), nn, BSZ(b));
347 BCUR(b) = p + BLEN(b);
348 BLIM(b) = p + nn;
349 BBASE(b) = p;
350 }
351}
352
353static PyObject *wbuf_pynew(PyTypeObject *ty, PyObject *arg, PyObject *kw)
354{
355 char *p;
356 size_t n = 64;
357 buf_pyobj *me = 0;
827f89d7 358 static const char *const kwlist[] = { "size", 0 };
46e6ad89 359
827f89d7 360 if (!PyArg_ParseTupleAndKeywords(arg, kw, "|O&:new", KWLIST,
46e6ad89 361 convszt, &n))
362 goto end;
363 me = (buf_pyobj *)ty->tp_alloc(ty, 0);
364 p = xmalloc(n);
0463996f 365 me->sub = 0;
46e6ad89 366 buf_init(&me->b, p, n);
367end:
368 return ((PyObject *)me);
369}
370
3d8f5f7c 371static Py_ssize_t wbuf_pysegcount(PyObject *me, Py_ssize_t *nn)
46e6ad89 372 { if (nn) *nn = BLEN(BUF_B(me)); return (1); }
373
3d8f5f7c 374static Py_ssize_t wbuf_pyreadbuf(PyObject *me, Py_ssize_t seg, void **q)
46e6ad89 375 { assert(seg == 0); *q = BBASE(BUF_B(me)); return (BLEN(BUF_B(me))); }
376
377static PyObject *wbmeth_zero(PyObject *me, PyObject *arg)
378{
379 void *p;
380 size_t n;
381 if (!PyArg_ParseTuple(arg, "O&:zero", convszt, &n)) return (0);
382 ensure(me, n);
383 p = buf_get(BUF_B(me), n); assert(p && BOK(BUF_B(me)));
384 memset(p, 0, n);
385 RETURN_ME;
386}
387
388static PyObject *wbmeth_put(PyObject *me, PyObject *arg)
389{
390 void *p;
6b54260d 391 Py_ssize_t n;
46e6ad89 392 if (!PyArg_ParseTuple(arg, "s#:put", &p, &n)) return (0);
393 ensure(me, n);
a1184906 394 buf_put(BUF_B(me), p, n); assert(BOK(BUF_B(me)));
46e6ad89 395 RETURN_ME;
396}
397
398#define WBMETH_PUTU_(n, W, w) \
399 static PyObject *wbmeth_putu##w(PyObject *me, PyObject *arg) \
400 { \
401 uint##n i; \
402 if (!PyArg_ParseTuple(arg, "O&:putu" #w, convu##n, &i)) return (0); \
403 ensure(me, SZ_##n); \
404 buf_putu##w(BUF_B(me), i); assert(BOK(BUF_B(me))); \
405 RETURN_ME; \
406 }
407DOUINTCONV(WBMETH_PUTU_)
408
9fa70ff7 409#define MASKz 0
46e6ad89 410#define SZ_z 1
411#define WBMETH_PUTBLK_(n, W, w) \
412 static PyObject *wbmeth_putblk##w(PyObject *me, PyObject *arg) \
413 { \
414 char *p; \
6b54260d 415 Py_ssize_t sz; \
9fa70ff7
MW
416 if (!PyArg_ParseTuple(arg, "s#:putblk" #w, &p, &sz)) goto end; \
417 if (MASK##W && sz > MASK##W) VALERR("too large"); \
46e6ad89 418 ensure(me, sz + SZ_##n); \
419 buf_putmem##w(BUF_B(me), p, sz); assert(BOK(BUF_B(me))); \
420 RETURN_ME; \
9fa70ff7
MW
421 end: \
422 return (0); \
46e6ad89 423 }
424BUF_DOSUFFIXES(WBMETH_PUTBLK_)
425
426static PyObject *wbmeth_putmp(PyObject *me, PyObject *arg)
427{
428 mp *x = 0;
429 if (!PyArg_ParseTuple(arg, "O&:putmp", convmp, &x)) return (0);
430 ensure(me, mp_octets(x) + 2);
431 buf_putmp(BUF_B(me), x); assert(BOK(BUF_B(me)));
432 RETURN_ME;
433}
434
435static PyObject *wbmeth_putgf(PyObject *me, PyObject *arg)
436{
437 mp *x = 0;
438 if (!PyArg_ParseTuple(arg, "O&:putgf", convgf, &x)) return (0);
439 ensure(me, mp_octets(x) + 2);
440 buf_putmp(BUF_B(me), x); assert(BOK(BUF_B(me)));
441 MP_DROP(x);
442 RETURN_ME;
443}
444
445static PyObject *wbmeth_putecpt(PyObject *me, PyObject *arg)
446{
447 ec pt = EC_INIT;
448 if (!PyArg_ParseTuple(arg, "O&:putecpt", convecpt, &pt)) return (0);
f52568b4 449 ensure(me, EC_ATINF(&pt) ? 2 : 6 + mp_octets(pt.x) + mp_octets(pt.y));
46e6ad89 450 buf_putec(BUF_B(me), &pt); assert(BOK(BUF_B(me)));
451 EC_DESTROY(&pt);
452 RETURN_ME;
453}
454
455static PyObject *wbmeth_putecptraw(PyObject *me, PyObject *arg)
456{
457 PyObject *ptobj;
458 ec pt = EC_INIT;
459 if (!PyArg_ParseTuple(arg, "O!:putecptraw", ecptcurve_pytype, &ptobj))
460 return (0);
461 EC_OUT(ECPT_C(ptobj), &pt, ECPT_P(ptobj));
462 ensure(me, ECPT_C(ptobj)->f->noctets * 2 + 1);
463 ec_putraw(ECPT_C(ptobj), BUF_B(me), &pt); assert(BOK(BUF_B(me)));
464 EC_DESTROY(&pt);
465 RETURN_ME;
466}
467
468static PyObject *wbmeth_putge(PyObject *me, PyObject *arg)
469{
470 PyObject *geobj;
471 if (!PyArg_ParseTuple(arg, "O!:putge", ge_pytype, &geobj)) return (0);
472 ensure(me, GE_G(geobj)->noctets);
473 G_TOBUF(GE_G(geobj), BUF_B(me), GE_X(geobj)); assert(BOK(BUF_B(me)));
474 RETURN_ME;
475}
476
477static PyObject *wbmeth_putgeraw(PyObject *me, PyObject *arg)
478{
479 PyObject *geobj;
480 if (!PyArg_ParseTuple(arg, "O!:putgeraw", ge_pytype, &geobj)) return (0);
481 ensure(me, GE_G(geobj)->noctets);
482 G_TORAW(GE_G(geobj), BUF_B(me), GE_X(geobj)); assert(BOK(BUF_B(me)));
483 RETURN_ME;
484}
485
486static PyObject *wbget_size(PyObject *me, void *hunoz)
487 { return (PyInt_FromLong(BLEN(BUF_B(me)))); }
488
0051d10f
MW
489static PyObject *wbget_contents(PyObject *me, void *hunoz)
490 { return (bytestring_pywrap(BBASE(BUF_B(me)), BLEN(BUF_B(me)))); }
491
46e6ad89 492static PyGetSetDef wbuf_pygetset[] = {
493#define GETSETNAME(op, name) wb##op##_##name
494 GET (size, "WBUF.size -> SIZE")
0051d10f 495 GET (contents, "WBUF.contents -> STR")
46e6ad89 496#undef GETSETNAME
497 { 0 }
498};
499
500static PyMethodDef wbuf_pymethods[] = {
501#define METHNAME(func) wbmeth_##func
60ddd740 502 METH (zero, "WBUF.zero(N)")
46e6ad89 503 METH (put, "WBUF.put(BYTES)")
504#define WBMETH_DECL_PUTU_(n, W, w) \
505 METH(putu##w, "WBUF.putu" #w "(INT)")
506 DOUINTCONV(WBMETH_DECL_PUTU_)
507#define WBMETH_DECL_PUTBLK_(n, W, w) \
508 METH(putblk##w, "WBUF.putblk" #w "(BYTES)")
509 BUF_DOSUFFIXES(WBMETH_DECL_PUTBLK_)
510 METH (putmp, "WBUF.putmp(X)")
511 METH (putgf, "WBUF.putgf(X)")
b4a8c467 512 METH (putecpt, "WBUF.putecpt(P)")
46e6ad89 513 METH (putecptraw, "WBUF.putecptraw(P)")
514 METH (putge, "WBUF.putge(X)")
515 METH (putgeraw, "WBUF.putgeraw(X)")
516#undef METHNAME
517 { 0 }
518};
519
520static PyBufferProcs wbuf_pybuffer = {
521 wbuf_pyreadbuf, /* @bf_getreadbuffer@ */
522 0, /* @bf_getwritebuffer@ */
523 wbuf_pysegcount, /* @bf_getsegcount@ */
524 0 /* @bf_getcharbuffer@ */
525};
526
527static PyTypeObject wbuf_pytype_skel = {
528 PyObject_HEAD_INIT(0) 0, /* Header */
c461c9b3 529 "WriteBuffer", /* @tp_name@ */
46e6ad89 530 sizeof(buf_pyobj), /* @tp_basicsize@ */
531 0, /* @tp_itemsize@ */
532
533 buf_pydealloc, /* @tp_dealloc@ */
534 0, /* @tp_print@ */
535 0, /* @tp_getattr@ */
536 0, /* @tp_setattr@ */
537 0, /* @tp_compare@ */
538 0, /* @tp_repr@ */
539 0, /* @tp_as_number@ */
540 0, /* @tp_as_sequence@ */
541 0, /* @tp_as_mapping@ */
542 0, /* @tp_hash@ */
543 0, /* @tp_call@ */
544 0, /* @tp_str@ */
545 0, /* @tp_getattro@ */
546 0, /* @tp_setattro@ */
547 &wbuf_pybuffer, /* @tp_as_buffer@ */
548 Py_TPFLAGS_DEFAULT | /* @tp_flags@ */
549 Py_TPFLAGS_BASETYPE,
550
551 /* @tp_doc@ */
06cd26e8 552"WriteBuffer([size = ?]): a write buffer.",
46e6ad89 553
554 0, /* @tp_traverse@ */
555 0, /* @tp_clear@ */
556 0, /* @tp_richcompare@ */
557 0, /* @tp_weaklistoffset@ */
558 0, /* @tp_iter@ */
963a6148 559 0, /* @tp_iternext@ */
46e6ad89 560 wbuf_pymethods, /* @tp_methods@ */
561 0, /* @tp_members@ */
562 wbuf_pygetset, /* @tp_getset@ */
563 0, /* @tp_base@ */
564 0, /* @tp_dict@ */
565 0, /* @tp_descr_get@ */
566 0, /* @tp_descr_set@ */
567 0, /* @tp_dictoffset@ */
568 0, /* @tp_init@ */
569 PyType_GenericAlloc, /* @tp_alloc@ */
570 wbuf_pynew, /* @tp_new@ */
571 0, /* @tp_free@ */
572 0 /* @tp_is_gc@ */
573};
574
575/*----- Initialization ----------------------------------------------------*/
576
577void buffer_pyinit(void)
578{
579 INITTYPE(rbuf, root);
580 INITTYPE(wbuf, root);
581}
582
583void buffer_pyinsert(PyObject *mod)
584{
585 INSEXC("BufferError", buferr, PyExc_Exception, 0);
586 INSERT("ReadBuffer", rbuf_pytype);
587 INSERT("WriteBuffer", wbuf_pytype);
588}
589
590/*----- That's all, folks -------------------------------------------------*/