-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_luxem.c
677 lines (595 loc) · 18.8 KB
/
_luxem.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
#include <Python.h>
#include "c/luxem_rawread.h"
#include "c/luxem_rawwrite.h"
#include <assert.h>
#if PY_MAJOR_VERSION >= 3
#define WRAP_STRING_FROM(pointer, size) PyUnicode_FromStringAndSize(pointer, size)
#define WRAP_STRING_TO(o, pointer, size) do { *pointer = PyUnicode_AsUTF8AndSize(o, (Py_ssize_t *)size); } while (0)
#define WRAP_STRING_CHECK(o) PyUnicode_Check(o)
#define WRAP_BYTES_FROM(pointer, size) PyBytes_FromStringAndSize(pointer, size)
#define WRAP_BYTES_TO(o, pointer, size) PyBytes_AsStringAndSize(o, pointer, (Py_ssize_t *)size)
#define WRAP_BYTES_CHECK(o) PyBytes_Check(o)
#define WRAP_INT_FROM_SIZET(o) PyLong_FromSize_t(o)
#define WRAP_FILE_CHECK(o) compat_file_check(o)
#define WRAP_FILE_INC(o) do {} while (0)
#define WRAP_FILE_DEC(o) do {} while (0)
#define WRAP_FILE_TO(o, mode) compat_file_file(o, mode)
static luxem_bool_t compat_file_check(PyObject *o)
{
_Py_IDENTIFIER(fileno);
return PyLong_Check(o) || _PyObject_HasAttrId(o, &PyId_fileno);
}
static FILE* compat_file_file(PyObject *o, char const *mode)
{
int fd = PyObject_AsFileDescriptor(o);
if (fd == -1) return NULL;
FILE* out = fdopen(fd, mode);
if (out == NULL)
PyErr_SetString(PyExc_TypeError, "Could not access file.");
return out;
}
#else
#define WRAP_STRING_FROM(pointer, size) PyString_FromStringAndSize(pointer, size)
#define WRAP_STRING_TO(o, pointer, size) PyString_AsStringAndSize(o, pointer, size)
#define WRAP_STRING_CHECK(o) PyString_Check(o)
#define WRAP_BYTES_FROM(pointer, size) PyString_FromStringAndSize(pointer, size)
#define WRAP_BYTES_TO(o, pointer, size) PyString_AsStringAndSize(o, pointer, size)
#define WRAP_BYTES_CHECK(o) PyString_Check(o)
#define WRAP_INT_FROM_SIZET(o) PyInt_FromSize_t(o)
#define WRAP_FILE_CHECK(o) PyFile_Check(o)
#define WRAP_FILE_INC(o) PyFile_IncUseCount((PyFileObject *)o)
#define WRAP_FILE_DEC(o) PyFile_DecUseCount((PyFileObject *)o)
#define WRAP_FILE_TO(o, mode) PyFile_AsFile(o)
#endif
/* ************************************************************************** */
static char const exception_marker;
/* Reader */
/**********/
typedef struct {
PyObject_HEAD
struct luxem_rawread_context_t *context;
PyObject *object_begin;
PyObject *object_end;
PyObject *array_begin;
PyObject *array_end;
PyObject *key;
PyObject *type;
PyObject *primitive;
PyThreadState *thread_state;
} Reader;
#define TRANSLATE_VOID_CALLBACK(name) \
static luxem_bool_t translate_rawread_##name(struct luxem_rawread_context_t *context, Reader *user_data) \
{ \
PyObject *arguments = Py_BuildValue("()"); \
if (!arguments) return luxem_false; \
{ \
PyObject *result = PyEval_CallObject(user_data->name, arguments); \
Py_DECREF(arguments); \
if (!result) \
{ \
luxem_rawread_get_error(context)->pointer = &exception_marker; \
luxem_rawread_get_error(context)->length = 0; \
return luxem_false; \
} \
Py_DECREF(result); \
} \
return luxem_true; \
}
TRANSLATE_VOID_CALLBACK(object_begin)
TRANSLATE_VOID_CALLBACK(object_end)
TRANSLATE_VOID_CALLBACK(array_begin)
TRANSLATE_VOID_CALLBACK(array_end)
#define TRANSLATE_STRING_CALLBACK(name) \
static luxem_bool_t translate_rawread_##name(struct luxem_rawread_context_t *context, Reader *user_data, struct luxem_string_t const *string) \
{ \
PyObject *prearguments = WRAP_STRING_FROM(string->pointer == 0 ? (char *) 1 : string->pointer, string->length); \
PyObject *arguments = Py_BuildValue("(O)", prearguments); \
Py_DECREF(prearguments); \
if (!arguments) return luxem_false; \
{ \
PyObject *result = PyEval_CallObject(user_data->name, arguments); \
Py_DECREF(arguments); \
if (!result) \
{ \
luxem_rawread_get_error(context)->pointer = &exception_marker; \
luxem_rawread_get_error(context)->length = 0; \
return luxem_false; \
} \
Py_DECREF(result); \
} \
return luxem_true; \
}
TRANSLATE_STRING_CALLBACK(key)
TRANSLATE_STRING_CALLBACK(type)
TRANSLATE_STRING_CALLBACK(primitive)
static PyObject *Reader_new(PyTypeObject *type, PyObject *positional_args, PyObject *named_args)
{
Reader *self = (Reader *)type->tp_alloc(type, 0);
if (self != NULL)
{
self->context = luxem_rawread_construct();
if (!self->context)
{
Py_DECREF(self);
return NULL;
}
{
struct luxem_rawread_callbacks_t *callbacks = luxem_rawread_callbacks(self->context);
callbacks->user_data = self;
callbacks->object_begin = (luxem_rawread_void_callback_t)translate_rawread_object_begin;
callbacks->object_end = (luxem_rawread_void_callback_t)translate_rawread_object_end;
callbacks->array_begin = (luxem_rawread_void_callback_t)translate_rawread_array_begin;
callbacks->array_end = (luxem_rawread_void_callback_t)translate_rawread_array_end;
callbacks->key = (luxem_rawread_string_callback_t)translate_rawread_key;
callbacks->type = (luxem_rawread_string_callback_t)translate_rawread_type;
callbacks->primitive = (luxem_rawread_string_callback_t)translate_rawread_primitive;
}
self->object_begin = NULL;
self->object_end = NULL;
self->array_begin = NULL;
self->array_end = NULL;
self->key = NULL;
self->type = NULL;
self->primitive = NULL;
self->thread_state = NULL;
}
return (PyObject *)self;
}
static int Reader_init(Reader *self, PyObject *positional_args, PyObject *named_args)
{
static char *named_args_list[] =
{
"object_begin",
"object_end",
"array_begin",
"array_end",
"key",
"type",
"primitive",
NULL
};
if (!PyArg_ParseTupleAndKeywords(
positional_args,
named_args,
"OOOOOOO",
named_args_list,
&self->object_begin,
&self->object_end,
&self->array_begin,
&self->array_end,
&self->key,
&self->type,
&self->primitive))
return -1;
Py_INCREF(self->object_begin);
Py_INCREF(self->object_end);
Py_INCREF(self->array_begin);
Py_INCREF(self->array_end);
Py_INCREF(self->key);
Py_INCREF(self->type);
Py_INCREF(self->primitive);
return 0;
}
static void Reader_dealloc(Reader *self)
{
luxem_rawread_destroy(self->context);
Py_XDECREF(self->object_begin);
Py_XDECREF(self->object_end);
Py_XDECREF(self->array_begin);
Py_XDECREF(self->array_end);
Py_XDECREF(self->key);
Py_XDECREF(self->type);
Py_XDECREF(self->primitive);
Py_TYPE(self)->tp_free((PyObject*)self);
}
void format_context_error(struct luxem_rawread_context_t *context)
{
if (luxem_rawread_get_error(context)->pointer != &exception_marker)
{
assert(luxem_rawread_get_error(context)->length > 0);
{
struct luxem_string_t const *error = luxem_rawread_get_error(context);
char const *error_format = "%.*s [offset %lu]";
int formatted_error_size = snprintf(NULL, 0, error_format, error->length, error->pointer, luxem_rawread_get_position(context));
assert(formatted_error_size >= 0);
if (formatted_error_size < 0)
{
PyErr_SetString(PyExc_ValueError, "Encountered an exception, then encountered an error while trying to format the exception.");
}
else
{
formatted_error_size += 1; /* Was returning one too small */
{
char *formatted_error = malloc(formatted_error_size);
snprintf(formatted_error, formatted_error_size, error_format, error->length, error->pointer, luxem_rawread_get_position(context));
PyErr_SetString(PyExc_ValueError, formatted_error);
free(formatted_error);
}
}
}
}
else
{
/* Pass through python exception */
assert(luxem_rawread_get_error(context)->length == 0);
}
}
void feed_unlock_gil(struct luxem_rawread_context_t *context, Reader *self)
{
assert(!self->thread_state);
self->thread_state = PyEval_SaveThread();
}
void feed_lock_gil(struct luxem_rawread_context_t *context, Reader *self)
{
assert(self->thread_state);
PyEval_RestoreThread(self->thread_state);
self->thread_state = NULL;
}
static PyObject *Reader_feed(Reader *self, PyObject *positional_args, PyObject *named_args)
{
PyObject *data;
luxem_bool_t finish = luxem_true;
static char *named_args_list[] =
{
"data",
"finish",
NULL
};
if (!PyArg_ParseTupleAndKeywords(
positional_args,
named_args,
"O|b",
named_args_list,
&data,
&finish))
return NULL;
if (WRAP_BYTES_CHECK(data))
{
struct luxem_string_t string;
size_t eaten = 0;
WRAP_BYTES_TO(data, (char **)&string.pointer, &string.length);
if (!luxem_rawread_feed(self->context, &string, &eaten, finish))
{
format_context_error(self->context);
return NULL;
}
return WRAP_INT_FROM_SIZET(eaten);
}
else if (WRAP_FILE_CHECK(data))
{
luxem_bool_t success;
FILE *file = WRAP_FILE_TO(data, "r");
WRAP_FILE_INC(data);
success = luxem_rawread_feed_file(self->context, file, feed_unlock_gil, feed_lock_gil);
WRAP_FILE_DEC(data);
if (!success)
{
format_context_error(self->context);
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
}
else
{
PyErr_SetString(PyExc_TypeError, "luxem.RawReader.feed requires a single bytes or binary file argument.");
return NULL;
}
}
static PyMethodDef Reader_methods[] =
{
{
"feed",
(PyCFunction)Reader_feed,
METH_VARARGS | METH_KEYWORDS,
"Stream from bytes or binary file argument."
},
{NULL}
};
static PyTypeObject ReaderType = {PyObject_HEAD_INIT(NULL) 0};
static luxem_bool_t ReaderType_init(void)
{
ReaderType.tp_name = "luxem.RawReader";
ReaderType.tp_basicsize = sizeof(Reader);
ReaderType.tp_dealloc = (destructor)Reader_dealloc;
ReaderType.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
ReaderType.tp_doc = "Decodes luxem data";
ReaderType.tp_methods = Reader_methods;
ReaderType.tp_init = (initproc)Reader_init;
ReaderType.tp_new = Reader_new;
return PyType_Ready(&ReaderType) >= 0;
}
/* ************************************************************************** */
/* luxem writer */
/****************/
typedef struct {
PyObject_HEAD
struct luxem_rawwrite_context_t *context;
PyObject *target;
FILE *file;
} Writer;
static luxem_bool_t translate_rawwrite_write(struct luxem_rawwrite_context_t *context, Writer *user_data, struct luxem_string_t const *string)
{
#if PY_MAJOR_VERSION >= 3
PyObject *arguments = Py_BuildValue("(y#)", string->pointer, string->length);
#else
PyObject *arguments = Py_BuildValue("(s#)", string->pointer, string->length);
#endif
if (!arguments) return luxem_false;
{
PyObject *result = PyEval_CallObject(user_data->target, arguments);
Py_DECREF(arguments);
if (!result)
{
luxem_rawwrite_get_error(context)->pointer = &exception_marker;
luxem_rawwrite_get_error(context)->length = 0;
return luxem_false;
}
Py_DECREF(result);
}
return luxem_true;
}
static PyObject *Writer_new(PyTypeObject *type, PyObject *positional_args, PyObject *named_args)
{
Writer *self = (Writer *)type->tp_alloc(type, 0);
if (self != NULL)
{
self->context = luxem_rawwrite_construct();
if (!self->context)
{
Py_DECREF(self);
return NULL;
}
self->target = NULL;
self->file = NULL;
}
return (PyObject *)self;
}
static int Writer_init(Writer *self, PyObject *positional_args, PyObject *named_args)
{
luxem_bool_t pretty = luxem_false, use_spaces = luxem_false;
int indent_multiple = 1;
static char *named_args_list[] =
{
"target",
"pretty",
"use_spaces",
"indent_multiple",
NULL
};
if (!PyArg_ParseTupleAndKeywords(
positional_args,
named_args,
"|Obbi",
named_args_list,
&self->target,
&pretty,
&use_spaces,
&indent_multiple))
return -1;
if (self->target)
{
Py_INCREF(self->target);
if (WRAP_FILE_CHECK(self->target))
{
self->file = WRAP_FILE_TO(self->target, "w");
if (self->file == NULL) return -1;
WRAP_FILE_INC(self->file);
luxem_rawwrite_set_file_out(self->context, self->file);
}
else
luxem_rawwrite_set_write_callback(self->context, (luxem_rawwrite_write_callback_t)translate_rawwrite_write, self);
}
else luxem_rawwrite_set_buffer_out(self->context);
if (pretty)
luxem_rawwrite_set_pretty(self->context, use_spaces ? ' ' : '\t', indent_multiple);
return 0;
}
static void Writer_dealloc(Writer *self)
{
luxem_rawwrite_destroy(self->context);
if (self->file != NULL)
{
fflush(self->file);
WRAP_FILE_DEC(self->file);
}
Py_XDECREF(self->target);
Py_TYPE(self)->tp_free((PyObject*)self);
}
static PyObject *translate_void_method(Writer *self, luxem_bool_t (*method)(struct luxem_rawwrite_context_t *))
{
if (!method(self->context))
{
if (luxem_rawwrite_get_error(self->context)->pointer != &exception_marker)
{
struct luxem_string_t const *error = luxem_rawwrite_get_error(self->context);
assert(error->length > 0);
PyErr_SetObject(PyExc_ValueError, WRAP_STRING_FROM(error->pointer, error->length));
}
else
{
/* Pass through python exception */
assert(luxem_rawwrite_get_error(self->context)->length == 0);
}
return NULL;
}
Py_INCREF((PyObject *)self);
return (PyObject *)self;
}
static PyObject *Writer_object_begin(Writer *self) { return translate_void_method(self, luxem_rawwrite_object_begin); }
static PyObject *Writer_object_end(Writer *self) { return translate_void_method(self, luxem_rawwrite_object_end); }
static PyObject *Writer_array_begin(Writer *self) { return translate_void_method(self, luxem_rawwrite_array_begin); }
static PyObject *Writer_array_end(Writer *self) { return translate_void_method(self, luxem_rawwrite_array_end); }
static PyObject *translate_string_method(Writer *self, PyObject *positional_args, luxem_bool_t (*method)(struct luxem_rawwrite_context_t *, struct luxem_string_t const *), char const *badargs)
{
PyObject *argument;
if (!PyArg_ParseTuple(
positional_args,
"O",
&argument))
return NULL;
if (WRAP_STRING_CHECK(argument))
{
struct luxem_string_t string;
WRAP_STRING_TO(argument, (char **)&string.pointer, &string.length);
if (!method(self->context, &string))
{
if (luxem_rawwrite_get_error(self->context)->pointer != &exception_marker)
{
struct luxem_string_t const *error = luxem_rawwrite_get_error(self->context);
assert(error->length > 0);
PyErr_SetObject(PyExc_ValueError, WRAP_STRING_FROM(error->pointer, error->length));
}
else
{
/* Pass through python exception */
assert(luxem_rawwrite_get_error(self->context)->length == 0);
}
return NULL;
}
}
else
{
PyErr_SetString(PyExc_TypeError, badargs);
return NULL;
}
Py_INCREF((PyObject *)self);
return (PyObject *)self;
}
static PyObject *Writer_key(Writer *self, PyObject *positional_args)
{ return translate_string_method(self, positional_args, luxem_rawwrite_key, "luxem.RawWriter.key requires a single string argument."); }
static PyObject *Writer_type(Writer *self, PyObject *positional_args)
{ return translate_string_method(self, positional_args, luxem_rawwrite_type, "luxem.RawWriter.type requires a single string argument."); }
static PyObject *Writer_primitive(Writer *self, PyObject *positional_args)
{ return translate_string_method(self, positional_args, luxem_rawwrite_primitive, "luxem.RawWriter.primitive requires a single string argument."); }
static PyObject *Writer_dump(Writer *self)
{
if (self->target)
{
PyErr_SetString(PyExc_TypeError, "luxem.RawWriter.dump can only be used if not using a custom serialize callback for serializing to file.");
return NULL;
}
else
{
struct luxem_string_t *rendered = luxem_rawwrite_buffer_render(self->context);
if (!rendered)
{
struct luxem_string_t const *error = luxem_rawwrite_get_error(self->context);
assert(error->length > 0);
PyErr_SetObject(PyExc_ValueError, WRAP_STRING_FROM(error->pointer, error->length));
return NULL;
}
PyObject *out = WRAP_BYTES_FROM(rendered->pointer, rendered->length);
free(rendered);
return out;
}
}
static PyMethodDef Writer_methods[] =
{
{"object_begin", (PyCFunction)Writer_object_begin, METH_NOARGS, "Start a new object."},
{"object_end", (PyCFunction)Writer_object_end, METH_NOARGS, "End current object."},
{"array_begin", (PyCFunction)Writer_array_begin, METH_NOARGS, "Start a new array."},
{"array_end", (PyCFunction)Writer_array_end, METH_NOARGS, "End current array."},
{"key", (PyCFunction)Writer_key, METH_VARARGS, "Write a key."},
{"type", (PyCFunction)Writer_type, METH_VARARGS, "Write a type."},
{"primitive", (PyCFunction)Writer_primitive, METH_VARARGS, "Write a primitive."},
{"dump", (PyCFunction)Writer_dump, METH_NOARGS, "If serializing to a buffer, returns all rendered data so far."},
{NULL}
};
static PyTypeObject WriterType = {PyObject_HEAD_INIT(NULL) 0};
static luxem_bool_t WriterType_init(void)
{
WriterType.tp_name = "luxem.RawWriter";
WriterType.tp_basicsize = sizeof(Writer);
WriterType.tp_dealloc = (destructor)Writer_dealloc;
WriterType.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
WriterType.tp_doc = "Encodes luxem data";
WriterType.tp_methods = Writer_methods;
WriterType.tp_init = (initproc)Writer_init;
WriterType.tp_new = Writer_new;
return PyType_Ready(&WriterType) >= 0;
}
/* ************************************************************************** */
/* luxem module + module entry point */
/*************************************/
static PyObject *translate_to_from_ascii16(PyObject *self, PyObject *positional_args, struct luxem_string_t const *(*function)(struct luxem_string_t const *, struct luxem_string_t *))
{
PyObject *argument;
if (!PyArg_ParseTuple(
positional_args,
"O",
&argument))
return NULL;
if (WRAP_STRING_CHECK(argument))
{
struct luxem_string_t string;
struct luxem_string_t error;
struct luxem_string_t const *out;
PyObject *out_string;
WRAP_STRING_TO(argument, (char **)&string.pointer, &string.length);
out = function(&string, &error);
if (!out)
{
PyErr_SetObject(PyExc_ValueError, WRAP_STRING_FROM(error.pointer, error.length));
return NULL;
}
out_string = WRAP_STRING_FROM(out->pointer, out->length);
free((void *)out);
return out_string;
}
else
{
PyErr_SetString(PyExc_TypeError, "A single string argument is required.");
return NULL;
}
}
static PyObject *translate_to_ascii16(PyObject *self, PyObject *positional_args)
{ return translate_to_from_ascii16(self, positional_args, luxem_to_ascii16); }
static PyObject *translate_from_ascii16(PyObject *self, PyObject *positional_args)
{ return translate_to_from_ascii16(self, positional_args, luxem_from_ascii16); }
static PyMethodDef luxem_methods[] =
{
{"to_ascii16", (PyCFunction)translate_to_ascii16, METH_VARARGS, "Encode ascii16."},
{"from_ascii16", (PyCFunction)translate_from_ascii16, METH_VARARGS, "Decode ascii16."},
{NULL}
};
#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef moduledef =
{
PyModuleDef_HEAD_INIT,
"_luxem",
NULL,
0,
luxem_methods,
NULL,
NULL,
NULL,
NULL
};
#define INITERROR return NULL
PyMODINIT_FUNC
PyInit__luxem(void)
#else
#define INITERROR return
void
init_luxem(void)
#endif
{
#if PY_MAJOR_VERSION >= 3
if (!ReaderType_init()) return NULL;
if (!WriterType_init()) return NULL;
PyObject *module = PyModule_Create(&moduledef);
#else
if (!ReaderType_init()) return;
if (!WriterType_init()) return;
PyObject *module = Py_InitModule3("_luxem", luxem_methods, "luxem C API internal-use module.");
#endif
if (module == NULL)
INITERROR;
Py_INCREF(&ReaderType);
PyModule_AddObject(module, "Reader", (PyObject *)&ReaderType);
PyModule_AddObject(module, "Writer", (PyObject *)&WriterType);
#if PY_MAJOR_VERSION >= 3
return module;
#endif
}