* [PATCH nft 1/2] utils: fix one compilation error with --with-mini-gmp
@ 2017-11-22 19:36 Pablo Neira Ayuso
2017-11-22 19:36 ` [PATCH nft 2/2] gmputil: turn mpz_printf into mpz_vfprintf to restore --with-mini-gmp Pablo Neira Ayuso
0 siblings, 1 reply; 3+ messages in thread
From: Pablo Neira Ayuso @ 2017-11-22 19:36 UTC (permalink / raw)
To: netfilter-devel; +Cc: phil
Restore some code that is needed, until we have a version of gmp_printf
that takes variable arguments.
In file included from ../include/utils.h:12:0,
from ../include/nftables.h:6,
from ../include/rule.h:5,
from segtree.c:15:
segtree.c: In function ‘ei_insert’:
../include/gmputil.h:12:20: error: too many arguments to function ‘mpz_printf’
#define gmp_printf mpz_printf
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
include/utils.h | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/include/utils.h b/include/utils.h
index 369195240e24..310389c22fab 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -15,7 +15,11 @@
#define pr_debug(fmt, arg...) printf(fmt, ##arg)
+#if defined(HAVE_LIBGMP)
#define pr_gmp_debug(fmt, arg...) gmp_printf(fmt, ##arg)
+#else
+#define pr_gmp_debug(fmt, arg...) ({ if (false) {}; 0; })
+#endif
#define __fmtstring(x, y) __attribute__((format(printf, x, y)))
#if 0
--
2.11.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH nft 2/2] gmputil: turn mpz_printf into mpz_vfprintf to restore --with-mini-gmp
2017-11-22 19:36 [PATCH nft 1/2] utils: fix one compilation error with --with-mini-gmp Pablo Neira Ayuso
@ 2017-11-22 19:36 ` Pablo Neira Ayuso
2017-11-22 19:40 ` Pablo Neira Ayuso
0 siblings, 1 reply; 3+ messages in thread
From: Pablo Neira Ayuso @ 2017-11-22 19:36 UTC (permalink / raw)
To: netfilter-devel; +Cc: phil
2535ba7006f2 ("src: get rid of printf") uses gmp_vfprintf() which
doesn't exists in mini-gmp.c, this breaks compilation with --mini-gmp.
This patch implements poor man's gmp_vfprintf that takes one single
argument which is what we need.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
@Phil: We're still hitting a compilation warning, since libnftables is
in place, it seems -Wno-sign-compare is ignored.
include/gmputil.h | 7 ++++---
src/gmputil.c | 8 +++++---
2 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/include/gmputil.h b/include/gmputil.h
index 9c372216cc52..084aa6226687 100644
--- a/include/gmputil.h
+++ b/include/gmputil.h
@@ -7,9 +7,10 @@
#include <gmp.h>
#else
#include <mini-gmp.h>
-/* mini-gmp doesn't come with gmp_printf, so we use our own minimal variant */
-extern int mpz_printf(const char *format, const mpz_t value);
-#define gmp_printf mpz_printf
+#include <stdio.h>
+/* mini-gmp doesn't come with gmp_vfprintf, so we use our own minimal variant */
+extern int mpz_vfprintf(FILE *fp, const char *format, va_list args);
+#define gmp_vfprintf mpz_vfprintf
#endif
#include <asm/byteorder.h>
diff --git a/src/gmputil.c b/src/gmputil.c
index 3cc4e61f5463..098e2ffb8b3e 100644
--- a/src/gmputil.c
+++ b/src/gmputil.c
@@ -145,9 +145,11 @@ void mpz_switch_byteorder(mpz_t rop, unsigned int len)
/* mini-gmp doesn't have a gmp_printf so we use our own minimal
* variant here which is able to format a single mpz_t.
*/
-int mpz_printf(const char *f, const mpz_t value)
+int mpz_vfprintf(FILE *fp, const char *f, va_list args)
{
+ const mpz_t *value = va_arg(args, const mpz_t *);
int n = 0;
+
while (*f) {
if (*f != '%') {
if (fputc(*f, stdout) != *f)
@@ -174,7 +176,7 @@ int mpz_printf(const char *f, const mpz_t value)
else
return -1;
- len = mpz_sizeinbase(value, base);
+ len = mpz_sizeinbase(*value, base);
while (prec-- > len) {
if (fputc('0', stdout) != '0')
return -1;
@@ -182,7 +184,7 @@ int mpz_printf(const char *f, const mpz_t value)
++n;
}
- str = mpz_get_str(NULL, base, value);
+ str = mpz_get_str(NULL, base, *value);
ok = str && fwrite(str, 1, len, stdout) == len;
free(str);
--
2.11.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH nft 2/2] gmputil: turn mpz_printf into mpz_vfprintf to restore --with-mini-gmp
2017-11-22 19:36 ` [PATCH nft 2/2] gmputil: turn mpz_printf into mpz_vfprintf to restore --with-mini-gmp Pablo Neira Ayuso
@ 2017-11-22 19:40 ` Pablo Neira Ayuso
0 siblings, 0 replies; 3+ messages in thread
From: Pablo Neira Ayuso @ 2017-11-22 19:40 UTC (permalink / raw)
To: netfilter-devel; +Cc: phil
On Wed, Nov 22, 2017 at 08:36:16PM +0100, Pablo Neira Ayuso wrote:
> 2535ba7006f2 ("src: get rid of printf") uses gmp_vfprintf() which
> doesn't exists in mini-gmp.c, this breaks compilation with --mini-gmp.
>
> This patch implements poor man's gmp_vfprintf that takes one single
> argument which is what we need.
>
> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
> ---
> @Phil: We're still hitting a compilation warning, since libnftables is
> in place, it seems -Wno-sign-compare is ignored.
mini-gmp.c: In function ‘mpn_get_str_bits’:
mini-gmp.c:1176:17: warning: comparison between signed and unsigned
integer expressions [-Wsign-compare]
if (shift >= GMP_LIMB_BITS && ++i < un)
^
mini-gmp.c: In function ‘mpz_and’:
mini-gmp.c:1406:31: warning: comparison between signed and unsigned
integer expressions [-Wsign-compare]
#define MPZ_REALLOC(z,n) ((n) > (z)->_mp_alloc \
^
mini-gmp.c:3650:8: note: in expansion of macro ‘MPZ_REALLOC’
rp = MPZ_REALLOC (r, rn + rc);
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-11-22 19:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-22 19:36 [PATCH nft 1/2] utils: fix one compilation error with --with-mini-gmp Pablo Neira Ayuso
2017-11-22 19:36 ` [PATCH nft 2/2] gmputil: turn mpz_printf into mpz_vfprintf to restore --with-mini-gmp Pablo Neira Ayuso
2017-11-22 19:40 ` Pablo Neira Ayuso
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).