From 30b274e28490f1371c90322f6930583928f516c0 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Wed, 9 Sep 2020 09:59:32 +0200 Subject: new package --- .gitignore | 9 ++ Makefile | 4 + PHPINFO | 8 + REFLECTION | 437 +++++++++++++++++++++++++++++++++++++++++++++++++++ php-pecl-trie.spec | 227 ++++++++++++++++++++++++++ php_trie-build.patch | 163 +++++++++++++++++++ 6 files changed, 848 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 PHPINFO create mode 100644 REFLECTION create mode 100644 php-pecl-trie.spec create mode 100644 php_trie-build.patch diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..01f0400 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +clog +package-*.xml +*.tgz +*.tar.bz2 +*.tar.gz +*.tar.xz +*.tar.xz.asc +*.src.rpm +*/*rpm diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..13af741 --- /dev/null +++ b/Makefile @@ -0,0 +1,4 @@ +SRCDIR := $(shell pwd) +NAME := $(shell basename $(SRCDIR)) +include ../../../common/Makefile + diff --git a/PHPINFO b/PHPINFO new file mode 100644 index 0000000..e36335e --- /dev/null +++ b/PHPINFO @@ -0,0 +1,8 @@ + +php_trie + +php_trie support => enabled +php_trie version => 0.1.0 +php_trie author => Lochemem Bruno Michael +Trie available => yes +Hat Trie available => yes diff --git a/REFLECTION b/REFLECTION new file mode 100644 index 0000000..3379c68 --- /dev/null +++ b/REFLECTION @@ -0,0 +1,437 @@ +Extension [ extension #91 php_trie version 0.1.0 ] { + + - Dependencies { + Dependency [ json (Required) ] + } + + - Functions { + Function [ function __construct ] { + } + Function [ static function fromArray ] { + + - Parameters [1] { + Parameter #0 [ array $array ] + } + } + Function [ function insert ] { + + - Parameters [2] { + Parameter #0 [ $key ] + Parameter #1 [ $entry ] + } + } + Function [ function keyExists ] { + + - Parameters [1] { + Parameter #0 [ $key ] + } + } + Function [ function search ] { + + - Parameters [1] { + Parameter #0 [ $key ] + } + } + Function [ function erase ] { + + - Parameters [1] { + Parameter #0 [ $key ] + } + } + Function [ function size ] { + } + Function [ function offsetSet ] { + + - Parameters [2] { + Parameter #0 [ $key ] + Parameter #1 [ $entry ] + } + } + Function [ function offsetGet ] { + + - Parameters [1] { + Parameter #0 [ $key ] + } + } + Function [ function offsetExists ] { + + - Parameters [1] { + Parameter #0 [ $key ] + } + } + Function [ function offsetUnset ] { + + - Parameters [1] { + Parameter #0 [ $key ] + } + } + Function [ function toArray ] { + } + Function [ function jsonSerialize ] { + } + Function [ function prefixSearch ] { + + - Parameters [1] { + Parameter #0 [ $prefix ] + } + } + Function [ function map ] { + + - Parameters [1] { + Parameter #0 [ callable $func ] + } + } + Function [ function filter ] { + + - Parameters [1] { + Parameter #0 [ callable $func ] + } + } + Function [ function merge ] { + + - Parameters [1] { + Parameter #0 [ object ...$tries ] + } + - Return [ array ] + } + } + + - Classes [3] { + Class [ class Trie implements ArrayAccess, JsonSerializable ] { + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [1] { + Method [ static public method fromArray ] { + + - Parameters [1] { + Parameter #0 [ array $array ] + } + } + } + + - Properties [0] { + } + + - Methods [16] { + Method [ public method __construct ] { + } + + Method [ public method insert ] { + + - Parameters [2] { + Parameter #0 [ $key ] + Parameter #1 [ $entry ] + } + } + + Method [ public method keyExists ] { + + - Parameters [1] { + Parameter #0 [ $key ] + } + } + + Method [ public method search ] { + + - Parameters [1] { + Parameter #0 [ $key ] + } + } + + Method [ public method erase ] { + + - Parameters [1] { + Parameter #0 [ $key ] + } + } + + Method [ public method size ] { + } + + Method [ public method offsetSet ] { + + - Parameters [2] { + Parameter #0 [ $key ] + Parameter #1 [ $entry ] + } + } + + Method [ public method offsetGet ] { + + - Parameters [1] { + Parameter #0 [ $key ] + } + } + + Method [ public method offsetExists ] { + + - Parameters [1] { + Parameter #0 [ $key ] + } + } + + Method [ public method offsetUnset ] { + + - Parameters [1] { + Parameter #0 [ $key ] + } + } + + Method [ public method toArray ] { + } + + Method [ public method jsonSerialize ] { + } + + Method [ public method prefixSearch ] { + + - Parameters [1] { + Parameter #0 [ $prefix ] + } + } + + Method [ public method map ] { + + - Parameters [1] { + Parameter #0 [ callable $func ] + } + } + + Method [ public method filter ] { + + - Parameters [1] { + Parameter #0 [ callable $func ] + } + } + + Method [ public method merge ] { + + - Parameters [1] { + Parameter #0 [ object ...$tries ] + } + - Return [ array ] + } + } + } + + Class [ class HatTrie implements ArrayAccess, JsonSerializable ] { + + - Constants [4] { + Constant [ public bool SHRINK ] { 1 } + Constant [ public bool NO_SHRINK ] { } + Constant [ public float DEFAULT_LOAD_FACTOR ] { 8 } + Constant [ public int DEFAULT_BURST_THRESHOLD ] { 16384 } + } + + - Static properties [0] { + } + + - Static methods [1] { + Method [ static public method fromArray ] { + + - Parameters [4] { + Parameter #0 [ array $array ] + Parameter #1 [ $burstThreshold ] + Parameter #2 [ $loadFactor ] + Parameter #3 [ $shrink ] + } + } + } + + - Properties [0] { + } + + - Methods [19] { + Method [ public method __construct ] { + + - Parameters [3] { + Parameter #0 [ $burstThreshold ] + Parameter #1 [ $loadFactor ] + Parameter #2 [ $shrink ] + } + } + + Method [ public method fold ] { + + - Parameters [2] { + Parameter #0 [ callable $func ] + Parameter #1 [ $accumulator ] + } + } + + Method [ public method size ] { + } + + Method [ public method filter ] { + + - Parameters [1] { + Parameter #0 [ callable $func ] + } + } + + Method [ public method insert ] { + + - Parameters [2] { + Parameter #0 [ $key ] + Parameter #1 [ $entry ] + } + } + + Method [ public method keyExists ] { + + - Parameters [1] { + Parameter #0 [ $key ] + } + } + + Method [ public method search ] { + + - Parameters [1] { + Parameter #0 [ $key ] + } + } + + Method [ public method erase ] { + + - Parameters [1] { + Parameter #0 [ $key ] + } + } + + Method [ public method prefixSearch ] { + + - Parameters [1] { + Parameter #0 [ $prefix ] + } + } + + Method [ public method prefixErase ] { + + - Parameters [1] { + Parameter #0 [ $prefix ] + } + } + + Method [ public method longestPrefix ] { + + - Parameters [1] { + Parameter #0 [ $prefix ] + } + } + + Method [ public method map ] { + + - Parameters [1] { + Parameter #0 [ callable $func ] + } + } + + Method [ public method offsetSet ] { + + - Parameters [2] { + Parameter #0 [ $key ] + Parameter #1 [ $entry ] + } + } + + Method [ public method offsetGet ] { + + - Parameters [1] { + Parameter #0 [ $key ] + } + } + + Method [ public method offsetExists ] { + + - Parameters [1] { + Parameter #0 [ $key ] + } + } + + Method [ public method offsetUnset ] { + + - Parameters [1] { + Parameter #0 [ $key ] + } + } + + Method [ public method toArray ] { + } + + Method [ public method jsonSerialize ] { + } + + Method [ public method merge ] { + + - Parameters [1] { + Parameter #0 [ object ...$tries ] + } + - Return [ array ] + } + } + } + + Class [ class TrieException extends RuntimeException implements Throwable ] { + + - Constants [0] { + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [4] { + Property [ protected $message ] + Property [ protected $code ] + Property [ protected $file ] + Property [ protected $line ] + } + + - Methods [10] { + Method [ public method __construct ] { + + - Parameters [3] { + Parameter #0 [ $message ] + Parameter #1 [ $code ] + Parameter #2 [ $previous ] + } + } + + Method [ public method __wakeup ] { + } + + Method [ final public method getMessage ] { + } + + Method [ final public method getCode ] { + } + + Method [ final public method getFile ] { + } + + Method [ final public method getLine ] { + } + + Method [ final public method getTrace ] { + } + + Method [ final public method getPrevious ] { + } + + Method [ final public method getTraceAsString ] { + } + + Method [ public method __toString ] { + } + } + } + } +} + diff --git a/php-pecl-trie.spec b/php-pecl-trie.spec new file mode 100644 index 0000000..38df8bb --- /dev/null +++ b/php-pecl-trie.spec @@ -0,0 +1,227 @@ +# remirepo spec file for php-pecl-trie +# +# Copyright (c) 2013-2020 Remi Collet +# License: CC-BY-SA +# http://creativecommons.org/licenses/by-sa/4.0/ +# +# Please, preserve the changelog entries +# +%if 0%{?scl:1} +%global sub_prefix %{scl_prefix} +%scl_package php-pecl-trie +%endif + +%global pecl_name php_trie +%global with_zts 0%{!?_without_zts:%{?__ztsphp:1}} +%global ini_name 40-%{pecl_name}.ini + +%global libver 0.6.0 + +Summary: PHP Trie extension +Name: %{?sub_prefix}php-pecl-trie +Version: 0.1.0 +Release: 0%{?dist}%{!?scl:%{!?nophptag:%(%{__php} -r 'echo ".".PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;')}} +License: PHP +URL: https://pecl.php.net/package/%{pecl_name} +Source0: https://pecl.php.net/get/%{pecl_name}-%{version}.tgz +# headers only library +Source1: https://github.com/Tessil/hat-trie/archive/v%{libver}.tar.gz + +# https://github.com/ace411/php-trie-ext/pull/1 +Patch0: %{pecl_name}-build.patch + +BuildRequires: %{?dtsprefix}gcc +BuildRequires: %{?scl_prefix}php-devel > 7.3 +BuildRequires: %{?scl_prefix}php-pear +BuildRequires: %{?scl_prefix}php-json + +BuildRequires: %{?scl_prefix}php-json%{?_isa} +Requires: %{?scl_prefix}php(zend-abi) = %{php_zend_api} +Requires: %{?scl_prefix}php(api) = %{php_core_api} +%{?_sclreq:Requires: %{?scl_prefix}runtime%{?_sclreq}%{?_isa}} + +Provides: %{?scl_prefix}php-%{pecl_name} = %{version} +Provides: %{?scl_prefix}php-%{pecl_name}%{?_isa} = %{version} +Provides: %{?scl_prefix}php-pecl(%{pecl_name}) = %{version} +Provides: %{?scl_prefix}php-pecl(%{pecl_name})%{?_isa} = %{version} +Provides: %{?scl_prefix}php-pecl-%{pecl_name} = %{version}-%{release} +Provides: %{?scl_prefix}php-pecl-%{pecl_name}%{?_isa} = %{version}-%{release} + +Provides: bundled(hat-trie) = %{libver} + +%if "%{?packager}" == "Remi Collet" && 0%{!?scl:1} && 0%{?rhel} +# Other third party repo stuff +Obsoletes: php73-pecl-%{pecl_name} <= %{version} +%if "%{php_version}" > "7.4" +Obsoletes: php74-pecl-%{pecl_name} <= %{version} +%endif +%endif + +%if 0%{?fedora} < 20 && 0%{?rhel} < 7 +# Filter shared private +%{?filter_provides_in: %filter_provides_in %{_libdir}/.*\.so$} +%{?filter_setup} +%endif + + +%description +Trie and HAT trie data structures for PHP. + +Package built for PHP %(%{__php} -r 'echo PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;')%{?scl: as Software Collection (%{scl} by %{?scl_vendor}%{!?scl_vendor:rh})}. + + +%prep +%setup -q -c -a 1 +mv %{pecl_name}-%{version} NTS + +# Don't install/register tests +sed -e 's/role="test"/role="src"/' \ + %{?_licensedir:-e '/LICENSE/s/role="doc"/role="src"/' } \ + -i package.xml + +cd NTS +%patch0 -p1 -b .pr1 + +# Sanity check, really often broken +extver=$(sed -n '/#define PHP_TRIE_EXT_EXTVER/{s/.* "//;s/".*$//;p}' php_trie_ext.h) +if test "x${extver}" != "x%{version}%{?prever:-%{prever}}"; then + : Error: Upstream extension version is ${extver}, expecting %{version}%{?prever:-%{prever}}. + exit 1 +fi +cd .. + +%if %{with_zts} +# Duplicate source tree for NTS / ZTS build +cp -pr NTS ZTS +%endif + +# Create configuration file +cat > %{ini_name} << 'EOF' +; Enable %{pecl_name} extension module +extension=%{pecl_name} +EOF + + +%build +%{?dtsenable} + +HATTRIE=$PWD/hat-trie-%{libver}/include/tsl + +cd NTS +%{_bindir}/phpize +%configure \ + --enable-php_trie \ + --with-hattrie=${HATTRIE} \ + --with-libdir=%{_lib} \ + --with-php-config=%{_bindir}/php-config + +make %{?_smp_mflags} + +%if %{with_zts} +cd ../ZTS +%{_bindir}/zts-phpize +%configure \ + --enable-php_trie \ + --with-hattrie=${HATTRIE} \ + --with-libdir=%{_lib} \ + --with-php-config=%{_bindir}/zts-php-config + +make %{?_smp_mflags} +%endif + + +%install +%{?dtsenable} + +make -C NTS install INSTALL_ROOT=%{buildroot} + +# install config file +install -D -m 644 %{ini_name} %{buildroot}%{php_inidir}/%{ini_name} + +# Install XML package description +install -D -m 644 package.xml %{buildroot}%{pecl_xmldir}/%{name}.xml + +%if %{with_zts} +make -C ZTS install INSTALL_ROOT=%{buildroot} + +install -D -m 644 %{ini_name} %{buildroot}%{php_ztsinidir}/%{ini_name} +%endif + +# Documentation +for i in $(grep 'role="doc"' package.xml | sed -e 's/^.*name="//;s/".*$//') +do install -Dpm 644 NTS/$i %{buildroot}%{pecl_docdir}/%{pecl_name}/$i +done + + +%if 0%{?fedora} < 24 && 0%{?rhel} < 8 +# when pear installed alone, after us +%triggerin -- %{?scl_prefix}php-pear +if [ -x %{__pecl} ] ; then + %{pecl_install} %{pecl_xmldir}/%{name}.xml >/dev/null || : +fi + +# posttrans as pear can be installed after us +%posttrans +if [ -x %{__pecl} ] ; then + %{pecl_install} %{pecl_xmldir}/%{name}.xml >/dev/null || : +fi + +%postun +if [ $1 -eq 0 -a -x %{__pecl} ] ; then + %{pecl_uninstall} %{pecl_name} >/dev/null || : +fi +%endif + + +%check +OPT="-n" +[ -f %{php_extdir}/json.so ] && OPT="$OPT -d extension=json" + +: Minimal load test for NTS extension +cd NTS +%{__php} $OPT \ + --define extension=modules/%{pecl_name}.so \ + --modules | grep %{pecl_name} + +: Upstream test suite for NTS extension +TEST_PHP_EXECUTABLE=%{__php} \ +TEST_PHP_ARGS="$OPT -d extension=$PWD/modules/%{pecl_name}.so" \ +NO_INTERACTION=1 \ +REPORT_EXIT_STATUS=1 \ +%{__php} -n run-tests.php + + +%if %{with_zts} +: Minimal load test for ZTS extension +cd ../ZTS +%{__ztsphp} $OPT \ + --define extension=modules/%{pecl_name}.so \ + --modules | grep %{pecl_name} + +: Upstream test suite for ZTS extension +TEST_PHP_EXECUTABLE=%{__ztsphp} \ +TEST_PHP_ARGS="$OPT -d extension=$PWD/modules/%{pecl_name}.so" \ +NO_INTERACTION=1 \ +REPORT_EXIT_STATUS=1 \ +%{__ztsphp} -n run-tests.php +%endif + + +%files +%{?_licensedir:%license NTS/LICENSE} +%doc %{pecl_docdir}/%{pecl_name} +%{pecl_xmldir}/%{name}.xml + +%config(noreplace) %{php_inidir}/%{ini_name} +%{php_extdir}/%{pecl_name}.so + +%if %{with_zts} +%config(noreplace) %{php_ztsinidir}/%{ini_name} +%{php_ztsextdir}/%{pecl_name}.so +%endif + + +%changelog +* Wed Sep 9 2020 Remi Collet - 0.1.0-1 +- initial package, version 0.1.0 (stable) +- open https://github.com/ace411/php-trie-ext/pull/1 fix build diff --git a/php_trie-build.patch b/php_trie-build.patch new file mode 100644 index 0000000..a834161 --- /dev/null +++ b/php_trie-build.patch @@ -0,0 +1,163 @@ +From c2e76aa7daf1829502736ed7d2659813bba52792 Mon Sep 17 00:00:00 2001 +From: Remi Collet +Date: Wed, 9 Sep 2020 09:13:44 +0200 +Subject: [PATCH 07/10] fix header config.m4 + +--- + config.m4 | 12 +++++------- + trie.h | 2 +- + 2 files changed, 6 insertions(+), 8 deletions(-) + +diff --git a/config.m4 b/config.m4 +index 2236ddf..52e086b 100644 +--- a/config.m4 ++++ b/config.m4 +@@ -15,30 +15,28 @@ if test "$PHP_PHP_TRIE" != "no"; then + AC_MSG_CHECKING([for Tessil/hat-trie library]) + if test -s $PHP_HATTRIE/$HATTRIE_HEADER; then + AC_MSG_RESULT(found $HATTRIE_HEADER) +- HATTRIE_LIB=$PHP_HATTRIE/$HATTRIE_HEADER ++ HATTRIE_LIB=$PHP_HATTRIE + else + for iter in $HEADER_INSTALL_DIRS; do + if test -s $iter/$HATTRIE_CPP_DIR/$HATTRIE_CPP_HEADER; then + AC_MSG_RESULT(found $HATTRIE_HEADER) +- HATTRIE_LIB=$iter/$HATTRIE_CPP_DIR/$HATTRIE_CPP_HEADER ++ HATTRIE_LIB=$iter/$HATTRIE_CPP_DIR + fi + done + fi + + if test -z "$HATTRIE_LIB"; then + AC_MSG_RESULT(hattrie lib is not properly installed. You will not be able to use the HAT trie) +- dnl AC_MSG_ERROR(Please install the hattrie library) ++ AC_MSG_ERROR(Please install the hattrie library) + fi + + dnl add support for C++ +- CXXFLAGS="-std=c++11" + PHP_REQUIRE_CXX() ++ PHP_ADD_INCLUDE($HATTRIE_LIB) + +- PHP_SUBST(PHP_TRIE_SHARED_LIBADD) + + dnl add C++11 standard library +- PHP_ADD_LIBRARY(stdc++, 1, PHP_TRIE_SHARED_LIBADD) + AC_DEFINE(HAVE_PHP_TRIE, 1, [ Have php_trie support ]) + +- PHP_NEW_EXTENSION(php_trie, php_trie.cpp, $ext_shared) ++ PHP_NEW_EXTENSION(php_trie, php_trie.cpp, $ext_shared,, -std=c++11, cxx) + fi +diff --git a/trie.h b/trie.h +index e653e80..b54918a 100644 +--- a/trie.h ++++ b/trie.h +@@ -15,7 +15,7 @@ + #include + #include + #include +-#include ++#include + + namespace trie + { + +From 8fff61e1dfd4fa2c22cc160711402bd68cdf525f Mon Sep 17 00:00:00 2001 +From: Remi Collet +Date: Wed, 9 Sep 2020 09:14:42 +0200 +Subject: [PATCH 08/10] fix test, seems order was wrong + +--- + tests/trie/merge.phpt | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/tests/trie/merge.phpt b/tests/trie/merge.phpt +index e59f3b3..5c7bb9e 100644 +--- a/tests/trie/merge.phpt ++++ b/tests/trie/merge.phpt +@@ -21,8 +21,8 @@ array(4) { + string(3) "foo" + ["baz"]=> + int(12) +- ["baff"]=> +- bool(false) + ["bar"]=> + string(3) "bar" +-} +\ No newline at end of file ++ ["baff"]=> ++ bool(false) ++} + +From 2b8feba9542c72339bf177169a776289212e2e5e Mon Sep 17 00:00:00 2001 +From: Remi Collet +Date: Wed, 9 Sep 2020 09:21:49 +0200 +Subject: [PATCH 09/10] add module dependency on json + +--- + php_trie.cpp | 9 ++++++++- + 1 file changed, 8 insertions(+), 1 deletion(-) + +diff --git a/php_trie.cpp b/php_trie.cpp +index 07d6015..1c766d7 100644 +--- a/php_trie.cpp ++++ b/php_trie.cpp +@@ -488,10 +488,17 @@ PHP_MINIT_FUNCTION(php_trie) + } + /* }}} */ + ++static zend_module_dep php_trie_deps[] = { ++ ZEND_MOD_REQUIRED("json") ++ ZEND_MOD_END ++}; ++ + /* {{{ php_trie_module_entry + */ + zend_module_entry php_trie_module_entry = { +- STANDARD_MODULE_HEADER, ++ STANDARD_MODULE_HEADER_EX, ++ NULL, ++ php_trie_deps, + "php_trie", /* Extension name */ + trie_methods, /* zend_function_entry */ + PHP_MINIT(php_trie), /* PHP_MINIT - Module initialization */ + +From cf7c464594e7c7628fdeb30159f7a458c61699d3 Mon Sep 17 00:00:00 2001 +From: Remi Collet +Date: Wed, 9 Sep 2020 09:25:12 +0200 +Subject: [PATCH 10/10] sort test result to avoid failure + +--- + tests/trie/merge.phpt | 16 +++++++++------- + 1 file changed, 9 insertions(+), 7 deletions(-) + +diff --git a/tests/trie/merge.phpt b/tests/trie/merge.phpt +index 5c7bb9e..4cdb86b 100644 +--- a/tests/trie/merge.phpt ++++ b/tests/trie/merge.phpt +@@ -13,16 +13,18 @@ $snd['baz'] = 12; + $thd = new Trie; + $thd['baff'] = false; + +-var_dump($fst->merge($snd, $thd)->toArray()); ++$res = $fst->merge($snd, $thd)->toArray(); ++ksort($res); ++var_dump($res); + ?> + --EXPECT-- + array(4) { +- ["foo"]=> +- string(3) "foo" +- ["baz"]=> +- int(12) +- ["bar"]=> +- string(3) "bar" + ["baff"]=> + bool(false) ++ ["bar"]=> ++ string(3) "bar" ++ ["baz"]=> ++ int(12) ++ ["foo"]=> ++ string(3) "foo" + } -- cgit