Re: with strict C99 the tests/mpz/convert.c needs #include

2020-11-10 Thread Vincent Lefevre
On 2020-11-09 10:14:37 +0100, Torbjorn Granlund wrote:
> Vincent Lefevre  writes:
> 
>   In the context of the call, the values will always be nonnegative
>   so that this is OK, but there is a risk that some future developer
>   might reuse this function in another context, where it would be
>   incorrect on platforms with signed char (in particular, there is
>   no warning in the comment).
> 
> Perhaps we could rename this function
> note_that_this_funtion_is_called_str_casecmp_and_not_strcasecmp, to
> avoid such looming disaster?  Or, to be more polite, perhaps
> please_note_that_this_funtion_is_called_str_casecmp_and_not_strcasecmp?

Since GMP developers are so smart, why does the test exist anyway?
Since GMP is expected to return the correct answer, it is not needed
to do the test.

Seriously, this function is used in a context to test the result of
mpz_get_str, and it is better to assume any kind of bug (which could
come from GMP or the compiler, for instance). In particular, do not
assume that the string returned by mpz_get_str necessarily consists
of valid digits. The consequence of a bug might be that some memory
location in the string is an invalid digit or is not explicitly set.
If this happens, the test tolower (c1) != tolower (c2) may be false
in such a case, so that the error may remain undetected. Something
like

  if (c1 < 0 || c2 < 0)
abort ();

would improve the test.

Moreover, there's something I don't understand. In the test,

   base = bsi % 62 + 1;

so that the base may be larger or equal to 37, but in such bases,
the case is significant, but it is not tested. I mean that with the
current test, you won't be able to distinguish "1a" from "1A".

-- 
Vincent Lefèvre  - Web: 
100% accessible validated (X)HTML - Blog: 
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)
___
gmp-bugs mailing list
gmp-bugs@gmplib.org
https://gmplib.org/mailman/listinfo/gmp-bugs


Re: with strict C99 the tests/mpz/convert.c needs #include

2020-11-09 Thread Torbjörn Granlund
Vincent Lefevre  writes:

  In the context of the call, the values will always be nonnegative
  so that this is OK, but there is a risk that some future developer
  might reuse this function in another context, where it would be
  incorrect on platforms with signed char (in particular, there is
  no warning in the comment).

Perhaps we could rename this function
note_that_this_funtion_is_called_str_casecmp_and_not_strcasecmp, to
avoid such looming disaster?  Or, to be more polite, perhaps
please_note_that_this_funtion_is_called_str_casecmp_and_not_strcasecmp?

-- 
Torbjörn
Please encrypt, key id 0xC8601622
___
gmp-bugs mailing list
gmp-bugs@gmplib.org
https://gmplib.org/mailman/listinfo/gmp-bugs


Re: with strict C99 the tests/mpz/convert.c needs #include

2020-11-08 Thread Marco Bodrato

Ciao,

Il 2020-11-08 00:45 Dennis Clarke ha scritto:

However the tests blow up due to :

convert.c:143:11: error: implicit declaration of function 'strcasecmp'
is invalid in C99


That file will be changed in the next release. Please look if the 
applied patch fits your needs.

https://gmplib.org/repo/gmp-6.2/rev/ad3ca09cfa38

Ĝis,
m
___
gmp-bugs mailing list
gmp-bugs@gmplib.org
https://gmplib.org/mailman/listinfo/gmp-bugs


Re: with strict C99 the tests/mpz/convert.c needs #include

2020-11-08 Thread Vincent Lefevre
On 2020-11-07 18:45:52 -0500, Dennis Clarke wrote:
> However the tests blow up due to :
> 
> convert.c:143:11: error: implicit declaration of function 'strcasecmp'
> is invalid in C99
> 
> So that is easy to fix.
> 
> ijiraq# diff -u ./tests/mpz/convert.c.orig ./tests/mpz/convert.c
> --- ./tests/mpz/convert.c.orig  2020-01-17 13:44:49.0 +
> +++ ./tests/mpz/convert.c   2020-11-07 22:51:36.823215000 +
> @@ -21,6 +21,7 @@
>  #include 
>  #include 
>  #include  /* for strlen */
> +#include  /* for strcasecmp */
> 
>  #include "gmp-impl.h"
>  #include "tests.h"
> ijiraq#

strcasecmp is not part of C99. It should be better to convert both
strings to uppercase (with toupper) or lowercase (with tolower),
then do a usual comparison.

-- 
Vincent Lefèvre  - Web: 
100% accessible validated (X)HTML - Blog: 
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)
___
gmp-bugs mailing list
gmp-bugs@gmplib.org
https://gmplib.org/mailman/listinfo/gmp-bugs


with strict C99 the tests/mpz/convert.c needs #include

2020-11-07 Thread Dennis Clarke


On a somewhat strange machine I was building with llvm/Clang on FreeBSD
and this :

ijiraq# uname -apKU
FreeBSD ijiraq 13.0-CURRENT FreeBSD 13.0-CURRENT #0 r367349: Wed Nov  4
22:48:25 UTC 2020
r...@freebsd-head-riscv64-build.jail.ci.freebsd.org:/usr/obj/usr/src/riscv.riscv64/sys/QEMU
 riscv riscv64 1300125 1300125
ijiraq#
ijiraq# cc --version
FreeBSD clang version 11.0.0 (g...@github.com:llvm/llvm-project.git
llvmorg-11.0.0-0-g176249bd673)
Target: riscv64-unknown-freebsd13.0
Thread model: posix
InstalledDir: /usr/bin
ijiraq#

CC=/usr/bin/cc

CFLAGS=-std=iso9899:1999 -m64 -g -O0 -pedantic -pedantic-errors
-march=rv64imafdc -mabi=lp64d -Weverything -Wno-reserved-id-macro
-Wno-unused-macros -Wno-missing-prototypes -Wno-padded -fno-fast-math
-fno-builtin

CPPFLAGS=-D_TS_ERRNO -D_POSIX_PTHREAD_SEMANTICS -D_LARGEFILE64_SOURCE
-D_XOPEN_SOURCE=600

CXXFLAGS=-m64 -g -O0 -march=rv64imafdc -mabi=lp64d -fno-fast-math
-fno-builtin

Wherein the config was :

./configure ABI=standard --enable-cxx --prefix=/opt/bw \
--libdir=/opt/bw/lib --disable-assembly


Seems to build fine.

However the tests blow up due to :

convert.c:143:11: error: implicit declaration of function 'strcasecmp'
is invalid in C99

So that is easy to fix.

ijiraq# diff -u ./tests/mpz/convert.c.orig ./tests/mpz/convert.c
--- ./tests/mpz/convert.c.orig  2020-01-17 13:44:49.0 +
+++ ./tests/mpz/convert.c   2020-11-07 22:51:36.823215000 +
@@ -21,6 +21,7 @@
 #include 
 #include 
 #include  /* for strlen */
+#include  /* for strcasecmp */

 #include "gmp-impl.h"
 #include "tests.h"
ijiraq#

Then tests continue swimmingly.


-- 
Dennis Clarke
RISC-V/SPARC/PPC/ARM/CISC
UNIX and Linux spoken
GreyBeard and suspenders optional
___
gmp-bugs mailing list
gmp-bugs@gmplib.org
https://gmplib.org/mailman/listinfo/gmp-bugs