Re: unused macro MPN_PTR_SWAP in mini-gmp.c
On 3/19/22 04:44, Niels Möller wrote: Paul Eggert writes: In libgmp 6.2.1, mini-gmp.c defines a macro without using it, causing the command "gcc -Wunused-macros -Werror" to fail with the following diagnostic: I haven't used -Wunused-macros before, I take it it warns only about macros defined in .c files? Since it's perfectly normal that macros defined in .h files are unused in some of the compilation units including the .h file? Yes, that's right. mini-gmp.c is a bit special, in that one more-or-less recommended usecase is to #include this file into some other compilation unit. E.g., like in https://gmplib.org/repo/gmp/file/tip/bootstrap.c#l33. But probably still shouln't define macros not used within mini-gmp.c; any additional utility macros should probably go in mini-gmp.h, and be compatible with public macros from gmp.h. MPN_PTR_SWAP is an internal macro, though, and I expect you don't want it to be public. A couple of days ago Marco gave a simple fix that looks like a win, as it also makes mini-gmp.c shorter and easier to read; please see attachment. Could you please install that? Thanks.--- Begin Message --- Ciao Paul, Il 2022-03-09 02:56 Paul Eggert ha scritto: In libgmp 6.2.1, mini-gmp.c defines a macro without using it, causing Thanks for spotting this! Proposed patch attached. There is also a different possible way to heal the problem: using it :-D diff -r a44f487c8d20 mini-gmp/mini-gmp.c --- a/mini-gmp/mini-gmp.c Fri Mar 11 21:13:20 2022 +0100 +++ b/mini-gmp/mini-gmp.c Thu Mar 17 19:15:51 2022 +0100 @@ -1938,8 +1938,7 @@ mpz_swap (mpz_t u, mpz_t v) { MP_SIZE_T_SWAP (u->_mp_size, v->_mp_size); - MP_SIZE_T_SWAP (u->_mp_alloc, v->_mp_alloc); - MP_PTR_SWAP (u->_mp_d, v->_mp_d); + MPN_PTR_SWAP (u->_mp_d, u->_mp_alloc, v->_mp_d, v->_mp_alloc); } Ĝis, m --- End Message --- ___ gmp-bugs mailing list gmp-bugs@gmplib.org https://gmplib.org/mailman/listinfo/gmp-bugs
Re: unused macro MPN_PTR_SWAP in mini-gmp.c
Ciao Paul, Il 2022-03-18 00:37 Paul Eggert ha scritto: On 3/17/22 11:32, Marco Bodrato wrote: - MP_SIZE_T_SWAP (u->_mp_alloc, v->_mp_alloc); - MP_PTR_SWAP (u->_mp_d, v->_mp_d); + MPN_PTR_SWAP (u->_mp_d, u->_mp_alloc, v->_mp_d, v->_mp_alloc); Thank you, this looks good. Slightly changed and pushed: https://gmplib.org/repo/gmp/rev/2a0dd4a874f1 Ĝis, m ___ gmp-bugs mailing list gmp-bugs@gmplib.org https://gmplib.org/mailman/listinfo/gmp-bugs
Re: unused macro MPN_PTR_SWAP in mini-gmp.c
Paul Eggert writes: > In libgmp 6.2.1, mini-gmp.c defines a macro without using it, causing > the command "gcc -Wunused-macros -Werror" to fail with the following > diagnostic: I haven't used -Wunused-macros before, I take it it warns only about macros defined in .c files? Since it's perfectly normal that macros defined in .h files are unused in some of the compilation units including the .h file? mini-gmp.c is a bit special, in that one more-or-less recommended usecase is to #include this file into some other compilation unit. E.g., like in https://gmplib.org/repo/gmp/file/tip/bootstrap.c#l33. But probably still shouln't define macros not used within mini-gmp.c; any additional utility macros should probably go in mini-gmp.h, and be compatible with public macros from gmp.h. Regards, /Niels -- Niels Möller. PGP key CB4962D070D77D7FCB8BA36271D8F1FF368C6677. Internet email is subject to wholesale government surveillance. ___ gmp-bugs mailing list gmp-bugs@gmplib.org https://gmplib.org/mailman/listinfo/gmp-bugs
Re: unused macro MPN_PTR_SWAP in mini-gmp.c
On 3/17/22 11:32, Marco Bodrato wrote: mpz_swap (mpz_t u, mpz_t v) { MP_SIZE_T_SWAP (u->_mp_size, v->_mp_size); - MP_SIZE_T_SWAP (u->_mp_alloc, v->_mp_alloc); - MP_PTR_SWAP (u->_mp_d, v->_mp_d); + MPN_PTR_SWAP (u->_mp_d, u->_mp_alloc, v->_mp_d, v->_mp_alloc); Thank you, this looks good. ___ gmp-bugs mailing list gmp-bugs@gmplib.org https://gmplib.org/mailman/listinfo/gmp-bugs
Re: unused macro MPN_PTR_SWAP in mini-gmp.c
Ciao Paul, Il 2022-03-09 02:56 Paul Eggert ha scritto: In libgmp 6.2.1, mini-gmp.c defines a macro without using it, causing Thanks for spotting this! Proposed patch attached. There is also a different possible way to heal the problem: using it :-D diff -r a44f487c8d20 mini-gmp/mini-gmp.c --- a/mini-gmp/mini-gmp.c Fri Mar 11 21:13:20 2022 +0100 +++ b/mini-gmp/mini-gmp.c Thu Mar 17 19:15:51 2022 +0100 @@ -1938,8 +1938,7 @@ mpz_swap (mpz_t u, mpz_t v) { MP_SIZE_T_SWAP (u->_mp_size, v->_mp_size); - MP_SIZE_T_SWAP (u->_mp_alloc, v->_mp_alloc); - MP_PTR_SWAP (u->_mp_d, v->_mp_d); + MPN_PTR_SWAP (u->_mp_d, u->_mp_alloc, v->_mp_d, v->_mp_alloc); } Ĝis, m ___ gmp-bugs mailing list gmp-bugs@gmplib.org https://gmplib.org/mailman/listinfo/gmp-bugs