mirror of
https://github.com/python/cpython.git
synced 2025-11-20 02:50:14 +00:00
Remove METH_OLDARGS:
Convert METH_OLDARGS -> METH_VARARGS: also PyArg_Parse -> PyArg_ParseTuple Convert METH_OLDARGS -> METH_NOARGS: remove args parameter Please review. All tests pass, but some modules don't have tests. I spot checked various functions to try to make sure nothing broke.
This commit is contained in:
parent
50905b557b
commit
ba3a16c6c3
11 changed files with 85 additions and 164 deletions
|
|
@ -1242,23 +1242,12 @@ MPZ_divm(PyObject *self, PyObject *args)
|
|||
} /* MPZ_divm() */
|
||||
|
||||
|
||||
/* MPZ methods-as-attributes */
|
||||
#ifdef MPZ_CONVERSIONS_AS_METHODS
|
||||
static PyObject *
|
||||
mpz_int(mpzobject *self, PyObject *args)
|
||||
#else /* def MPZ_CONVERSIONS_AS_METHODS */
|
||||
static PyObject *
|
||||
mpz_int(mpzobject *self)
|
||||
#endif /* def MPZ_CONVERSIONS_AS_METHODS else */
|
||||
{
|
||||
long sli;
|
||||
|
||||
|
||||
#ifdef MPZ_CONVERSIONS_AS_METHODS
|
||||
if (!PyArg_NoArgs(args))
|
||||
return NULL;
|
||||
#endif /* def MPZ_CONVERSIONS_AS_METHODS */
|
||||
|
||||
if (mpz_size(&self->mpz) > 1
|
||||
|| (sli = (long)mpz_get_ui(&self->mpz)) < (long)0 ) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
|
|
@ -1273,11 +1262,7 @@ mpz_int(mpzobject *self)
|
|||
} /* mpz_int() */
|
||||
|
||||
static PyObject *
|
||||
#ifdef MPZ_CONVERSIONS_AS_METHODS
|
||||
mpz_long(mpzobject *self, PyObject *args)
|
||||
#else /* def MPZ_CONVERSIONS_AS_METHODS */
|
||||
mpz_long(mpzobject *self)
|
||||
#endif /* def MPZ_CONVERSIONS_AS_METHODS else */
|
||||
{
|
||||
int i, isnegative;
|
||||
unsigned long int uli;
|
||||
|
|
@ -1287,11 +1272,6 @@ mpz_long(mpzobject *self)
|
|||
MP_INT mpzscratch;
|
||||
|
||||
|
||||
#ifdef MPZ_CONVERSIONS_AS_METHODS
|
||||
if (!PyArg_NoArgs(args))
|
||||
return NULL;
|
||||
#endif /* def MPZ_CONVERSIONS_AS_METHODS */
|
||||
|
||||
/* determine length of python-long to be allocated */
|
||||
if ((longobjp = _PyLong_New(i = (int)
|
||||
((mpz_size(&self->mpz) * BITS_PER_MP_LIMB
|
||||
|
|
@ -1352,13 +1332,8 @@ mpz_long(mpzobject *self)
|
|||
/* I would have avoided pow() anyways, so ... */
|
||||
static const double multiplier = 256.0 * 256.0 * 256.0 * 256.0;
|
||||
|
||||
#ifdef MPZ_CONVERSIONS_AS_METHODS
|
||||
static PyObject *
|
||||
mpz_float(mpzobject *self, PyObject *args)
|
||||
#else /* def MPZ_CONVERSIONS_AS_METHODS */
|
||||
static PyObject *
|
||||
mpz_float(mpzobject *self)
|
||||
#endif /* def MPZ_CONVERSIONS_AS_METHODS else */
|
||||
{
|
||||
int i, isnegative;
|
||||
double x;
|
||||
|
|
@ -1366,11 +1341,6 @@ mpz_float(mpzobject *self)
|
|||
MP_INT mpzscratch;
|
||||
|
||||
|
||||
#ifdef MPZ_CONVERSIONS_AS_METHODS
|
||||
if (!PyArg_NoArgs(args))
|
||||
return NULL;
|
||||
#endif /* def MPZ_CONVERSIONS_AS_METHODS */
|
||||
|
||||
i = (int)mpz_size(&self->mpz);
|
||||
|
||||
/* determine sign, and copy abs(self) to scratch var */
|
||||
|
|
@ -1406,40 +1376,20 @@ mpz_float(mpzobject *self)
|
|||
|
||||
} /* mpz_float() */
|
||||
|
||||
#ifdef MPZ_CONVERSIONS_AS_METHODS
|
||||
static PyObject *
|
||||
mpz_hex(mpzobject *self, PyObject *args)
|
||||
#else /* def MPZ_CONVERSIONS_AS_METHODS */
|
||||
static PyObject *
|
||||
mpz_hex(mpzobject *self)
|
||||
#endif /* def MPZ_CONVERSIONS_AS_METHODS else */
|
||||
{
|
||||
#ifdef MPZ_CONVERSIONS_AS_METHODS
|
||||
if (!PyArg_NoArgs(args))
|
||||
return NULL;
|
||||
#endif /* def MPZ_CONVERSIONS_AS_METHODS */
|
||||
|
||||
return mpz_format((PyObject *)self, 16, (unsigned char)1);
|
||||
} /* mpz_hex() */
|
||||
|
||||
#ifdef MPZ_CONVERSIONS_AS_METHODS
|
||||
static PyObject *
|
||||
mpz_oct(mpzobject *self, PyObject *args)
|
||||
#else /* def MPZ_CONVERSIONS_AS_METHODS */
|
||||
static PyObject *
|
||||
mpz_oct(mpzobject *self)
|
||||
#endif /* def MPZ_CONVERSIONS_AS_METHODS else */
|
||||
{
|
||||
#ifdef MPZ_CONVERSIONS_AS_METHODS
|
||||
if (!PyArg_NoArgs(args))
|
||||
return NULL;
|
||||
#endif /* def MPZ_CONVERSIONS_AS_METHODS */
|
||||
|
||||
return mpz_format((PyObject *)self, 8, (unsigned char)1);
|
||||
} /* mpz_oct() */
|
||||
|
||||
static PyObject *
|
||||
mpz_binary(mpzobject *self, PyObject *args)
|
||||
mpz_binary(mpzobject *self)
|
||||
{
|
||||
int size;
|
||||
PyStringObject *strobjp;
|
||||
|
|
@ -1447,9 +1397,6 @@ mpz_binary(mpzobject *self, PyObject *args)
|
|||
MP_INT mp;
|
||||
unsigned long ldigit;
|
||||
|
||||
if (!PyArg_NoArgs(args))
|
||||
return NULL;
|
||||
|
||||
if (mpz_cmp_ui(&self->mpz, (unsigned long int)0) < 0) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"mpz.binary() arg must be >= 0");
|
||||
|
|
@ -1493,13 +1440,13 @@ mpz_binary(mpzobject *self, PyObject *args)
|
|||
|
||||
static PyMethodDef mpz_methods[] = {
|
||||
#ifdef MPZ_CONVERSIONS_AS_METHODS
|
||||
{"int", mpz_int},
|
||||
{"long", mpz_long},
|
||||
{"float", mpz_float},
|
||||
{"hex", mpz_hex},
|
||||
{"oct", mpz_oct},
|
||||
{"int", mpz_int, METH_NOARGS},
|
||||
{"long", mpz_long, METH_NOARGS},
|
||||
{"float", mpz_float, METH_NOARGS},
|
||||
{"hex", mpz_hex, METH_NOARGS},
|
||||
{"oct", mpz_oct, METH_NOARGS},
|
||||
#endif /* def MPZ_CONVERSIONS_AS_METHODS */
|
||||
{"binary", (PyCFunction)mpz_binary},
|
||||
{"binary", (PyCFunction)mpz_binary, METH_NOARGS},
|
||||
{NULL, NULL} /* sentinel */
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue