Switch to using METH_NOARGS where possible.

Convert to use PyModule_*() instead of manipulating the module dict directly.
This commit is contained in:
Fred Drake 2002-04-01 14:28:58 +00:00
parent 43c9d8ad23
commit acee69faf8
1 changed files with 18 additions and 38 deletions

View File

@ -44,11 +44,8 @@ sizeof_error(const char* fatname, const char* typename,
}
static PyObject*
test_config(PyObject *self, PyObject *args)
test_config(PyObject *self)
{
if (!PyArg_ParseTuple(args, ":test_config"))
return NULL;
#define CHECK_SIZEOF(FATNAME, TYPE) \
if (FATNAME != sizeof(TYPE)) \
return sizeof_error(#FATNAME, #TYPE, FATNAME, sizeof(TYPE))
@ -69,12 +66,10 @@ test_config(PyObject *self, PyObject *args)
}
static PyObject*
test_list_api(PyObject *self, PyObject *args)
test_list_api(PyObject *self)
{
PyObject* list;
int i;
if (!PyArg_ParseTuple(args, ":test_list_api"))
return NULL;
/* SF bug 132008: PyList_Reverse segfaults */
#define NLIST 30
@ -157,13 +152,10 @@ test_dict_inner(int count)
}
static PyObject*
test_dict_iteration(PyObject* self, PyObject* args)
test_dict_iteration(PyObject* self)
{
int i;
if (!PyArg_ParseTuple(args, ":test_dict_iteration"))
return NULL;
for (i = 0; i < 200; i++) {
if (test_dict_inner(i) < 0) {
return NULL;
@ -208,11 +200,8 @@ raise_test_long_error(const char* msg)
#include "testcapi_long.h"
static PyObject *
test_long_api(PyObject* self, PyObject* args)
test_long_api(PyObject* self)
{
if (!PyArg_ParseTuple(args, ":test_long_api"))
return NULL;
return TESTNAME(raise_test_long_error);
}
@ -241,11 +230,8 @@ raise_test_longlong_error(const char* msg)
#include "testcapi_long.h"
static PyObject *
test_longlong_api(PyObject* self, PyObject* args)
test_longlong_api(PyObject* self)
{
if (!PyArg_ParseTuple(args, ":test_longlong_api"))
return NULL;
return TESTNAME(raise_test_longlong_error);
}
@ -261,14 +247,11 @@ test_longlong_api(PyObject* self, PyObject* args)
it fails.
*/
static PyObject *
test_L_code(PyObject *self, PyObject *args)
test_L_code(PyObject *self)
{
PyObject *tuple, *num;
LONG_LONG value;
if (!PyArg_ParseTuple(args, ":test_L_code"))
return NULL;
tuple = PyTuple_New(1);
if (tuple == NULL)
return NULL;
@ -313,15 +296,12 @@ test_L_code(PyObject *self, PyObject *args)
of an error.
*/
static PyObject *
test_u_code(PyObject *self, PyObject *args)
test_u_code(PyObject *self)
{
PyObject *tuple, *obj;
Py_UNICODE *value;
int len;
if (!PyArg_ParseTuple(args, ":test_u_code"))
return NULL;
tuple = PyTuple_New(1);
if (tuple == NULL)
return NULL;
@ -381,17 +361,17 @@ raise_exception(PyObject *self, PyObject *args)
}
static PyMethodDef TestMethods[] = {
{"raise_exception", raise_exception, METH_VARARGS},
{"test_config", test_config, METH_VARARGS},
{"test_list_api", test_list_api, METH_VARARGS},
{"test_dict_iteration", test_dict_iteration, METH_VARARGS},
{"test_long_api", test_long_api, METH_VARARGS},
{"raise_exception", raise_exception, METH_VARARGS},
{"test_config", (PyCFunction)test_config, METH_NOARGS},
{"test_list_api", (PyCFunction)test_list_api, METH_NOARGS},
{"test_dict_iteration", (PyCFunction)test_dict_iteration,METH_NOARGS},
{"test_long_api", (PyCFunction)test_long_api, METH_NOARGS},
#ifdef HAVE_LONG_LONG
{"test_longlong_api", test_longlong_api, METH_VARARGS},
{"test_L_code", test_L_code, METH_VARARGS},
{"test_longlong_api", (PyCFunction)test_longlong_api, METH_NOARGS},
{"test_L_code", (PyCFunction)test_L_code, METH_NOARGS},
#endif
#ifdef Py_USING_UNICODE
{"test_u_code", test_u_code, METH_VARARGS},
{"test_u_code", (PyCFunction)test_u_code, METH_NOARGS},
#endif
{NULL, NULL} /* sentinel */
};
@ -399,11 +379,11 @@ static PyMethodDef TestMethods[] = {
DL_EXPORT(void)
init_testcapi(void)
{
PyObject *m, *d;
PyObject *m;
m = Py_InitModule("_testcapi", TestMethods);
TestError = PyErr_NewException("_testcapi.error", NULL, NULL);
d = PyModule_GetDict(m);
PyDict_SetItemString(d, "error", TestError);
Py_INCREF(TestError);
PyModule_AddObject(m, "error", TestError);
}