Skip to content

Commit 6f74ba2

Browse files
author
georg.brandl
committed
Make use of METH_O and METH_NOARGS where possible.
Use Py_UnpackTuple instead of PyArg_ParseTuple where possible. git-svn-id: http://svn.python.org/projects/python/trunk@46533 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 77e356d commit 6f74ba2

26 files changed

Lines changed: 186 additions & 404 deletions

Modules/_bsddb.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,7 @@ DB_append(DBObject* self, PyObject* args)
10411041
DBT key, data;
10421042
DB_TXN *txn = NULL;
10431043

1044-
if (!PyArg_ParseTuple(args, "O|O:append", &dataobj, &txnobj))
1044+
if (!PyArg_UnpackTuple(args, "append", 1, 2, &dataobj, &txnobj))
10451045
return NULL;
10461046

10471047
CHECK_DB_NOT_CLOSED(self);
@@ -2895,7 +2895,7 @@ DB_keys(DBObject* self, PyObject* args)
28952895
PyObject* txnobj = NULL;
28962896
DB_TXN *txn = NULL;
28972897

2898-
if (!PyArg_ParseTuple(args,"|O:keys", &txnobj))
2898+
if (!PyArg_UnpackTuple(args, "keys", 0, 1, &txnobj))
28992899
return NULL;
29002900
if (!checkTxnObj(txnobj, &txn))
29012901
return NULL;
@@ -2909,7 +2909,7 @@ DB_items(DBObject* self, PyObject* args)
29092909
PyObject* txnobj = NULL;
29102910
DB_TXN *txn = NULL;
29112911

2912-
if (!PyArg_ParseTuple(args,"|O:items", &txnobj))
2912+
if (!PyArg_UnpackTuple(args, "items", 0, 1, &txnobj))
29132913
return NULL;
29142914
if (!checkTxnObj(txnobj, &txn))
29152915
return NULL;
@@ -2923,7 +2923,7 @@ DB_values(DBObject* self, PyObject* args)
29232923
PyObject* txnobj = NULL;
29242924
DB_TXN *txn = NULL;
29252925

2926-
if (!PyArg_ParseTuple(args,"|O:values", &txnobj))
2926+
if (!PyArg_UnpackTuple(args, "values", 0, 1, &txnobj))
29272927
return NULL;
29282928
if (!checkTxnObj(txnobj, &txn))
29292929
return NULL;

Modules/_codecsmodule.c

Lines changed: 15 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,12 @@ one argument, the encoding name in all lower case letters, and return\n\
4848
a tuple of functions (encoder, decoder, stream_reader, stream_writer).");
4949

5050
static
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

6859
PyDoc_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

8876
PyDoc_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

128110
PyDoc_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
171147
PyObject *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

883847
PyDoc_STRVAR(lookup_error__doc__,
@@ -899,7 +863,7 @@ static PyObject *lookup_error(PyObject *self, PyObject *args)
899863
/* --- Module API --------------------------------------------------------- */
900864

901865
static 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__},

Modules/_hashopenssl.c

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,10 @@ EVP_dealloc(PyObject *ptr)
7777
PyDoc_STRVAR(EVP_copy__doc__, "Return a copy of the hash object.");
7878

