diff --git a/src/gmpy2.c b/src/gmpy2.c index 3652cdc5..8f0326e0 100644 --- a/src/gmpy2.c +++ b/src/gmpy2.c @@ -754,7 +754,7 @@ static PyMethodDef Pygmpy_methods [] = { "is_lucas_prp", GMPY_mpz_is_lucas_prp, METH_VARARGS, doc_mpz_is_lucas_prp }, { "is_odd", GMPy_MPZ_Function_IsOdd, METH_O, GMPy_doc_mpz_function_is_odd }, { "is_power", GMPy_MPZ_Function_IsPower, METH_O, GMPy_doc_mpz_function_is_power }, - { "is_prime", GMPy_MPZ_Function_IsPrime, METH_VARARGS, GMPy_doc_mpz_function_is_prime }, + { "is_prime", (PyCFunction)GMPy_MPZ_Function_IsPrime, METH_FASTCALL, GMPy_doc_mpz_function_is_prime }, { "is_probab_prime", (PyCFunction)GMPy_MPZ_Function_IsProbabPrime, METH_FASTCALL, GMPy_doc_mpz_function_is_probab_prime }, { "is_selfridge_prp", GMPY_mpz_is_selfridge_prp, METH_VARARGS, doc_mpz_is_selfridge_prp }, { "is_square", GMPy_MPZ_Function_IsSquare, METH_O, GMPy_doc_mpz_function_is_square }, @@ -762,10 +762,10 @@ static PyMethodDef Pygmpy_methods [] = { "is_strong_bpsw_prp", GMPY_mpz_is_strongbpsw_prp, METH_VARARGS, doc_mpz_is_strongbpsw_prp }, { "is_strong_lucas_prp", GMPY_mpz_is_stronglucas_prp, METH_VARARGS, doc_mpz_is_stronglucas_prp }, { "is_strong_selfridge_prp", GMPY_mpz_is_strongselfridge_prp, METH_VARARGS, doc_mpz_is_strongselfridge_prp }, - { "jacobi", GMPy_MPZ_Function_Jacobi, METH_VARARGS, GMPy_doc_mpz_function_jacobi }, - { "kronecker", GMPy_MPZ_Function_Kronecker, METH_VARARGS, GMPy_doc_mpz_function_kronecker }, + { "jacobi", (PyCFunction)GMPy_MPZ_Function_Jacobi, METH_FASTCALL, GMPy_doc_mpz_function_jacobi }, + { "kronecker", (PyCFunction)GMPy_MPZ_Function_Kronecker, METH_FASTCALL, GMPy_doc_mpz_function_kronecker }, { "lcm", (PyCFunction)GMPy_MPZ_Function_LCM, METH_FASTCALL, GMPy_doc_mpz_function_lcm }, - { "legendre", GMPy_MPZ_Function_Legendre, METH_VARARGS, GMPy_doc_mpz_function_legendre }, + { "legendre", (PyCFunction)GMPy_MPZ_Function_Legendre, METH_FASTCALL, GMPy_doc_mpz_function_legendre }, { "license", GMPy_get_license, METH_NOARGS, GMPy_doc_license }, { "lucas", GMPy_MPZ_Function_Lucas, METH_O, GMPy_doc_mpz_function_lucas }, { "lucasu", GMPY_mpz_lucasu, METH_VARARGS, doc_mpz_lucasu }, diff --git a/src/gmpy2_mpz.c b/src/gmpy2_mpz.c index fa289b4f..ab4a0c92 100644 --- a/src/gmpy2_mpz.c +++ b/src/gmpy2_mpz.c @@ -106,7 +106,7 @@ static PyMethodDef GMPy_MPZ_methods[] = { { "is_even", GMPy_MPZ_Method_IsEven, METH_NOARGS, GMPy_doc_mpz_method_is_even }, { "is_odd", GMPy_MPZ_Method_IsOdd, METH_NOARGS, GMPy_doc_mpz_method_is_odd }, { "is_power", GMPy_MPZ_Method_IsPower, METH_NOARGS, GMPy_doc_mpz_method_is_power }, - { "is_prime", GMPy_MPZ_Method_IsPrime, METH_VARARGS, GMPy_doc_mpz_method_is_prime }, + { "is_prime", (PyCFunction)GMPy_MPZ_Method_IsPrime, METH_FASTCALL, GMPy_doc_mpz_method_is_prime }, { "is_probab_prime", (PyCFunction)GMPy_MPZ_Method_IsProbabPrime, METH_FASTCALL, GMPy_doc_mpz_method_is_probab_prime }, { "is_square", GMPy_MPZ_Method_IsSquare, METH_NOARGS, GMPy_doc_mpz_method_is_square }, { "num_digits", (PyCFunction)GMPy_MPZ_Method_NumDigits, METH_FASTCALL, GMPy_doc_mpz_method_num_digits }, diff --git a/src/gmpy2_mpz_misc.c b/src/gmpy2_mpz_misc.c index 28781310..d38fed4a 100644 --- a/src/gmpy2_mpz_misc.c +++ b/src/gmpy2_mpz_misc.c @@ -1321,22 +1321,20 @@ PyDoc_STRVAR(GMPy_doc_mpz_function_is_prime, "to n Miller-Rabin tests are performed."); static PyObject * -GMPy_MPZ_Function_IsPrime(PyObject *self, PyObject *args) +GMPy_MPZ_Function_IsPrime(PyObject *self, PyObject * const *args, + Py_ssize_t nargs) { int i; unsigned long reps = 25; MPZ_Object* tempx; - Py_ssize_t argc; - - argc = PyTuple_GET_SIZE(args); - if (argc == 0 || argc > 2) { + if (nargs == 0 || nargs > 2) { TYPE_ERROR("is_prime() requires 'mpz'[,'int'] arguments"); return NULL; } - if (PyTuple_GET_SIZE(args) == 2) { - reps = GMPy_Integer_AsUnsignedLong(PyTuple_GET_ITEM(args, 1)); + if (nargs == 2) { + reps = GMPy_Integer_AsUnsignedLong(args[1]); if (reps == (unsigned long)(-1) && PyErr_Occurred()) { return NULL; } @@ -1346,7 +1344,7 @@ GMPy_MPZ_Function_IsPrime(PyObject *self, PyObject *args) } } - if (!(tempx = GMPy_MPZ_From_Integer(PyTuple_GET_ITEM(args, 0), NULL))) { + if (!(tempx = GMPy_MPZ_From_Integer(args[0], NULL))) { return NULL; } @@ -1371,21 +1369,19 @@ PyDoc_STRVAR(GMPy_doc_mpz_method_is_prime, "to n Miller-Rabin tests are performed."); static PyObject * -GMPy_MPZ_Method_IsPrime(PyObject *self, PyObject *args) +GMPy_MPZ_Method_IsPrime(PyObject *self, PyObject * const *args, + Py_ssize_t nargs) { int i; unsigned long reps = 25; - Py_ssize_t argc; - - argc = PyTuple_GET_SIZE(args); - if (argc > 1) { + if (nargs > 1) { TYPE_ERROR("is_prime() takes at most 1 argument"); return NULL; } - if (PyTuple_GET_SIZE(args) == 1) { - reps = GMPy_Integer_AsUnsignedLong(PyTuple_GET_ITEM(args, 0)); + if (nargs == 1) { + reps = GMPy_Integer_AsUnsignedLong(args[0]); if (reps == (unsigned long)(-1) && PyErr_Occurred()) { return NULL; } @@ -1559,18 +1555,19 @@ PyDoc_STRVAR(GMPy_doc_mpz_function_jacobi, "Return the Jacobi symbol (x|y). y must be odd and >0."); static PyObject * -GMPy_MPZ_Function_Jacobi(PyObject *self, PyObject *args) +GMPy_MPZ_Function_Jacobi(PyObject *self, PyObject *const *args, + Py_ssize_t nargs) { MPZ_Object *tempx = NULL, *tempy = NULL; long res; - if (PyTuple_GET_SIZE(args) != 2) { + if (nargs != 2) { TYPE_ERROR("jacobi() requires 'mpz','mpz' arguments"); return NULL; } - if (!(tempx = GMPy_MPZ_From_Integer(PyTuple_GET_ITEM(args, 0), NULL)) || - !(tempy = GMPy_MPZ_From_Integer(PyTuple_GET_ITEM(args, 1), NULL))) { + if (!(tempx = GMPy_MPZ_From_Integer(args[0], NULL)) || + !(tempy = GMPy_MPZ_From_Integer(args[1], NULL))) { Py_XDECREF((PyObject*)tempx); Py_XDECREF((PyObject*)tempy); @@ -1595,18 +1592,19 @@ PyDoc_STRVAR(GMPy_doc_mpz_function_legendre, "Return the Legendre symbol (x|y). y is assumed to be an odd prime."); static PyObject * -GMPy_MPZ_Function_Legendre(PyObject *self, PyObject *args) +GMPy_MPZ_Function_Legendre(PyObject *self, PyObject * const *args, + Py_ssize_t nargs) { MPZ_Object *tempx = NULL, *tempy = NULL; long res; - if (PyTuple_GET_SIZE(args) != 2) { + if (nargs != 2) { TYPE_ERROR("legendre() requires 'mpz','mpz' arguments"); return NULL; } - if (!(tempx = GMPy_MPZ_From_Integer(PyTuple_GET_ITEM(args, 0), NULL)) || - !(tempy = GMPy_MPZ_From_Integer(PyTuple_GET_ITEM(args, 1), NULL))) { + if (!(tempx = GMPy_MPZ_From_Integer(args[0], NULL)) || + !(tempy = GMPy_MPZ_From_Integer(args[1], NULL))) { Py_XDECREF((PyObject*)tempx); Py_XDECREF((PyObject*)tempy); @@ -1631,18 +1629,19 @@ PyDoc_STRVAR(GMPy_doc_mpz_function_kronecker, "Return the Kronecker-Jacobi symbol (x|y)."); static PyObject * -GMPy_MPZ_Function_Kronecker(PyObject *self, PyObject *args) +GMPy_MPZ_Function_Kronecker(PyObject *self, PyObject * const *args, + Py_ssize_t nargs) { MPZ_Object *tempx = NULL, *tempy = NULL; long res; - if (PyTuple_GET_SIZE(args) != 2) { + if (nargs != 2) { TYPE_ERROR("kronecker() requires 'mpz','mpz' arguments"); return NULL; } - if (!(tempx = GMPy_MPZ_From_Integer(PyTuple_GET_ITEM(args, 0), NULL)) || - !(tempy = GMPy_MPZ_From_Integer(PyTuple_GET_ITEM(args, 1), NULL))) { + if (!(tempx = GMPy_MPZ_From_Integer(args[0], NULL)) || + !(tempy = GMPy_MPZ_From_Integer(args[1], NULL))) { Py_XDECREF((PyObject*)tempx); Py_XDECREF((PyObject*)tempy); diff --git a/src/gmpy2_mpz_misc.h b/src/gmpy2_mpz_misc.h index 2a15c653..a4b388ff 100644 --- a/src/gmpy2_mpz_misc.h +++ b/src/gmpy2_mpz_misc.h @@ -54,7 +54,7 @@ static PyObject * GMPy_MPZ_Method_IsSquare(PyObject *self, PyObject *other); static PyObject * GMPy_MPZ_Method_IsDivisible(PyObject *self, PyObject *other); static PyObject * GMPy_MPZ_Method_IsCongruent(PyObject *self, PyObject *const *args, Py_ssize_t nargs); static PyObject * GMPy_MPZ_Method_IsPower(PyObject *self, PyObject *other); -static PyObject * GMPy_MPZ_Method_IsPrime(PyObject *self, PyObject *args); +static PyObject * GMPy_MPZ_Method_IsPrime(PyObject *self, PyObject *const *args, Py_ssize_t nargs); static PyObject * GMPy_MPZ_Method_IsProbabPrime(PyObject *self, PyObject *const *args, Py_ssize_t nargs); static PyObject * GMPy_MPZ_Method_IsEven(PyObject *self, PyObject *other); static PyObject * GMPy_MPZ_Method_IsOdd(PyObject *self, PyObject *other); @@ -85,15 +85,15 @@ static PyObject * GMPy_MPZ_Function_IsSquare(PyObject *self, PyObject *other); static PyObject * GMPy_MPZ_Function_IsDivisible(PyObject *self, PyObject * const *args, Py_ssize_t nargs); static PyObject * GMPy_MPZ_Function_IsCongruent(PyObject *self, PyObject * const *args, Py_ssize_t nargs); static PyObject * GMPy_MPZ_Function_IsPower(PyObject *self, PyObject *other); -static PyObject * GMPy_MPZ_Function_IsPrime(PyObject *self, PyObject *args); +static PyObject * GMPy_MPZ_Function_IsPrime(PyObject *self, PyObject * const *args, Py_ssize_t nargs); static PyObject * GMPy_MPZ_Function_IsProbabPrime(PyObject *self, PyObject *const *args, Py_ssize_t nargs); static PyObject * GMPy_MPZ_Function_NextPrime(PyObject *self, PyObject *other); #if (__GNU_MP_VERSION > 6) || (__GNU_MP_VERSION == 6 && __GNU_MP_VERSION_MINOR >= 3) static PyObject * GMPy_MPZ_Function_PrevPrime(PyObject *self, PyObject *other); #endif -static PyObject * GMPy_MPZ_Function_Jacobi(PyObject *self, PyObject *args); -static PyObject * GMPy_MPZ_Function_Legendre(PyObject *self, PyObject *args); -static PyObject * GMPy_MPZ_Function_Kronecker(PyObject *self, PyObject *args); +static PyObject * GMPy_MPZ_Function_Jacobi(PyObject *self, PyObject * const *args, Py_ssize_t nargs); +static PyObject * GMPy_MPZ_Function_Legendre(PyObject *self, PyObject * const *args, Py_ssize_t nargs); +static PyObject * GMPy_MPZ_Function_Kronecker(PyObject *self, PyObject * const *args, Py_ssize_t nargs); static PyObject * GMPy_MPZ_Function_IsEven(PyObject *self, PyObject *other); static PyObject * GMPy_MPZ_Function_IsOdd(PyObject *self, PyObject *other);