Bug #74039 [Com]: is_infinite(-INF) returns false

[email protected] ("bug at example dot com")
Newsgroups php.bugs
Message-ID <[email protected]>
Edit report at https://bugs.php.net/bug.php?id=74039&edit=1

 ID:                 74039
 Comment by:         bug at example dot com
 Reported by:        bugs dot php dot net at chsc dot dk
 Summary:            is_infinite(-INF) returns false
 Status:             Closed
 Type:               Bug
 Package:            Math related
 Operating System:   Alpine Linux
 PHP Version:        7.0.15
 Assigned To:        nikic
 Block user comment: N
 Private report:     N

 New Comment:

$ man isfinite 

says that isfinite() is a C99 feature. In order to see what's going on compiler diagnostics helps (please note that the return type of main is int according to all known standards):

main.c
------
#include <stdio.h>
#include <math.h>

int main()
{
   double d = 0;
   printf ("%d\n", isfinite (d));
   return 0;
}
------

   $ gcc -Wall -Werror main.c
   cc1: warnings being treated as errors
   main.c: In function 'main':
   main.c:7: error: implicit declaration of function 'isfinite'

The default mode of GCC is C99 since GCC 5, before it was C89. For those older compilers you have to explitly switch C99-mode on:

   $ gcc -Wall -Werror -std=c99 main.c

The reason why there is an linker error is that for the implicitly declared isfinite() the symbol is the object file and the symbol used in the libc is not "isfinite" but here on my machine "__finite":

   $ nm main.o
                    U __finite
   0000000000000000 T main
                    U printf


Previous Comments:
------------------------------------------------------------------------
[2017-03-20 12:48:39] georgi at unixsol dot org

The C example code does not compile on CentOS 5:

georgi@cent5:~$ cat > z.c
#include <math.h>
#ifndef isfinite
# error Not defined
#endif
void main() {}
georgi@cent5:~$ gcc z.c
z.c:3:3: error: #error Not defined
z.c: In function ‘main’:
z.c:5: warning: return type of ‘main’ is not ‘int’


georgi@cent5:~$ rpm -qa | grep glibc | sort | uniq
glibc-2.5-58.el5_6.3
glibc-common-2.5-58.el5_6.3
glibc-devel-2.5-58.el5_6.3
glibc-headers-2.5-58.el5_6.3

------------------------------------------------------------------------
[2017-03-17 19:12:35] [email protected]

CentOS issue also reported in bug #74265.

------------------------------------------------------------------------
[2017-03-17 16:50:40] [email protected]

Does

#include <math.h>
#ifndef isfinite
# error Not defined
#endif
void main() {}

compile for you? This seems pretty weird, because glibc should have isfinite().

------------------------------------------------------------------------
[2017-03-17 16:32:12] georgi at unixsol dot org

The fix in https://github.com/php/php-src/commit/714d825b62e719447686da6efe3b4063c2f25749 breaks the build for me for PHP 7.1.3 and PHP 7.0.17 branches:

The build fails with:

ext/filter/.libs/logical_filters.o: In function `php_filter_float':
/home/georgi/build/BUILD/php71-7.1.3/src/ext/filter/logical_filters.c:411: undefined reference to `isfinite'
ext/intl/collator/.libs/collator_is_numeric.o: In function `collator_is_numeric':
/home/georgi/build/BUILD/php71-7.1.3/src/ext/intl/collator/collator_is_numeric.c:255: undefined reference to `isfinite'
ext/standard/.libs/math.o: In function `zif_is_finite':
/home/georgi/build/BUILD/php71-7.1.3/src/ext/standard/math.c:589: undefined reference to `isfinite'
ext/standard/.libs/math.o: In function `_php_math_round':
/home/georgi/build/BUILD/php71-7.1.3/src/ext/standard/math.c:133: undefined reference to `isfinite'
/home/georgi/build/BUILD/php71-7.1.3/src/ext/standard/math.c:201: undefined reference to `isfinite'
ext/standard/.libs/var.o:/home/georgi/build/BUILD/php71-7.1.3/src/ext/standard/var.c:473: more undefined references to `isfinite' follow

After reverting 714d825b62e719447686da6efe3b4063c2f25749, I can build both 7.0 and 7.1 as before.

I can provide any logs necessary to track the problem. The build machine is CentOS 5.5 with glibc-devel-2.5-58.el5_6.3.

------------------------------------------------------------------------
[2017-02-05 17:15:44] [email protected]

Fixed by https://github.com/php/php-src/commit/9ea0949f43959ff0cf519e7a10ef9de7a538cde3.

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=74039


--
Edit this bug report at https://bugs.php.net/bug.php?id=74039&edit=1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.