From 7e2147be23ee8720f9e462a93af55917d2bd3985 Mon Sep 17 00:00:00 2001 From: Alex Dowad Date: Tue, 26 May 2020 19:56:52 +0200 Subject: [PATCH 1/2] Clean up some unused code (and fix some comments) in build scripts - Fix typo in build/php.m4 - Nothing uses HAVE_INTTYPES_H; so remove check for header file - Nothing defines ZEND_ACCONFIG_H_NO_C_PROTOS; so remove #ifndef - `format_money` was removed in 2019, so no longer needed - Nothing uses HAVE_NETDB_H; so remove check for header file - Nothing checks HAVE_TERMIOS_H; so remove check for header file (This was actually added when Wez Furlong was adding the original implementation of PTY support in `proc_open`, since replaced.) - Nothing checks HAVE_SYS_AUXV_H; so remove check for header file - PHP_BUILD_DATE variable is not used for anything, so remove it This variable was added to the Makefile, but from there, was not used for anything. The comments suggest it was intended to allow 'reproducible builds'. Presumably, this means that if a bug is found in a PHP binary somewhere, one could look at the Makefile which it was built from, see the date, and then could check the same code version out from source control. But... there can easily be multiple commits to the repo in the same day. Also, what makes us think that the Makefile which a binary was built from will be easily available? Besides, ext/standard/info.c already embeds the build date and time in each binary... but it does it using `__DATE__` and `__TIME__` (see `php_print_info`). - Nothing checks HAVE_FINITE; so don't check for function - Grammar fix to comment in build/php.m4 - Nothing sets $php_ldflags_add_usr_lib variable in configure, so remove conditional This was added in 2002, when Rasmus was having difficulty building PHP on some host and needed to have /usr/lib in the rpath. It was never documented and probably has never been used by anyone else. --- Zend/Zend.m4 | 2 +- build/php.m4 | 6 +++--- configure.ac | 28 ++-------------------------- ext/standard/string.c | 3 --- 4 files changed, 6 insertions(+), 33 deletions(-) diff --git a/Zend/Zend.m4 b/Zend/Zend.m4 index b0f913aac3e09..76f9dd8810c74 100644 --- a/Zend/Zend.m4 +++ b/Zend/Zend.m4 @@ -146,7 +146,7 @@ _LT_AC_TRY_DLOPEN_SELF([ ]) dnl Checks for library functions. -AC_CHECK_FUNCS(getpid kill finite sigsetjmp) +AC_CHECK_FUNCS(getpid kill sigsetjmp) ZEND_CHECK_FLOAT_PRECISION diff --git a/build/php.m4 b/build/php.m4 index 6aaf739815de9..d181bbeeba1d1 100644 --- a/build/php.m4 +++ b/build/php.m4 @@ -870,7 +870,7 @@ AC_DEFUN([PHP_SELECT_SAPI],[ +--------------------------------------------------------------------+ | *** ATTENTION *** | | | -| You've configured multiple SAPIs to be build. You can build only | +| You've configured multiple SAPIs to be built. You can build only | | one SAPI module plus CGI, CLI and FPM binaries at the same time. | +--------------------------------------------------------------------+ ]) @@ -2218,8 +2218,8 @@ AC_DEFUN([PHP_DETECT_SUNCC],[ dnl dnl PHP_CRYPT_R_STYLE dnl -dnl Detect the style of crypt_r() is any is available see -dnl APR_CHECK_CRYPT_R_STYLE() for original version. +dnl Detect the style of crypt_r() if any is available. +dnl See APR_CHECK_CRYPT_R_STYLE() for original version. dnl AC_DEFUN([PHP_CRYPT_R_STYLE], [ diff --git a/configure.ac b/configure.ac index e830acfb25582..99e04e6c1d0be 100644 --- a/configure.ac +++ b/configure.ac @@ -43,8 +43,6 @@ AH_TOP([ #define ZEND_DLIMPORT ]) AH_BOTTOM([ -#ifndef ZEND_ACCONFIG_H_NO_C_PROTOS - #include #ifdef HAVE_SYS_TYPES_H @@ -61,8 +59,6 @@ AH_BOTTOM([ #include -#endif /* ifndef ZEND_ACCONFIG_H_NO_C_PROTOS */ - #endif /* PHP_CONFIG_H */ ]) @@ -372,7 +368,6 @@ dnl ---------------------------------------------------------------------------- dnl QNX requires unix.h to allow functions in libunix to work properly. AC_CHECK_HEADERS([ \ -inttypes.h \ stdint.h \ dirent.h \ sys/param.h \ @@ -389,8 +384,6 @@ grp.h \ ieeefp.h \ langinfo.h \ malloc.h \ -monetary.h \ -netdb.h \ poll.h \ pty.h \ pwd.h \ @@ -398,7 +391,6 @@ resolv.h \ strings.h \ syslog.h \ sysexits.h \ -sys/auxv.h \ sys/ioctl.h \ sys/file.h \ sys/mman.h \ @@ -415,7 +407,6 @@ sys/sysexits.h \ sys/uio.h \ sys/wait.h \ sys/loadavg.h \ -termios.h \ unistd.h \ unix.h \ utime.h \ @@ -1272,28 +1263,14 @@ AC_SUBST(EXPANDED_LOCALSTATEDIR) AC_SUBST(EXPANDED_PHP_CONFIG_FILE_PATH) AC_SUBST(EXPANDED_PHP_CONFIG_FILE_SCAN_DIR) -if test -n "$php_ldflags_add_usr_lib"; then - PHP_RPATHS="$PHP_RPATHS /usr/lib" -fi - PHP_UTILIZE_RPATHS -if test -z "$php_ldflags_add_usr_lib"; then - PHP_REMOVE_USR_LIB(PHP_LDFLAGS) - PHP_REMOVE_USR_LIB(LDFLAGS) -fi +PHP_REMOVE_USR_LIB(PHP_LDFLAGS) +PHP_REMOVE_USR_LIB(LDFLAGS) EXTRA_LDFLAGS="$EXTRA_LDFLAGS $PHP_LDFLAGS" EXTRA_LDFLAGS_PROGRAM="$EXTRA_LDFLAGS_PROGRAM $PHP_LDFLAGS" -dnl SOURCE_DATE_EPOCH for reproducible builds -dnl https://reproducible-builds.org/specs/source-date-epoch/ -PHP_BUILD_DATE=`date --utc --date="@${SOURCE_DATE_EPOCH:-$(date +%s)}" +%Y-%m-%d 2>/dev/null` -if test $? -ne 0 ; then -PHP_BUILD_DATE=`date -u +%Y-%m-%d` -fi -AC_DEFINE_UNQUOTED(PHP_BUILD_DATE,"$PHP_BUILD_DATE",[PHP build date]) - UNAME=`uname -a | xargs` PHP_UNAME=${PHP_UNAME:-$UNAME} AC_DEFINE_UNQUOTED(PHP_UNAME,"$PHP_UNAME",[uname -a output]) @@ -1356,7 +1333,6 @@ PHP_SUBST(LIBTOOL) PHP_SUBST(LN_S) PHP_SUBST_OLD(NATIVE_RPATHS) PHP_SUBST_OLD(PEAR_INSTALLDIR) -PHP_SUBST(PHP_BUILD_DATE) PHP_SUBST_OLD(PHP_LDFLAGS) PHP_SUBST_OLD(PHP_LIBS) PHP_SUBST(OVERALL_TARGET) diff --git a/ext/standard/string.c b/ext/standard/string.c index 8a8c889f08209..1178b08730bcd 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -25,9 +25,6 @@ #ifdef HAVE_LANGINFO_H # include #endif -#ifdef HAVE_MONETARY_H -# include -#endif /* * This define is here because some versions of libintl redefine setlocale From 1c4463c77aa0291d065d5177428bbe080ca4755a Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Fri, 19 Jun 2020 16:50:59 +0200 Subject: [PATCH 2/2] Allow casting CurlHandle to int (int) $curlHandle will return spl_object_id($curlHandle). This makes curl handle objects backwards compatible with code using (int) $curlHandle to obtain a resource ID. Closes GH-5743. --- ext/curl/interface.c | 14 ++++++++++++++ ext/curl/tests/curl_int_cast.phpt | 20 ++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 ext/curl/tests/curl_int_cast.phpt diff --git a/ext/curl/interface.c b/ext/curl/interface.c index 85ac0f0b3078d..6957e9e73a649 100644 --- a/ext/curl/interface.c +++ b/ext/curl/interface.c @@ -241,6 +241,7 @@ static void curl_free_obj(zend_object *object); static HashTable *curl_get_gc(zend_object *object, zval **table, int *n); static zend_function *curl_get_constructor(zend_object *object); static zend_object *curl_clone_obj(zend_object *object); +static int curl_cast_object(zend_object *obj, zval *result, int type); php_curl *init_curl_handle_into_zval(zval *curl); static inline int build_mime_structure_from_hash(php_curl *ch, zval *zpostfields); @@ -1204,6 +1205,7 @@ PHP_MINIT_FUNCTION(curl) curl_object_handlers.get_gc = curl_get_gc; curl_object_handlers.get_constructor = curl_get_constructor; curl_object_handlers.clone_obj = curl_clone_obj; + curl_object_handlers.cast_object = curl_cast_object; curl_multi_register_class(class_CurlMultiHandle_methods); curl_share_register_class(class_CurlShareHandle_methods); @@ -1303,6 +1305,18 @@ static HashTable *curl_get_gc(zend_object *object, zval **table, int *n) return zend_std_get_properties(object); } +static int curl_cast_object(zend_object *obj, zval *result, int type) +{ + if (type == IS_LONG) { + /* For better backward compatibility, make (int) $curl_handle return the object ID, + * similar to how it previously returned the resource ID. */ + ZVAL_LONG(result, obj->handle); + return SUCCESS; + } + + return zend_std_cast_object_tostring(obj, result, type); +} + /* {{{ PHP_MSHUTDOWN_FUNCTION */ PHP_MSHUTDOWN_FUNCTION(curl) diff --git a/ext/curl/tests/curl_int_cast.phpt b/ext/curl/tests/curl_int_cast.phpt new file mode 100644 index 0000000000000..3f31b24210611 --- /dev/null +++ b/ext/curl/tests/curl_int_cast.phpt @@ -0,0 +1,20 @@ +--TEST-- +Casting CurlHandle to int returns object ID +--FILE-- + +--EXPECT-- +int(1) +int(2) +int(2)