From b55d14e022847dacddd5e30e773b268e9c81a5e1 Mon Sep 17 00:00:00 2001 From: Tyson Andre Date: Wed, 16 Aug 2017 15:31:08 -0700 Subject: [PATCH 1/7] Implement spl_object_id alias for runkit_object_id `spl_object_id` will be built into PHP 7.2.0. By default, provide a fast native alias for PHP <= 7.1 --- .travis.yml | 7 +++++++ README.md | 7 +++++++ config.m4 | 11 +++++++++++ config.w32 | 2 ++ runkit_object_id-api.php | 13 +++++++++++++ runkit_object_id.c | 20 +++++++++++++++++++- 6 files changed, 59 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e6effc6..79a257c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,9 @@ language: php +dist: trusty + php: + - 7.2 - 7.1 - 7.0 - 5.6 @@ -28,6 +31,10 @@ matrix: env: CC=gcc-4.6 CFLAGS="-g -O3" - php: 7.0 env: CC=gcc-4.6 CXX=g++-4.6 USE_32BIT=1 VALGRIND=1 PHP_CUSTOM=maintainer-zts PHP_CONFIGURE_ARGS='--disable-all --enable-maintainer-zts --enable-debug --enable-cgi --enable-session --enable-json' + - php: 7.2 + env: CC=gcc-4.6 CFLAGS="-g -O3" + - php: 7.2 + env: CC=gcc-4.6 CXX=g++-4.6 USE_32BIT=1 VALGRIND=1 PHP_CUSTOM=maintainer-zts PHP_CONFIGURE_ARGS='--disable-all --enable-maintainer-zts --enable-debug --enable-cgi --enable-session --enable-json' cache: diff --git a/README.md b/README.md index 8d863e4..0d94267 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,16 @@ runkit\_object\_id (by the runkit7 project) =========================================== +(Also provides a native implementation of `spl_object_id`) + For the safest function in [runkit(7)](https://github.com/runkit7/runkit7). This implements `runkit_object_id() : ?int`, which is similar to `spl_object_hash() : string`, but returns an integer instead of a string. The `runkit_object_id()` is faster if you need to take the ids of a large number of objects, and avoids the memory overhead of storing extra strings. +By default, this provides a native alias (for PHP <= 7.1) for [`spl_object_id`](https://github.com/php/php-src/pull/2611), which is a native part of PHP 7.2. +Add `--enable-runkit-spl_object-id=no` to the `configure` options to disable this. + Both `runkit_object_id($obj)` and `spl_object_hash($obj)` return identifiers that are unique **for the lifetime of the object**. After the object is garbage collected, that identifier can/will be used again. @@ -21,6 +26,8 @@ Motivation [An integer id has been a requested function for a while, but doesn't seem like it will be added to the php standard libraries](http://grokbase.com/t/php/php-internals/08chfwdavh/new-function-proposal-spl-object-id#2008121730trg75pyz8mn92dqwemjb14k8) +This will be built into php 7.2+ as `spl_object_id()`, but this module provides aliases for php <= 7.1 + Installation ------------ diff --git a/config.m4 b/config.m4 index 33ef2dd..69bfab2 100644 --- a/config.m4 +++ b/config.m4 @@ -4,7 +4,18 @@ dnl config.m4 for extension runkit_object_id PHP_ARG_ENABLE(runkit_object_id, whether to enable runkit_object_id support, [ --enable-runkit_object_id Enable runkit_object_id support], no, yes) +PHP_ARG_ENABLE(runkit_spl_object_id, whether to enable spl_object_id in PHP <= 7.1, +[ --enable-runkit-spl_object_id Enable spl_object_id support], inherit, no) + + if test "$PHP_RUNKIT" != "no"; then + if test "$ENABLE" != "no"; then + PHP_RUNKIT_SPL_OBJECT_ID=yes + fi + if test "$PHP_RUNKIT_SPL_OBJECT_ID" != "no"; then + AC_DEFINE(PHP_RUNKIT_SPL_OBJECT_ID, 1, [Whether to define spl_object_id in php <= 7.1]) + fi + PHP_NEW_EXTENSION(runkit_object_id, runkit_object_id.c \ , $ext_shared,, -Wdeclaration-after-statement -Werror -Wall -Wno-deprecated-declarations -Wno-pedantic) fi diff --git a/config.w32 b/config.w32 index cb32c71..978a12f 100644 --- a/config.w32 +++ b/config.w32 @@ -2,7 +2,9 @@ // vim:ft=javascript ARG_ENABLE("runkit_object_id", "Enable runkit_object_id support", "no"); +ARG_ENABLE("runkit-spl_object_id", "Disable runtime manipulation", "yes"); if (PHP_RUNKIT_OBJECT_ID != "no") { + AC_DEFINE("PHP_RUNKIT_SPL_OBJECT_ID", PHP_RUNKIT_OBJECT_ID == "yes", "Runkit spl_object_id substitute"); EXTENSION("runkit_object_id", "runkit_object_id.c"); } diff --git a/runkit_object_id-api.php b/runkit_object_id-api.php index 46136cf..0735115 100644 --- a/runkit_object_id-api.php +++ b/runkit_object_id-api.php @@ -22,3 +22,16 @@ function runkit_object_id($obj) { } return null; } + +/** + * (Will be built into php 7.2+) + * + * Gets a unique integer identifier (Will be reused when the object is garbage collected) for an object. + * This is similar to `spl_object_hash`, but returns an int instead of a string. + * + * @param object $obj - The object + * @return ?int - Returns null if given a non-object. + */ +function spl_object_id($obj) { + return runkit_object_id($obj); +} diff --git a/runkit_object_id.c b/runkit_object_id.c index e06f3c7..121f9b1 100644 --- a/runkit_object_id.c +++ b/runkit_object_id.c @@ -26,6 +26,12 @@ #include "php_runkit_object_id.h" #include "SAPI.h" +#ifdef PHP_RUNKIT_SPL_OBJECT_ID +#if PHP_VERSION_ID < 70200 +#define PHP_RUNKIT_PROVIDES_SPL_OBJECT_ID +#endif +#endif + ZEND_BEGIN_ARG_INFO_EX(arginfo_runkit_object_id, 0, 0, 1) ZEND_ARG_INFO(0, obj) ZEND_END_ARG_INFO() @@ -52,6 +58,10 @@ PHP_FUNCTION(runkit_object_id) zend_function_entry runkit_object_id_functions[] = { PHP_FE(runkit_object_id, arginfo_runkit_object_id) + // Add native spl_object_id substitute for PHP <= 7.1 by default +#ifdef PHP_RUNKIT_PROVIDES_SPL_OBJECT_ID + PHP_FALIAS(spl_object_id, runkit_object_id, arginfo_runkit_object_id) +#endif PHP_FE_END }; @@ -82,7 +92,15 @@ PHP_MINFO_FUNCTION(runkit_object_id) { php_info_print_table_start(); php_info_print_table_header(2, "runkit_object_id support", "enabled"); - + php_info_print_table_header(2, "spl_object_id alias support", +#ifdef PHP_RUNKIT_PROVIDES_SPL_OBJECT_ID + "enabled" +#elif PHP_VERSION_ID >= 70200 + "unnecessary in php 7.2+" +#else + "disabled" +#endif + ); } /* }}} */ From 6bb65c967ec551c8249fd16a07c17ccdfaa4a250 Mon Sep 17 00:00:00 2001 From: Tyson Andre Date: Wed, 16 Aug 2017 16:04:43 -0700 Subject: [PATCH 2/7] use DownloadFile utility instead of wget --- appveyor.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 39cd318..fa83801 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -5,13 +5,12 @@ version: '{branch}.{build}' install: - cmd: choco feature enable -n=allowGlobalConfirmation -- cmd: cinst wget - cmd: mkdir %APPVEYOR_BUILD_FOLDER%\bin build_script: - cmd: >- "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\vcvars32.bat" - wget http://windows.php.net/downloads/php-sdk/php-sdk-binary-tools-20110915.zip + appveyor DownloadFile http://windows.php.net/downloads/php-sdk/php-sdk-binary-tools-20110915.zip 7z x -y php-sdk-binary-tools-20110915.zip -oC:\projects\php-sdk @@ -23,7 +22,7 @@ build_script: xcopy %APPVEYOR_BUILD_FOLDER% C:\projects\php-src\ext\runkit /s /e /y - wget http://windows.php.net/downloads/php-sdk/deps-7.0-vc14-x86.7z + appveyor DownloadFile http://windows.php.net/downloads/php-sdk/deps-7.0-vc14-x86.7z 7z x -y deps-7.0-vc14-x86.7z -oC:\projects\php-src From a6162ac8312618f590328f1f700c1b2946f9eca0 Mon Sep 17 00:00:00 2001 From: Tyson Andre Date: Wed, 16 Aug 2017 16:07:00 -0700 Subject: [PATCH 3/7] Upgrade g++ and gcc from 4.6 to 4.8 as part of OS upgrade --- .travis.yml | 26 +++++++++++++------------- ci/g++-32.sh | 2 +- ci/gcc-32.sh | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/.travis.yml b/.travis.yml index 79a257c..0bd3f10 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,25 +16,25 @@ php: matrix: exclude: - php: 5.4 - env: CC=gcc-4.6 CFLAGS="-g" VALGRIND=1 + env: CC=gcc-4.8 CFLAGS="-g" VALGRIND=1 - php: 5.4 - env: CC=gcc-4.6 CXX=g++-4.6 USE_32BIT=1 VALGRIND=1 PHP_CUSTOM=maintainer-zts PHP_CONFIGURE_ARGS='--disable-all --enable-maintainer-zts --enable-debug --enable-cgi --enable-session --enable-json' + env: CC=gcc-4.8 CXX=g++-4.8 USE_32BIT=1 VALGRIND=1 PHP_CUSTOM=maintainer-zts PHP_CONFIGURE_ARGS='--disable-all --enable-maintainer-zts --enable-debug --enable-cgi --enable-session --enable-json' - php: 5.5 - env: CC=gcc-4.6 CFLAGS="-g -O3" + env: CC=gcc-4.8 CFLAGS="-g -O3" - php: 5.5 - env: CC=gcc-4.6 CXX=g++-4.6 USE_32BIT=1 VALGRIND=1 PHP_CUSTOM=maintainer-zts PHP_CONFIGURE_ARGS='--disable-all --enable-maintainer-zts --enable-debug --enable-cgi --enable-session --enable-json' + env: CC=gcc-4.8 CXX=g++-4.8 USE_32BIT=1 VALGRIND=1 PHP_CUSTOM=maintainer-zts PHP_CONFIGURE_ARGS='--disable-all --enable-maintainer-zts --enable-debug --enable-cgi --enable-session --enable-json' - php: 5.6 - env: CC=gcc-4.6 CFLAGS="-g -O3" + env: CC=gcc-4.8 CFLAGS="-g -O3" - php: 5.6 - env: CC=gcc-4.6 CXX=g++-4.6 USE_32BIT=1 VALGRIND=1 PHP_CUSTOM=maintainer-zts PHP_CONFIGURE_ARGS='--disable-all --enable-maintainer-zts --enable-debug --enable-cgi --enable-session --enable-json' + env: CC=gcc-4.8 CXX=g++-4.8 USE_32BIT=1 VALGRIND=1 PHP_CUSTOM=maintainer-zts PHP_CONFIGURE_ARGS='--disable-all --enable-maintainer-zts --enable-debug --enable-cgi --enable-session --enable-json' - php: 7.0 - env: CC=gcc-4.6 CFLAGS="-g -O3" + env: CC=gcc-4.8 CFLAGS="-g -O3" - php: 7.0 - env: CC=gcc-4.6 CXX=g++-4.6 USE_32BIT=1 VALGRIND=1 PHP_CUSTOM=maintainer-zts PHP_CONFIGURE_ARGS='--disable-all --enable-maintainer-zts --enable-debug --enable-cgi --enable-session --enable-json' + env: CC=gcc-4.8 CXX=g++-4.8 USE_32BIT=1 VALGRIND=1 PHP_CUSTOM=maintainer-zts PHP_CONFIGURE_ARGS='--disable-all --enable-maintainer-zts --enable-debug --enable-cgi --enable-session --enable-json' - php: 7.2 - env: CC=gcc-4.6 CFLAGS="-g -O3" + env: CC=gcc-4.8 CFLAGS="-g -O3" - php: 7.2 - env: CC=gcc-4.6 CXX=g++-4.6 USE_32BIT=1 VALGRIND=1 PHP_CUSTOM=maintainer-zts PHP_CONFIGURE_ARGS='--disable-all --enable-maintainer-zts --enable-debug --enable-cgi --enable-session --enable-json' + env: CC=gcc-4.8 CXX=g++-4.8 USE_32BIT=1 VALGRIND=1 PHP_CUSTOM=maintainer-zts PHP_CONFIGURE_ARGS='--disable-all --enable-maintainer-zts --enable-debug --enable-cgi --enable-session --enable-json' cache: @@ -42,9 +42,9 @@ cache: - $HOME/travis_cache env: - - CC=gcc-4.6 CFLAGS="-g -O3" - - CC=gcc-4.6 CFLAGS="-g" VALGRIND=1 - - CC=gcc-4.6 CXX=g++-4.6 USE_32BIT=1 VALGRIND=1 PHP_CUSTOM=maintainer-zts PHP_CONFIGURE_ARGS='--disable-all --enable-maintainer-zts --enable-debug --enable-cgi --enable-session --enable-json' + - CC=gcc-4.8 CFLAGS="-g -O3" + - CC=gcc-4.8 CFLAGS="-g" VALGRIND=1 + - CC=gcc-4.8 CXX=g++-4.8 USE_32BIT=1 VALGRIND=1 PHP_CUSTOM=maintainer-zts PHP_CONFIGURE_ARGS='--disable-all --enable-maintainer-zts --enable-debug --enable-cgi --enable-session --enable-json' install: - sudo apt-get update -qq diff --git a/ci/g++-32.sh b/ci/g++-32.sh index b9a6e18..0ddb20b 100755 --- a/ci/g++-32.sh +++ b/ci/g++-32.sh @@ -1,2 +1,2 @@ #!/bin/sh -exec g++-4.6 -m32 "$@" +exec g++-4.8 -m32 "$@" diff --git a/ci/gcc-32.sh b/ci/gcc-32.sh index 3ec94dc..453c660 100755 --- a/ci/gcc-32.sh +++ b/ci/gcc-32.sh @@ -1,2 +1,2 @@ #!/bin/sh -exec gcc-4.6 -m32 "$@" +exec gcc-4.8 -m32 "$@" From e5b8b49537ce7c8880b4c0f1637279a9bb9ed7ef Mon Sep 17 00:00:00 2001 From: Tyson Andre Date: Wed, 16 Aug 2017 16:10:59 -0700 Subject: [PATCH 4/7] Add test of spl_object_id alias --- tests/spl_object_id.phpt | 49 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tests/spl_object_id.phpt diff --git a/tests/spl_object_id.phpt b/tests/spl_object_id.phpt new file mode 100644 index 0000000..1dd135f --- /dev/null +++ b/tests/spl_object_id.phpt @@ -0,0 +1,49 @@ +--TEST-- +spl_object_id should fetch the object handle. +--SKIPIF-- += 70200) exit("skip redundant test in php 7.2"); +if (!extension_loaded("runkit_object_id")) exit("skip"); +?> +--INI-- +error_reporting=E_ALL +--FILE-- + +--EXPECTF-- +Warning: spl_object_id() expects parameter 1 to be object, array given in %s on line %d +NULL + +Warning: spl_object_id() expects parameter 1 to be object, null given in %s on line %d +NULL + +Warning: spl_object_id() expects parameter 1 to be object, boolean given in %s on line %d +NULL + +Warning: spl_object_id() expects parameter 1 to be object, boolean given in %s on line %d +NULL + +Warning: spl_object_id() expects parameter 1 to be object, integer given in %s on line %d +NULL + +Warning: spl_object_id() expects parameter 1 to be object, %s given in %s on line %d +NULL + +Warning: spl_object_id() expects parameter 1 to be object, string given in %s on line %d +NULL +int(1) +int(2) +int(1) From 7da6ef5e3b827676659b886ef78344266c1098e0 Mon Sep 17 00:00:00 2001 From: Tyson Andre Date: Wed, 16 Aug 2017 16:14:02 -0700 Subject: [PATCH 5/7] Remove 5.3 from travis, not supported in travis trusty builds. --- .travis.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0bd3f10..7084a71 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,6 @@ php: - 5.6 - 5.5 - 5.4 - - 5.3 # Run minimal tests to cover 32-bit, 64-bit, and clang # Exclude everything else. @@ -63,8 +62,6 @@ before_script: script: - phpize - ./configure --enable-runkit_object_id - # Fix not failing makes in php 5.2 and 5.3 - - perl -i -pe 's/\-\@if/\@if/' Makefile - make - REPORT_EXIT_STATUS=1 NO_INTERACTION=1 make test From 20591e29af7a358d4acb0019f3217e16d01fc331 Mon Sep 17 00:00:00 2001 From: Tyson Andre Date: Wed, 16 Aug 2017 16:14:21 -0700 Subject: [PATCH 6/7] Bump appveyor testing PHP version to 7.1 --- appveyor.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index fa83801..5c7699e 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,5 +1,5 @@ # Based on igbinary's appveyor config. -# This tests against the latest stable minor version of PHP 7 (Currently 7.0) +# This tests against the latest stable minor version of PHP 7 (Currently 7.1) # Author: Tyson Andre version: '{branch}.{build}' @@ -16,15 +16,15 @@ build_script: C:\projects\php-sdk\bin\phpsdk_setvars.bat - git clone --depth=1 --branch=PHP-7.0 https://github.com/php/php-src C:\projects\php-src + git clone --depth=1 --branch=PHP-7.1 https://github.com/php/php-src C:\projects\php-src mkdir C:\projects\php-src\ext\runkit xcopy %APPVEYOR_BUILD_FOLDER% C:\projects\php-src\ext\runkit /s /e /y - appveyor DownloadFile http://windows.php.net/downloads/php-sdk/deps-7.0-vc14-x86.7z + appveyor DownloadFile http://windows.php.net/downloads/php-sdk/deps-7.1-vc14-x86.7z - 7z x -y deps-7.0-vc14-x86.7z -oC:\projects\php-src + 7z x -y deps-7.1-vc14-x86.7z -oC:\projects\php-src cd C:\projects\php-src From 637e850a8b1b3bbd70034f3f4b71f5f9e526d5c3 Mon Sep 17 00:00:00 2001 From: Tyson Andre Date: Wed, 16 Aug 2017 16:18:23 -0700 Subject: [PATCH 7/7] update motivation section --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0d94267..8fc258b 100644 --- a/README.md +++ b/README.md @@ -24,9 +24,8 @@ See [runkit\_object\_id-api.php](./runkit_object_id-api.php) for function stubs, Motivation ---------- -[An integer id has been a requested function for a while, but doesn't seem like it will be added to the php standard libraries](http://grokbase.com/t/php/php-internals/08chfwdavh/new-function-proposal-spl-object-id#2008121730trg75pyz8mn92dqwemjb14k8) - -This will be built into php 7.2+ as `spl_object_id()`, but this module provides aliases for php <= 7.1 +[An integer object id has been a requested function for a while.](http://grokbase.com/t/php/php-internals/08chfwdavh/new-function-proposal-spl-object-id#2008121730trg75pyz8mn92dqwemjb14k8) +[`spl_object_id()` is getting added to PHP 7.2](https://github.com/php/php-src/pull/2611), but there's nothing for php <= 7.1 Installation ------------