[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
varargs fixes for gmp 4.0
From: |
Marcus Meissner |
Subject: |
varargs fixes for gmp 4.0 |
Date: |
Tue, 11 Jun 2002 11:32:03 +0200 |
User-agent: |
Mutt/1.3.22.1i |
Hi,
The test for varargs does not work on x86_64 since they have a rather
weird varargs handling which does not allow deviation from the standard nor
hacks.
This fixes t-scanf.c to work correctly on all of our supported platforms.
Ciao, Marcus
--- tests/misc/t-scanf.c Sat Nov 24 22:10:00 2001
+++ /build/meissner/root/t-scanf.c Mon May 6 16:22:02 2002
@@ -56,8 +56,7 @@
int option_libc_scanf = 0;
-typedef int (*fun1_t) _PROTO ((const char *, const char *, void *));
-typedef int (*fun2_t) _PROTO ((const char *, const char *, void *, void *));
+typedef int (*fun_t) _PROTO ((const char *, const char *, ...));
int
@@ -117,9 +116,11 @@
rewind (fp);
ret = gmp_vfscanf (fp, fmt, ap);
+ va_end(ap);
got_ftell = ftell (fp);
ASSERT_ALWAYS (got_ftell != -1L);
+
fromstring_next_c = getc (fp);
ASSERT_ALWAYS (fclose (fp) == 0);
@@ -127,17 +128,34 @@
}
int
-fromstring_fscanf1 (const char *input, const char *fmt, void *a1)
+#if HAVE_STDARG
+fromstring_fscanf1 (const char *input, const char *fmt, ...)
+#else
+fromstring_gmp_fscanf (va_alist)
+ va_dcl
+#endif
{
FILE *fp;
int ret;
+ va_list ap;
+
+#ifdef HAVE_STDARG
+ va_start(ap,fmt);
+#else
+ const char *input;
+ const char *fmt;
+ va_start (ap);
+ input = va_arg (ap, const char *);
+ fmt = va_arg (ap, const char *);
+#endif
ASSERT_ALWAYS ((fp = fopen (TEMPFILE, "w+")) != NULL);
ASSERT_ALWAYS (fputs (input, fp) != EOF);
ASSERT_ALWAYS (fflush (fp) == 0);
rewind (fp);
- ret = fscanf (fp, fmt, a1);
+ ret = vfscanf (fp, fmt, ap);
+ va_end(ap);
got_ftell = ftell (fp);
ASSERT_ALWAYS (got_ftell != -1L);
@@ -440,8 +458,7 @@
mpz_t got, want;
long got_l, want_ftell;
int error = 0;
- fun1_t fun1;
- fun2_t fun2;
+ fun_t fun;
const char *name;
char fmt[128];
@@ -473,13 +490,11 @@
switch (j) {
case 0:
name = "gmp_sscanf";
- fun1 = (fun1_t) gmp_sscanf;
- fun2 = (fun2_t) gmp_sscanf;
+ fun = (fun_t) gmp_sscanf;
break;
case 1:
name = "gmp_fscanf";
- fun1 = (fun1_t) fromstring_gmp_fscanf;
- fun2 = (fun2_t) fromstring_gmp_fscanf;
+ fun = (fun_t) fromstring_gmp_fscanf;
break;
case 2:
#ifdef __GLIBC__
@@ -489,8 +504,7 @@
if (! libc_scanf_convert (fmt))
continue;
name = "standard sscanf";
- fun1 = (fun1_t) wrap_sscanf1;
- fun2 = (fun2_t) wrap_sscanf2;
+ fun = (fun_t) wrap_sscanf1;
break;
case 3:
#ifdef __GLIBC__
@@ -500,8 +514,7 @@
if (! libc_scanf_convert (fmt))
continue;
name = "standard fscanf";
- fun1 = fromstring_fscanf1;
- fun2 = fromstring_fscanf2;
+ fun = fromstring_fscanf1;
break;
default:
ASSERT_ALWAYS (0);
@@ -516,17 +529,17 @@
case 1:
mpz_set_si (got, -999L);
if (ignore)
- got_ret = (*fun1) (data[i].input, fmt, &got_upto);
+ got_ret = (*fun) (data[i].input, fmt, &got_upto);
else
- got_ret = (*fun2) (data[i].input, fmt, got, &got_upto);
+ got_ret = (*fun) (data[i].input, fmt, got, &got_upto);
break;
case 2:
case 3:
got_l = -999L;
if (ignore)
- got_ret = (*fun1) (data[i].input, fmt, &got_upto);
+ got_ret = (*fun) (data[i].input, fmt, &got_upto);
else
- got_ret = (*fun2) (data[i].input, fmt, &got_l, &got_upto);
+ got_ret = (*fun) (data[i].input, fmt, &got_l, &got_upto);
mpz_set_si (got, got_l);
break;
default:
@@ -826,8 +839,7 @@
mpq_t got, want;
long got_l, want_ftell;
int error = 0;
- fun1_t fun1;
- fun2_t fun2;
+ fun_t fun;
const char *name;
char fmt[128];
@@ -862,13 +874,11 @@
switch (j) {
case 0:
name = "gmp_sscanf";
- fun1 = (fun1_t) gmp_sscanf;
- fun2 = (fun2_t) gmp_sscanf;
+ fun = (fun_t) gmp_sscanf;
break;
case 1:
name = "gmp_fscanf";
- fun1 = (fun1_t) fromstring_gmp_fscanf;
- fun2 = (fun2_t) fromstring_gmp_fscanf;
+ fun = (fun_t) fromstring_gmp_fscanf;
break;
case 2:
if (strchr (data[i].input, '/') != NULL)
@@ -876,8 +886,7 @@
if (! libc_scanf_convert (fmt))
continue;
name = "standard sscanf";
- fun1 = (fun1_t) wrap_sscanf1;
- fun2 = (fun2_t) wrap_sscanf2;
+ fun = (fun_t) wrap_sscanf1;
break;
case 3:
if (strchr (data[i].input, '/') != NULL)
@@ -885,8 +894,7 @@
if (! libc_scanf_convert (fmt))
continue;
name = "standard fscanf";
- fun1 = fromstring_fscanf1;
- fun2 = fromstring_fscanf2;
+ fun = fromstring_fscanf1;
break;
default:
ASSERT_ALWAYS (0);
@@ -901,17 +909,17 @@
case 1:
mpq_set_si (got, -999L, 121L);
if (ignore)
- got_ret = (*fun1) (data[i].input, fmt, &got_upto);
+ got_ret = (*fun) (data[i].input, fmt, &got_upto);
else
- got_ret = (*fun2) (data[i].input, fmt, got, &got_upto);
+ got_ret = (*fun) (data[i].input, fmt, got, &got_upto);
break;
case 2:
case 3:
got_l = -999L;
if (ignore)
- got_ret = (*fun1) (data[i].input, fmt, &got_upto);
+ got_ret = (*fun) (data[i].input, fmt, &got_upto);
else
- got_ret = (*fun2) (data[i].input, fmt, &got_l, &got_upto);
+ got_ret = (*fun) (data[i].input, fmt, &got_l, &got_upto);
mpq_set_si (got, got_l, (got_l == -999L ? 121L : 1L));
break;
default:
@@ -1082,8 +1090,7 @@
double got_d;
long want_ftell;
int error = 0;
- fun1_t fun1;
- fun2_t fun2;
+ fun_t fun;
const char *name;
char fmt[128];
@@ -1118,27 +1125,23 @@
switch (j) {
case 0:
name = "gmp_sscanf";
- fun1 = (fun1_t) gmp_sscanf;
- fun2 = (fun2_t) gmp_sscanf;
+ fun = (fun_t) gmp_sscanf;
break;
case 1:
name = "gmp_fscanf";
- fun1 = (fun1_t) fromstring_gmp_fscanf;
- fun2 = (fun2_t) fromstring_gmp_fscanf;
+ fun = (fun_t) fromstring_gmp_fscanf;
break;
case 2:
if (! libc_scanf_convert (fmt))
continue;
name = "standard sscanf";
- fun1 = (fun1_t) wrap_sscanf1;
- fun2 = (fun2_t) wrap_sscanf2;
+ fun = (fun_t) wrap_sscanf1;
break;
case 3:
if (! libc_scanf_convert (fmt))
continue;
name = "standard fscanf";
- fun1 = fromstring_fscanf1;
- fun2 = fromstring_fscanf2;
+ fun = fromstring_fscanf1;
break;
default:
ASSERT_ALWAYS (0);
@@ -1153,17 +1156,17 @@
case 1:
mpf_set_si (got, -999L);
if (ignore)
- got_ret = (*fun1) (data[i].input, fmt, &got_upto);
+ got_ret = (*fun) (data[i].input, fmt, &got_upto);
else
- got_ret = (*fun2) (data[i].input, fmt, got, &got_upto);
+ got_ret = (*fun) (data[i].input, fmt, got, &got_upto);
break;
case 2:
case 3:
got_d = -999L;
if (ignore)
- got_ret = (*fun1) (data[i].input, fmt, &got_upto);
+ got_ret = (*fun) (data[i].input, fmt, &got_upto);
else
- got_ret = (*fun2) (data[i].input, fmt, &got_d, &got_upto);
+ got_ret = (*fun) (data[i].input, fmt, &got_d, &got_upto);
mpf_set_d (got, got_d);
break;
default:
- varargs fixes for gmp 4.0,
Marcus Meissner <=