summaryrefslogtreecommitdiffstats
path: root/Modules/mpzmodule.c
diff options
context:
space:
mode:
authorPeter Schneider-Kamp <nowonder@nowonder.de>2000-07-10 17:14:00 (GMT)
committerPeter Schneider-Kamp <nowonder@nowonder.de>2000-07-10 17:14:00 (GMT)
commit3646366f4cbca51f0654184a59aa9b35f10604ce (patch)
treed54e2b01b7eb969866c0bfe32558899457375ddb /Modules/mpzmodule.c
parentf82b04ecbb0b27635501c1b119c674c11bb0cd4e (diff)
downloadcpython-3646366f4cbca51f0654184a59aa9b35f10604ce.zip
cpython-3646366f4cbca51f0654184a59aa9b35f10604ce.tar.gz
cpython-3646366f4cbca51f0654184a59aa9b35f10604ce.tar.bz2
ANSI-fication, added #ifdef construction in mpz_coerce
Diffstat (limited to 'Modules/mpzmodule.c')
-rw-r--r--Modules/mpzmodule.c192
1 files changed, 54 insertions, 138 deletions
diff --git a/Modules/mpzmodule.c b/Modules/mpzmodule.c
index 2d10df5..accd967 100644
--- a/Modules/mpzmodule.c
+++ b/Modules/mpzmodule.c
@@ -115,10 +115,7 @@ newmpzobject()
#endif /* def MPZ_GET_STR_BUG */
static PyObject *
-mpz_format(objp, base, withname)
- PyObject *objp;
- int base;
- unsigned char withname;
+mpz_format(PyObject *objp, int base, unsigned char withname)
{
mpzobject *mpzp = (mpzobject *)objp;
PyStringObject *strobjp;
@@ -257,8 +254,7 @@ mpz_format(objp, base, withname)
/* MPZ methods */
static void
-mpz_dealloc(mpzp)
- mpzobject *mpzp;
+mpz_dealloc(mpzobject *mpzp)
{
#ifdef MPZ_DEBUG
fputs( "mpz_dealloc() called...\n", stderr );
@@ -272,8 +268,7 @@ mpz_dealloc(mpzp)
static mpzobject *mpz_value_zero, *mpz_value_one, *mpz_value_mone;
static int
-mpz_compare(a, b)
- mpzobject *a, *b;
+mpz_compare(mpzobject *a, mpzobject *b)
{
int cmpres;
@@ -284,9 +279,7 @@ mpz_compare(a, b)
} /* mpz_compare() */
static PyObject *
-mpz_addition(a, b)
- mpzobject *a;
- mpzobject *b;
+mpz_addition(mpzobject *a, mpzobject *b)
{
mpzobject *z;
@@ -311,9 +304,7 @@ mpz_addition(a, b)
} /* mpz_addition() */
static PyObject *
-mpz_substract(a, b)
- mpzobject *a;
- mpzobject *b;
+mpz_substract(mpzobject *a, mpzobject *b)
{
mpzobject *z;
@@ -333,9 +324,7 @@ mpz_substract(a, b)
} /* mpz_substract() */
static PyObject *
-mpz_multiply(a, b)
- mpzobject *a;
- mpzobject *b;
+mpz_multiply(mpzobject *a, mpzobject *b)
{
#ifdef MPZ_SPARE_MALLOC
int cmpres;
@@ -372,9 +361,7 @@ mpz_multiply(a, b)
} /* mpz_multiply() */
static PyObject *
-mpz_divide(a, b)
- mpzobject *a;
- mpzobject *b;
+mpz_divide(mpzobject *a, mpzobject *b)
{
#ifdef MPZ_SPARE_MALLOC
int cmpres;
@@ -443,9 +430,7 @@ mpz_divide(a, b)
} /* mpz_divide() */
static PyObject *
-mpz_remainder(a, b)
- mpzobject *a;
- mpzobject *b;
+mpz_remainder(mpzobject *a, mpzobject *b)
{
#ifdef MPZ_SPARE_MALLOC
int cmpres;
@@ -514,9 +499,7 @@ mpz_remainder(a, b)
} /* mpz_remainder() */
static PyObject *
-mpz_div_and_mod(a, b)
- mpzobject *a;
- mpzobject *b;
+mpz_div_and_mod(mpzobject *a, mpzobject *b)
{
PyObject *z = NULL;
mpzobject *x = NULL, *y = NULL;
@@ -574,10 +557,7 @@ mpz_div_and_mod(a, b)
} /* mpz_div_and_mod() */
static PyObject *
-mpz_power(a, b, m)
- mpzobject *a;
- mpzobject *b;
- mpzobject *m;
+mpz_power(mpzobject *a, mpzobject *b, mpzobject *m)
{
mpzobject *z;
int cmpres;
@@ -668,8 +648,7 @@ mpz_power(a, b, m)
static PyObject *
-mpz_negative(v)
- mpzobject *v;
+mpz_negative(mpzobject *v)
{
mpzobject *z;
@@ -691,8 +670,7 @@ mpz_negative(v)
static PyObject *
-mpz_positive(v)
- mpzobject *v;
+mpz_positive(mpzobject *v)
{
Py_INCREF(v);
return (PyObject *)v;
@@ -700,8 +678,7 @@ mpz_positive(v)
static PyObject *
-mpz_absolute(v)
- mpzobject *v;
+mpz_absolute(mpzobject *v)
{
mpzobject *z;
@@ -719,15 +696,13 @@ mpz_absolute(v)
} /* mpz_absolute() */
static int
-mpz_nonzero(v)
- mpzobject *v;
+mpz_nonzero(mpzobject *v)
{
return mpz_cmp_ui(&v->mpz, (unsigned long int)0) != 0;
} /* mpz_nonzero() */
static PyObject *
-py_mpz_invert(v)
- mpzobject *v;
+py_mpz_invert(mpzobject *v)
{
mpzobject *z;
@@ -741,9 +716,7 @@ py_mpz_invert(v)
} /* py_mpz_invert() */
static PyObject *
-mpz_lshift(a, b)
- mpzobject *a;
- mpzobject *b;
+mpz_lshift(mpzobject *a, mpzobject *b)
{
int cmpres;
mpzobject *z;
@@ -781,9 +754,7 @@ mpz_lshift(a, b)
} /* mpz_lshift() */
static PyObject *
-mpz_rshift(a, b)
- mpzobject *a;
- mpzobject *b;
+mpz_rshift(mpzobject *a, mpzobject *b)
{
int cmpres;
mpzobject *z;
@@ -812,9 +783,7 @@ mpz_rshift(a, b)
} /* mpz_rshift() */
static PyObject *
-mpz_andfunc(a, b)
- mpzobject *a;
- mpzobject *b;
+mpz_andfunc(mpzobject *a, mpzobject *b)
{
mpzobject *z;
@@ -828,10 +797,7 @@ mpz_andfunc(a, b)
/* hack Hack HAck HACk HACK, XXX this code is dead slow */
void
-mpz_xor(res, op1, op2)
- MP_INT *res;
- const MP_INT *op1;
- const MP_INT *op2;
+mpz_xor(MP_INT *res, const MP_INT *op1, const MP_INT *op2)
{
MP_INT tmpmpz;
@@ -846,9 +812,7 @@ mpz_xor(res, op1, op2)
} /* mpz_xor() HACK */
static PyObject *
-mpz_xorfunc(a, b)
- mpzobject *a;
- mpzobject *b;
+mpz_xorfunc(mpzobject *a, mpzobject *b)
{
mpzobject *z;
@@ -861,9 +825,7 @@ mpz_xorfunc(a, b)
} /* mpz_xorfunc() */
static PyObject *
-mpz_orfunc(a, b)
- mpzobject *a;
- mpzobject *b;
+mpz_orfunc(mpzobject *a, mpzobject *b)
{
mpzobject *z;
@@ -880,9 +842,7 @@ mpz_orfunc(a, b)
#include "longintrepr.h"
static PyObject *
-MPZ_mpz(self, args)
- PyObject *self;
- PyObject *args;
+MPZ_mpz(PyObject *self, PyObject *args)
{
mpzobject *mpzp;
PyObject *objp;
@@ -993,8 +953,7 @@ MPZ_mpz(self, args)
} /* MPZ_mpz() */
static mpzobject *
-mpz_mpzcoerce(z)
- PyObject *z;
+mpz_mpzcoerce(PyObject *z)
{
/* shortcut: 9 out of 10 times the type is already ok */
if (is_mpzobject(z)) {
@@ -1016,9 +975,7 @@ static void mpz_divm(MP_INT *res, const MP_INT *num,
const MP_INT *den, const MP_INT *mod);
static PyObject *
-MPZ_powm(self, args)
- PyObject *self;
- PyObject *args;
+MPZ_powm(PyObject *self, PyObject *args)
{
PyObject *base, *exp, *mod;
mpzobject *mpzbase = NULL, *mpzexp = NULL, *mpzmod = NULL;
@@ -1069,9 +1026,7 @@ MPZ_powm(self, args)
static PyObject *
-MPZ_gcd(self, args)
- PyObject *self;
- PyObject *args;
+MPZ_gcd(PyObject *self, PyObject *args)
{
PyObject *op1, *op2;
mpzobject *mpzop1 = NULL, *mpzop2 = NULL;
@@ -1100,9 +1055,7 @@ MPZ_gcd(self, args)
static PyObject *
-MPZ_gcdext(self, args)
- PyObject *self;
- PyObject *args;
+MPZ_gcdext(PyObject *self, PyObject *args)
{
PyObject *op1, *op2, *z = NULL;
mpzobject *mpzop1 = NULL, *mpzop2 = NULL;
@@ -1141,9 +1094,7 @@ MPZ_gcdext(self, args)
static PyObject *
-MPZ_sqrt(self, args)
- PyObject *self;
- PyObject *args;
+MPZ_sqrt(PyObject *self, PyObject *args)
{
PyObject *op;
mpzobject *mpzop = NULL;
@@ -1168,9 +1119,7 @@ MPZ_sqrt(self, args)
static PyObject *
-MPZ_sqrtrem(self, args)
- PyObject *self;
- PyObject *args;
+MPZ_sqrtrem(PyObject *self, PyObject *args)
{
PyObject *op, *z = NULL;
mpzobject *mpzop = NULL;
@@ -1203,15 +1152,7 @@ MPZ_sqrtrem(self, args)
static void
-#if __STDC__
mpz_divm(MP_INT *res, const MP_INT *num, const MP_INT *den, const MP_INT *mod)
-#else
-mpz_divm(res, num, den, mod)
- MP_INT *res;
- const MP_INT *num;
- const MP_INT *den;
- const MP_INT *mod;
-#endif
{
MP_INT s0, s1, q, r, x, d0, d1;
@@ -1274,9 +1215,7 @@ mpz_divm(res, num, den, mod)
static PyObject *
-MPZ_divm(self, args)
- PyObject *self;
- PyObject *args;
+MPZ_divm(PyObject *self, PyObject *args)
{
PyObject *num, *den, *mod;
mpzobject *mpznum, *mpzden, *mpzmod = NULL;
@@ -1316,13 +1255,10 @@ MPZ_divm(self, args)
/* MPZ methods-as-attributes */
#ifdef MPZ_CONVERSIONS_AS_METHODS
static PyObject *
-mpz_int(self, args)
- mpzobject *self;
- PyObject *args;
+mpz_int(mpzobject *self, PyObject *args)
#else /* def MPZ_CONVERSIONS_AS_METHODS */
static PyObject *
-mpz_int(self)
- mpzobject *self;
+mpz_int(mpzobject *self)
#endif /* def MPZ_CONVERSIONS_AS_METHODS else */
{
long sli;
@@ -1348,12 +1284,9 @@ mpz_int(self)
static PyObject *
#ifdef MPZ_CONVERSIONS_AS_METHODS
-mpz_long(self, args)
- mpzobject *self;
- PyObject *args;
+mpz_long(mpzobject *self, PyObject *args)
#else /* def MPZ_CONVERSIONS_AS_METHODS */
-mpz_long(self)
- mpzobject *self;
+mpz_long(mpzobject *self)
#endif /* def MPZ_CONVERSIONS_AS_METHODS else */
{
int i, isnegative;
@@ -1431,13 +1364,10 @@ static const double multiplier = 256.0 * 256.0 * 256.0 * 256.0;
#ifdef MPZ_CONVERSIONS_AS_METHODS
static PyObject *
-mpz_float(self, args)
- mpzobject *self;
- PyObject *args;
+mpz_float(mpzobject *self, PyObject *args)
#else /* def MPZ_CONVERSIONS_AS_METHODS */
static PyObject *
-mpz_float(self)
- mpzobject *self;
+mpz_float(mpzobject *self)
#endif /* def MPZ_CONVERSIONS_AS_METHODS else */
{
int i, isnegative;
@@ -1488,13 +1418,10 @@ mpz_float(self)
#ifdef MPZ_CONVERSIONS_AS_METHODS
static PyObject *
-mpz_hex(self, args)
- mpzobject *self;
- PyObject *args;
+mpz_hex(mpzobject *self, PyObject *args)
#else /* def MPZ_CONVERSIONS_AS_METHODS */
static PyObject *
-mpz_hex(self)
- mpzobject *self;
+mpz_hex(mpzobject *self)
#endif /* def MPZ_CONVERSIONS_AS_METHODS else */
{
#ifdef MPZ_CONVERSIONS_AS_METHODS
@@ -1502,18 +1429,15 @@ mpz_hex(self)
return NULL;
#endif /* def MPZ_CONVERSIONS_AS_METHODS */
- return mpz_format(self, 16, (unsigned char)1);
+ return mpz_format((PyObject *)self, 16, (unsigned char)1);
} /* mpz_hex() */
#ifdef MPZ_CONVERSIONS_AS_METHODS
static PyObject *
-mpz_oct(self, args)
- mpzobject *self;
- PyObject *args;
+mpz_oct(mpzobject *self, PyObject *args)
#else /* def MPZ_CONVERSIONS_AS_METHODS */
static PyObject *
-mpz_oct(self)
- mpzobject *self;
+mpz_oct(mpzobject *self)
#endif /* def MPZ_CONVERSIONS_AS_METHODS else */
{
#ifdef MPZ_CONVERSIONS_AS_METHODS
@@ -1521,13 +1445,11 @@ mpz_oct(self)
return NULL;
#endif /* def MPZ_CONVERSIONS_AS_METHODS */
- return mpz_format(self, 8, (unsigned char)1);
+ return mpz_format((PyObject *)self, 8, (unsigned char)1);
} /* mpz_oct() */
static PyObject *
-mpz_binary(self, args)
- mpzobject *self;
- PyObject *args;
+mpz_binary(mpzobject *self, PyObject *args)
{
int size;
PyStringObject *strobjp;
@@ -1586,18 +1508,14 @@ static PyMethodDef mpz_methods[] = {
};
static PyObject *
-mpz_getattr(self, name)
- mpzobject *self;
- char *name;
+mpz_getattr(mpzobject *self, char *name)
{
return Py_FindMethod(mpz_methods, (PyObject *)self, name);
} /* mpz_getattr() */
static int
-mpz_coerce(pv, pw)
- PyObject **pv;
- PyObject **pw;
+mpz_coerce(PyObject **pv, PyObject **pw)
{
PyObject *z;
@@ -1616,8 +1534,13 @@ mpz_coerce(pv, pw)
*pw = z;
}
else {
- if ((z = mpz_float(*pv, NULL)) == NULL)
+#ifdef MPZ_CONVERSIONS_AS_METHODS
+ if ((z = mpz_float((mpzobject *)(*pv), NULL)) == NULL)
+ return -1;
+#else /* def MPZ_CONVERSIONS_AS_METHODS */
+ if ((z = mpz_float((mpzobject *)(*pv))) == NULL)
return -1;
+#endif /* def MPZ_CONVERSIONS_AS_METHODS else */
Py_INCREF(*pw);
*pv = z;
@@ -1628,8 +1551,7 @@ mpz_coerce(pv, pw)
static PyObject *
-mpz_repr(v)
- PyObject *v;
+mpz_repr(PyObject *v)
{
return mpz_format(v, 10, (unsigned char)1);
} /* mpz_repr() */
@@ -1730,8 +1652,7 @@ static mp_test_error( location )
#define MP_DO_TEST(basep,size)
#endif /* def MP_TEST_ALLOC else */
-void *mp_allocate( alloc_size )
- size_t alloc_size;
+void *mp_allocate(size_t alloc_size)
{
void *res;
@@ -1753,10 +1674,7 @@ void *mp_allocate( alloc_size )
} /* mp_allocate() */
-void *mp_reallocate( ptr, old_size, new_size )
- void *ptr;
- size_t old_size;
- size_t new_size;
+void *mp_reallocate(void *ptr, size_t old_size, size_t new_size)
{
void *res;
@@ -1781,9 +1699,7 @@ void *mp_reallocate( ptr, old_size, new_size )
} /* mp_reallocate() */
-void mp_free( ptr, size )
- void *ptr;
- size_t size;
+void mp_free(void *ptr, size_t size)
{
#ifdef MPZ_DEBUG