Commit acee69fa authored by Fred Drake's avatar Fred Drake

Switch to using METH_NOARGS where possible.

Convert to use PyModule_*() instead of manipulating the module dict directly.
parent 43c9d8ad
...@@ -44,11 +44,8 @@ sizeof_error(const char* fatname, const char* typename, ...@@ -44,11 +44,8 @@ sizeof_error(const char* fatname, const char* typename,
} }
static PyObject* 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) \ #define CHECK_SIZEOF(FATNAME, TYPE) \
if (FATNAME != sizeof(TYPE)) \ if (FATNAME != sizeof(TYPE)) \
return sizeof_error(#FATNAME, #TYPE, FATNAME, sizeof(TYPE)) return sizeof_error(#FATNAME, #TYPE, FATNAME, sizeof(TYPE))
...@@ -69,12 +66,10 @@ test_config(PyObject *self, PyObject *args) ...@@ -69,12 +66,10 @@ test_config(PyObject *self, PyObject *args)
} }
static PyObject* static PyObject*
test_list_api(PyObject *self, PyObject *args) test_list_api(PyObject *self)
{ {
PyObject* list; PyObject* list;
int i; int i;
if (!PyArg_ParseTuple(args, ":test_list_api"))
return NULL;
/* SF bug 132008: PyList_Reverse segfaults */ /* SF bug 132008: PyList_Reverse segfaults */
#define NLIST 30 #define NLIST 30
...@@ -157,13 +152,10 @@ test_dict_inner(int count) ...@@ -157,13 +152,10 @@ test_dict_inner(int count)
} }
static PyObject* static PyObject*
test_dict_iteration(PyObject* self, PyObject* args) test_dict_iteration(PyObject* self)
{ {
int i; int i;
if (!PyArg_ParseTuple(args, ":test_dict_iteration"))
return NULL;
for (i = 0; i < 200; i++) { for (i = 0; i < 200; i++) {
if (test_dict_inner(i) < 0) { if (test_dict_inner(i) < 0) {
return NULL; return NULL;
...@@ -208,11 +200,8 @@ raise_test_long_error(const char* msg) ...@@ -208,11 +200,8 @@ raise_test_long_error(const char* msg)
#include "testcapi_long.h" #include "testcapi_long.h"
static PyObject * 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); return TESTNAME(raise_test_long_error);
} }
...@@ -241,11 +230,8 @@ raise_test_longlong_error(const char* msg) ...@@ -241,11 +230,8 @@ raise_test_longlong_error(const char* msg)
#include "testcapi_long.h" #include "testcapi_long.h"
static PyObject * 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); return TESTNAME(raise_test_longlong_error);
} }
...@@ -261,14 +247,11 @@ test_longlong_api(PyObject* self, PyObject* args) ...@@ -261,14 +247,11 @@ test_longlong_api(PyObject* self, PyObject* args)
it fails. it fails.
*/ */
static PyObject * static PyObject *
test_L_code(PyObject *self, PyObject *args) test_L_code(PyObject *self)
{ {
PyObject *tuple, *num; PyObject *tuple, *num;
LONG_LONG value; LONG_LONG value;
if (!PyArg_ParseTuple(args, ":test_L_code"))
return NULL;
tuple = PyTuple_New(1); tuple = PyTuple_New(1);
if (tuple == NULL) if (tuple == NULL)
return NULL; return NULL;
...@@ -313,15 +296,12 @@ test_L_code(PyObject *self, PyObject *args) ...@@ -313,15 +296,12 @@ test_L_code(PyObject *self, PyObject *args)
of an error. of an error.
*/ */
static PyObject * static PyObject *
test_u_code(PyObject *self, PyObject *args) test_u_code(PyObject *self)
{ {
PyObject *tuple, *obj; PyObject *tuple, *obj;
Py_UNICODE *value; Py_UNICODE *value;
int len; int len;
if (!PyArg_ParseTuple(args, ":test_u_code"))
return NULL;
tuple = PyTuple_New(1); tuple = PyTuple_New(1);
if (tuple == NULL) if (tuple == NULL)
return NULL; return NULL;
...@@ -382,16 +362,16 @@ raise_exception(PyObject *self, PyObject *args) ...@@ -382,16 +362,16 @@ raise_exception(PyObject *self, PyObject *args)
static PyMethodDef TestMethods[] = { static PyMethodDef TestMethods[] = {
{"raise_exception", raise_exception, METH_VARARGS}, {"raise_exception", raise_exception, METH_VARARGS},
{"test_config", test_config, METH_VARARGS}, {"test_config", (PyCFunction)test_config, METH_NOARGS},
{"test_list_api", test_list_api, METH_VARARGS}, {"test_list_api", (PyCFunction)test_list_api, METH_NOARGS},
{"test_dict_iteration", test_dict_iteration, METH_VARARGS}, {"test_dict_iteration", (PyCFunction)test_dict_iteration,METH_NOARGS},
{"test_long_api", test_long_api, METH_VARARGS}, {"test_long_api", (PyCFunction)test_long_api, METH_NOARGS},
#ifdef HAVE_LONG_LONG #ifdef HAVE_LONG_LONG
{"test_longlong_api", test_longlong_api, METH_VARARGS}, {"test_longlong_api", (PyCFunction)test_longlong_api, METH_NOARGS},
{"test_L_code", test_L_code, METH_VARARGS}, {"test_L_code", (PyCFunction)test_L_code, METH_NOARGS},
#endif #endif
#ifdef Py_USING_UNICODE #ifdef Py_USING_UNICODE
{"test_u_code", test_u_code, METH_VARARGS}, {"test_u_code", (PyCFunction)test_u_code, METH_NOARGS},
#endif #endif
{NULL, NULL} /* sentinel */ {NULL, NULL} /* sentinel */
}; };
...@@ -399,11 +379,11 @@ static PyMethodDef TestMethods[] = { ...@@ -399,11 +379,11 @@ static PyMethodDef TestMethods[] = {
DL_EXPORT(void) DL_EXPORT(void)
init_testcapi(void) init_testcapi(void)
{ {
PyObject *m, *d; PyObject *m;
m = Py_InitModule("_testcapi", TestMethods); m = Py_InitModule("_testcapi", TestMethods);
TestError = PyErr_NewException("_testcapi.error", NULL, NULL); TestError = PyErr_NewException("_testcapi.error", NULL, NULL);
d = PyModule_GetDict(m); Py_INCREF(TestError);
PyDict_SetItemString(d, "error", TestError); PyModule_AddObject(m, "error", TestError);
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment