Skip to content

Commit

Permalink
Merge pull request #3 from runkit7/add-spl_object_id-alias
Browse files Browse the repository at this point in the history
Update CI environment, and implement spl_object_id alias for runkit_object_id
  • Loading branch information
TysonAndre authored Aug 16, 2017
2 parents c7b8260 + 637e850 commit 9b84082
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 24 deletions.
32 changes: 18 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,49 @@
language: php

dist: trusty

php:
- 7.2
- 7.1
- 7.0
- 5.6
- 5.5
- 5.4
- 5.3

# Run minimal tests to cover 32-bit, 64-bit, and clang
# Exclude everything else.
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.8 CFLAGS="-g -O3"
- php: 7.2
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:
directories:
- $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
Expand All @@ -56,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

Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -19,7 +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)
[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
------------
Expand Down
11 changes: 5 additions & 6 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
# 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}'
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
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
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.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
Expand Down
2 changes: 1 addition & 1 deletion ci/g++-32.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/sh
exec g++-4.6 -m32 "$@"
exec g++-4.8 -m32 "$@"
2 changes: 1 addition & 1 deletion ci/gcc-32.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/sh
exec gcc-4.6 -m32 "$@"
exec gcc-4.8 -m32 "$@"
11 changes: 11 additions & 0 deletions config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions config.w32
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
13 changes: 13 additions & 0 deletions runkit_object_id-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
20 changes: 19 additions & 1 deletion runkit_object_id.c
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
};

Expand Down Expand Up @@ -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
);
}
/* }}} */

Expand Down
49 changes: 49 additions & 0 deletions tests/spl_object_id.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
--TEST--
spl_object_id should fetch the object handle.
--SKIPIF--
<?php
if (PHP_VERSION_ID >= 70200) exit("skip redundant test in php 7.2");
if (!extension_loaded("runkit_object_id")) exit("skip");
?>
--INI--
error_reporting=E_ALL
--FILE--
<?php
var_dump(spl_object_id(array()));
var_dump(spl_object_id(null));
var_dump(spl_object_id(false));
var_dump(spl_object_id(true));
var_dump(spl_object_id(42));
var_dump(spl_object_id(1.5));
var_dump(spl_object_id('x'));
$x = new stdClass();
$y = new stdClass();
var_dump(spl_object_id($x));
var_dump(spl_object_id($y));
var_dump(spl_object_id($x));

?>
--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)

0 comments on commit 9b84082

Please sign in to comment.