@@ -48,21 +48,12 @@ one argument, the encoding name in all lower case letters, and return\n\
4848a tuple of functions (encoder, decoder, stream_reader, stream_writer)." );
4949
5050static
51- PyObject * codec_register (PyObject * self , PyObject * args )
51+ PyObject * codec_register (PyObject * self , PyObject * search_function )
5252{
53- PyObject * search_function ;
54-
55- if (!PyArg_ParseTuple (args , "O:register" , & search_function ))
56- goto onError ;
57-
5853 if (PyCodec_Register (search_function ))
59- goto onError ;
60-
61- Py_INCREF (Py_None );
62- return Py_None ;
54+ return NULL ;
6355
64- onError :
65- return NULL ;
56+ Py_RETURN_NONE ;
6657}
6758
6859PyDoc_STRVAR (lookup__doc__ ,
@@ -77,12 +68,9 @@ PyObject *codec_lookup(PyObject *self, PyObject *args)
7768 char * encoding ;
7869
7970 if (!PyArg_ParseTuple (args , "s:lookup" , & encoding ))
80- goto onError ;
71+ return NULL ;
8172
8273 return _PyCodec_Lookup (encoding );
83-
84- onError :
85- return NULL ;
8674}
8775
8876PyDoc_STRVAR (encode__doc__ ,
@@ -116,13 +104,7 @@ codec_encode(PyObject *self, PyObject *args)
116104#endif
117105
118106 /* Encode via the codec registry */
119- v = PyCodec_Encode (v , encoding , errors );
120- if (v == NULL )
121- goto onError ;
122- return v ;
123-
124- onError :
125- return NULL ;
107+ return PyCodec_Encode (v , encoding , errors );
126108}
127109
128110PyDoc_STRVAR (decode__doc__ ,
@@ -156,13 +138,7 @@ codec_decode(PyObject *self, PyObject *args)
156138#endif
157139
158140 /* Decode via the codec registry */
159- v = PyCodec_Decode (v , encoding , errors );
160- if (v == NULL )
161- goto onError ;
162- return v ;
163-
164- onError :
165- return NULL ;
141+ return PyCodec_Decode (v , encoding , errors );
166142}
167143
168144/* --- Helpers ------------------------------------------------------------ */
@@ -171,22 +147,11 @@ static
171147PyObject * codec_tuple (PyObject * unicode ,
172148 Py_ssize_t len )
173149{
174- PyObject * v ,* w ;
175-
150+ PyObject * v ;
176151 if (unicode == NULL )
177- return NULL ;
178- v = PyTuple_New (2 );
179- if (v == NULL ) {
180- Py_DECREF (unicode );
181- return NULL ;
182- }
183- PyTuple_SET_ITEM (v ,0 ,unicode );
184- w = PyInt_FromSsize_t (len );
185- if (w == NULL ) {
186- Py_DECREF (v );
187- return NULL ;
188- }
189- PyTuple_SET_ITEM (v ,1 ,w );
152+ return NULL ;
153+ v = Py_BuildValue ("On" , unicode , len );
154+ Py_DECREF (unicode );
190155 return v ;
191156}
192157
@@ -419,7 +384,7 @@ utf_16_ex_decode(PyObject *self,
419384 final ? NULL : & consumed );
420385 if (unicode == NULL )
421386 return NULL ;
422- tuple = Py_BuildValue ("Oii " , unicode , consumed , byteorder );
387+ tuple = Py_BuildValue ("Oni " , unicode , consumed , byteorder );
423388 Py_DECREF (unicode );
424389 return tuple ;
425390}
@@ -604,8 +569,8 @@ utf_7_encode(PyObject *self,
604569 return NULL ;
605570 v = codec_tuple (PyUnicode_EncodeUTF7 (PyUnicode_AS_UNICODE (str ),
606571 PyUnicode_GET_SIZE (str ),
607- 0 ,
608- 0 ,
572+ 0 ,
573+ 0 ,
609574 errors ),
610575 PyUnicode_GET_SIZE (str ));
611576 Py_DECREF (str );
@@ -876,8 +841,7 @@ static PyObject *register_error(PyObject *self, PyObject *args)
876841 return NULL ;
877842 if (PyCodec_RegisterError (name , handler ))
878843 return NULL ;
879- Py_INCREF (Py_None );
880- return Py_None ;
844+ Py_RETURN_NONE ;
881845}
882846
883847PyDoc_STRVAR (lookup_error__doc__ ,
@@ -899,7 +863,7 @@ static PyObject *lookup_error(PyObject *self, PyObject *args)
899863/* --- Module API --------------------------------------------------------- */
900864
901865static PyMethodDef _codecs_functions [] = {
902- {"register" , codec_register , METH_VARARGS ,
866+ {"register" , codec_register , METH_O ,
903867 register__doc__ },
904868 {"lookup" , codec_lookup , METH_VARARGS ,
905869 lookup__doc__ },
0 commit comments