7979
static PyObject *
80-
EVP_copy(EVPobject *self, PyObject *args)
80+
EVP_copy(EVPobject *self, PyObject *unused)
8181
{
8282
EVPobject *newobj;
8383

84-
if (!PyArg_ParseTuple(args, ":copy"))
85-
return NULL;
86-
8784
if ( (newobj = newEVPobject(self->name))==NULL)
8885
return NULL;
8986

@@ -95,16 +92,13 @@ PyDoc_STRVAR(EVP_digest__doc__,
9592
"Return the digest value as a string of binary data.");
9693

9794
static PyObject *
98-
EVP_digest(EVPobject *self, PyObject *args)
95+
EVP_digest(EVPobject *self, PyObject *unused)
9996
{
10097
unsigned char digest[EVP_MAX_MD_SIZE];
10198
EVP_MD_CTX temp_ctx;
10299
PyObject *retval;
103100
unsigned int digest_size;
104101

105-
if (!PyArg_ParseTuple(args, ":digest"))
106-
return NULL;
107-
108102
EVP_MD_CTX_copy(&temp_ctx, &self->ctx);
109103
digest_size = EVP_MD_CTX_size(&temp_ctx);
110104
EVP_DigestFinal(&temp_ctx, digest, NULL);
@@ -118,17 +112,14 @@ PyDoc_STRVAR(EVP_hexdigest__doc__,
118112
"Return the digest value as a string of hexadecimal digits.");
119113

120114
static PyObject *
121-
EVP_hexdigest(EVPobject *self, PyObject *args)
115+
EVP_hexdigest(EVPobject *self, PyObject *unused)
122116
{
123117
unsigned char digest[EVP_MAX_MD_SIZE];
124118
EVP_MD_CTX temp_ctx;
125119
PyObject *retval;
126120
char *hex_digest;
127121
unsigned int i, j, digest_size;
128122

129-
if (!PyArg_ParseTuple(args, ":hexdigest"))
130-
return NULL;
131-
132123
/* Get the raw (binary) digest value */
133124
EVP_MD_CTX_copy(&temp_ctx, &self->ctx);
134125
digest_size = EVP_MD_CTX_size(&temp_ctx);
@@ -182,9 +173,9 @@ EVP_update(EVPobject *self, PyObject *args)
182173

183174
static PyMethodDef EVP_methods[] = {
184175
{"update", (PyCFunction)EVP_update, METH_VARARGS, EVP_update__doc__},
185-
{"digest", (PyCFunction)EVP_digest, METH_VARARGS, EVP_digest__doc__},
186-
{"hexdigest", (PyCFunction)EVP_hexdigest, METH_VARARGS, EVP_hexdigest__doc__},
187-
{"copy", (PyCFunction)EVP_copy, METH_VARARGS, EVP_copy__doc__},
176+
{"digest", (PyCFunction)EVP_digest, METH_NOARGS, EVP_digest__doc__},
177+
{"hexdigest", (PyCFunction)EVP_hexdigest, METH_NOARGS, EVP_hexdigest__doc__},
178+
{"copy", (PyCFunction)EVP_copy, METH_NOARGS, EVP_copy__doc__},
188179
{NULL, NULL} /* sentinel */
189180
};
190181

Modules/_hotshot.c

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,7 @@ profiler_runcall(ProfilerObject *self, PyObject *args)
10581058
PyObject *callkw = NULL;
10591059
PyObject *callable;
10601060

1061-
if (PyArg_ParseTuple(args, "O|OO:runcall",
1061+
if (PyArg_UnpackTuple(args, "runcall", 1, 3,
10621062
&callable, &callargs, &callkw)) {
10631063
if (is_available(self)) {
10641064
do_start(self);
@@ -1575,31 +1575,26 @@ PyDoc_STR(
15751575
;
15761576

15771577
static PyObject *
1578-
hotshot_resolution(PyObject *unused, PyObject *args)
1578+
hotshot_resolution(PyObject *self, PyObject *unused)
15791579
{
1580-
PyObject *result = NULL;
1581-
1582-
if (PyArg_ParseTuple(args, ":resolution")) {
1583-
if (timeofday_diff == 0) {
1584-
calibrate();
1585-
calibrate();
1586-
calibrate();
1587-
}
1580+
if (timeofday_diff == 0) {
1581+
calibrate();
1582+
calibrate();
1583+
calibrate();
1584+
}
15881585
#ifdef MS_WINDOWS
1589-
result = Py_BuildValue("ii", timeofday_diff, frequency.LowPart);
1586+
return Py_BuildValue("ii", timeofday_diff, frequency.LowPart);
15901587
#else
1591-
result = Py_BuildValue("ii", timeofday_diff, rusage_diff);
1588+
return Py_BuildValue("ii", timeofday_diff, rusage_diff);
15921589
#endif
1593-
}
1594-
return result;
15951590
}
15961591

15971592

15981593
static PyMethodDef functions[] = {
15991594
{"coverage", hotshot_coverage, METH_VARARGS, coverage__doc__},
16001595
{"profiler", hotshot_profiler, METH_VARARGS, profiler__doc__},
16011596
{"logreader", hotshot_logreader, METH_VARARGS, logreader__doc__},
1602-
{"resolution", hotshot_resolution, METH_VARARGS, resolution__doc__},
1597+
{"resolution", hotshot_resolution, METH_NOARGS, resolution__doc__},
16031598
{NULL, NULL}
16041599
};
16051600

Modules/_localemodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ PyLocale_strcoll(PyObject* self, PyObject* args)
281281
wchar_t *ws1 = NULL, *ws2 = NULL;
282282
int rel1 = 0, rel2 = 0, len1, len2;
283283

284-
if (!PyArg_ParseTuple(args, "OO:strcoll", &os1, &os2))
284+
if (!PyArg_UnpackTuple(args, "strcoll", 2, 2, &os1, &os2))
285285
return NULL;
286286
/* If both arguments are byte strings, use strcoll. */
287287
if (PyString_Check(os1) && PyString_Check(os2))

Modules/_sre.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2891,7 +2891,7 @@ match_start(MatchObject* self, PyObject* args)
28912891
int index;
28922892

28932893
PyObject* index_ = Py_False; /* zero */
2894-
if (!PyArg_ParseTuple(args, "|O:start", &index_))
2894+
if (!PyArg_UnpackTuple(args, "start", 0, 1, &index_))
28952895
return NULL;
28962896

28972897
index = match_getindex(self, index_);
@@ -2914,7 +2914,7 @@ match_end(MatchObject* self, PyObject* args)
29142914
int index;
29152915

29162916
PyObject* index_ = Py_False; /* zero */
2917-
if (!PyArg_ParseTuple(args, "|O:end", &index_))
2917+
if (!PyArg_UnpackTuple(args, "end", 0, 1, &index_))
29182918
return NULL;
29192919

29202920
index = match_getindex(self, index_);
@@ -2964,7 +2964,7 @@ match_span(MatchObject* self, PyObject* args)
29642964
int index;
29652965

29662966
PyObject* index_ = Py_False; /* zero */
2967-
if (!PyArg_ParseTuple(args, "|O:span", &index_))
2967+
if (!PyArg_UnpackTuple(args, "span", 0, 1, &index_))
29682968
return NULL;
29692969

29702970
index = match_getindex(self, index_);

0 commit comments

Comments
 (0)