Make use of METH_O and METH_NOARGS where possible.
Use Py_UnpackTuple instead of PyArg_ParseTuple where possible.
diff --git a/Modules/_codecsmodule.c b/Modules/_codecsmodule.c
index d8d23c4..080fa74 100644
--- a/Modules/_codecsmodule.c
+++ b/Modules/_codecsmodule.c
@@ -48,21 +48,12 @@
a tuple of functions (encoder, decoder, stream_reader, stream_writer).");
static
-PyObject *codec_register(PyObject *self, PyObject *args)
+PyObject *codec_register(PyObject *self, PyObject *search_function)
{
- PyObject *search_function;
-
- if (!PyArg_ParseTuple(args, "O:register", &search_function))
- goto onError;
-
if (PyCodec_Register(search_function))
- goto onError;
+ return NULL;
- Py_INCREF(Py_None);
- return Py_None;
-
- onError:
- return NULL;
+ Py_RETURN_NONE;
}
PyDoc_STRVAR(lookup__doc__,
@@ -77,12 +68,9 @@
char *encoding;
if (!PyArg_ParseTuple(args, "s:lookup", &encoding))
- goto onError;
+ return NULL;
return _PyCodec_Lookup(encoding);
-
- onError:
- return NULL;
}
PyDoc_STRVAR(encode__doc__,
@@ -116,13 +104,7 @@
#endif
/* Encode via the codec registry */
- v = PyCodec_Encode(v, encoding, errors);
- if (v == NULL)
- goto onError;
- return v;
-
- onError:
- return NULL;
+ return PyCodec_Encode(v, encoding, errors);
}
PyDoc_STRVAR(decode__doc__,
@@ -156,13 +138,7 @@
#endif
/* Decode via the codec registry */
- v = PyCodec_Decode(v, encoding, errors);
- if (v == NULL)
- goto onError;
- return v;
-
- onError:
- return NULL;
+ return PyCodec_Decode(v, encoding, errors);
}
/* --- Helpers ------------------------------------------------------------ */
@@ -171,22 +147,11 @@
PyObject *codec_tuple(PyObject *unicode,
Py_ssize_t len)
{
- PyObject *v,*w;
-
+ PyObject *v;
if (unicode == NULL)
- return NULL;
- v = PyTuple_New(2);
- if (v == NULL) {
- Py_DECREF(unicode);
- return NULL;
- }
- PyTuple_SET_ITEM(v,0,unicode);
- w = PyInt_FromSsize_t(len);
- if (w == NULL) {
- Py_DECREF(v);
- return NULL;
- }
- PyTuple_SET_ITEM(v,1,w);
+ return NULL;
+ v = Py_BuildValue("On", unicode, len);
+ Py_DECREF(unicode);
return v;
}
@@ -419,7 +384,7 @@
final ? NULL : &consumed);
if (unicode == NULL)
return NULL;
- tuple = Py_BuildValue("Oii", unicode, consumed, byteorder);
+ tuple = Py_BuildValue("Oni", unicode, consumed, byteorder);
Py_DECREF(unicode);
return tuple;
}
@@ -604,8 +569,8 @@
return NULL;
v = codec_tuple(PyUnicode_EncodeUTF7(PyUnicode_AS_UNICODE(str),
PyUnicode_GET_SIZE(str),
- 0,
- 0,
+ 0,
+ 0,
errors),
PyUnicode_GET_SIZE(str));
Py_DECREF(str);
@@ -876,8 +841,7 @@
return NULL;
if (PyCodec_RegisterError(name, handler))
return NULL;
- Py_INCREF(Py_None);
- return Py_None;
+ Py_RETURN_NONE;
}
PyDoc_STRVAR(lookup_error__doc__,
@@ -899,7 +863,7 @@
/* --- Module API --------------------------------------------------------- */
static PyMethodDef _codecs_functions[] = {
- {"register", codec_register, METH_VARARGS,
+ {"register", codec_register, METH_O,
register__doc__},
{"lookup", codec_lookup, METH_VARARGS,
lookup__doc__},