### Bug Summary

File: | Modules/cjkcodecs/multibytecodec.c
Location: | line 545, column 5
Description: | The left operand of '==' is a garbage value

### Annotated Source Code

1 | /*
2 | * multibytecodec.c: Common Multibyte Codec Implementation
3 | *
4 | * Written by Hye-Shik Chang <perky@FreeBSD.org>
5 | */
6 |
7 | #define PY_SSIZE_T_CLEAN
8 | #include "Python.h"
9 | #include "structmember.h"
10 | #include "multibytecodec.h"
11 |
12 | typedef struct {
13 | const Py_UNICODE *inbuf, *inbuf_top, *inbuf_end;
14 | unsigned char *outbuf, *outbuf_end;
15 | PyObject *excobj, *outobj;
16 | } MultibyteEncodeBuffer;
17 |
18 | typedef struct {
19 | const unsigned char *inbuf, *inbuf_top, *inbuf_end;
20 | Py_UNICODE *outbuf, *outbuf_end;
21 | PyObject *excobj, *outobj;
22 | } MultibyteDecodeBuffer;
23 |
24 | PyDoc_STRVAR(MultibyteCodec_Encode__doc__,static char MultibyteCodec_Encode__doc__[] = "I.encode(unicode[, errors]) -> (string, length consumed)\n\nReturn an encoded string version of `unicode'. errors may be given to\nset a different error handling scheme. Default is 'strict' meaning that\nencoding errors raise a UnicodeEncodeError. Other possible values are\n'ignore', 'replace' and 'xmlcharrefreplace' as well as any other name\nregistered with codecs.register_error that can handle UnicodeEncodeErrors."
25 | "I.encode(unicode[, errors]) -> (string, length consumed)\n\static char MultibyteCodec_Encode__doc__[] = "I.encode(unicode[, errors]) -> (string, length consumed)\n\nReturn an encoded string version of `unicode'. errors may be given to\nset a different error handling scheme. Default is 'strict' meaning that\nencoding errors raise a UnicodeEncodeError. Other possible values are\n'ignore', 'replace' and 'xmlcharrefreplace' as well as any other name\nregistered with codecs.register_error that can handle UnicodeEncodeErrors."
26 | \n\static char MultibyteCodec_Encode__doc__[] = "I.encode(unicode[, errors]) -> (string, length consumed)\n\nReturn an encoded string version of `unicode'. errors may be given to\nset a different error handling scheme. Default is 'strict' meaning that\nencoding errors raise a UnicodeEncodeError. Other possible values are\n'ignore', 'replace' and 'xmlcharrefreplace' as well as any other name\nregistered with codecs.register_error that can handle UnicodeEncodeErrors."
27 | Return an encoded string version of `unicode'. errors may be given to\n\static char MultibyteCodec_Encode__doc__[] = "I.encode(unicode[, errors]) -> (string, length consumed)\n\nReturn an encoded string version of `unicode'. errors may be given to\nset a different error handling scheme. Default is 'strict' meaning that\nencoding errors raise a UnicodeEncodeError. Other possible values are\n'ignore', 'replace' and 'xmlcharrefreplace' as well as any other name\nregistered with codecs.register_error that can handle UnicodeEncodeErrors."
28 | set a different error handling scheme. Default is 'strict' meaning that\n\static char MultibyteCodec_Encode__doc__[] = "I.encode(unicode[, errors]) -> (string, length consumed)\n\nReturn an encoded string version of `unicode'. errors may be given to\nset a different error handling scheme. Default is 'strict' meaning that\nencoding errors raise a UnicodeEncodeError. Other possible values are\n'ignore', 'replace' and 'xmlcharrefreplace' as well as any other name\nregistered with codecs.register_error that can handle UnicodeEncodeErrors."
29 | encoding errors raise a UnicodeEncodeError. Other possible values are\n\static char MultibyteCodec_Encode__doc__[] = "I.encode(unicode[, errors]) -> (string, length consumed)\n\nReturn an encoded string version of `unicode'. errors may be given to\nset a different error handling scheme. Default is 'strict' meaning that\nencoding errors raise a UnicodeEncodeError. Other possible values are\n'ignore', 'replace' and 'xmlcharrefreplace' as well as any other name\nregistered with codecs.register_error that can handle UnicodeEncodeErrors."
30 | 'ignore', 'replace' and 'xmlcharrefreplace' as well as any other name\n\static char MultibyteCodec_Encode__doc__[] = "I.encode(unicode[, errors]) -> (string, length consumed)\n\nReturn an encoded string version of `unicode'. errors may be given to\nset a different error handling scheme. Default is 'strict' meaning that\nencoding errors raise a UnicodeEncodeError. Other possible values are\n'ignore', 'replace' and 'xmlcharrefreplace' as well as any other name\nregistered with codecs.register_error that can handle UnicodeEncodeErrors."
31 | registered with codecs.register_error that can handle UnicodeEncodeErrors.")static char MultibyteCodec_Encode__doc__[] = "I.encode(unicode[, errors]) -> (string, length consumed)\n\nReturn an encoded string version of `unicode'. errors may be given to\nset a different error handling scheme. Default is 'strict' meaning that\nencoding errors raise a UnicodeEncodeError. Other possible values are\n'ignore', 'replace' and 'xmlcharrefreplace' as well as any other name\nregistered with codecs.register_error that can handle UnicodeEncodeErrors.";
32 |
33 | PyDoc_STRVAR(MultibyteCodec_Decode__doc__,static char MultibyteCodec_Decode__doc__[] = "I.decode(string[, errors]) -> (unicodeobject, length consumed)\n\nDecodes `string' using I, an MultibyteCodec instance. errors may be given\nto set a different error handling scheme. Default is 'strict' meaning\nthat encoding errors raise a UnicodeDecodeError. Other possible values\nare 'ignore' and 'replace' as well as any other name registered with\ncodecs.register_error that is able to handle UnicodeDecodeErrors."
34 | "I.decode(string[, errors]) -> (unicodeobject, length consumed)\n\static char MultibyteCodec_Decode__doc__[] = "I.decode(string[, errors]) -> (unicodeobject, length consumed)\n\nDecodes `string' using I, an MultibyteCodec instance. errors may be given\nto set a different error handling scheme. Default is 'strict' meaning\nthat encoding errors raise a UnicodeDecodeError. Other possible values\nare 'ignore' and 'replace' as well as any other name registered with\ncodecs.register_error that is able to handle UnicodeDecodeErrors."
35 | \n\static char MultibyteCodec_Decode__doc__[] = "I.decode(string[, errors]) -> (unicodeobject, length consumed)\n\nDecodes `string' using I, an MultibyteCodec instance. errors may be given\nto set a different error handling scheme. Default is 'strict' meaning\nthat encoding errors raise a UnicodeDecodeError. Other possible values\nare 'ignore' and 'replace' as well as any other name registered with\ncodecs.register_error that is able to handle UnicodeDecodeErrors."
36 | Decodes `string' using I, an MultibyteCodec instance. errors may be given\n\static char MultibyteCodec_Decode__doc__[] = "I.decode(string[, errors]) -> (unicodeobject, length consumed)\n\nDecodes `string' using I, an MultibyteCodec instance. errors may be given\nto set a different error handling scheme. Default is 'strict' meaning\nthat encoding errors raise a UnicodeDecodeError. Other possible values\nare 'ignore' and 'replace' as well as any other name registered with\ncodecs.register_error that is able to handle UnicodeDecodeErrors."
37 | to set a different error handling scheme. Default is 'strict' meaning\n\static char MultibyteCodec_Decode__doc__[] = "I.decode(string[, errors]) -> (unicodeobject, length consumed)\n\nDecodes `string' using I, an MultibyteCodec instance. errors may be given\nto set a different error handling scheme. Default is 'strict' meaning\nthat encoding errors raise a UnicodeDecodeError. Other possible values\nare 'ignore' and 'replace' as well as any other name registered with\ncodecs.register_error that is able to handle UnicodeDecodeErrors."
38 | that encoding errors raise a UnicodeDecodeError. Other possible values\n\static char MultibyteCodec_Decode__doc__[] = "I.decode(string[, errors]) -> (unicodeobject, length consumed)\n\nDecodes `string' using I, an MultibyteCodec instance. errors may be given\nto set a different error handling scheme. Default is 'strict' meaning\nthat encoding errors raise a UnicodeDecodeError. Other possible values\nare 'ignore' and 'replace' as well as any other name registered with\ncodecs.register_error that is able to handle UnicodeDecodeErrors."
39 | are 'ignore' and 'replace' as well as any other name registered with\n\static char MultibyteCodec_Decode__doc__[] = "I.decode(string[, errors]) -> (unicodeobject, length consumed)\n\nDecodes `string' using I, an MultibyteCodec instance. errors may be given\nto set a different error handling scheme. Default is 'strict' meaning\nthat encoding errors raise a UnicodeDecodeError. Other possible values\nare 'ignore' and 'replace' as well as any other name registered with\ncodecs.register_error that is able to handle UnicodeDecodeErrors."
40 | codecs.register_error that is able to handle UnicodeDecodeErrors.")static char MultibyteCodec_Decode__doc__[] = "I.decode(string[, errors]) -> (unicodeobject, length consumed)\n\nDecodes `string' using I, an MultibyteCodec instance. errors may be given\nto set a different error handling scheme. Default is 'strict' meaning\nthat encoding errors raise a UnicodeDecodeError. Other possible values\nare 'ignore' and 'replace' as well as any other name registered with\ncodecs.register_error that is able to handle UnicodeDecodeErrors.";
41 |
42 | static char *codeckwarglist[] = {"input", "errors", NULL((void*)0)};
43 | static char *incnewkwarglist[] = {"errors", NULL((void*)0)};
44 | static char *incrementalkwarglist[] = {"input", "final", NULL((void*)0)};
45 | static char *streamkwarglist[] = {"stream", "errors", NULL((void*)0)};
46 |
47 | static PyObject *multibytecodec_encode(MultibyteCodec *,
48 | MultibyteCodec_State *, const Py_UNICODE **, Py_ssize_t,
49 | PyObject *, int);
50 |
51 | #define MBENC_RESET0x0001<<1 MBENC_MAX0x0001<<1 /* reset after an encoding session */
52 |
53 | static PyObject *
54 | make_tuple(PyObject *object, Py_ssize_t len)
55 | {
56 | PyObject *v, *w;
57 |
58 | if (object == NULL((void*)0))
59 | return NULL((void*)0);
60 |
61 | v = PyTuple_New(2);
62 | if (v == NULL((void*)0)) {
63 | Py_DECREF(object)do { if (_Py_RefTotal-- , --((PyObject*)(object))->ob_refcnt != 0) { if (((PyObject*)object)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 63, (PyObject *)(object)); } else _Py_Dealloc((PyObject *)( object)); } while (0);
64 | return NULL((void*)0);
65 | }
66 | PyTuple_SET_ITEM(v, 0, object)(((PyTupleObject *)(v))->ob_item[0] = object);
67 |
68 | w = PyLong_FromSsize_t(len);
69 | if (w == NULL((void*)0)) {
70 | Py_DECREF(v)do { if (_Py_RefTotal-- , --((PyObject*)(v))->ob_refcnt != 0) { if (((PyObject*)v)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 70, (PyObject *)(v)); } else _Py_Dealloc((PyObject *)(v)); } while (0);
71 | return NULL((void*)0);
72 | }
73 | PyTuple_SET_ITEM(v, 1, w)(((PyTupleObject *)(v))->ob_item[1] = w);
74 |
75 | return v;
76 | }
77 |
78 | static PyObject *
79 | internal_error_callback(const char *errors)
80 | {
81 | if (errors == NULL((void*)0) || strcmp(errors, "strict") == 0)
82 | return ERROR_STRICT(PyObject *)(1);
83 | else if (strcmp(errors, "ignore") == 0)
84 | return ERROR_IGNORE(PyObject *)(2);
85 | else if (strcmp(errors, "replace") == 0)
86 | return ERROR_REPLACE(PyObject *)(3);
87 | else
88 | return PyUnicode_FromStringPyUnicodeUCS2_FromString(errors);
89 | }
90 |
91 | static PyObject *
92 | call_error_callback(PyObject *errors, PyObject *exc)
93 | {
94 | PyObject *args, *cb, *r;
95 | const char *str;
96 |
97 | assert(PyUnicode_Check(errors))(__builtin_expect(!(((((((PyObject*)(errors))->ob_type))-> tp_flags & ((1L<<28))) != 0)), 0) ? __assert_rtn(__func__ , "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 97, "PyUnicode_Check(errors)") : (void)0);
98 | str = _PyUnicode_AsString(errors);
99 | if (str == NULL((void*)0))
100 | return NULL((void*)0);
101 | cb = PyCodec_LookupError(str);
102 | if (cb == NULL((void*)0))
103 | return NULL((void*)0);
104 |
105 | args = PyTuple_New(1);
106 | if (args == NULL((void*)0)) {
107 | Py_DECREF(cb)do { if (_Py_RefTotal-- , --((PyObject*)(cb))->ob_refcnt != 0) { if (((PyObject*)cb)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 107, (PyObject *)(cb)); } else _Py_Dealloc((PyObject *)(cb) ); } while (0);
108 | return NULL((void*)0);
109 | }
110 |
111 | PyTuple_SET_ITEM(args, 0, exc)(((PyTupleObject *)(args))->ob_item[0] = exc);
112 | Py_INCREF(exc)( _Py_RefTotal++ , ((PyObject*)(exc))->ob_refcnt++);
113 |
114 | r = PyObject_CallObject(cb, args);
115 | Py_DECREF(args)do { if (_Py_RefTotal-- , --((PyObject*)(args))->ob_refcnt != 0) { if (((PyObject*)args)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 115, (PyObject *)(args)); } else _Py_Dealloc((PyObject *)(args )); } while (0);
116 | Py_DECREF(cb)do { if (_Py_RefTotal-- , --((PyObject*)(cb))->ob_refcnt != 0) { if (((PyObject*)cb)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 116, (PyObject *)(cb)); } else _Py_Dealloc((PyObject *)(cb) ); } while (0);
117 | return r;
118 | }
119 |
120 | static PyObject *
121 | codecctx_errors_get(MultibyteStatefulCodecContext *self)
122 | {
123 | const char *errors;
124 |
125 | if (self->errors == ERROR_STRICT(PyObject *)(1))
126 | errors = "strict";
127 | else if (self->errors == ERROR_IGNORE(PyObject *)(2))
128 | errors = "ignore";
129 | else if (self->errors == ERROR_REPLACE(PyObject *)(3))
130 | errors = "replace";
131 | else {
132 | Py_INCREF(self->errors)( _Py_RefTotal++ , ((PyObject*)(self->errors))->ob_refcnt ++);
133 | return self->errors;
134 | }
135 |
136 | return PyUnicode_FromStringPyUnicodeUCS2_FromString(errors);
137 | }
138 |
139 | static int
140 | codecctx_errors_set(MultibyteStatefulCodecContext *self, PyObject *value,
141 | void *closure)
142 | {
143 | PyObject *cb;
144 | const char *str;
145 |
146 | if (!PyUnicode_Check(value)((((((PyObject*)(value))->ob_type))->tp_flags & ((1L <<28))) != 0)) {
147 | PyErr_SetString(PyExc_TypeError, "errors must be a string");
148 | return -1;
149 | }
150 |
151 | str = _PyUnicode_AsString(value);
152 | if (str == NULL((void*)0))
153 | return -1;
154 |
155 | cb = internal_error_callback(str);
156 | if (cb == NULL((void*)0))
157 | return -1;
158 |
159 | ERROR_DECREF(self->errors)do { if (self->errors != ((void*)0) && ((self-> errors) < (PyObject *)(1) || (PyObject *)(3) < (self-> errors))) { do { if (_Py_RefTotal-- , --((PyObject*)(self-> errors))->ob_refcnt != 0) { if (((PyObject*)self->errors )->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 159, (PyObject *)(self->errors)); } else _Py_Dealloc((PyObject *)(self->errors)); } while (0); } } while (0);;
160 | self->errors = cb;
161 | return 0;
162 | }
163 |
164 | /* This getset handlers list is used by all the stateful codec objects */
165 | static PyGetSetDef codecctx_getsets[] = {
166 | {"errors", (getter)codecctx_errors_get,
167 | (setter)codecctx_errors_set,
168 | PyDoc_STR("how to treat errors")"how to treat errors"},
169 | {NULL((void*)0),}
170 | };
171 |
172 | static int
173 | expand_encodebuffer(MultibyteEncodeBuffer *buf, Py_ssize_t esize)
174 | {
175 | Py_ssize_t orgpos, orgsize, incsize;
176 |
177 | orgpos = (Py_ssize_t)((char *)buf->outbuf -
178 | PyBytes_AS_STRING(buf->outobj)((__builtin_expect(!(((((((PyObject*)(buf->outobj))->ob_type ))->tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn (__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 178, "PyBytes_Check(buf->outobj)") : (void)0), (((PyBytesObject *)(buf->outobj))->ob_sval)));
179 | orgsize = PyBytes_GET_SIZE(buf->outobj)((__builtin_expect(!(((((((PyObject*)(buf->outobj))->ob_type ))->tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn (__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 179, "PyBytes_Check(buf->outobj)") : (void)0),(((PyVarObject *)(buf->outobj))->ob_size));
180 | incsize = (esize < (orgsize >> 1) ? (orgsize >> 1) | 1 : esize);
181 |
182 | if (orgsize > PY_SSIZE_T_MAX((Py_ssize_t)(((size_t)-1)>>1)) - incsize)
183 | return -1;
184 |
185 | if (_PyBytes_Resize(&buf->outobj, orgsize + incsize) == -1)
186 | return -1;
187 |
188 | buf->outbuf = (unsigned char *)PyBytes_AS_STRING(buf->outobj)((__builtin_expect(!(((((((PyObject*)(buf->outobj))->ob_type ))->tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn (__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 188, "PyBytes_Check(buf->outobj)") : (void)0), (((PyBytesObject *)(buf->outobj))->ob_sval)) +orgpos;
189 | buf->outbuf_end = (unsigned char *)PyBytes_AS_STRING(buf->outobj)((__builtin_expect(!(((((((PyObject*)(buf->outobj))->ob_type ))->tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn (__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 189, "PyBytes_Check(buf->outobj)") : (void)0), (((PyBytesObject *)(buf->outobj))->ob_sval))
190 | + PyBytes_GET_SIZE(buf->outobj)((__builtin_expect(!(((((((PyObject*)(buf->outobj))->ob_type ))->tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn (__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 190, "PyBytes_Check(buf->outobj)") : (void)0),(((PyVarObject *)(buf->outobj))->ob_size));
191 |
192 | return 0;
193 | }
194 | #define REQUIRE_ENCODEBUFFER(buf, s){ if ((s) < 1 || (buf)->outbuf + (s) > (buf)->outbuf_end ) if (expand_encodebuffer(buf, s) == -1) goto errorexit; } { \
195 | if ((s) < 1 || (buf)->outbuf + (s) > (buf)->outbuf_end) \
196 | if (expand_encodebuffer(buf, s) == -1) \
197 | goto errorexit; \
198 | }
199 |
200 | static int
201 | expand_decodebuffer(MultibyteDecodeBuffer *buf, Py_ssize_t esize)
202 | {
203 | Py_ssize_t orgpos, orgsize;
204 |
205 | orgpos = (Py_ssize_t)(buf->outbuf - PyUnicode_AS_UNICODE(buf->outobj)((__builtin_expect(!(((((((PyObject*)(buf->outobj))->ob_type ))->tp_flags & ((1L<<28))) != 0)), 0) ? __assert_rtn (__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 205, "PyUnicode_Check(buf->outobj)") : (void)0),(((PyUnicodeObject *)(buf->outobj))->str)));
206 | orgsize = PyUnicode_GET_SIZE(buf->outobj)((__builtin_expect(!(((((((PyObject*)(buf->outobj))->ob_type ))->tp_flags & ((1L<<28))) != 0)), 0) ? __assert_rtn (__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 206, "PyUnicode_Check(buf->outobj)") : (void)0),(((PyUnicodeObject *)(buf->outobj))->length));
207 | if (PyUnicode_ResizePyUnicodeUCS2_Resize(&buf->outobj, orgsize + (
208 | esize < (orgsize >> 1) ? (orgsize >> 1) | 1 : esize)) == -1)
209 | return -1;
210 |
211 | buf->outbuf = PyUnicode_AS_UNICODE(buf->outobj)((__builtin_expect(!(((((((PyObject*)(buf->outobj))->ob_type ))->tp_flags & ((1L<<28))) != 0)), 0) ? __assert_rtn (__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 211, "PyUnicode_Check(buf->outobj)") : (void)0),(((PyUnicodeObject *)(buf->outobj))->str)) + orgpos;
212 | buf->outbuf_end = PyUnicode_AS_UNICODE(buf->outobj)((__builtin_expect(!(((((((PyObject*)(buf->outobj))->ob_type ))->tp_flags & ((1L<<28))) != 0)), 0) ? __assert_rtn (__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 212, "PyUnicode_Check(buf->outobj)") : (void)0),(((PyUnicodeObject *)(buf->outobj))->str))
213 | + PyUnicode_GET_SIZE(buf->outobj)((__builtin_expect(!(((((((PyObject*)(buf->outobj))->ob_type ))->tp_flags & ((1L<<28))) != 0)), 0) ? __assert_rtn (__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 213, "PyUnicode_Check(buf->outobj)") : (void)0),(((PyUnicodeObject *)(buf->outobj))->length));
214 |
215 | return 0;
216 | }
217 | #define REQUIRE_DECODEBUFFER(buf, s){ if ((s) < 1 || (buf)->outbuf + (s) > (buf)->outbuf_end ) if (expand_decodebuffer(buf, s) == -1) goto errorexit; } { \
218 | if ((s) < 1 || (buf)->outbuf + (s) > (buf)->outbuf_end) \
219 | if (expand_decodebuffer(buf, s) == -1) \
220 | goto errorexit; \
221 | }
222 |
223 |
224 | /**
225 | * MultibyteCodec object
226 | */
227 |
228 | static int
229 | multibytecodec_encerror(MultibyteCodec *codec,
230 | MultibyteCodec_State *state,
231 | MultibyteEncodeBuffer *buf,
232 | PyObject *errors, Py_ssize_t e)
233 | {
234 | PyObject *retobj = NULL((void*)0), *retstr = NULL((void*)0), *tobj;
235 | Py_ssize_t retstrsize, newpos;
236 | Py_ssize_t esize, start, end;
237 | const char *reason;
238 |
239 | if (e > 0) {
240 | reason = "illegal multibyte sequence";
241 | esize = e;
242 | }
243 | else {
244 | switch (e) {
245 | case MBERR_TOOSMALL(-1):
246 | REQUIRE_ENCODEBUFFER(buf, -1){ if ((-1) < 1 || (buf)->outbuf + (-1) > (buf)->outbuf_end ) if (expand_encodebuffer(buf, -1) == -1) goto errorexit; };
247 | return 0; /* retry it */
248 | case MBERR_TOOFEW(-2):
249 | reason = "incomplete multibyte sequence";
250 | esize = (Py_ssize_t)(buf->inbuf_end - buf->inbuf);
251 | break;
252 | case MBERR_INTERNAL(-3):
253 | PyErr_SetString(PyExc_RuntimeError,
254 | "internal codec error");
255 | return -1;
256 | default:
257 | PyErr_SetString(PyExc_RuntimeError,
258 | "unknown runtime error");
259 | return -1;
260 | }
261 | }
262 |
263 | if (errors == ERROR_REPLACE(PyObject *)(3)) {
264 | const Py_UNICODE replchar = '?', *inbuf = &replchar;
265 | Py_ssize_t r;
266 |
267 | for (;;) {
268 | Py_ssize_t outleft;
269 |
270 | outleft = (Py_ssize_t)(buf->outbuf_end - buf->outbuf);
271 | r = codec->encode(state, codec->config, &inbuf, 1,
272 | &buf->outbuf, outleft, 0);
273 | if (r == MBERR_TOOSMALL(-1)) {
274 | REQUIRE_ENCODEBUFFER(buf, -1){ if ((-1) < 1 || (buf)->outbuf + (-1) > (buf)->outbuf_end ) if (expand_encodebuffer(buf, -1) == -1) goto errorexit; };
275 | continue;
276 | }
277 | else
278 | break;
279 | }
280 |
281 | if (r != 0) {
282 | REQUIRE_ENCODEBUFFER(buf, 1){ if ((1) < 1 || (buf)->outbuf + (1) > (buf)->outbuf_end ) if (expand_encodebuffer(buf, 1) == -1) goto errorexit; };
283 | *buf->outbuf++ = '?';
284 | }
285 | }
286 | if (errors == ERROR_IGNORE(PyObject *)(2) || errors == ERROR_REPLACE(PyObject *)(3)) {
287 | buf->inbuf += esize;
288 | return 0;
289 | }
290 |
291 | start = (Py_ssize_t)(buf->inbuf - buf->inbuf_top);
292 | end = start + esize;
293 |
294 | /* use cached exception object if available */
295 | if (buf->excobj == NULL((void*)0)) {
296 | buf->excobj = PyUnicodeEncodeError_Create(codec->encoding,
297 | buf->inbuf_top,
298 | buf->inbuf_end - buf->inbuf_top,
299 | start, end, reason);
300 | if (buf->excobj == NULL((void*)0))
301 | goto errorexit;
302 | }
303 | else
304 | if (PyUnicodeEncodeError_SetStart(buf->excobj, start) != 0 ||
305 | PyUnicodeEncodeError_SetEnd(buf->excobj, end) != 0 ||
306 | PyUnicodeEncodeError_SetReason(buf->excobj, reason) != 0)
307 | goto errorexit;
308 |
309 | if (errors == ERROR_STRICT(PyObject *)(1)) {
310 | PyCodec_StrictErrors(buf->excobj);
311 | goto errorexit;
312 | }
313 |
314 | retobj = call_error_callback(errors, buf->excobj);
315 | if (retobj == NULL((void*)0))
316 | goto errorexit;
317 |
318 | if (!PyTuple_Check(retobj)((((((PyObject*)(retobj))->ob_type))->tp_flags & (( 1L<<26))) != 0) || PyTuple_GET_SIZE(retobj)(((PyVarObject*)(retobj))->ob_size) != 2 ||
319 | !PyUnicode_Check((tobj = PyTuple_GET_ITEM(retobj, 0)))((((((PyObject*)((tobj = (((PyTupleObject *)(retobj))->ob_item [0]))))->ob_type))->tp_flags & ((1L<<28))) != 0) ||
320 | !PyLong_Check(PyTuple_GET_ITEM(retobj, 1))((((((PyObject*)((((PyTupleObject *)(retobj))->ob_item[1]) ))->ob_type))->tp_flags & ((1L<<24))) != 0)) {
321 | PyErr_SetString(PyExc_TypeError,
322 | "encoding error handler must return "
323 | "(unicode, int) tuple");
324 | goto errorexit;
325 | }
326 |
327 | {
328 | const Py_UNICODE *uraw = PyUnicode_AS_UNICODE(tobj)((__builtin_expect(!(((((((PyObject*)(tobj))->ob_type))-> tp_flags & ((1L<<28))) != 0)), 0) ? __assert_rtn(__func__ , "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 328, "PyUnicode_Check(tobj)") : (void)0),(((PyUnicodeObject *)(tobj))->str));
329 |
330 | retstr = multibytecodec_encode(codec, state, &uraw,
331 | PyUnicode_GET_SIZE(tobj)((__builtin_expect(!(((((((PyObject*)(tobj))->ob_type))-> tp_flags & ((1L<<28))) != 0)), 0) ? __assert_rtn(__func__ , "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 331, "PyUnicode_Check(tobj)") : (void)0),(((PyUnicodeObject *)(tobj))->length)), ERROR_STRICT(PyObject *)(1),
332 | MBENC_FLUSH0x0001);
333 | if (retstr == NULL((void*)0))
334 | goto errorexit;
335 | }
336 |
337 | assert(PyBytes_Check(retstr))(__builtin_expect(!(((((((PyObject*)(retstr))->ob_type))-> tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn(__func__ , "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 337, "PyBytes_Check(retstr)") : (void)0);
338 | retstrsize = PyBytes_GET_SIZE(retstr)((__builtin_expect(!(((((((PyObject*)(retstr))->ob_type))-> tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn(__func__ , "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 338, "PyBytes_Check(retstr)") : (void)0),(((PyVarObject*)(retstr ))->ob_size));
339 | REQUIRE_ENCODEBUFFER(buf, retstrsize){ if ((retstrsize) < 1 || (buf)->outbuf + (retstrsize) > (buf)->outbuf_end) if (expand_encodebuffer(buf, retstrsize ) == -1) goto errorexit; };
340 |
341 | memcpy(buf->outbuf, PyBytes_AS_STRING(retstr), retstrsize)((__builtin_object_size (buf->outbuf, 0) != (size_t) -1) ? __builtin___memcpy_chk (buf->outbuf, ((__builtin_expect(! (((((((PyObject*)(retstr))->ob_type))->tp_flags & ( (1L<<27))) != 0)), 0) ? __assert_rtn(__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 341, "PyBytes_Check(retstr)") : (void)0), (((PyBytesObject * )(retstr))->ob_sval)), retstrsize, __builtin_object_size ( buf->outbuf, 0)) : __inline_memcpy_chk (buf->outbuf, (( __builtin_expect(!(((((((PyObject*)(retstr))->ob_type))-> tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn(__func__ , "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 341, "PyBytes_Check(retstr)") : (void)0), (((PyBytesObject * )(retstr))->ob_sval)), retstrsize));
342 | buf->outbuf += retstrsize;
343 |
344 | newpos = PyLong_AsSsize_t(PyTuple_GET_ITEM(retobj, 1)(((PyTupleObject *)(retobj))->ob_item[1]));
345 | if (newpos < 0 && !PyErr_Occurred())
346 | newpos += (Py_ssize_t)(buf->inbuf_end - buf->inbuf_top);
347 | if (newpos < 0 || buf->inbuf_top + newpos > buf->inbuf_end) {
348 | PyErr_Clear();
349 | PyErr_Format(PyExc_IndexError,
350 | "position %zd from error handler out of bounds",
351 | newpos);
352 | goto errorexit;
353 | }
354 | buf->inbuf = buf->inbuf_top + newpos;
355 |
356 | Py_DECREF(retobj)do { if (_Py_RefTotal-- , --((PyObject*)(retobj))->ob_refcnt != 0) { if (((PyObject*)retobj)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 356, (PyObject *)(retobj)); } else _Py_Dealloc((PyObject *) (retobj)); } while (0);
357 | Py_DECREF(retstr)do { if (_Py_RefTotal-- , --((PyObject*)(retstr))->ob_refcnt != 0) { if (((PyObject*)retstr)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 357, (PyObject *)(retstr)); } else _Py_Dealloc((PyObject *) (retstr)); } while (0);
358 | return 0;
359 |
360 | errorexit:
361 | Py_XDECREF(retobj)do { if ((retobj) == ((void*)0)) ; else do { if (_Py_RefTotal -- , --((PyObject*)(retobj))->ob_refcnt != 0) { if (((PyObject *)retobj)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 361, (PyObject *)(retobj)); } else _Py_Dealloc((PyObject *) (retobj)); } while (0); } while (0);
362 | Py_XDECREF(retstr)do { if ((retstr) == ((void*)0)) ; else do { if (_Py_RefTotal -- , --((PyObject*)(retstr))->ob_refcnt != 0) { if (((PyObject *)retstr)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 362, (PyObject *)(retstr)); } else _Py_Dealloc((PyObject *) (retstr)); } while (0); } while (0);
363 | return -1;
364 | }
365 |
366 | static int
367 | multibytecodec_decerror(MultibyteCodec *codec,
368 | MultibyteCodec_State *state,
369 | MultibyteDecodeBuffer *buf,
370 | PyObject *errors, Py_ssize_t e)
371 | {
372 | PyObject *retobj = NULL((void*)0), *retuni = NULL((void*)0);
373 | Py_ssize_t retunisize, newpos;
374 | const char *reason;
375 | Py_ssize_t esize, start, end;
376 |
377 | if (e > 0) {
378 | reason = "illegal multibyte sequence";
379 | esize = e;
380 | }
381 | else {
382 | switch (e) {
383 | case MBERR_TOOSMALL(-1):
384 | REQUIRE_DECODEBUFFER(buf, -1){ if ((-1) < 1 || (buf)->outbuf + (-1) > (buf)->outbuf_end ) if (expand_decodebuffer(buf, -1) == -1) goto errorexit; };
385 | return 0; /* retry it */
386 | case MBERR_TOOFEW(-2):
387 | reason = "incomplete multibyte sequence";
388 | esize = (Py_ssize_t)(buf->inbuf_end - buf->inbuf);
389 | break;
390 | case MBERR_INTERNAL(-3):
391 | PyErr_SetString(PyExc_RuntimeError,
392 | "internal codec error");
393 | return -1;
394 | default:
395 | PyErr_SetString(PyExc_RuntimeError,
396 | "unknown runtime error");
397 | return -1;
398 | }
399 | }
400 |
401 | if (errors == ERROR_REPLACE(PyObject *)(3)) {
402 | REQUIRE_DECODEBUFFER(buf, 1){ if ((1) < 1 || (buf)->outbuf + (1) > (buf)->outbuf_end ) if (expand_decodebuffer(buf, 1) == -1) goto errorexit; };
403 | *buf->outbuf++ = Py_UNICODE_REPLACEMENT_CHARACTER((Py_UNICODE) 0xFFFD);
404 | }
405 | if (errors == ERROR_IGNORE(PyObject *)(2) || errors == ERROR_REPLACE(PyObject *)(3)) {
406 | buf->inbuf += esize;
407 | return 0;
408 | }
409 |
410 | start = (Py_ssize_t)(buf->inbuf - buf->inbuf_top);
411 | end = start + esize;
412 |
413 | /* use cached exception object if available */
414 | if (buf->excobj == NULL((void*)0)) {
415 | buf->excobj = PyUnicodeDecodeError_Create(codec->encoding,
416 | (const char *)buf->inbuf_top,
417 | (Py_ssize_t)(buf->inbuf_end - buf->inbuf_top),
418 | start, end, reason);
419 | if (buf->excobj == NULL((void*)0))
420 | goto errorexit;
421 | }
422 | else
423 | if (PyUnicodeDecodeError_SetStart(buf->excobj, start) ||
424 | PyUnicodeDecodeError_SetEnd(buf->excobj, end) ||
425 | PyUnicodeDecodeError_SetReason(buf->excobj, reason))
426 | goto errorexit;
427 |
428 | if (errors == ERROR_STRICT(PyObject *)(1)) {
429 | PyCodec_StrictErrors(buf->excobj);
430 | goto errorexit;
431 | }
432 |
433 | retobj = call_error_callback(errors, buf->excobj);
434 | if (retobj == NULL((void*)0))
435 | goto errorexit;
436 |
437 | if (!PyTuple_Check(retobj)((((((PyObject*)(retobj))->ob_type))->tp_flags & (( 1L<<26))) != 0) || PyTuple_GET_SIZE(retobj)(((PyVarObject*)(retobj))->ob_size) != 2 ||
438 | !PyUnicode_Check((retuni = PyTuple_GET_ITEM(retobj, 0)))((((((PyObject*)((retuni = (((PyTupleObject *)(retobj))->ob_item [0]))))->ob_type))->tp_flags & ((1L<<28))) != 0) ||
439 | !PyLong_Check(PyTuple_GET_ITEM(retobj, 1))((((((PyObject*)((((PyTupleObject *)(retobj))->ob_item[1]) ))->ob_type))->tp_flags & ((1L<<24))) != 0)) {
440 | PyErr_SetString(PyExc_TypeError,
441 | "decoding error handler must return "
442 | "(unicode, int) tuple");
443 | goto errorexit;
444 | }
445 |
446 | retunisize = PyUnicode_GET_SIZE(retuni)((__builtin_expect(!(((((((PyObject*)(retuni))->ob_type))-> tp_flags & ((1L<<28))) != 0)), 0) ? __assert_rtn(__func__ , "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 446, "PyUnicode_Check(retuni)") : (void)0),(((PyUnicodeObject *)(retuni))->length));
447 | if (retunisize > 0) {
448 | REQUIRE_DECODEBUFFER(buf, retunisize){ if ((retunisize) < 1 || (buf)->outbuf + (retunisize) > (buf)->outbuf_end) if (expand_decodebuffer(buf, retunisize ) == -1) goto errorexit; };
449 | memcpy((char *)buf->outbuf, PyUnicode_AS_DATA(retuni),((__builtin_object_size ((char *)buf->outbuf, 0) != (size_t ) -1) ? __builtin___memcpy_chk ((char *)buf->outbuf, ((__builtin_expect (!(((((((PyObject*)(retuni))->ob_type))->tp_flags & ((1L<<28))) != 0)), 0) ? __assert_rtn(__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 449, "PyUnicode_Check(retuni)") : (void)0),((const char *)( (PyUnicodeObject *)(retuni))->str)), retunisize * 2, __builtin_object_size ((char *)buf->outbuf, 0)) : __inline_memcpy_chk ((char *) buf->outbuf, ((__builtin_expect(!(((((((PyObject*)(retuni) )->ob_type))->tp_flags & ((1L<<28))) != 0)), 0 ) ? __assert_rtn(__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 449, "PyUnicode_Check(retuni)") : (void)0),((const char *)( (PyUnicodeObject *)(retuni))->str)), retunisize * 2))
450 | retunisize * Py_UNICODE_SIZE)((__builtin_object_size ((char *)buf->outbuf, 0) != (size_t ) -1) ? __builtin___memcpy_chk ((char *)buf->outbuf, ((__builtin_expect (!(((((((PyObject*)(retuni))->ob_type))->tp_flags & ((1L<<28))) != 0)), 0) ? __assert_rtn(__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 449, "PyUnicode_Check(retuni)") : (void)0),((const char *)( (PyUnicodeObject *)(retuni))->str)), retunisize * 2, __builtin_object_size ((char *)buf->outbuf, 0)) : __inline_memcpy_chk ((char *) buf->outbuf, ((__builtin_expect(!(((((((PyObject*)(retuni) )->ob_type))->tp_flags & ((1L<<28))) != 0)), 0 ) ? __assert_rtn(__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 449, "PyUnicode_Check(retuni)") : (void)0),((const char *)( (PyUnicodeObject *)(retuni))->str)), retunisize * 2));
451 | buf->outbuf += retunisize;
452 | }
453 |
454 | newpos = PyLong_AsSsize_t(PyTuple_GET_ITEM(retobj, 1)(((PyTupleObject *)(retobj))->ob_item[1]));
455 | if (newpos < 0 && !PyErr_Occurred())
456 | newpos += (Py_ssize_t)(buf->inbuf_end - buf->inbuf_top);
457 | if (newpos < 0 || buf->inbuf_top + newpos > buf->inbuf_end) {
458 | PyErr_Clear();
459 | PyErr_Format(PyExc_IndexError,
460 | "position %zd from error handler out of bounds",
461 | newpos);
462 | goto errorexit;
463 | }
464 | buf->inbuf = buf->inbuf_top + newpos;
465 | Py_DECREF(retobj)do { if (_Py_RefTotal-- , --((PyObject*)(retobj))->ob_refcnt != 0) { if (((PyObject*)retobj)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 465, (PyObject *)(retobj)); } else _Py_Dealloc((PyObject *) (retobj)); } while (0);
466 | return 0;
467 |
468 | errorexit:
469 | Py_XDECREF(retobj)do { if ((retobj) == ((void*)0)) ; else do { if (_Py_RefTotal -- , --((PyObject*)(retobj))->ob_refcnt != 0) { if (((PyObject *)retobj)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 469, (PyObject *)(retobj)); } else _Py_Dealloc((PyObject *) (retobj)); } while (0); } while (0);
470 | return -1;
471 | }
472 |
473 | static PyObject *
474 | multibytecodec_encode(MultibyteCodec *codec,
475 | MultibyteCodec_State *state,
476 | const Py_UNICODE **data, Py_ssize_t datalen,
477 | PyObject *errors, int flags)
478 | {
479 | MultibyteEncodeBuffer buf;
480 | Py_ssize_t finalsize, r = 0;
481 |
482 | if (datalen == 0)
1 | Taking false branch
483 | return PyBytes_FromStringAndSize(NULL((void*)0), 0);
484 |
485 | buf.excobj = NULL((void*)0);
486 | buf.outbuf = NULL((void*)0);
487 | buf.inbuf = buf.inbuf_top = *data;
488 | buf.inbuf_end = buf.inbuf_top + datalen;
489 |
490 | if (datalen > (PY_SSIZE_T_MAX((Py_ssize_t)(((size_t)-1)>>1)) - 16) / 2) {
2 | Taking true branch
491 | PyErr_NoMemory();
492 | goto errorexit;
3 | Control jumps to line 544
493 | }
494 |
495 | buf.outobj = PyBytes_FromStringAndSize(NULL((void*)0), datalen * 2 + 16);
496 | if (buf.outobj == NULL((void*)0))
497 | goto errorexit;
498 | buf.outbuf = (unsigned char *)PyBytes_AS_STRING(buf.outobj)((__builtin_expect(!(((((((PyObject*)(buf.outobj))->ob_type ))->tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn (__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 498, "PyBytes_Check(buf.outobj)") : (void)0), (((PyBytesObject *)(buf.outobj))->ob_sval));
499 | buf.outbuf_end = buf.outbuf + PyBytes_GET_SIZE(buf.outobj)((__builtin_expect(!(((((((PyObject*)(buf.outobj))->ob_type ))->tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn (__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 499, "PyBytes_Check(buf.outobj)") : (void)0),(((PyVarObject *)(buf.outobj))->ob_size));
500 |
501 | while (buf.inbuf < buf.inbuf_end) {
502 | Py_ssize_t inleft, outleft;
503 |
504 | /* we don't reuse inleft and outleft here.
505 | * error callbacks can relocate the cursor anywhere on buffer*/
506 | inleft = (Py_ssize_t)(buf.inbuf_end - buf.inbuf);
507 | outleft = (Py_ssize_t)(buf.outbuf_end - buf.outbuf);
508 | r = codec->encode(state, codec->config, &buf.inbuf, inleft,
509 | &buf.outbuf, outleft, flags);
510 | if ((r == 0) || (r == MBERR_TOOFEW(-2) && !(flags & MBENC_FLUSH0x0001)))
511 | break;
512 | else if (multibytecodec_encerror(codec, state, &buf, errors,r))
513 | goto errorexit;
514 | else if (r == MBERR_TOOFEW(-2))
515 | break;
516 | }
517 |
518 | if (codec->encreset != NULL((void*)0))
519 | for (;;) {
520 | Py_ssize_t outleft;
521 |
522 | outleft = (Py_ssize_t)(buf.outbuf_end - buf.outbuf);
523 | r = codec->encreset(state, codec->config, &buf.outbuf,
524 | outleft);
525 | if (r == 0)
526 | break;
527 | else if (multibytecodec_encerror(codec, state,
528 | &buf, errors, r))
529 | goto errorexit;
530 | }
531 |
532 | finalsize = (Py_ssize_t)((char *)buf.outbuf -
533 | PyBytes_AS_STRING(buf.outobj)((__builtin_expect(!(((((((PyObject*)(buf.outobj))->ob_type ))->tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn (__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 533, "PyBytes_Check(buf.outobj)") : (void)0), (((PyBytesObject *)(buf.outobj))->ob_sval)));
534 |
535 | if (finalsize != PyBytes_GET_SIZE(buf.outobj)((__builtin_expect(!(((((((PyObject*)(buf.outobj))->ob_type ))->tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn (__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 535, "PyBytes_Check(buf.outobj)") : (void)0),(((PyVarObject *)(buf.outobj))->ob_size)))
536 | if (_PyBytes_Resize(&buf.outobj, finalsize) == -1)
537 | goto errorexit;
538 |
539 | *data = buf.inbuf;
540 | Py_XDECREF(buf.excobj)do { if ((buf.excobj) == ((void*)0)) ; else do { if (_Py_RefTotal -- , --((PyObject*)(buf.excobj))->ob_refcnt != 0) { if ((( PyObject*)buf.excobj)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 540, (PyObject *)(buf.excobj)); } else _Py_Dealloc((PyObject *)(buf.excobj)); } while (0); } while (0);
541 | return buf.outobj;
542 |
543 | errorexit:
544 | Py_XDECREF(buf.excobj)do { if ((buf.excobj) == ((void*)0)) ; else do { if (_Py_RefTotal -- , --((PyObject*)(buf.excobj))->ob_refcnt != 0) { if ((( PyObject*)buf.excobj)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 544, (PyObject *)(buf.excobj)); } else _Py_Dealloc((PyObject *)(buf.excobj)); } while (0); } while (0);
545 | Py_XDECREF(buf.outobj)do { if ((buf.outobj) == ((void*)0)) ; else do { if (_Py_RefTotal -- , --((PyObject*)(buf.outobj))->ob_refcnt != 0) { if ((( PyObject*)buf.outobj)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 545, (PyObject *)(buf.outobj)); } else _Py_Dealloc((PyObject *)(buf.outobj)); } while (0); } while (0);
4 | Within the expansion of the macro 'Py_XDECREF':
a | The left operand of '==' is a garbage value
546 | return NULL((void*)0);
547 | }
548 |
549 | static PyObject *
550 | MultibyteCodec_Encode(MultibyteCodecObject *self,
551 | PyObject *args, PyObject *kwargs)
552 | {
553 | MultibyteCodec_State state;
554 | Py_UNICODE *data;
555 | PyObject *errorcb, *r, *arg, *ucvt;
556 | const char *errors = NULL((void*)0);
557 | Py_ssize_t datalen;
558 |
559 | if (!PyArg_ParseTupleAndKeywords_PyArg_ParseTupleAndKeywords_SizeT(args, kwargs, "O|z:encode",
560 | codeckwarglist, &arg, &errors))
561 | return NULL((void*)0);
562 |
563 | if (PyUnicode_Check(arg)((((((PyObject*)(arg))->ob_type))->tp_flags & ((1L<< 28))) != 0))
564 | ucvt = NULL((void*)0);
565 | else {
566 | arg = ucvt = PyObject_Str(arg);
567 | if (arg == NULL((void*)0))
568 | return NULL((void*)0);
569 | else if (!PyUnicode_Check(arg)((((((PyObject*)(arg))->ob_type))->tp_flags & ((1L<< 28))) != 0)) {
570 | PyErr_SetString(PyExc_TypeError,
571 | "couldn't convert the object to unicode.");
572 | Py_DECREF(ucvt)do { if (_Py_RefTotal-- , --((PyObject*)(ucvt))->ob_refcnt != 0) { if (((PyObject*)ucvt)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 572, (PyObject *)(ucvt)); } else _Py_Dealloc((PyObject *)(ucvt )); } while (0);
573 | return NULL((void*)0);
574 | }
575 | }
576 |
577 | data = PyUnicode_AS_UNICODE(arg)((__builtin_expect(!(((((((PyObject*)(arg))->ob_type))-> tp_flags & ((1L<<28))) != 0)), 0) ? __assert_rtn(__func__ , "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 577, "PyUnicode_Check(arg)") : (void)0),(((PyUnicodeObject * )(arg))->str));
578 | datalen = PyUnicode_GET_SIZE(arg)((__builtin_expect(!(((((((PyObject*)(arg))->ob_type))-> tp_flags & ((1L<<28))) != 0)), 0) ? __assert_rtn(__func__ , "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 578, "PyUnicode_Check(arg)") : (void)0),(((PyUnicodeObject * )(arg))->length));
579 |
580 | errorcb = internal_error_callback(errors);
581 | if (errorcb == NULL((void*)0)) {
582 | Py_XDECREF(ucvt)do { if ((ucvt) == ((void*)0)) ; else do { if (_Py_RefTotal-- , --((PyObject*)(ucvt))->ob_refcnt != 0) { if (((PyObject *)ucvt)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 582, (PyObject *)(ucvt)); } else _Py_Dealloc((PyObject *)(ucvt )); } while (0); } while (0);
583 | return NULL((void*)0);
584 | }
585 |
586 | if (self->codec->encinit != NULL((void*)0) &&
587 | self->codec->encinit(&state, self->codec->config) != 0)
588 | goto errorexit;
589 | r = multibytecodec_encode(self->codec, &state,
590 | (const Py_UNICODE **)&data, datalen, errorcb,
591 | MBENC_FLUSH0x0001 | MBENC_RESET0x0001<<1);
592 | if (r == NULL((void*)0))
593 | goto errorexit;
594 |
595 | ERROR_DECREF(errorcb)do { if (errorcb != ((void*)0) && ((errorcb) < (PyObject *)(1) || (PyObject *)(3) < (errorcb))) { do { if (_Py_RefTotal -- , --((PyObject*)(errorcb))->ob_refcnt != 0) { if (((PyObject *)errorcb)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 595, (PyObject *)(errorcb)); } else _Py_Dealloc((PyObject * )(errorcb)); } while (0); } } while (0);;
596 | Py_XDECREF(ucvt)do { if ((ucvt) == ((void*)0)) ; else do { if (_Py_RefTotal-- , --((PyObject*)(ucvt))->ob_refcnt != 0) { if (((PyObject *)ucvt)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 596, (PyObject *)(ucvt)); } else _Py_Dealloc((PyObject *)(ucvt )); } while (0); } while (0);
597 | return make_tuple(r, datalen);
598 |
599 | errorexit:
600 | ERROR_DECREF(errorcb)do { if (errorcb != ((void*)0) && ((errorcb) < (PyObject *)(1) || (PyObject *)(3) < (errorcb))) { do { if (_Py_RefTotal -- , --((PyObject*)(errorcb))->ob_refcnt != 0) { if (((PyObject *)errorcb)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 600, (PyObject *)(errorcb)); } else _Py_Dealloc((PyObject * )(errorcb)); } while (0); } } while (0);;
601 | Py_XDECREF(ucvt)do { if ((ucvt) == ((void*)0)) ; else do { if (_Py_RefTotal-- , --((PyObject*)(ucvt))->ob_refcnt != 0) { if (((PyObject *)ucvt)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 601, (PyObject *)(ucvt)); } else _Py_Dealloc((PyObject *)(ucvt )); } while (0); } while (0);
602 | return NULL((void*)0);
603 | }
604 |
605 | static PyObject *
606 | MultibyteCodec_Decode(MultibyteCodecObject *self,
607 | PyObject *args, PyObject *kwargs)
608 | {
609 | MultibyteCodec_State state;
610 | MultibyteDecodeBuffer buf;
611 | PyObject *errorcb;
612 | Py_buffer pdata;
613 | const char *data, *errors = NULL((void*)0);
614 | Py_ssize_t datalen, finalsize;
615 |
616 | if (!PyArg_ParseTupleAndKeywords_PyArg_ParseTupleAndKeywords_SizeT(args, kwargs, "y*|z:decode",
617 | codeckwarglist, &pdata, &errors))
618 | return NULL((void*)0);
619 | data = pdata.buf;
620 | datalen = pdata.len;
621 |
622 | errorcb = internal_error_callback(errors);
623 | if (errorcb == NULL((void*)0)) {
624 | PyBuffer_Release(&pdata);
625 | return NULL((void*)0);
626 | }
627 |
628 | if (datalen == 0) {
629 | PyBuffer_Release(&pdata);
630 | ERROR_DECREF(errorcb)do { if (errorcb != ((void*)0) && ((errorcb) < (PyObject *)(1) || (PyObject *)(3) < (errorcb))) { do { if (_Py_RefTotal -- , --((PyObject*)(errorcb))->ob_refcnt != 0) { if (((PyObject *)errorcb)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 630, (PyObject *)(errorcb)); } else _Py_Dealloc((PyObject * )(errorcb)); } while (0); } } while (0);;
631 | return make_tuple(PyUnicode_FromUnicodePyUnicodeUCS2_FromUnicode(NULL((void*)0), 0), 0);
632 | }
633 |
634 | buf.excobj = NULL((void*)0);
635 | buf.inbuf = buf.inbuf_top = (unsigned char *)data;
636 | buf.inbuf_end = buf.inbuf_top + datalen;
637 | buf.outobj = PyUnicode_FromUnicodePyUnicodeUCS2_FromUnicode(NULL((void*)0), datalen);
638 | if (buf.outobj == NULL((void*)0))
639 | goto errorexit;
640 | buf.outbuf = PyUnicode_AS_UNICODE(buf.outobj)((__builtin_expect(!(((((((PyObject*)(buf.outobj))->ob_type ))->tp_flags & ((1L<<28))) != 0)), 0) ? __assert_rtn (__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 640, "PyUnicode_Check(buf.outobj)") : (void)0),(((PyUnicodeObject *)(buf.outobj))->str));
641 | buf.outbuf_end = buf.outbuf + PyUnicode_GET_SIZE(buf.outobj)((__builtin_expect(!(((((((PyObject*)(buf.outobj))->ob_type ))->tp_flags & ((1L<<28))) != 0)), 0) ? __assert_rtn (__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 641, "PyUnicode_Check(buf.outobj)") : (void)0),(((PyUnicodeObject *)(buf.outobj))->length));
642 |
643 | if (self->codec->decinit != NULL((void*)0) &&
644 | self->codec->decinit(&state, self->codec->config) != 0)
645 | goto errorexit;
646 |
647 | while (buf.inbuf < buf.inbuf_end) {
648 | Py_ssize_t inleft, outleft, r;
649 |
650 | inleft = (Py_ssize_t)(buf.inbuf_end - buf.inbuf);
651 | outleft = (Py_ssize_t)(buf.outbuf_end - buf.outbuf);
652 |
653 | r = self->codec->decode(&state, self->codec->config,
654 | &buf.inbuf, inleft, &buf.outbuf, outleft);
655 | if (r == 0)
656 | break;
657 | else if (multibytecodec_decerror(self->codec, &state,
658 | &buf, errorcb, r))
659 | goto errorexit;
660 | }
661 |
662 | finalsize = (Py_ssize_t)(buf.outbuf -
663 | PyUnicode_AS_UNICODE(buf.outobj)((__builtin_expect(!(((((((PyObject*)(buf.outobj))->ob_type ))->tp_flags & ((1L<<28))) != 0)), 0) ? __assert_rtn (__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 663, "PyUnicode_Check(buf.outobj)") : (void)0),(((PyUnicodeObject *)(buf.outobj))->str)));
664 |
665 | if (finalsize != PyUnicode_GET_SIZE(buf.outobj)((__builtin_expect(!(((((((PyObject*)(buf.outobj))->ob_type ))->tp_flags & ((1L<<28))) != 0)), 0) ? __assert_rtn (__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 665, "PyUnicode_Check(buf.outobj)") : (void)0),(((PyUnicodeObject *)(buf.outobj))->length)))
666 | if (PyUnicode_ResizePyUnicodeUCS2_Resize(&buf.outobj, finalsize) == -1)
667 | goto errorexit;
668 |
669 | PyBuffer_Release(&pdata);
670 | Py_XDECREF(buf.excobj)do { if ((buf.excobj) == ((void*)0)) ; else do { if (_Py_RefTotal -- , --((PyObject*)(buf.excobj))->ob_refcnt != 0) { if ((( PyObject*)buf.excobj)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 670, (PyObject *)(buf.excobj)); } else _Py_Dealloc((PyObject *)(buf.excobj)); } while (0); } while (0);
671 | ERROR_DECREF(errorcb)do { if (errorcb != ((void*)0) && ((errorcb) < (PyObject *)(1) || (PyObject *)(3) < (errorcb))) { do { if (_Py_RefTotal -- , --((PyObject*)(errorcb))->ob_refcnt != 0) { if (((PyObject *)errorcb)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 671, (PyObject *)(errorcb)); } else _Py_Dealloc((PyObject * )(errorcb)); } while (0); } } while (0);;
672 | return make_tuple(buf.outobj, datalen);
673 |
674 | errorexit:
675 | PyBuffer_Release(&pdata);
676 | ERROR_DECREF(errorcb)do { if (errorcb != ((void*)0) && ((errorcb) < (PyObject *)(1) || (PyObject *)(3) < (errorcb))) { do { if (_Py_RefTotal -- , --((PyObject*)(errorcb))->ob_refcnt != 0) { if (((PyObject *)errorcb)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 676, (PyObject *)(errorcb)); } else _Py_Dealloc((PyObject * )(errorcb)); } while (0); } } while (0);;
677 | Py_XDECREF(buf.excobj)do { if ((buf.excobj) == ((void*)0)) ; else do { if (_Py_RefTotal -- , --((PyObject*)(buf.excobj))->ob_refcnt != 0) { if ((( PyObject*)buf.excobj)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 677, (PyObject *)(buf.excobj)); } else _Py_Dealloc((PyObject *)(buf.excobj)); } while (0); } while (0);
678 | Py_XDECREF(buf.outobj)do { if ((buf.outobj) == ((void*)0)) ; else do { if (_Py_RefTotal -- , --((PyObject*)(buf.outobj))->ob_refcnt != 0) { if ((( PyObject*)buf.outobj)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 678, (PyObject *)(buf.outobj)); } else _Py_Dealloc((PyObject *)(buf.outobj)); } while (0); } while (0);
679 |
680 | return NULL((void*)0);
681 | }
682 |
683 | static struct PyMethodDef multibytecodec_methods[] = {
684 | {"encode", (PyCFunction)MultibyteCodec_Encode,
685 | METH_VARARGS0x0001 | METH_KEYWORDS0x0002,
686 | MultibyteCodec_Encode__doc__},
687 | {"decode", (PyCFunction)MultibyteCodec_Decode,
688 | METH_VARARGS0x0001 | METH_KEYWORDS0x0002,
689 | MultibyteCodec_Decode__doc__},
690 | {NULL((void*)0), NULL((void*)0)},
691 | };
692 |
693 | static void
694 | multibytecodec_dealloc(MultibyteCodecObject *self)
695 | {
696 | PyObject_Del_PyObject_DebugFree(self);
697 | }
698 |
699 | static PyTypeObject MultibyteCodec_Type = {
700 | PyVarObject_HEAD_INIT(NULL, 0){ { 0, 0, 1, ((void*)0) }, 0 },
701 | "MultibyteCodec", /* tp_name */
702 | sizeof(MultibyteCodecObject), /* tp_basicsize */
703 | 0, /* tp_itemsize */
704 | /* methods */
705 | (destructor)multibytecodec_dealloc, /* tp_dealloc */
706 | 0, /* tp_print */
707 | 0, /* tp_getattr */
708 | 0, /* tp_setattr */
709 | 0, /* tp_reserved */
710 | 0, /* tp_repr */
711 | 0, /* tp_as_number */
712 | 0, /* tp_as_sequence */
713 | 0, /* tp_as_mapping */
714 | 0, /* tp_hash */
715 | 0, /* tp_call */
716 | 0, /* tp_str */
717 | PyObject_GenericGetAttr, /* tp_getattro */
718 | 0, /* tp_setattro */
719 | 0, /* tp_as_buffer */
720 | Py_TPFLAGS_DEFAULT( 0 | (1L<<18) | 0), /* tp_flags */
721 | 0, /* tp_doc */
722 | 0, /* tp_traverse */
723 | 0, /* tp_clear */
724 | 0, /* tp_richcompare */
725 | 0, /* tp_weaklistoffset */
726 | 0, /* tp_iter */
727 | 0, /* tp_iterext */
728 | multibytecodec_methods, /* tp_methods */
729 | };
730 |
731 |
732 | /**
733 | * Utility functions for stateful codec mechanism
734 | */
735 |
736 | #define STATEFUL_DCTX(o)((MultibyteStatefulDecoderContext *)(o)) ((MultibyteStatefulDecoderContext *)(o))
737 | #define STATEFUL_ECTX(o)((MultibyteStatefulEncoderContext *)(o)) ((MultibyteStatefulEncoderContext *)(o))
738 |
739 | static PyObject *
740 | encoder_encode_stateful(MultibyteStatefulEncoderContext *ctx,
741 | PyObject *unistr, int final)
742 | {
743 | PyObject *ucvt, *r = NULL((void*)0);
744 | Py_UNICODE *inbuf, *inbuf_end, *inbuf_tmp = NULL((void*)0);
745 | Py_ssize_t datalen, origpending;
746 |
747 | if (PyUnicode_Check(unistr)((((((PyObject*)(unistr))->ob_type))->tp_flags & (( 1L<<28))) != 0))
748 | ucvt = NULL((void*)0);
749 | else {
750 | unistr = ucvt = PyObject_Str(unistr);
751 | if (unistr == NULL((void*)0))
752 | return NULL((void*)0);
753 | else if (!PyUnicode_Check(unistr)((((((PyObject*)(unistr))->ob_type))->tp_flags & (( 1L<<28))) != 0)) {
754 | PyErr_SetString(PyExc_TypeError,
755 | "couldn't convert the object to unicode.");
756 | Py_DECREF(ucvt)do { if (_Py_RefTotal-- , --((PyObject*)(ucvt))->ob_refcnt != 0) { if (((PyObject*)ucvt)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 756, (PyObject *)(ucvt)); } else _Py_Dealloc((PyObject *)(ucvt )); } while (0);
757 | return NULL((void*)0);
758 | }
759 | }
760 |
761 | datalen = PyUnicode_GET_SIZE(unistr)((__builtin_expect(!(((((((PyObject*)(unistr))->ob_type))-> tp_flags & ((1L<<28))) != 0)), 0) ? __assert_rtn(__func__ , "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 761, "PyUnicode_Check(unistr)") : (void)0),(((PyUnicodeObject *)(unistr))->length));
762 | origpending = ctx->pendingsize;
763 |
764 | if (origpending > 0) {
765 | if (datalen > PY_SSIZE_T_MAX((Py_ssize_t)(((size_t)-1)>>1)) - ctx->pendingsize) {
766 | PyErr_NoMemory();
767 | /* inbuf_tmp == NULL */
768 | goto errorexit;
769 | }
770 | inbuf_tmp = PyMem_New(Py_UNICODE, datalen + ctx->pendingsize)( ((size_t)(datalen + ctx->pendingsize) > ((Py_ssize_t) (((size_t)-1)>>1)) / sizeof(Py_UNICODE)) ? ((void*)0) : ( (Py_UNICODE *) PyMem_Malloc((datalen + ctx->pendingsize ) * sizeof(Py_UNICODE)) ) );
771 | if (inbuf_tmp == NULL((void*)0))
772 | goto errorexit;
773 | memcpy(inbuf_tmp, ctx->pending,((__builtin_object_size (inbuf_tmp, 0) != (size_t) -1) ? __builtin___memcpy_chk (inbuf_tmp, ctx->pending, 2 * ctx->pendingsize, __builtin_object_size (inbuf_tmp, 0)) : __inline_memcpy_chk (inbuf_tmp, ctx->pending , 2 * ctx->pendingsize))
774 | Py_UNICODE_SIZE * ctx->pendingsize)((__builtin_object_size (inbuf_tmp, 0) != (size_t) -1) ? __builtin___memcpy_chk (inbuf_tmp, ctx->pending, 2 * ctx->pendingsize, __builtin_object_size (inbuf_tmp, 0)) : __inline_memcpy_chk (inbuf_tmp, ctx->pending , 2 * ctx->pendingsize));
775 | memcpy(inbuf_tmp + ctx->pendingsize,((__builtin_object_size (inbuf_tmp + ctx->pendingsize, 0) != (size_t) -1) ? __builtin___memcpy_chk (inbuf_tmp + ctx->pendingsize , ((__builtin_expect(!(((((((PyObject*)(unistr))->ob_type) )->tp_flags & ((1L<<28))) != 0)), 0) ? __assert_rtn (__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 776, "PyUnicode_Check(unistr)") : (void)0),(((PyUnicodeObject *)(unistr))->str)), 2 * datalen, __builtin_object_size (inbuf_tmp + ctx->pendingsize, 0)) : __inline_memcpy_chk (inbuf_tmp + ctx->pendingsize, ((__builtin_expect(!(((((((PyObject*)(unistr ))->ob_type))->tp_flags & ((1L<<28))) != 0)), 0) ? __assert_rtn(__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 776, "PyUnicode_Check(unistr)") : (void)0),(((PyUnicodeObject *)(unistr))->str)), 2 * datalen))
776 | PyUnicode_AS_UNICODE(unistr),((__builtin_object_size (inbuf_tmp + ctx->pendingsize, 0) != (size_t) -1) ? __builtin___memcpy_chk (inbuf_tmp + ctx->pendingsize , ((__builtin_expect(!(((((((PyObject*)(unistr))->ob_type) )->tp_flags & ((1L<<28))) != 0)), 0) ? __assert_rtn (__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 776, "PyUnicode_Check(unistr)") : (void)0),(((PyUnicodeObject *)(unistr))->str)), 2 * datalen, __builtin_object_size (inbuf_tmp + ctx->pendingsize, 0)) : __inline_memcpy_chk (inbuf_tmp + ctx->pendingsize, ((__builtin_expect(!(((((((PyObject*)(unistr ))->ob_type))->tp_flags & ((1L<<28))) != 0)), 0) ? __assert_rtn(__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 776, "PyUnicode_Check(unistr)") : (void)0),(((PyUnicodeObject *)(unistr))->str)), 2 * datalen))
777 | Py_UNICODE_SIZE * datalen)((__builtin_object_size (inbuf_tmp + ctx->pendingsize, 0) != (size_t) -1) ? __builtin___memcpy_chk (inbuf_tmp + ctx->pendingsize , ((__builtin_expect(!(((((((PyObject*)(unistr))->ob_type) )->tp_flags & ((1L<<28))) != 0)), 0) ? __assert_rtn (__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 776, "PyUnicode_Check(unistr)") : (void)0),(((PyUnicodeObject *)(unistr))->str)), 2 * datalen, __builtin_object_size (inbuf_tmp + ctx->pendingsize, 0)) : __inline_memcpy_chk (inbuf_tmp + ctx->pendingsize, ((__builtin_expect(!(((((((PyObject*)(unistr ))->ob_type))->tp_flags & ((1L<<28))) != 0)), 0) ? __assert_rtn(__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 776, "PyUnicode_Check(unistr)") : (void)0),(((PyUnicodeObject *)(unistr))->str)), 2 * datalen));
778 | datalen += ctx->pendingsize;
779 | ctx->pendingsize = 0;
780 | inbuf = inbuf_tmp;
781 | }
782 | else
783 | inbuf = (Py_UNICODE *)PyUnicode_AS_UNICODE(unistr)((__builtin_expect(!(((((((PyObject*)(unistr))->ob_type))-> tp_flags & ((1L<<28))) != 0)), 0) ? __assert_rtn(__func__ , "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 783, "PyUnicode_Check(unistr)") : (void)0),(((PyUnicodeObject *)(unistr))->str));
784 |
785 | inbuf_end = inbuf + datalen;
786 |
787 | r = multibytecodec_encode(ctx->codec, &ctx->state,
788 | (const Py_UNICODE **)&inbuf,
789 | datalen, ctx->errors, final ? MBENC_FLUSH0x0001 : 0);
790 | if (r == NULL((void*)0)) {
791 | /* recover the original pending buffer */
792 | if (origpending > 0)
793 | memcpy(ctx->pending, inbuf_tmp,((__builtin_object_size (ctx->pending, 0) != (size_t) -1) ? __builtin___memcpy_chk (ctx->pending, inbuf_tmp, 2 * origpending , __builtin_object_size (ctx->pending, 0)) : __inline_memcpy_chk (ctx->pending, inbuf_tmp, 2 * origpending))
794 | Py_UNICODE_SIZE * origpending)((__builtin_object_size (ctx->pending, 0) != (size_t) -1) ? __builtin___memcpy_chk (ctx->pending, inbuf_tmp, 2 * origpending , __builtin_object_size (ctx->pending, 0)) : __inline_memcpy_chk (ctx->pending, inbuf_tmp, 2 * origpending));
795 | ctx->pendingsize = origpending;
796 | goto errorexit;
797 | }
798 |
799 | if (inbuf < inbuf_end) {
800 | ctx->pendingsize = (Py_ssize_t)(inbuf_end - inbuf);
801 | if (ctx->pendingsize > MAXENCPENDING2) {
802 | /* normal codecs can't reach here */
803 | ctx->pendingsize = 0;
804 | PyErr_SetString(PyExc_UnicodeError,
805 | "pending buffer overflow");
806 | goto errorexit;
807 | }
808 | memcpy(ctx->pending, inbuf,((__builtin_object_size (ctx->pending, 0) != (size_t) -1) ? __builtin___memcpy_chk (ctx->pending, inbuf, ctx->pendingsize * 2, __builtin_object_size (ctx->pending, 0)) : __inline_memcpy_chk (ctx->pending, inbuf, ctx->pendingsize * 2))
809 | ctx->pendingsize * Py_UNICODE_SIZE)((__builtin_object_size (ctx->pending, 0) != (size_t) -1) ? __builtin___memcpy_chk (ctx->pending, inbuf, ctx->pendingsize * 2, __builtin_object_size (ctx->pending, 0)) : __inline_memcpy_chk (ctx->pending, inbuf, ctx->pendingsize * 2));
810 | }
811 |
812 | if (inbuf_tmp != NULL((void*)0))
813 | PyMem_DelPyMem_Free(inbuf_tmp);
814 | Py_XDECREF(ucvt)do { if ((ucvt) == ((void*)0)) ; else do { if (_Py_RefTotal-- , --((PyObject*)(ucvt))->ob_refcnt != 0) { if (((PyObject *)ucvt)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 814, (PyObject *)(ucvt)); } else _Py_Dealloc((PyObject *)(ucvt )); } while (0); } while (0);
815 | return r;
816 |
817 | errorexit:
818 | if (inbuf_tmp != NULL((void*)0))
819 | PyMem_DelPyMem_Free(inbuf_tmp);
820 | Py_XDECREF(r)do { if ((r) == ((void*)0)) ; else do { if (_Py_RefTotal-- , -- ((PyObject*)(r))->ob_refcnt != 0) { if (((PyObject*)r)-> ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 820, (PyObject *)(r)); } else _Py_Dealloc((PyObject *)(r)); } while (0); } while (0);
821 | Py_XDECREF(ucvt)do { if ((ucvt) == ((void*)0)) ; else do { if (_Py_RefTotal-- , --((PyObject*)(ucvt))->ob_refcnt != 0) { if (((PyObject *)ucvt)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 821, (PyObject *)(ucvt)); } else _Py_Dealloc((PyObject *)(ucvt )); } while (0); } while (0);
822 | return NULL((void*)0);
823 | }
824 |
825 | static int
826 | decoder_append_pending(MultibyteStatefulDecoderContext *ctx,
827 | MultibyteDecodeBuffer *buf)
828 | {
829 | Py_ssize_t npendings;
830 |
831 | npendings = (Py_ssize_t)(buf->inbuf_end - buf->inbuf);
832 | if (npendings + ctx->pendingsize > MAXDECPENDING8 ||
833 | npendings > PY_SSIZE_T_MAX((Py_ssize_t)(((size_t)-1)>>1)) - ctx->pendingsize) {
834 | PyErr_SetString(PyExc_UnicodeError, "pending buffer overflow");
835 | return -1;
836 | }
837 | memcpy(ctx->pending + ctx->pendingsize, buf->inbuf, npendings)((__builtin_object_size (ctx->pending + ctx->pendingsize , 0) != (size_t) -1) ? __builtin___memcpy_chk (ctx->pending + ctx->pendingsize, buf->inbuf, npendings, __builtin_object_size (ctx->pending + ctx->pendingsize, 0)) : __inline_memcpy_chk (ctx->pending + ctx->pendingsize, buf->inbuf, npendings ));
838 | ctx->pendingsize += npendings;
839 | return 0;
840 | }
841 |
842 | static int
843 | decoder_prepare_buffer(MultibyteDecodeBuffer *buf, const char *data,
844 | Py_ssize_t size)
845 | {
846 | buf->inbuf = buf->inbuf_top = (const unsigned char *)data;
847 | buf->inbuf_end = buf->inbuf_top + size;
848 | if (buf->outobj == NULL((void*)0)) { /* only if outobj is not allocated yet */
849 | buf->outobj = PyUnicode_FromUnicodePyUnicodeUCS2_FromUnicode(NULL((void*)0), size);
850 | if (buf->outobj == NULL((void*)0))
851 | return -1;
852 | buf->outbuf = PyUnicode_AS_UNICODE(buf->outobj)((__builtin_expect(!(((((((PyObject*)(buf->outobj))->ob_type ))->tp_flags & ((1L<<28))) != 0)), 0) ? __assert_rtn (__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 852, "PyUnicode_Check(buf->outobj)") : (void)0),(((PyUnicodeObject *)(buf->outobj))->str));
853 | buf->outbuf_end = buf->outbuf +
854 | PyUnicode_GET_SIZE(buf->outobj)((__builtin_expect(!(((((((PyObject*)(buf->outobj))->ob_type ))->tp_flags & ((1L<<28))) != 0)), 0) ? __assert_rtn (__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 854, "PyUnicode_Check(buf->outobj)") : (void)0),(((PyUnicodeObject *)(buf->outobj))->length));
855 | }
856 |
857 | return 0;
858 | }
859 |
860 | static int
861 | decoder_feed_buffer(MultibyteStatefulDecoderContext *ctx,
862 | MultibyteDecodeBuffer *buf)
863 | {
864 | while (buf->inbuf < buf->inbuf_end) {
865 | Py_ssize_t inleft, outleft;
866 | Py_ssize_t r;
867 |
868 | inleft = (Py_ssize_t)(buf->inbuf_end - buf->inbuf);
869 | outleft = (Py_ssize_t)(buf->outbuf_end - buf->outbuf);
870 |
871 | r = ctx->codec->decode(&ctx->state, ctx->codec->config,
872 | &buf->inbuf, inleft, &buf->outbuf, outleft);
873 | if (r == 0 || r == MBERR_TOOFEW(-2))
874 | break;
875 | else if (multibytecodec_decerror(ctx->codec, &ctx->state,
876 | buf, ctx->errors, r))
877 | return -1;
878 | }
879 | return 0;
880 | }
881 |
882 |
883 | /**
884 | * MultibyteIncrementalEncoder object
885 | */
886 |
887 | static PyObject *
888 | mbiencoder_encode(MultibyteIncrementalEncoderObject *self,
889 | PyObject *args, PyObject *kwargs)
890 | {
891 | PyObject *data;
892 | int final = 0;
893 |
894 | if (!PyArg_ParseTupleAndKeywords_PyArg_ParseTupleAndKeywords_SizeT(args, kwargs, "O|i:encode",
895 | incrementalkwarglist, &data, &final))
896 | return NULL((void*)0);
897 |
898 | return encoder_encode_stateful(STATEFUL_ECTX(self)((MultibyteStatefulEncoderContext *)(self)), data, final);
899 | }
900 |
901 | static PyObject *
902 | mbiencoder_reset(MultibyteIncrementalEncoderObject *self)
903 | {
904 | if (self->codec->decreset != NULL((void*)0) &&
905 | self->codec->decreset(&self->state, self->codec->config) != 0)
906 | return NULL((void*)0);
907 | self->pendingsize = 0;
908 |
909 | Py_RETURN_NONEreturn ( _Py_RefTotal++ , ((PyObject*)((&_Py_NoneStruct)) )->ob_refcnt++), (&_Py_NoneStruct);
910 | }
911 |
912 | static struct PyMethodDef mbiencoder_methods[] = {
913 | {"encode", (PyCFunction)mbiencoder_encode,
914 | METH_VARARGS0x0001 | METH_KEYWORDS0x0002, NULL((void*)0)},
915 | {"reset", (PyCFunction)mbiencoder_reset,
916 | METH_NOARGS0x0004, NULL((void*)0)},
917 | {NULL((void*)0), NULL((void*)0)},
918 | };
919 |
920 | static PyObject *
921 | mbiencoder_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
922 | {
923 | MultibyteIncrementalEncoderObject *self;
924 | PyObject *codec = NULL((void*)0);
925 | char *errors = NULL((void*)0);
926 |
927 | if (!PyArg_ParseTupleAndKeywords_PyArg_ParseTupleAndKeywords_SizeT(args, kwds, "|s:IncrementalEncoder",
928 | incnewkwarglist, &errors))
929 | return NULL((void*)0);
930 |
931 | self = (MultibyteIncrementalEncoderObject *)type->tp_alloc(type, 0);
932 | if (self == NULL((void*)0))
933 | return NULL((void*)0);
934 |
935 | codec = PyObject_GetAttrString((PyObject *)type, "codec");
936 | if (codec == NULL((void*)0))
937 | goto errorexit;
938 | if (!MultibyteCodec_Check(codec)((codec)->ob_type == &MultibyteCodec_Type)) {
939 | PyErr_SetString(PyExc_TypeError, "codec is unexpected type");
940 | goto errorexit;
941 | }
942 |
943 | self->codec = ((MultibyteCodecObject *)codec)->codec;
944 | self->pendingsize = 0;
945 | self->errors = internal_error_callback(errors);
946 | if (self->errors == NULL((void*)0))
947 | goto errorexit;
948 | if (self->codec->encinit != NULL((void*)0) &&
949 | self->codec->encinit(&self->state, self->codec->config) != 0)
950 | goto errorexit;
951 |
952 | Py_DECREF(codec)do { if (_Py_RefTotal-- , --((PyObject*)(codec))->ob_refcnt != 0) { if (((PyObject*)codec)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 952, (PyObject *)(codec)); } else _Py_Dealloc((PyObject *)( codec)); } while (0);
953 | return (PyObject *)self;
954 |
955 | errorexit:
956 | Py_XDECREF(self)do { if ((self) == ((void*)0)) ; else do { if (_Py_RefTotal-- , --((PyObject*)(self))->ob_refcnt != 0) { if (((PyObject *)self)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 956, (PyObject *)(self)); } else _Py_Dealloc((PyObject *)(self )); } while (0); } while (0);
957 | Py_XDECREF(codec)do { if ((codec) == ((void*)0)) ; else do { if (_Py_RefTotal-- , --((PyObject*)(codec))->ob_refcnt != 0) { if (((PyObject *)codec)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 957, (PyObject *)(codec)); } else _Py_Dealloc((PyObject *)( codec)); } while (0); } while (0);
958 | return NULL((void*)0);
959 | }
960 |
961 | static int
962 | mbiencoder_init(PyObject *self, PyObject *args, PyObject *kwds)
963 | {
964 | return 0;
965 | }
966 |
967 | static int
968 | mbiencoder_traverse(MultibyteIncrementalEncoderObject *self,
969 | visitproc visit, void *arg)
970 | {
971 | if (ERROR_ISCUSTOM(self->errors)((self->errors) < (PyObject *)(1) || (PyObject *)(3) < (self->errors)))
972 | Py_VISIT(self->errors)do { if (self->errors) { int vret = visit((PyObject *)(self ->errors), arg); if (vret) return vret; } } while (0);
973 | return 0;
974 | }
975 |
976 | static void
977 | mbiencoder_dealloc(MultibyteIncrementalEncoderObject *self)
978 | {
979 | PyObject_GC_UnTrack(self);
980 | ERROR_DECREF(self->errors)do { if (self->errors != ((void*)0) && ((self-> errors) < (PyObject *)(1) || (PyObject *)(3) < (self-> errors))) { do { if (_Py_RefTotal-- , --((PyObject*)(self-> errors))->ob_refcnt != 0) { if (((PyObject*)self->errors )->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 980, (PyObject *)(self->errors)); } else _Py_Dealloc((PyObject *)(self->errors)); } while (0); } } while (0);;
981 | Py_TYPE(self)(((PyObject*)(self))->ob_type)->tp_free(self);
982 | }
983 |
984 | static PyTypeObject MultibyteIncrementalEncoder_Type = {
985 | PyVarObject_HEAD_INIT(NULL, 0){ { 0, 0, 1, ((void*)0) }, 0 },
986 | "MultibyteIncrementalEncoder", /* tp_name */
987 | sizeof(MultibyteIncrementalEncoderObject), /* tp_basicsize */
988 | 0, /* tp_itemsize */
989 | /* methods */
990 | (destructor)mbiencoder_dealloc, /* tp_dealloc */
991 | 0, /* tp_print */
992 | 0, /* tp_getattr */
993 | 0, /* tp_setattr */
994 | 0, /* tp_reserved */
995 | 0, /* tp_repr */
996 | 0, /* tp_as_number */
997 | 0, /* tp_as_sequence */
998 | 0, /* tp_as_mapping */
999 | 0, /* tp_hash */
1000 | 0, /* tp_call */
1001 | 0, /* tp_str */
1002 | PyObject_GenericGetAttr, /* tp_getattro */
1003 | 0, /* tp_setattro */
1004 | 0, /* tp_as_buffer */
1005 | Py_TPFLAGS_DEFAULT( 0 | (1L<<18) | 0) | Py_TPFLAGS_HAVE_GC(1L<<14)
1006 | | Py_TPFLAGS_BASETYPE(1L<<10), /* tp_flags */
1007 | 0, /* tp_doc */
1008 | (traverseproc)mbiencoder_traverse, /* tp_traverse */
1009 | 0, /* tp_clear */
1010 | 0, /* tp_richcompare */
1011 | 0, /* tp_weaklistoffset */
1012 | 0, /* tp_iter */
1013 | 0, /* tp_iterext */
1014 | mbiencoder_methods, /* tp_methods */
1015 | 0, /* tp_members */
1016 | codecctx_getsets, /* tp_getset */
1017 | 0, /* tp_base */
1018 | 0, /* tp_dict */
1019 | 0, /* tp_descr_get */
1020 | 0, /* tp_descr_set */
1021 | 0, /* tp_dictoffset */
1022 | mbiencoder_init, /* tp_init */
1023 | 0, /* tp_alloc */
1024 | mbiencoder_new, /* tp_new */
1025 | };
1026 |
1027 |
1028 | /**
1029 | * MultibyteIncrementalDecoder object
1030 | */
1031 |
1032 | static PyObject *
1033 | mbidecoder_decode(MultibyteIncrementalDecoderObject *self,
1034 | PyObject *args, PyObject *kwargs)
1035 | {
1036 | MultibyteDecodeBuffer buf;
1037 | char *data, *wdata = NULL((void*)0);
1038 | Py_buffer pdata;
1039 | Py_ssize_t wsize, finalsize = 0, size, origpending;
1040 | int final = 0;
1041 |
1042 | if (!PyArg_ParseTupleAndKeywords_PyArg_ParseTupleAndKeywords_SizeT(args, kwargs, "y*|i:decode",
1043 | incrementalkwarglist, &pdata, &final))
1044 | return NULL((void*)0);
1045 | data = pdata.buf;
1046 | size = pdata.len;
1047 |
1048 | buf.outobj = buf.excobj = NULL((void*)0);
1049 | origpending = self->pendingsize;
1050 |
1051 | if (self->pendingsize == 0) {
1052 | wsize = size;
1053 | wdata = data;
1054 | }
1055 | else {
1056 | if (size > PY_SSIZE_T_MAX((Py_ssize_t)(((size_t)-1)>>1)) - self->pendingsize) {
1057 | PyErr_NoMemory();
1058 | goto errorexit;
1059 | }
1060 | wsize = size + self->pendingsize;
1061 | wdata = PyMem_Malloc(wsize);
1062 | if (wdata == NULL((void*)0))
1063 | goto errorexit;
1064 | memcpy(wdata, self->pending, self->pendingsize)((__builtin_object_size (wdata, 0) != (size_t) -1) ? __builtin___memcpy_chk (wdata, self->pending, self->pendingsize, __builtin_object_size (wdata, 0)) : __inline_memcpy_chk (wdata, self->pending, self ->pendingsize));
1065 | memcpy(wdata + self->pendingsize, data, size)((__builtin_object_size (wdata + self->pendingsize, 0) != ( size_t) -1) ? __builtin___memcpy_chk (wdata + self->pendingsize , data, size, __builtin_object_size (wdata + self->pendingsize , 0)) : __inline_memcpy_chk (wdata + self->pendingsize, data , size));
1066 | self->pendingsize = 0;
1067 | }
1068 |
1069 | if (decoder_prepare_buffer(&buf, wdata, wsize) != 0)
1070 | goto errorexit;
1071 |
1072 | if (decoder_feed_buffer(STATEFUL_DCTX(self)((MultibyteStatefulDecoderContext *)(self)), &buf))
1073 | goto errorexit;
1074 |
1075 | if (final && buf.inbuf < buf.inbuf_end) {
1076 | if (multibytecodec_decerror(self->codec, &self->state,
1077 | &buf, self->errors, MBERR_TOOFEW(-2))) {
1078 | /* recover the original pending buffer */
1079 | memcpy(self->pending, wdata, origpending)((__builtin_object_size (self->pending, 0) != (size_t) -1) ? __builtin___memcpy_chk (self->pending, wdata, origpending , __builtin_object_size (self->pending, 0)) : __inline_memcpy_chk (self->pending, wdata, origpending));
1080 | self->pendingsize = origpending;
1081 | goto errorexit;
1082 | }
1083 | }
1084 |
1085 | if (buf.inbuf < buf.inbuf_end) { /* pending sequence still exists */
1086 | if (decoder_append_pending(STATEFUL_DCTX(self)((MultibyteStatefulDecoderContext *)(self)), &buf) != 0)
1087 | goto errorexit;
1088 | }
1089 |
1090 | finalsize = (Py_ssize_t)(buf.outbuf - PyUnicode_AS_UNICODE(buf.outobj)((__builtin_expect(!(((((((PyObject*)(buf.outobj))->ob_type ))->tp_flags & ((1L<<28))) != 0)), 0) ? __assert_rtn (__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1090, "PyUnicode_Check(buf.outobj)") : (void)0),(((PyUnicodeObject *)(buf.outobj))->str)));
1091 | if (finalsize != PyUnicode_GET_SIZE(buf.outobj)((__builtin_expect(!(((((((PyObject*)(buf.outobj))->ob_type ))->tp_flags & ((1L<<28))) != 0)), 0) ? __assert_rtn (__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1091, "PyUnicode_Check(buf.outobj)") : (void)0),(((PyUnicodeObject *)(buf.outobj))->length)))
1092 | if (PyUnicode_ResizePyUnicodeUCS2_Resize(&buf.outobj, finalsize) == -1)
1093 | goto errorexit;
1094 |
1095 | PyBuffer_Release(&pdata);
1096 | if (wdata != data)
1097 | PyMem_DelPyMem_Free(wdata);
1098 | Py_XDECREF(buf.excobj)do { if ((buf.excobj) == ((void*)0)) ; else do { if (_Py_RefTotal -- , --((PyObject*)(buf.excobj))->ob_refcnt != 0) { if ((( PyObject*)buf.excobj)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1098, (PyObject *)(buf.excobj)); } else _Py_Dealloc((PyObject *)(buf.excobj)); } while (0); } while (0);
1099 | return buf.outobj;
1100 |
1101 | errorexit:
1102 | PyBuffer_Release(&pdata);
1103 | if (wdata != NULL((void*)0) && wdata != data)
1104 | PyMem_DelPyMem_Free(wdata);
1105 | Py_XDECREF(buf.excobj)do { if ((buf.excobj) == ((void*)0)) ; else do { if (_Py_RefTotal -- , --((PyObject*)(buf.excobj))->ob_refcnt != 0) { if ((( PyObject*)buf.excobj)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1105, (PyObject *)(buf.excobj)); } else _Py_Dealloc((PyObject *)(buf.excobj)); } while (0); } while (0);
1106 | Py_XDECREF(buf.outobj)do { if ((buf.outobj) == ((void*)0)) ; else do { if (_Py_RefTotal -- , --((PyObject*)(buf.outobj))->ob_refcnt != 0) { if ((( PyObject*)buf.outobj)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1106, (PyObject *)(buf.outobj)); } else _Py_Dealloc((PyObject *)(buf.outobj)); } while (0); } while (0);
1107 | return NULL((void*)0);
1108 | }
1109 |
1110 | static PyObject *
1111 | mbidecoder_reset(MultibyteIncrementalDecoderObject *self)
1112 | {
1113 | if (self->codec->decreset != NULL((void*)0) &&
1114 | self->codec->decreset(&self->state, self->codec->config) != 0)
1115 | return NULL((void*)0);
1116 | self->pendingsize = 0;
1117 |
1118 | Py_RETURN_NONEreturn ( _Py_RefTotal++ , ((PyObject*)((&_Py_NoneStruct)) )->ob_refcnt++), (&_Py_NoneStruct);
1119 | }
1120 |
1121 | static struct PyMethodDef mbidecoder_methods[] = {
1122 | {"decode", (PyCFunction)mbidecoder_decode,
1123 | METH_VARARGS0x0001 | METH_KEYWORDS0x0002, NULL((void*)0)},
1124 | {"reset", (PyCFunction)mbidecoder_reset,
1125 | METH_NOARGS0x0004, NULL((void*)0)},
1126 | {NULL((void*)0), NULL((void*)0)},
1127 | };
1128 |
1129 | static PyObject *
1130 | mbidecoder_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
1131 | {
1132 | MultibyteIncrementalDecoderObject *self;
1133 | PyObject *codec = NULL((void*)0);
1134 | char *errors = NULL((void*)0);
1135 |
1136 | if (!PyArg_ParseTupleAndKeywords_PyArg_ParseTupleAndKeywords_SizeT(args, kwds, "|s:IncrementalDecoder",
1137 | incnewkwarglist, &errors))
1138 | return NULL((void*)0);
1139 |
1140 | self = (MultibyteIncrementalDecoderObject *)type->tp_alloc(type, 0);
1141 | if (self == NULL((void*)0))
1142 | return NULL((void*)0);
1143 |
1144 | codec = PyObject_GetAttrString((PyObject *)type, "codec");
1145 | if (codec == NULL((void*)0))
1146 | goto errorexit;
1147 | if (!MultibyteCodec_Check(codec)((codec)->ob_type == &MultibyteCodec_Type)) {
1148 | PyErr_SetString(PyExc_TypeError, "codec is unexpected type");
1149 | goto errorexit;
1150 | }
1151 |
1152 | self->codec = ((MultibyteCodecObject *)codec)->codec;
1153 | self->pendingsize = 0;
1154 | self->errors = internal_error_callback(errors);
1155 | if (self->errors == NULL((void*)0))
1156 | goto errorexit;
1157 | if (self->codec->decinit != NULL((void*)0) &&
1158 | self->codec->decinit(&self->state, self->codec->config) != 0)
1159 | goto errorexit;
1160 |
1161 | Py_DECREF(codec)do { if (_Py_RefTotal-- , --((PyObject*)(codec))->ob_refcnt != 0) { if (((PyObject*)codec)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1161, (PyObject *)(codec)); } else _Py_Dealloc((PyObject *) (codec)); } while (0);
1162 | return (PyObject *)self;
1163 |
1164 | errorexit:
1165 | Py_XDECREF(self)do { if ((self) == ((void*)0)) ; else do { if (_Py_RefTotal-- , --((PyObject*)(self))->ob_refcnt != 0) { if (((PyObject *)self)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1165, (PyObject *)(self)); } else _Py_Dealloc((PyObject *)( self)); } while (0); } while (0);
1166 | Py_XDECREF(codec)do { if ((codec) == ((void*)0)) ; else do { if (_Py_RefTotal-- , --((PyObject*)(codec))->ob_refcnt != 0) { if (((PyObject *)codec)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1166, (PyObject *)(codec)); } else _Py_Dealloc((PyObject *) (codec)); } while (0); } while (0);
1167 | return NULL((void*)0);
1168 | }
1169 |
1170 | static int
1171 | mbidecoder_init(PyObject *self, PyObject *args, PyObject *kwds)
1172 | {
1173 | return 0;
1174 | }
1175 |
1176 | static int
1177 | mbidecoder_traverse(MultibyteIncrementalDecoderObject *self,
1178 | visitproc visit, void *arg)
1179 | {
1180 | if (ERROR_ISCUSTOM(self->errors)((self->errors) < (PyObject *)(1) || (PyObject *)(3) < (self->errors)))
1181 | Py_VISIT(self->errors)do { if (self->errors) { int vret = visit((PyObject *)(self ->errors), arg); if (vret) return vret; } } while (0);
1182 | return 0;
1183 | }
1184 |
1185 | static void
1186 | mbidecoder_dealloc(MultibyteIncrementalDecoderObject *self)
1187 | {
1188 | PyObject_GC_UnTrack(self);
1189 | ERROR_DECREF(self->errors)do { if (self->errors != ((void*)0) && ((self-> errors) < (PyObject *)(1) || (PyObject *)(3) < (self-> errors))) { do { if (_Py_RefTotal-- , --((PyObject*)(self-> errors))->ob_refcnt != 0) { if (((PyObject*)self->errors )->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1189, (PyObject *)(self->errors)); } else _Py_Dealloc((PyObject *)(self->errors)); } while (0); } } while (0);;
1190 | Py_TYPE(self)(((PyObject*)(self))->ob_type)->tp_free(self);
1191 | }
1192 |
1193 | static PyTypeObject MultibyteIncrementalDecoder_Type = {
1194 | PyVarObject_HEAD_INIT(NULL, 0){ { 0, 0, 1, ((void*)0) }, 0 },
1195 | "MultibyteIncrementalDecoder", /* tp_name */
1196 | sizeof(MultibyteIncrementalDecoderObject), /* tp_basicsize */
1197 | 0, /* tp_itemsize */
1198 | /* methods */
1199 | (destructor)mbidecoder_dealloc, /* tp_dealloc */
1200 | 0, /* tp_print */
1201 | 0, /* tp_getattr */
1202 | 0, /* tp_setattr */
1203 | 0, /* tp_reserved */
1204 | 0, /* tp_repr */
1205 | 0, /* tp_as_number */
1206 | 0, /* tp_as_sequence */
1207 | 0, /* tp_as_mapping */
1208 | 0, /* tp_hash */
1209 | 0, /* tp_call */
1210 | 0, /* tp_str */
1211 | PyObject_GenericGetAttr, /* tp_getattro */
1212 | 0, /* tp_setattro */
1213 | 0, /* tp_as_buffer */
1214 | Py_TPFLAGS_DEFAULT( 0 | (1L<<18) | 0) | Py_TPFLAGS_HAVE_GC(1L<<14)
1215 | | Py_TPFLAGS_BASETYPE(1L<<10), /* tp_flags */
1216 | 0, /* tp_doc */
1217 | (traverseproc)mbidecoder_traverse, /* tp_traverse */
1218 | 0, /* tp_clear */
1219 | 0, /* tp_richcompare */
1220 | 0, /* tp_weaklistoffset */
1221 | 0, /* tp_iter */
1222 | 0, /* tp_iterext */
1223 | mbidecoder_methods, /* tp_methods */
1224 | 0, /* tp_members */
1225 | codecctx_getsets, /* tp_getset */
1226 | 0, /* tp_base */
1227 | 0, /* tp_dict */
1228 | 0, /* tp_descr_get */
1229 | 0, /* tp_descr_set */
1230 | 0, /* tp_dictoffset */
1231 | mbidecoder_init, /* tp_init */
1232 | 0, /* tp_alloc */
1233 | mbidecoder_new, /* tp_new */
1234 | };
1235 |
1236 |
1237 | /**
1238 | * MultibyteStreamReader object
1239 | */
1240 |
1241 | static PyObject *
1242 | mbstreamreader_iread(MultibyteStreamReaderObject *self,
1243 | const char *method, Py_ssize_t sizehint)
1244 | {
1245 | MultibyteDecodeBuffer buf;
1246 | PyObject *cres;
1247 | Py_ssize_t rsize, finalsize = 0;
1248 |
1249 | if (sizehint == 0)
1250 | return PyUnicode_FromUnicodePyUnicodeUCS2_FromUnicode(NULL((void*)0), 0);
1251 |
1252 | buf.outobj = buf.excobj = NULL((void*)0);
1253 | cres = NULL((void*)0);
1254 |
1255 | for (;;) {
1256 | int endoffile;
1257 |
1258 | if (sizehint < 0)
1259 | cres = PyObject_CallMethod_PyObject_CallMethod_SizeT(self->stream,
1260 | (char *)method, NULL((void*)0));
1261 | else
1262 | cres = PyObject_CallMethod_PyObject_CallMethod_SizeT(self->stream,
1263 | (char *)method, "i", sizehint);
1264 | if (cres == NULL((void*)0))
1265 | goto errorexit;
1266 |
1267 | if (!PyBytes_Check(cres)((((((PyObject*)(cres))->ob_type))->tp_flags & ((1L <<27))) != 0)) {
1268 | PyErr_Format(PyExc_TypeError,
1269 | "stream function returned a "
1270 | "non-bytes object (%.100s)",
1271 | cres->ob_type->tp_name);
1272 | goto errorexit;
1273 | }
1274 |
1275 | endoffile = (PyBytes_GET_SIZE(cres)((__builtin_expect(!(((((((PyObject*)(cres))->ob_type))-> tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn(__func__ , "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1275, "PyBytes_Check(cres)") : (void)0),(((PyVarObject*)(cres ))->ob_size)) == 0);
1276 |
1277 | if (self->pendingsize > 0) {
1278 | PyObject *ctr;
1279 | char *ctrdata;
1280 |
1281 | if (PyBytes_GET_SIZE(cres)((__builtin_expect(!(((((((PyObject*)(cres))->ob_type))-> tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn(__func__ , "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1281, "PyBytes_Check(cres)") : (void)0),(((PyVarObject*)(cres ))->ob_size)) > PY_SSIZE_T_MAX((Py_ssize_t)(((size_t)-1)>>1)) - self->pendingsize) {
1282 | PyErr_NoMemory();
1283 | goto errorexit;
1284 | }
1285 | rsize = PyBytes_GET_SIZE(cres)((__builtin_expect(!(((((((PyObject*)(cres))->ob_type))-> tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn(__func__ , "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1285, "PyBytes_Check(cres)") : (void)0),(((PyVarObject*)(cres ))->ob_size)) + self->pendingsize;
1286 | ctr = PyBytes_FromStringAndSize(NULL((void*)0), rsize);
1287 | if (ctr == NULL((void*)0))
1288 | goto errorexit;
1289 | ctrdata = PyBytes_AS_STRING(ctr)((__builtin_expect(!(((((((PyObject*)(ctr))->ob_type))-> tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn(__func__ , "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1289, "PyBytes_Check(ctr)") : (void)0), (((PyBytesObject *) (ctr))->ob_sval));
1290 | memcpy(ctrdata, self->pending, self->pendingsize)((__builtin_object_size (ctrdata, 0) != (size_t) -1) ? __builtin___memcpy_chk (ctrdata, self->pending, self->pendingsize, __builtin_object_size (ctrdata, 0)) : __inline_memcpy_chk (ctrdata, self->pending , self->pendingsize));
1291 | memcpy(ctrdata + self->pendingsize,((__builtin_object_size (ctrdata + self->pendingsize, 0) != (size_t) -1) ? __builtin___memcpy_chk (ctrdata + self->pendingsize , ((__builtin_expect(!(((((((PyObject*)(cres))->ob_type))-> tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn(__func__ , "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1292, "PyBytes_Check(cres)") : (void)0), (((PyBytesObject * )(cres))->ob_sval)), ((__builtin_expect(!(((((((PyObject*) (cres))->ob_type))->tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn(__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1293, "PyBytes_Check(cres)") : (void)0),(((PyVarObject*)(cres ))->ob_size)), __builtin_object_size (ctrdata + self->pendingsize , 0)) : __inline_memcpy_chk (ctrdata + self->pendingsize, ( (__builtin_expect(!(((((((PyObject*)(cres))->ob_type))-> tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn(__func__ , "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1292, "PyBytes_Check(cres)") : (void)0), (((PyBytesObject * )(cres))->ob_sval)), ((__builtin_expect(!(((((((PyObject*) (cres))->ob_type))->tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn(__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1293, "PyBytes_Check(cres)") : (void)0),(((PyVarObject*)(cres ))->ob_size))))
1292 | PyBytes_AS_STRING(cres),((__builtin_object_size (ctrdata + self->pendingsize, 0) != (size_t) -1) ? __builtin___memcpy_chk (ctrdata + self->pendingsize , ((__builtin_expect(!(((((((PyObject*)(cres))->ob_type))-> tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn(__func__ , "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1292, "PyBytes_Check(cres)") : (void)0), (((PyBytesObject * )(cres))->ob_sval)), ((__builtin_expect(!(((((((PyObject*) (cres))->ob_type))->tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn(__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1293, "PyBytes_Check(cres)") : (void)0),(((PyVarObject*)(cres ))->ob_size)), __builtin_object_size (ctrdata + self->pendingsize , 0)) : __inline_memcpy_chk (ctrdata + self->pendingsize, ( (__builtin_expect(!(((((((PyObject*)(cres))->ob_type))-> tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn(__func__ , "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1292, "PyBytes_Check(cres)") : (void)0), (((PyBytesObject * )(cres))->ob_sval)), ((__builtin_expect(!(((((((PyObject*) (cres))->ob_type))->tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn(__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1293, "PyBytes_Check(cres)") : (void)0),(((PyVarObject*)(cres ))->ob_size))))
1293 | PyBytes_GET_SIZE(cres))((__builtin_object_size (ctrdata + self->pendingsize, 0) != (size_t) -1) ? __builtin___memcpy_chk (ctrdata + self->pendingsize , ((__builtin_expect(!(((((((PyObject*)(cres))->ob_type))-> tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn(__func__ , "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1292, "PyBytes_Check(cres)") : (void)0), (((PyBytesObject * )(cres))->ob_sval)), ((__builtin_expect(!(((((((PyObject*) (cres))->ob_type))->tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn(__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1293, "PyBytes_Check(cres)") : (void)0),(((PyVarObject*)(cres ))->ob_size)), __builtin_object_size (ctrdata + self->pendingsize , 0)) : __inline_memcpy_chk (ctrdata + self->pendingsize, ( (__builtin_expect(!(((((((PyObject*)(cres))->ob_type))-> tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn(__func__ , "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1292, "PyBytes_Check(cres)") : (void)0), (((PyBytesObject * )(cres))->ob_sval)), ((__builtin_expect(!(((((((PyObject*) (cres))->ob_type))->tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn(__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1293, "PyBytes_Check(cres)") : (void)0),(((PyVarObject*)(cres ))->ob_size))));
1294 | Py_DECREF(cres)do { if (_Py_RefTotal-- , --((PyObject*)(cres))->ob_refcnt != 0) { if (((PyObject*)cres)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1294, (PyObject *)(cres)); } else _Py_Dealloc((PyObject *)( cres)); } while (0);
1295 | cres = ctr;
1296 | self->pendingsize = 0;
1297 | }
1298 |
1299 | rsize = PyBytes_GET_SIZE(cres)((__builtin_expect(!(((((((PyObject*)(cres))->ob_type))-> tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn(__func__ , "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1299, "PyBytes_Check(cres)") : (void)0),(((PyVarObject*)(cres ))->ob_size));
1300 | if (decoder_prepare_buffer(&buf, PyBytes_AS_STRING(cres)((__builtin_expect(!(((((((PyObject*)(cres))->ob_type))-> tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn(__func__ , "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1300, "PyBytes_Check(cres)") : (void)0), (((PyBytesObject * )(cres))->ob_sval)),
1301 | rsize) != 0)
1302 | goto errorexit;
1303 |
1304 | if (rsize > 0 && decoder_feed_buffer(
1305 | (MultibyteStatefulDecoderContext *)self, &buf))
1306 | goto errorexit;
1307 |
1308 | if (endoffile || sizehint < 0) {
1309 | if (buf.inbuf < buf.inbuf_end &&
1310 | multibytecodec_decerror(self->codec, &self->state,
1311 | &buf, self->errors, MBERR_TOOFEW(-2)))
1312 | goto errorexit;
1313 | }
1314 |
1315 | if (buf.inbuf < buf.inbuf_end) { /* pending sequence exists */
1316 | if (decoder_append_pending(STATEFUL_DCTX(self)((MultibyteStatefulDecoderContext *)(self)),
1317 | &buf) != 0)
1318 | goto errorexit;
1319 | }
1320 |
1321 | finalsize = (Py_ssize_t)(buf.outbuf -
1322 | PyUnicode_AS_UNICODE(buf.outobj)((__builtin_expect(!(((((((PyObject*)(buf.outobj))->ob_type ))->tp_flags & ((1L<<28))) != 0)), 0) ? __assert_rtn (__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1322, "PyUnicode_Check(buf.outobj)") : (void)0),(((PyUnicodeObject *)(buf.outobj))->str)));
1323 | Py_DECREF(cres)do { if (_Py_RefTotal-- , --((PyObject*)(cres))->ob_refcnt != 0) { if (((PyObject*)cres)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1323, (PyObject *)(cres)); } else _Py_Dealloc((PyObject *)( cres)); } while (0);
1324 | cres = NULL((void*)0);
1325 |
1326 | if (sizehint < 0 || finalsize != 0 || rsize == 0)
1327 | break;
1328 |
1329 | sizehint = 1; /* read 1 more byte and retry */
1330 | }
1331 |
1332 | if (finalsize != PyUnicode_GET_SIZE(buf.outobj)((__builtin_expect(!(((((((PyObject*)(buf.outobj))->ob_type ))->tp_flags & ((1L<<28))) != 0)), 0) ? __assert_rtn (__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1332, "PyUnicode_Check(buf.outobj)") : (void)0),(((PyUnicodeObject *)(buf.outobj))->length)))
1333 | if (PyUnicode_ResizePyUnicodeUCS2_Resize(&buf.outobj, finalsize) == -1)
1334 | goto errorexit;
1335 |
1336 | Py_XDECREF(cres)do { if ((cres) == ((void*)0)) ; else do { if (_Py_RefTotal-- , --((PyObject*)(cres))->ob_refcnt != 0) { if (((PyObject *)cres)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1336, (PyObject *)(cres)); } else _Py_Dealloc((PyObject *)( cres)); } while (0); } while (0);
1337 | Py_XDECREF(buf.excobj)do { if ((buf.excobj) == ((void*)0)) ; else do { if (_Py_RefTotal -- , --((PyObject*)(buf.excobj))->ob_refcnt != 0) { if ((( PyObject*)buf.excobj)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1337, (PyObject *)(buf.excobj)); } else _Py_Dealloc((PyObject *)(buf.excobj)); } while (0); } while (0);
1338 | return buf.outobj;
1339 |
1340 | errorexit:
1341 | Py_XDECREF(cres)do { if ((cres) == ((void*)0)) ; else do { if (_Py_RefTotal-- , --((PyObject*)(cres))->ob_refcnt != 0) { if (((PyObject *)cres)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1341, (PyObject *)(cres)); } else _Py_Dealloc((PyObject *)( cres)); } while (0); } while (0);
1342 | Py_XDECREF(buf.excobj)do { if ((buf.excobj) == ((void*)0)) ; else do { if (_Py_RefTotal -- , --((PyObject*)(buf.excobj))->ob_refcnt != 0) { if ((( PyObject*)buf.excobj)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1342, (PyObject *)(buf.excobj)); } else _Py_Dealloc((PyObject *)(buf.excobj)); } while (0); } while (0);
1343 | Py_XDECREF(buf.outobj)do { if ((buf.outobj) == ((void*)0)) ; else do { if (_Py_RefTotal -- , --((PyObject*)(buf.outobj))->ob_refcnt != 0) { if ((( PyObject*)buf.outobj)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1343, (PyObject *)(buf.outobj)); } else _Py_Dealloc((PyObject *)(buf.outobj)); } while (0); } while (0);
1344 | return NULL((void*)0);
1345 | }
1346 |
1347 | static PyObject *
1348 | mbstreamreader_read(MultibyteStreamReaderObject *self, PyObject *args)
1349 | {
1350 | PyObject *sizeobj = NULL((void*)0);
1351 | Py_ssize_t size;
1352 |
1353 | if (!PyArg_UnpackTuple(args, "read", 0, 1, &sizeobj))
1354 | return NULL((void*)0);
1355 |
1356 | if (sizeobj == Py_None(&_Py_NoneStruct) || sizeobj == NULL((void*)0))
1357 | size = -1;
1358 | else if (PyLong_Check(sizeobj)((((((PyObject*)(sizeobj))->ob_type))->tp_flags & ( (1L<<24))) != 0))
1359 | size = PyLong_AsSsize_t(sizeobj);
1360 | else {
1361 | PyErr_SetString(PyExc_TypeError, "arg 1 must be an integer");
1362 | return NULL((void*)0);
1363 | }
1364 |
1365 | if (size == -1 && PyErr_Occurred())
1366 | return NULL((void*)0);
1367 |
1368 | return mbstreamreader_iread(self, "read", size);
1369 | }
1370 |
1371 | static PyObject *
1372 | mbstreamreader_readline(MultibyteStreamReaderObject *self, PyObject *args)
1373 | {
1374 | PyObject *sizeobj = NULL((void*)0);
1375 | Py_ssize_t size;
1376 |
1377 | if (!PyArg_UnpackTuple(args, "readline", 0, 1, &sizeobj))
1378 | return NULL((void*)0);
1379 |
1380 | if (sizeobj == Py_None(&_Py_NoneStruct) || sizeobj == NULL((void*)0))
1381 | size = -1;
1382 | else if (PyLong_Check(sizeobj)((((((PyObject*)(sizeobj))->ob_type))->tp_flags & ( (1L<<24))) != 0))
1383 | size = PyLong_AsSsize_t(sizeobj);
1384 | else {
1385 | PyErr_SetString(PyExc_TypeError, "arg 1 must be an integer");
1386 | return NULL((void*)0);
1387 | }
1388 |
1389 | if (size == -1 && PyErr_Occurred())
1390 | return NULL((void*)0);
1391 |
1392 | return mbstreamreader_iread(self, "readline", size);
1393 | }
1394 |
1395 | static PyObject *
1396 | mbstreamreader_readlines(MultibyteStreamReaderObject *self, PyObject *args)
1397 | {
1398 | PyObject *sizehintobj = NULL((void*)0), *r, *sr;
1399 | Py_ssize_t sizehint;
1400 |
1401 | if (!PyArg_UnpackTuple(args, "readlines", 0, 1, &sizehintobj))
1402 | return NULL((void*)0);
1403 |
1404 | if (sizehintobj == Py_None(&_Py_NoneStruct) || sizehintobj == NULL((void*)0))
1405 | sizehint = -1;
1406 | else if (PyLong_Check(sizehintobj)((((((PyObject*)(sizehintobj))->ob_type))->tp_flags & ((1L<<24))) != 0))
1407 | sizehint = PyLong_AsSsize_t(sizehintobj);
1408 | else {
1409 | PyErr_SetString(PyExc_TypeError, "arg 1 must be an integer");
1410 | return NULL((void*)0);
1411 | }
1412 |
1413 | if (sizehint == -1 && PyErr_Occurred())
1414 | return NULL((void*)0);
1415 |
1416 | r = mbstreamreader_iread(self, "read", sizehint);
1417 | if (r == NULL((void*)0))
1418 | return NULL((void*)0);
1419 |
1420 | sr = PyUnicode_SplitlinesPyUnicodeUCS2_Splitlines(r, 1);
1421 | Py_DECREF(r)do { if (_Py_RefTotal-- , --((PyObject*)(r))->ob_refcnt != 0) { if (((PyObject*)r)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1421, (PyObject *)(r)); } else _Py_Dealloc((PyObject *)(r)) ; } while (0);
1422 | return sr;
1423 | }
1424 |
1425 | static PyObject *
1426 | mbstreamreader_reset(MultibyteStreamReaderObject *self)
1427 | {
1428 | if (self->codec->decreset != NULL((void*)0) &&
1429 | self->codec->decreset(&self->state, self->codec->config) != 0)
1430 | return NULL((void*)0);
1431 | self->pendingsize = 0;
1432 |
1433 | Py_RETURN_NONEreturn ( _Py_RefTotal++ , ((PyObject*)((&_Py_NoneStruct)) )->ob_refcnt++), (&_Py_NoneStruct);
1434 | }
1435 |
1436 | static struct PyMethodDef mbstreamreader_methods[] = {
1437 | {"read", (PyCFunction)mbstreamreader_read,
1438 | METH_VARARGS0x0001, NULL((void*)0)},
1439 | {"readline", (PyCFunction)mbstreamreader_readline,
1440 | METH_VARARGS0x0001, NULL((void*)0)},
1441 | {"readlines", (PyCFunction)mbstreamreader_readlines,
1442 | METH_VARARGS0x0001, NULL((void*)0)},
1443 | {"reset", (PyCFunction)mbstreamreader_reset,
1444 | METH_NOARGS0x0004, NULL((void*)0)},
1445 | {NULL((void*)0), NULL((void*)0)},
1446 | };
1447 |
1448 | static PyMemberDef mbstreamreader_members[] = {
1449 | {"stream", T_OBJECT6,
1450 | offsetof(MultibyteStreamReaderObject, stream)__builtin_offsetof(MultibyteStreamReaderObject, stream),
1451 | READONLY1, NULL((void*)0)},
1452 | {NULL((void*)0),}
1453 | };
1454 |
1455 | static PyObject *
1456 | mbstreamreader_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
1457 | {
1458 | MultibyteStreamReaderObject *self;
1459 | PyObject *stream, *codec = NULL((void*)0);
1460 | char *errors = NULL((void*)0);
1461 |
1462 | if (!PyArg_ParseTupleAndKeywords_PyArg_ParseTupleAndKeywords_SizeT(args, kwds, "O|s:StreamReader",
1463 | streamkwarglist, &stream, &errors))
1464 | return NULL((void*)0);
1465 |
1466 | self = (MultibyteStreamReaderObject *)type->tp_alloc(type, 0);
1467 | if (self == NULL((void*)0))
1468 | return NULL((void*)0);
1469 |
1470 | codec = PyObject_GetAttrString((PyObject *)type, "codec");
1471 | if (codec == NULL((void*)0))
1472 | goto errorexit;
1473 | if (!MultibyteCodec_Check(codec)((codec)->ob_type == &MultibyteCodec_Type)) {
1474 | PyErr_SetString(PyExc_TypeError, "codec is unexpected type");
1475 | goto errorexit;
1476 | }
1477 |
1478 | self->codec = ((MultibyteCodecObject *)codec)->codec;
1479 | self->stream = stream;
1480 | Py_INCREF(stream)( _Py_RefTotal++ , ((PyObject*)(stream))->ob_refcnt++);
1481 | self->pendingsize = 0;
1482 | self->errors = internal_error_callback(errors);
1483 | if (self->errors == NULL((void*)0))
1484 | goto errorexit;
1485 | if (self->codec->decinit != NULL((void*)0) &&
1486 | self->codec->decinit(&self->state, self->codec->config) != 0)
1487 | goto errorexit;
1488 |
1489 | Py_DECREF(codec)do { if (_Py_RefTotal-- , --((PyObject*)(codec))->ob_refcnt != 0) { if (((PyObject*)codec)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1489, (PyObject *)(codec)); } else _Py_Dealloc((PyObject *) (codec)); } while (0);
1490 | return (PyObject *)self;
1491 |
1492 | errorexit:
1493 | Py_XDECREF(self)do { if ((self) == ((void*)0)) ; else do { if (_Py_RefTotal-- , --((PyObject*)(self))->ob_refcnt != 0) { if (((PyObject *)self)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1493, (PyObject *)(self)); } else _Py_Dealloc((PyObject *)( self)); } while (0); } while (0);
1494 | Py_XDECREF(codec)do { if ((codec) == ((void*)0)) ; else do { if (_Py_RefTotal-- , --((PyObject*)(codec))->ob_refcnt != 0) { if (((PyObject *)codec)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1494, (PyObject *)(codec)); } else _Py_Dealloc((PyObject *) (codec)); } while (0); } while (0);
1495 | return NULL((void*)0);
1496 | }
1497 |
1498 | static int
1499 | mbstreamreader_init(PyObject *self, PyObject *args, PyObject *kwds)
1500 | {
1501 | return 0;
1502 | }
1503 |
1504 | static int
1505 | mbstreamreader_traverse(MultibyteStreamReaderObject *self,
1506 | visitproc visit, void *arg)
1507 | {
1508 | if (ERROR_ISCUSTOM(self->errors)((self->errors) < (PyObject *)(1) || (PyObject *)(3) < (self->errors)))
1509 | Py_VISIT(self->errors)do { if (self->errors) { int vret = visit((PyObject *)(self ->errors), arg); if (vret) return vret; } } while (0);
1510 | Py_VISIT(self->stream)do { if (self->stream) { int vret = visit((PyObject *)(self ->stream), arg); if (vret) return vret; } } while (0);
1511 | return 0;
1512 | }
1513 |
1514 | static void
1515 | mbstreamreader_dealloc(MultibyteStreamReaderObject *self)
1516 | {
1517 | PyObject_GC_UnTrack(self);
1518 | ERROR_DECREF(self->errors)do { if (self->errors != ((void*)0) && ((self-> errors) < (PyObject *)(1) || (PyObject *)(3) < (self-> errors))) { do { if (_Py_RefTotal-- , --((PyObject*)(self-> errors))->ob_refcnt != 0) { if (((PyObject*)self->errors )->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1518, (PyObject *)(self->errors)); } else _Py_Dealloc((PyObject *)(self->errors)); } while (0); } } while (0);;
1519 | Py_XDECREF(self->stream)do { if ((self->stream) == ((void*)0)) ; else do { if (_Py_RefTotal -- , --((PyObject*)(self->stream))->ob_refcnt != 0) { if (((PyObject*)self->stream)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1519, (PyObject *)(self->stream)); } else _Py_Dealloc((PyObject *)(self->stream)); } while (0); } while (0);
1520 | Py_TYPE(self)(((PyObject*)(self))->ob_type)->tp_free(self);
1521 | }
1522 |
1523 | static PyTypeObject MultibyteStreamReader_Type = {
1524 | PyVarObject_HEAD_INIT(NULL, 0){ { 0, 0, 1, ((void*)0) }, 0 },
1525 | "MultibyteStreamReader", /* tp_name */
1526 | sizeof(MultibyteStreamReaderObject), /* tp_basicsize */
1527 | 0, /* tp_itemsize */
1528 | /* methods */
1529 | (destructor)mbstreamreader_dealloc, /* tp_dealloc */
1530 | 0, /* tp_print */
1531 | 0, /* tp_getattr */
1532 | 0, /* tp_setattr */
1533 | 0, /* tp_reserved */
1534 | 0, /* tp_repr */
1535 | 0, /* tp_as_number */
1536 | 0, /* tp_as_sequence */
1537 | 0, /* tp_as_mapping */
1538 | 0, /* tp_hash */
1539 | 0, /* tp_call */
1540 | 0, /* tp_str */
1541 | PyObject_GenericGetAttr, /* tp_getattro */
1542 | 0, /* tp_setattro */
1543 | 0, /* tp_as_buffer */
1544 | Py_TPFLAGS_DEFAULT( 0 | (1L<<18) | 0) | Py_TPFLAGS_HAVE_GC(1L<<14)
1545 | | Py_TPFLAGS_BASETYPE(1L<<10), /* tp_flags */
1546 | 0, /* tp_doc */
1547 | (traverseproc)mbstreamreader_traverse, /* tp_traverse */
1548 | 0, /* tp_clear */
1549 | 0, /* tp_richcompare */
1550 | 0, /* tp_weaklistoffset */
1551 | 0, /* tp_iter */
1552 | 0, /* tp_iterext */
1553 | mbstreamreader_methods, /* tp_methods */
1554 | mbstreamreader_members, /* tp_members */
1555 | codecctx_getsets, /* tp_getset */
1556 | 0, /* tp_base */
1557 | 0, /* tp_dict */
1558 | 0, /* tp_descr_get */
1559 | 0, /* tp_descr_set */
1560 | 0, /* tp_dictoffset */
1561 | mbstreamreader_init, /* tp_init */
1562 | 0, /* tp_alloc */
1563 | mbstreamreader_new, /* tp_new */
1564 | };
1565 |
1566 |
1567 | /**
1568 | * MultibyteStreamWriter object
1569 | */
1570 |
1571 | static int
1572 | mbstreamwriter_iwrite(MultibyteStreamWriterObject *self,
1573 | PyObject *unistr)
1574 | {
1575 | PyObject *str, *wr;
1576 |
1577 | str = encoder_encode_stateful(STATEFUL_ECTX(self)((MultibyteStatefulEncoderContext *)(self)), unistr, 0);
1578 | if (str == NULL((void*)0))
1579 | return -1;
1580 |
1581 | wr = PyObject_CallMethod_PyObject_CallMethod_SizeT(self->stream, "write", "O", str);
1582 | Py_DECREF(str)do { if (_Py_RefTotal-- , --((PyObject*)(str))->ob_refcnt != 0) { if (((PyObject*)str)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1582, (PyObject *)(str)); } else _Py_Dealloc((PyObject *)(str )); } while (0);
1583 | if (wr == NULL((void*)0))
1584 | return -1;
1585 |
1586 | Py_DECREF(wr)do { if (_Py_RefTotal-- , --((PyObject*)(wr))->ob_refcnt != 0) { if (((PyObject*)wr)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1586, (PyObject *)(wr)); } else _Py_Dealloc((PyObject *)(wr )); } while (0);
1587 | return 0;
1588 | }
1589 |
1590 | static PyObject *
1591 | mbstreamwriter_write(MultibyteStreamWriterObject *self, PyObject *strobj)
1592 | {
1593 | if (mbstreamwriter_iwrite(self, strobj))
1594 | return NULL((void*)0);
1595 | else
1596 | Py_RETURN_NONEreturn ( _Py_RefTotal++ , ((PyObject*)((&_Py_NoneStruct)) )->ob_refcnt++), (&_Py_NoneStruct);
1597 | }
1598 |
1599 | static PyObject *
1600 | mbstreamwriter_writelines(MultibyteStreamWriterObject *self, PyObject *lines)
1601 | {
1602 | PyObject *strobj;
1603 | int i, r;
1604 |
1605 | if (!PySequence_Check(lines)) {
1606 | PyErr_SetString(PyExc_TypeError,
1607 | "arg must be a sequence object");
1608 | return NULL((void*)0);
1609 | }
1610 |
1611 | for (i = 0; i < PySequence_LengthPySequence_Size(lines); i++) {
1612 | /* length can be changed even within this loop */
1613 | strobj = PySequence_GetItem(lines, i);
1614 | if (strobj == NULL((void*)0))
1615 | return NULL((void*)0);
1616 |
1617 | r = mbstreamwriter_iwrite(self, strobj);
1618 | Py_DECREF(strobj)do { if (_Py_RefTotal-- , --((PyObject*)(strobj))->ob_refcnt != 0) { if (((PyObject*)strobj)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1618, (PyObject *)(strobj)); } else _Py_Dealloc((PyObject * )(strobj)); } while (0);
1619 | if (r == -1)
1620 | return NULL((void*)0);
1621 | }
1622 |
1623 | Py_RETURN_NONEreturn ( _Py_RefTotal++ , ((PyObject*)((&_Py_NoneStruct)) )->ob_refcnt++), (&_Py_NoneStruct);
1624 | }
1625 |
1626 | static PyObject *
1627 | mbstreamwriter_reset(MultibyteStreamWriterObject *self)
1628 | {
1629 | const Py_UNICODE *pending;
1630 | PyObject *pwrt;
1631 |
1632 | pending = self->pending;
1633 | pwrt = multibytecodec_encode(self->codec, &self->state,
1634 | &pending, self->pendingsize, self->errors,
1635 | MBENC_FLUSH0x0001 | MBENC_RESET0x0001<<1);
1636 | /* some pending buffer can be truncated when UnicodeEncodeError is
1637 | * raised on 'strict' mode. but, 'reset' method is designed to
1638 | * reset the pending buffer or states so failed string sequence
1639 | * ought to be missed */
1640 | self->pendingsize = 0;
1641 | if (pwrt == NULL((void*)0))
1642 | return NULL((void*)0);
1643 |
1644 | assert(PyBytes_Check(pwrt))(__builtin_expect(!(((((((PyObject*)(pwrt))->ob_type))-> tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn(__func__ , "/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1644, "PyBytes_Check(pwrt)") : (void)0);
1645 | if (PyBytes_Size(pwrt) > 0) {
1646 | PyObject *wr;
1647 | wr = PyObject_CallMethod_PyObject_CallMethod_SizeT(self->stream, "write", "O", pwrt);
1648 | if (wr == NULL((void*)0)) {
1649 | Py_DECREF(pwrt)do { if (_Py_RefTotal-- , --((PyObject*)(pwrt))->ob_refcnt != 0) { if (((PyObject*)pwrt)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1649, (PyObject *)(pwrt)); } else _Py_Dealloc((PyObject *)( pwrt)); } while (0);
1650 | return NULL((void*)0);
1651 | }
1652 | }
1653 | Py_DECREF(pwrt)do { if (_Py_RefTotal-- , --((PyObject*)(pwrt))->ob_refcnt != 0) { if (((PyObject*)pwrt)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1653, (PyObject *)(pwrt)); } else _Py_Dealloc((PyObject *)( pwrt)); } while (0);
1654 |
1655 | Py_RETURN_NONEreturn ( _Py_RefTotal++ , ((PyObject*)((&_Py_NoneStruct)) )->ob_refcnt++), (&_Py_NoneStruct);
1656 | }
1657 |
1658 | static PyObject *
1659 | mbstreamwriter_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
1660 | {
1661 | MultibyteStreamWriterObject *self;
1662 | PyObject *stream, *codec = NULL((void*)0);
1663 | char *errors = NULL((void*)0);
1664 |
1665 | if (!PyArg_ParseTupleAndKeywords_PyArg_ParseTupleAndKeywords_SizeT(args, kwds, "O|s:StreamWriter",
1666 | streamkwarglist, &stream, &errors))
1667 | return NULL((void*)0);
1668 |
1669 | self = (MultibyteStreamWriterObject *)type->tp_alloc(type, 0);
1670 | if (self == NULL((void*)0))
1671 | return NULL((void*)0);
1672 |
1673 | codec = PyObject_GetAttrString((PyObject *)type, "codec");
1674 | if (codec == NULL((void*)0))
1675 | goto errorexit;
1676 | if (!MultibyteCodec_Check(codec)((codec)->ob_type == &MultibyteCodec_Type)) {
1677 | PyErr_SetString(PyExc_TypeError, "codec is unexpected type");
1678 | goto errorexit;
1679 | }
1680 |
1681 | self->codec = ((MultibyteCodecObject *)codec)->codec;
1682 | self->stream = stream;
1683 | Py_INCREF(stream)( _Py_RefTotal++ , ((PyObject*)(stream))->ob_refcnt++);
1684 | self->pendingsize = 0;
1685 | self->errors = internal_error_callback(errors);
1686 | if (self->errors == NULL((void*)0))
1687 | goto errorexit;
1688 | if (self->codec->encinit != NULL((void*)0) &&
1689 | self->codec->encinit(&self->state, self->codec->config) != 0)
1690 | goto errorexit;
1691 |
1692 | Py_DECREF(codec)do { if (_Py_RefTotal-- , --((PyObject*)(codec))->ob_refcnt != 0) { if (((PyObject*)codec)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1692, (PyObject *)(codec)); } else _Py_Dealloc((PyObject *) (codec)); } while (0);
1693 | return (PyObject *)self;
1694 |
1695 | errorexit:
1696 | Py_XDECREF(self)do { if ((self) == ((void*)0)) ; else do { if (_Py_RefTotal-- , --((PyObject*)(self))->ob_refcnt != 0) { if (((PyObject *)self)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1696, (PyObject *)(self)); } else _Py_Dealloc((PyObject *)( self)); } while (0); } while (0);
1697 | Py_XDECREF(codec)do { if ((codec) == ((void*)0)) ; else do { if (_Py_RefTotal-- , --((PyObject*)(codec))->ob_refcnt != 0) { if (((PyObject *)codec)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1697, (PyObject *)(codec)); } else _Py_Dealloc((PyObject *) (codec)); } while (0); } while (0);
1698 | return NULL((void*)0);
1699 | }
1700 |
1701 | static int
1702 | mbstreamwriter_init(PyObject *self, PyObject *args, PyObject *kwds)
1703 | {
1704 | return 0;
1705 | }
1706 |
1707 | static int
1708 | mbstreamwriter_traverse(MultibyteStreamWriterObject *self,
1709 | visitproc visit, void *arg)
1710 | {
1711 | if (ERROR_ISCUSTOM(self->errors)((self->errors) < (PyObject *)(1) || (PyObject *)(3) < (self->errors)))
1712 | Py_VISIT(self->errors)do { if (self->errors) { int vret = visit((PyObject *)(self ->errors), arg); if (vret) return vret; } } while (0);
1713 | Py_VISIT(self->stream)do { if (self->stream) { int vret = visit((PyObject *)(self ->stream), arg); if (vret) return vret; } } while (0);
1714 | return 0;
1715 | }
1716 |
1717 | static void
1718 | mbstreamwriter_dealloc(MultibyteStreamWriterObject *self)
1719 | {
1720 | PyObject_GC_UnTrack(self);
1721 | ERROR_DECREF(self->errors)do { if (self->errors != ((void*)0) && ((self-> errors) < (PyObject *)(1) || (PyObject *)(3) < (self-> errors))) { do { if (_Py_RefTotal-- , --((PyObject*)(self-> errors))->ob_refcnt != 0) { if (((PyObject*)self->errors )->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1721, (PyObject *)(self->errors)); } else _Py_Dealloc((PyObject *)(self->errors)); } while (0); } } while (0);;
1722 | Py_XDECREF(self->stream)do { if ((self->stream) == ((void*)0)) ; else do { if (_Py_RefTotal -- , --((PyObject*)(self->stream))->ob_refcnt != 0) { if (((PyObject*)self->stream)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1722, (PyObject *)(self->stream)); } else _Py_Dealloc((PyObject *)(self->stream)); } while (0); } while (0);
1723 | Py_TYPE(self)(((PyObject*)(self))->ob_type)->tp_free(self);
1724 | }
1725 |
1726 | static struct PyMethodDef mbstreamwriter_methods[] = {
1727 | {"write", (PyCFunction)mbstreamwriter_write,
1728 | METH_O0x0008, NULL((void*)0)},
1729 | {"writelines", (PyCFunction)mbstreamwriter_writelines,
1730 | METH_O0x0008, NULL((void*)0)},
1731 | {"reset", (PyCFunction)mbstreamwriter_reset,
1732 | METH_NOARGS0x0004, NULL((void*)0)},
1733 | {NULL((void*)0), NULL((void*)0)},
1734 | };
1735 |
1736 | static PyMemberDef mbstreamwriter_members[] = {
1737 | {"stream", T_OBJECT6,
1738 | offsetof(MultibyteStreamWriterObject, stream)__builtin_offsetof(MultibyteStreamWriterObject, stream),
1739 | READONLY1, NULL((void*)0)},
1740 | {NULL((void*)0),}
1741 | };
1742 |
1743 | static PyTypeObject MultibyteStreamWriter_Type = {
1744 | PyVarObject_HEAD_INIT(NULL, 0){ { 0, 0, 1, ((void*)0) }, 0 },
1745 | "MultibyteStreamWriter", /* tp_name */
1746 | sizeof(MultibyteStreamWriterObject), /* tp_basicsize */
1747 | 0, /* tp_itemsize */
1748 | /* methods */
1749 | (destructor)mbstreamwriter_dealloc, /* tp_dealloc */
1750 | 0, /* tp_print */
1751 | 0, /* tp_getattr */
1752 | 0, /* tp_setattr */
1753 | 0, /* tp_reserved */
1754 | 0, /* tp_repr */
1755 | 0, /* tp_as_number */
1756 | 0, /* tp_as_sequence */
1757 | 0, /* tp_as_mapping */
1758 | 0, /* tp_hash */
1759 | 0, /* tp_call */
1760 | 0, /* tp_str */
1761 | PyObject_GenericGetAttr, /* tp_getattro */
1762 | 0, /* tp_setattro */
1763 | 0, /* tp_as_buffer */
1764 | Py_TPFLAGS_DEFAULT( 0 | (1L<<18) | 0) | Py_TPFLAGS_HAVE_GC(1L<<14)
1765 | | Py_TPFLAGS_BASETYPE(1L<<10), /* tp_flags */
1766 | 0, /* tp_doc */
1767 | (traverseproc)mbstreamwriter_traverse, /* tp_traverse */
1768 | 0, /* tp_clear */
1769 | 0, /* tp_richcompare */
1770 | 0, /* tp_weaklistoffset */
1771 | 0, /* tp_iter */
1772 | 0, /* tp_iterext */
1773 | mbstreamwriter_methods, /* tp_methods */
1774 | mbstreamwriter_members, /* tp_members */
1775 | codecctx_getsets, /* tp_getset */
1776 | 0, /* tp_base */
1777 | 0, /* tp_dict */
1778 | 0, /* tp_descr_get */
1779 | 0, /* tp_descr_set */
1780 | 0, /* tp_dictoffset */
1781 | mbstreamwriter_init, /* tp_init */
1782 | 0, /* tp_alloc */
1783 | mbstreamwriter_new, /* tp_new */
1784 | };
1785 |
1786 |
1787 | /**
1788 | * Exposed factory function
1789 | */
1790 |
1791 | static PyObject *
1792 | __create_codec(PyObject *ignore, PyObject *arg)
1793 | {
1794 | MultibyteCodecObject *self;
1795 | MultibyteCodec *codec;
1796 |
1797 | if (!PyCapsule_IsValid(arg, PyMultibyteCodec_CAPSULE_NAME"multibytecodec.__map_*")) {
1798 | PyErr_SetString(PyExc_ValueError, "argument type invalid");
1799 | return NULL((void*)0);
1800 | }
1801 |
1802 | codec = PyCapsule_GetPointer(arg, PyMultibyteCodec_CAPSULE_NAME"multibytecodec.__map_*");
1803 | if (codec->codecinit != NULL((void*)0) && codec->codecinit(codec->config) != 0)
1804 | return NULL((void*)0);
1805 |
1806 | self = PyObject_New(MultibyteCodecObject, &MultibyteCodec_Type)( (MultibyteCodecObject *) _PyObject_New(&MultibyteCodec_Type ) );
1807 | if (self == NULL((void*)0))
1808 | return NULL((void*)0);
1809 | self->codec = codec;
1810 |
1811 | return (PyObject *)self;
1812 | }
1813 |
1814 | static struct PyMethodDef __methods[] = {
1815 | {"__create_codec", (PyCFunction)__create_codec, METH_O0x0008},
1816 | {NULL((void*)0), NULL((void*)0)},
1817 | };
1818 |
1819 |
1820 | static struct PyModuleDef _multibytecodecmodule = {
1821 | PyModuleDef_HEAD_INIT{ { 0, 0, 1, ((void*)0) }, ((void*)0), 0, ((void*)0), },
1822 | "_multibytecodec",
1823 | NULL((void*)0),
1824 | -1,
1825 | __methods,
1826 | NULL((void*)0),
1827 | NULL((void*)0),
1828 | NULL((void*)0),
1829 | NULL((void*)0)
1830 | };
1831 |
1832 | PyMODINIT_FUNCPyObject*
1833 | PyInit__multibytecodec(void)
1834 | {
1835 | int i;
1836 | PyObject *m;
1837 | PyTypeObject *typelist[] = {
1838 | &MultibyteIncrementalEncoder_Type,
1839 | &MultibyteIncrementalDecoder_Type,
1840 | &MultibyteStreamReader_Type,
1841 | &MultibyteStreamWriter_Type,
1842 | NULL((void*)0)
1843 | };
1844 |
1845 | if (PyType_Ready(&MultibyteCodec_Type) < 0)
1846 | return NULL((void*)0);
1847 |
1848 | m = PyModule_Create(&_multibytecodecmodule)PyModule_Create2TraceRefs(&_multibytecodecmodule, 1013);
1849 | if (m == NULL((void*)0))
1850 | return NULL((void*)0);
1851 |
1852 | for (i = 0; typelist[i] != NULL((void*)0); i++) {
1853 | if (PyType_Ready(typelist[i]) < 0)
1854 | return NULL((void*)0);
1855 | Py_INCREF(typelist[i])( _Py_RefTotal++ , ((PyObject*)(typelist[i]))->ob_refcnt++ );
1856 | PyModule_AddObject(m, typelist[i]->tp_name,
1857 | (PyObject *)typelist[i]);
1858 | }
1859 |
1860 | if (PyErr_Occurred()) {
1861 | Py_FatalError("can't initialize the _multibytecodec module");
1862 | Py_DECREF(m)do { if (_Py_RefTotal-- , --((PyObject*)(m))->ob_refcnt != 0) { if (((PyObject*)m)->ob_refcnt < 0) _Py_NegativeRefcount ("/Users/brett/Dev/python/3.x/py3k/Modules/cjkcodecs/multibytecodec.c" , 1862, (PyObject *)(m)); } else _Py_Dealloc((PyObject *)(m)) ; } while (0);
1863 | m = NULL((void*)0);
1864 | }
1865 | return m;
1866 | }