From 91718574488ee11ffa7471bb915a8873bffb3cbc Mon Sep 17 00:00:00 2001 From: Justin Boswell Date: Fri, 12 Mar 2021 11:47:55 -0800 Subject: [PATCH] Updated CRT library, test process, EventLoopGroup API updates (#16) * Updated to latest aws-crt-ffi, updated EventLoopGroup/options init * Removed test-ci target, just use test for everything now * Added event_loop_group API to CRT/stubs * Removed headers (all generated) from format-check * Added the ability to force extension vs FFI * make test will now trigger composer run test/phpunit, and force tests with both FFI and extension * Updated builder version, removed redundant php7 test run * Removed type annotations that anger php5, limited backends on php5 --- .github/workflows/ci.yml | 16 +-- Makefile.frag | 20 +-- builder.json | 2 +- composer.json | 14 +- composer.lock | 215 +++++++++++++---------------- crt/aws-crt-ffi | 2 +- ext/awscrt.stub.php | 10 +- ext/awscrt_arginfo.h | 24 +++- ext/crt.c | 35 ++++- format-check.sh | 2 +- src/AWS/CRT/CRT.php | 63 +++++++-- src/AWS/CRT/IO/EventLoopGroup.php | 7 +- src/AWS/CRT/Internal/Extension.php | 2 +- 13 files changed, 237 insertions(+), 175 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fe86680..aeb9e68 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ on: - '!main' env: - BUILDER_VERSION: v0.8.1 + BUILDER_VERSION: v0.8.9 BUILDER_SOURCE: releases BUILDER_HOST: https://d19elf31gohf1l.cloudfront.net PACKAGE_NAME: aws-crt-php @@ -15,27 +15,17 @@ env: RUN: ${{ github.run_id }}-${{ github.run_number }} jobs: - php7-linux-x64-ffi: + php7-linux-x64: runs-on: ubuntu-latest steps: - name: Build PHP 7.4 with ffi - run: | - echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u awslabs --password-stdin - export DOCKER_IMAGE=docker.pkg.github.com/awslabs/aws-crt-builder/aws-crt-php7-linux-x64:${{ env.BUILDER_VERSION }} - docker pull $DOCKER_IMAGE - docker run --env GITHUB_REF --env LC_ALL=C.UTF-8 --env TEST_FFI=1 $DOCKER_IMAGE --version=${{env.BUILDER_VERSION}} build -p ${{ env.PACKAGE_NAME }} --spec=downstream --skip-install - - php7-linux-x64-ext: - runs-on: ubuntu-latest - steps: - - name: Build PHP 7.4 extension run: | echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u awslabs --password-stdin export DOCKER_IMAGE=docker.pkg.github.com/awslabs/aws-crt-builder/aws-crt-php7-linux-x64:${{ env.BUILDER_VERSION }} docker pull $DOCKER_IMAGE docker run --env GITHUB_REF --env LC_ALL=C.UTF-8 $DOCKER_IMAGE --version=${{env.BUILDER_VERSION}} build -p ${{ env.PACKAGE_NAME }} --spec=downstream --skip-install - php5-linux-x64-ext: + php5-linux-x64: runs-on: ubuntu-latest steps: - name: Build PHP 5.6 extension diff --git a/Makefile.frag b/Makefile.frag index b1d8389..dae5778 100644 --- a/Makefile.frag +++ b/Makefile.frag @@ -58,19 +58,19 @@ ext/api.h : src/api.h # FFI target ffi: src/libaws-crt-ffi.so - TEST_FFI = 1 # copy the lib into the src folder -src/libaws-crt-ffi.so: $(BUILD_DIR)/aws-crt-ffi-shared/libaws-crt-ffi.so $(INSTALL_DIR)/src/api.h - cp -v $(BUILD_DIR)/aws-crt-ffi-shared/libaws-crt-ffi.so $(INSTALL_DIR)/src/libaws-crt-ffi.so +src/libaws-crt-ffi.so: $(BUILD_DIR)/aws-crt-ffi-shared/libaws-crt-ffi.so src/api.h + cp -v $(BUILD_DIR)/aws-crt-ffi-shared/libaws-crt-ffi.so src/libaws-crt-ffi.so -ifeq ($(TEST_FFI),1) -test-ci: test-ffi +# Test the FFI interface on PHP7+ +ifeq ($(AT_LEAST_PHP7), 1) +test: src/libaws-crt-ffi.so + composer update + AWS_CRT_PHP_EXTENSION=1 composer run test + AWS_CRT_PHP_FFI=1 composer run test else -test-ci: test -endif - -# Test the FFI interface -test-ffi: src/libaws-crt-ffi.so +test: ext/api.h ext/awscrt_arginfo.h ext/crt.lo composer update composer run test +endif diff --git a/builder.json b/builder.json index d2c9e83..d57286e 100644 --- a/builder.json +++ b/builder.json @@ -32,6 +32,6 @@ "NO_INTERACTION": "1" }, "test_steps": [ - ["make", "test-ci"] + ["make", "test"] ] } diff --git a/composer.json b/composer.json index 6a849c5..e887136 100644 --- a/composer.json +++ b/composer.json @@ -10,6 +10,9 @@ "email": "aws-sdk-common-runtime@amazon.com" } ], + "config": { + "platform": {"php": "5.6"} + }, "minimum-stability": "alpha", "require": { }, @@ -30,14 +33,7 @@ ] }, "scripts": { - "test": "phpunit src/tests" + "test": "@php -d extension=modules/awscrt.so vendor/bin/phpunit src/tests" }, - "license": "Apache-2.0", - "authors": [ - { - "name": "AWS Common Runtime Team", - "email": "aws-sdk-common-runtime@amazon.com" - } - ] + "license": "Apache-2.0" } - diff --git a/composer.lock b/composer.lock index accfcb2..b475aab 100644 --- a/composer.lock +++ b/composer.lock @@ -4,36 +4,39 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "701910d2701734e6469f8b2ce89efcd1", + "content-hash": "d1e4715f1331f5ef3a9a1966360c6cd6", "packages": [], "packages-dev": [ { "name": "doctrine/instantiator", - "version": "1.4.0", + "version": "1.0.5", "source": { "type": "git", "url": "https://github.com/doctrine/instantiator.git", - "reference": "d56bf6102915de5702778fe20f2de3b2fe570b5b" + "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/d56bf6102915de5702778fe20f2de3b2fe570b5b", - "reference": "d56bf6102915de5702778fe20f2de3b2fe570b5b", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/8e884e78f9f0eb1329e445619e04456e64d8051d", + "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d", "shasum": "" }, "require": { - "php": "^7.1 || ^8.0" + "php": ">=5.3,<8.0-DEV" }, "require-dev": { - "doctrine/coding-standard": "^8.0", + "athletic/athletic": "~0.1.8", "ext-pdo": "*", "ext-phar": "*", - "phpbench/phpbench": "^0.13 || 1.0.0-alpha2", - "phpstan/phpstan": "^0.12", - "phpstan/phpstan-phpunit": "^0.12", - "phpunit/phpunit": "^7.0 || ^8.0 || ^9.0" + "phpunit/phpunit": "~4.0", + "squizlabs/php_codesniffer": "~2.0" }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, "autoload": { "psr-4": { "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/" @@ -47,59 +50,42 @@ { "name": "Marco Pivetta", "email": "ocramius@gmail.com", - "homepage": "https://ocramius.github.io/" + "homepage": "http://ocramius.github.com/" } ], "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", - "homepage": "https://www.doctrine-project.org/projects/instantiator.html", + "homepage": "https://github.com/doctrine/instantiator", "keywords": [ "constructor", "instantiate" ], "support": { "issues": "https://github.com/doctrine/instantiator/issues", - "source": "https://github.com/doctrine/instantiator/tree/1.4.0" + "source": "https://github.com/doctrine/instantiator/tree/master" }, - "funding": [ - { - "url": "https://www.doctrine-project.org/sponsorship.html", - "type": "custom" - }, - { - "url": "https://www.patreon.com/phpdoctrine", - "type": "patreon" - }, - { - "url": "https://tidelift.com/funding/github/packagist/doctrine%2Finstantiator", - "type": "tidelift" - } - ], - "time": "2020-11-10T18:47:58+00:00" + "time": "2015-06-14T21:17:01+00:00" }, { "name": "myclabs/deep-copy", - "version": "1.10.2", + "version": "1.7.0", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "776f831124e9c62e1a2c601ecc52e776d8bb7220" + "reference": "3b8a3a99ba1f6a3952ac2747d989303cbd6b7a3e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/776f831124e9c62e1a2c601ecc52e776d8bb7220", - "reference": "776f831124e9c62e1a2c601ecc52e776d8bb7220", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3b8a3a99ba1f6a3952ac2747d989303cbd6b7a3e", + "reference": "3b8a3a99ba1f6a3952ac2747d989303cbd6b7a3e", "shasum": "" }, "require": { - "php": "^7.1 || ^8.0" - }, - "replace": { - "myclabs/deep-copy": "self.version" + "php": "^5.6 || ^7.0" }, "require-dev": { "doctrine/collections": "^1.0", "doctrine/common": "^2.6", - "phpunit/phpunit": "^7.1" + "phpunit/phpunit": "^4.1" }, "type": "library", "autoload": { @@ -124,42 +110,41 @@ ], "support": { "issues": "https://github.com/myclabs/DeepCopy/issues", - "source": "https://github.com/myclabs/DeepCopy/tree/1.10.2" + "source": "https://github.com/myclabs/DeepCopy/tree/1.x" }, - "funding": [ - { - "url": "https://tidelift.com/funding/github/packagist/myclabs/deep-copy", - "type": "tidelift" - } - ], - "time": "2020-11-13T09:40:50+00:00" + "time": "2017-10-19T19:58:43+00:00" }, { "name": "phpdocumentor/reflection-common", - "version": "2.2.0", + "version": "1.0.1", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionCommon.git", - "reference": "1d01c49d4ed62f25aa84a747ad35d5a16924662b" + "reference": "21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/1d01c49d4ed62f25aa84a747ad35d5a16924662b", - "reference": "1d01c49d4ed62f25aa84a747ad35d5a16924662b", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6", + "reference": "21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6", "shasum": "" }, "require": { - "php": "^7.2 || ^8.0" + "php": ">=5.5" + }, + "require-dev": { + "phpunit/phpunit": "^4.6" }, "type": "library", "extra": { "branch-alias": { - "dev-2.x": "2.x-dev" + "dev-master": "1.0.x-dev" } }, "autoload": { "psr-4": { - "phpDocumentor\\Reflection\\": "src/" + "phpDocumentor\\Reflection\\": [ + "src" + ] } }, "notification-url": "https://packagist.org/downloads/", @@ -183,43 +168,40 @@ ], "support": { "issues": "https://github.com/phpDocumentor/ReflectionCommon/issues", - "source": "https://github.com/phpDocumentor/ReflectionCommon/tree/2.x" + "source": "https://github.com/phpDocumentor/ReflectionCommon/tree/master" }, - "time": "2020-06-27T09:03:43+00:00" + "time": "2017-09-11T18:02:19+00:00" }, { "name": "phpdocumentor/reflection-docblock", - "version": "5.2.2", + "version": "3.3.2", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "069a785b2141f5bcf49f3e353548dc1cce6df556" + "reference": "bf329f6c1aadea3299f08ee804682b7c45b326a2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/069a785b2141f5bcf49f3e353548dc1cce6df556", - "reference": "069a785b2141f5bcf49f3e353548dc1cce6df556", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/bf329f6c1aadea3299f08ee804682b7c45b326a2", + "reference": "bf329f6c1aadea3299f08ee804682b7c45b326a2", "shasum": "" }, "require": { - "ext-filter": "*", - "php": "^7.2 || ^8.0", - "phpdocumentor/reflection-common": "^2.2", - "phpdocumentor/type-resolver": "^1.3", - "webmozart/assert": "^1.9.1" + "php": "^5.6 || ^7.0", + "phpdocumentor/reflection-common": "^1.0.0", + "phpdocumentor/type-resolver": "^0.4.0", + "webmozart/assert": "^1.0" }, "require-dev": { - "mockery/mockery": "~1.3.2" + "mockery/mockery": "^0.9.4", + "phpunit/phpunit": "^4.4" }, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "5.x-dev" - } - }, "autoload": { "psr-4": { - "phpDocumentor\\Reflection\\": "src" + "phpDocumentor\\Reflection\\": [ + "src/" + ] } }, "notification-url": "https://packagist.org/downloads/", @@ -230,49 +212,48 @@ { "name": "Mike van Riel", "email": "me@mikevanriel.com" - }, - { - "name": "Jaap van Otterdijk", - "email": "account@ijaap.nl" } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", "support": { "issues": "https://github.com/phpDocumentor/ReflectionDocBlock/issues", - "source": "https://github.com/phpDocumentor/ReflectionDocBlock/tree/master" + "source": "https://github.com/phpDocumentor/ReflectionDocBlock/tree/release/3.x" }, - "time": "2020-09-03T19:13:55+00:00" + "time": "2017-11-10T14:09:06+00:00" }, { "name": "phpdocumentor/type-resolver", - "version": "1.4.0", + "version": "0.4.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "6a467b8989322d92aa1c8bf2bebcc6e5c2ba55c0" + "reference": "9c977708995954784726e25d0cd1dddf4e65b0f7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/6a467b8989322d92aa1c8bf2bebcc6e5c2ba55c0", - "reference": "6a467b8989322d92aa1c8bf2bebcc6e5c2ba55c0", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/9c977708995954784726e25d0cd1dddf4e65b0f7", + "reference": "9c977708995954784726e25d0cd1dddf4e65b0f7", "shasum": "" }, "require": { - "php": "^7.2 || ^8.0", - "phpdocumentor/reflection-common": "^2.0" + "php": "^5.5 || ^7.0", + "phpdocumentor/reflection-common": "^1.0" }, "require-dev": { - "ext-tokenizer": "*" + "mockery/mockery": "^0.9.4", + "phpunit/phpunit": "^5.2||^4.8.24" }, "type": "library", "extra": { "branch-alias": { - "dev-1.x": "1.x-dev" + "dev-master": "1.0.x-dev" } }, "autoload": { "psr-4": { - "phpDocumentor\\Reflection\\": "src" + "phpDocumentor\\Reflection\\": [ + "src/" + ] } }, "notification-url": "https://packagist.org/downloads/", @@ -285,12 +266,11 @@ "email": "me@mikevanriel.com" } ], - "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", "support": { "issues": "https://github.com/phpDocumentor/TypeResolver/issues", - "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.4.0" + "source": "https://github.com/phpDocumentor/TypeResolver/tree/master" }, - "time": "2020-09-17T18:55:26+00:00" + "time": "2017-07-14T14:27:02+00:00" }, { "name": "phpspec/prophecy", @@ -579,29 +559,29 @@ }, { "name": "phpunit/php-token-stream", - "version": "2.0.2", + "version": "1.4.12", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "791198a2c6254db10131eecfe8c06670700904db" + "reference": "1ce90ba27c42e4e44e6d8458241466380b51fa16" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/791198a2c6254db10131eecfe8c06670700904db", - "reference": "791198a2c6254db10131eecfe8c06670700904db", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/1ce90ba27c42e4e44e6d8458241466380b51fa16", + "reference": "1ce90ba27c42e4e44e6d8458241466380b51fa16", "shasum": "" }, "require": { "ext-tokenizer": "*", - "php": "^7.0" + "php": ">=5.3.3" }, "require-dev": { - "phpunit/phpunit": "^6.2.4" + "phpunit/phpunit": "~4.2" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0-dev" + "dev-master": "1.4-dev" } }, "autoload": { @@ -626,10 +606,10 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-token-stream/issues", - "source": "https://github.com/sebastianbergmann/php-token-stream/tree/master" + "source": "https://github.com/sebastianbergmann/php-token-stream/tree/1.4" }, "abandoned": true, - "time": "2017-11-27T05:48:46+00:00" + "time": "2017-12-04T08:55:13+00:00" }, { "name": "phpunit/phpunit", @@ -1343,20 +1323,20 @@ }, { "name": "symfony/polyfill-ctype", - "version": "v1.22.1", + "version": "v1.19.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "c6c942b1ac76c82448322025e084cadc56048b4e" + "reference": "aed596913b70fae57be53d86faa2e9ef85a2297b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/c6c942b1ac76c82448322025e084cadc56048b4e", - "reference": "c6c942b1ac76c82448322025e084cadc56048b4e", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/aed596913b70fae57be53d86faa2e9ef85a2297b", + "reference": "aed596913b70fae57be53d86faa2e9ef85a2297b", "shasum": "" }, "require": { - "php": ">=7.1" + "php": ">=5.3.3" }, "suggest": { "ext-ctype": "For best performance" @@ -1364,7 +1344,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "1.22-dev" + "dev-main": "1.19-dev" }, "thanks": { "name": "symfony/polyfill", @@ -1402,7 +1382,7 @@ "portable" ], "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/v1.22.1" + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.19.0" }, "funding": [ { @@ -1418,31 +1398,31 @@ "type": "tidelift" } ], - "time": "2021-01-07T16:49:33+00:00" + "time": "2020-10-23T09:01:57+00:00" }, { "name": "symfony/yaml", - "version": "v4.4.19", + "version": "v3.4.47", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "17ed9f14c1aa05b1a5cf2e2c5ef2d0be28058ef9" + "reference": "88289caa3c166321883f67fe5130188ebbb47094" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/17ed9f14c1aa05b1a5cf2e2c5ef2d0be28058ef9", - "reference": "17ed9f14c1aa05b1a5cf2e2c5ef2d0be28058ef9", + "url": "https://api.github.com/repos/symfony/yaml/zipball/88289caa3c166321883f67fe5130188ebbb47094", + "reference": "88289caa3c166321883f67fe5130188ebbb47094", "shasum": "" }, "require": { - "php": ">=7.1.3", + "php": "^5.5.9|>=7.0.8", "symfony/polyfill-ctype": "~1.8" }, "conflict": { "symfony/console": "<3.4" }, "require-dev": { - "symfony/console": "^3.4|^4.0|^5.0" + "symfony/console": "~3.4|~4.0" }, "suggest": { "symfony/console": "For validating YAML files using the lint command" @@ -1470,10 +1450,10 @@ "homepage": "https://symfony.com/contributors" } ], - "description": "Loads and dumps YAML files", + "description": "Symfony Yaml Component", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/yaml/tree/v4.4.19" + "source": "https://github.com/symfony/yaml/tree/v3.4.47" }, "funding": [ { @@ -1489,7 +1469,7 @@ "type": "tidelift" } ], - "time": "2021-01-27T09:09:26+00:00" + "time": "2020-10-24T10:57:07+00:00" }, { "name": "webmozart/assert", @@ -1546,11 +1526,14 @@ } ], "aliases": [], - "minimum-stability": "stable", + "minimum-stability": "alpha", "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": [], "platform-dev": [], + "platform-overrides": { + "php": "5.6" + }, "plugin-api-version": "2.0.0" } diff --git a/crt/aws-crt-ffi b/crt/aws-crt-ffi index ea85a85..93a2f64 160000 --- a/crt/aws-crt-ffi +++ b/crt/aws-crt-ffi @@ -1 +1 @@ -Subproject commit ea85a85a82128a2c32378a5fc40249f27c46c8f5 +Subproject commit 93a2f64b7edf4ca39651657e4bee673d55da24a4 diff --git a/ext/awscrt.stub.php b/ext/awscrt.stub.php index d8dc24a..bab5cc1 100644 --- a/ext/awscrt.stub.php +++ b/ext/awscrt.stub.php @@ -10,6 +10,12 @@ function aws_crt_error_str(int $error_code): string {} function aws_crt_error_debug_str(int $error_code): string {} -function aws_crt_event_loop_group_new(int $max_threads): int {} +function aws_crt_event_loop_group_options_new(): object {} -function aws_crt_event_loop_group_release(int $event_loop_group): void {} +function aws_crt_event_loop_group_options_release(object $elg_options): void {} + +function aws_crt_event_loop_group_options_set_max_threads(object $elg_options, int $max_threads): void {} + +function aws_crt_event_loop_group_new(object $options): object {} + +function aws_crt_event_loop_group_release(object $event_loop_group): void {} diff --git a/ext/awscrt_arginfo.h b/ext/awscrt_arginfo.h index 53d0dc0..b4d6fa3 100644 --- a/ext/awscrt_arginfo.h +++ b/ext/awscrt_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 04ff04fec5e4293918658ac98394d98387fa977b */ + * Stub hash: a2ad6edf64d0416356ba2a9a4c8b184615054a7c */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_last_error, 0, 0, IS_LONG, 0) ZEND_END_ARG_INFO() @@ -12,12 +12,24 @@ ZEND_END_ARG_INFO() #define arginfo_aws_crt_error_debug_str arginfo_aws_crt_error_name -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_event_loop_group_new, 0, 1, IS_LONG, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_event_loop_group_options_new, 0, 0, IS_OBJECT, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_event_loop_group_options_release, 0, 1, IS_VOID, 0) + ZEND_ARG_TYPE_INFO(0, elg_options, IS_OBJECT, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_event_loop_group_options_set_max_threads, 0, 2, IS_VOID, 0) + ZEND_ARG_TYPE_INFO(0, elg_options, IS_OBJECT, 0) ZEND_ARG_TYPE_INFO(0, max_threads, IS_LONG, 0) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_event_loop_group_new, 0, 1, IS_OBJECT, 0) + ZEND_ARG_TYPE_INFO(0, options, IS_OBJECT, 0) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_event_loop_group_release, 0, 1, IS_VOID, 0) - ZEND_ARG_TYPE_INFO(0, event_loop_group, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, event_loop_group, IS_OBJECT, 0) ZEND_END_ARG_INFO() @@ -25,6 +37,9 @@ ZEND_FUNCTION(aws_crt_last_error); ZEND_FUNCTION(aws_crt_error_name); ZEND_FUNCTION(aws_crt_error_str); ZEND_FUNCTION(aws_crt_error_debug_str); +ZEND_FUNCTION(aws_crt_event_loop_group_options_new); +ZEND_FUNCTION(aws_crt_event_loop_group_options_release); +ZEND_FUNCTION(aws_crt_event_loop_group_options_set_max_threads); ZEND_FUNCTION(aws_crt_event_loop_group_new); ZEND_FUNCTION(aws_crt_event_loop_group_release); @@ -34,6 +49,9 @@ static const zend_function_entry ext_functions[] = { ZEND_FE(aws_crt_error_name, arginfo_aws_crt_error_name) ZEND_FE(aws_crt_error_str, arginfo_aws_crt_error_str) ZEND_FE(aws_crt_error_debug_str, arginfo_aws_crt_error_debug_str) + ZEND_FE(aws_crt_event_loop_group_options_new, arginfo_aws_crt_event_loop_group_options_new) + ZEND_FE(aws_crt_event_loop_group_options_release, arginfo_aws_crt_event_loop_group_options_release) + ZEND_FE(aws_crt_event_loop_group_options_set_max_threads, arginfo_aws_crt_event_loop_group_options_set_max_threads) ZEND_FE(aws_crt_event_loop_group_new, arginfo_aws_crt_event_loop_group_new) ZEND_FE(aws_crt_event_loop_group_release, arginfo_aws_crt_event_loop_group_release) ZEND_FE_END diff --git a/ext/crt.c b/ext/crt.c index cd945d8..dac54ff 100644 --- a/ext/crt.c +++ b/ext/crt.c @@ -81,14 +81,43 @@ PHP_FUNCTION(aws_crt_error_debug_str) { AWS_RETURN_STRING(aws_crt_error_debug_str(error_code)); } -PHP_FUNCTION(aws_crt_event_loop_group_new) { +PHP_FUNCTION(aws_crt_event_loop_group_options_new) { + aws_crt_event_loop_group_options *options = aws_crt_event_loop_group_options_new(); + RETURN_LONG((zend_ulong)options); +} + +PHP_FUNCTION(aws_crt_event_loop_group_options_release) { + zend_ulong php_options = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &php_options) == FAILURE) { + return; + } + + aws_crt_event_loop_group_options *options = (void *)php_options; + aws_crt_event_loop_group_options_release(options); +} + +PHP_FUNCTION(aws_crt_event_loop_group_options_set_max_threads) { + zend_ulong php_options = 0; zend_ulong num_threads = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &num_threads) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &php_options, &num_threads) == FAILURE) { RETURN_NULL(); } - struct aws_event_loop_group *elg = aws_crt_event_loop_group_new(num_threads); + aws_crt_event_loop_group_options *options = (void *)php_options; + aws_crt_event_loop_group_options_set_max_threads(options, num_threads); +} + +PHP_FUNCTION(aws_crt_event_loop_group_new) { + zend_ulong php_options = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &php_options) == FAILURE) { + RETURN_NULL(); + } + + aws_crt_event_loop_group_options *options = (void *)php_options; + struct aws_event_loop_group *elg = aws_crt_event_loop_group_new(options); RETURN_LONG((zend_ulong)elg); } diff --git a/format-check.sh b/format-check.sh index b0f86dd..eb2f524 100755 --- a/format-check.sh +++ b/format-check.sh @@ -10,7 +10,7 @@ if NOT type $CLANG_FORMAT 2> /dev/null ; then fi FAIL=0 -SOURCE_FILES=`find src ext -type f \( -name '*.h' -o -name '*.c' \)` +SOURCE_FILES=`find src ext -type f \( -name '*.c' \)` for i in $SOURCE_FILES do $CLANG_FORMAT -output-replacements-xml $i | grep -c " /dev/null diff --git a/src/AWS/CRT/CRT.php b/src/AWS/CRT/CRT.php index 510c406..fcddcd4 100644 --- a/src/AWS/CRT/CRT.php +++ b/src/AWS/CRT/CRT.php @@ -20,15 +20,30 @@ final class CRT { function __construct() { if (is_null(self::$impl)) { - try { - self::$impl = new Extension(); - } catch (RuntimeException $rex) { - try { - self::$impl = new FFI(); - } catch (RuntimeException $frex) { - throw new RuntimeException('Unable to initialize AWS CRT via extension or FFI', -1, $frex); + // Figure out what backends are/should be available + $backends = ['Extension']; + if (version_compare(PHP_VERSION, '7.0.0') >= 0) { + $backends = ['Extension', 'FFI']; + if (getenv('AWS_CRT_PHP_EXTENSION')) { + $backends = ['Extension']; + } else if (getenv('AWS_CRT_PHP_FFI')) { + $backends = ['FFI']; } } + + // Try to load each backend, give up if none succeed + $exceptions = []; + foreach ($backends as $backend) { + try { + $backend = 'AWS\\CRT\\Internal\\' . $backend; + self::$impl = new $backend(); + } catch (RuntimeException $rex) { + array_push($exceptions, $rex); + } + } + if (is_null(self::$impl)) { + throw new RuntimeException('Unable to initialize AWS CRT via ' . join(', ', $backends) . ": \n" . join("\n", $exceptions), -1); + } } ++self::$refcount; } @@ -42,7 +57,7 @@ final class CRT { /** * @return integer last error code reported within the CRT */ - public static function last_error(): int { + public static function last_error() { return self::$impl->aws_crt_last_error(); } @@ -50,7 +65,7 @@ final class CRT { * @param integer $error Error code from the CRT, usually delivered via callback or {@see last_error} * @return string Human-readable description of the provided error code */ - public static function error_str(int $error) : string { + public static function error_str($error) { return self::$impl->aws_crt_error_str((int) $error); } @@ -58,16 +73,38 @@ final class CRT { * @param integer $error Error code from the CRT, usually delivered via callback or {@see last_error} * @return string Name/enum identifier for the provided error code */ - public static function error_name(int $error) : string { + public static function error_name($error) { return self::$impl->aws_crt_error_name((int) $error); } /** - * @param integer $num_threads Maximum threads to use in the event loop group + * @return object Pointer to native event_loop_group_options + */ + function event_loop_group_options_new() { + return self::$impl->aws_crt_event_loop_group_options_new(); + } + + /** + * @param object $elg_options Pointer to native event_loop_group_options + */ + function event_loop_group_options_release($elg_options) { + self::$impl->aws_crt_event_loop_group_options_release($elg_options); + } + + /** + * @param object $elg_options Pointer to native event_loop_group_options + * @param integer $max_threads Maximum number of threads to allow the event loop group to use, default: 0/1 per CPU core + */ + function event_loop_group_options_set_max_threads($elg_options, $max_threads) { + self::$impl->aws_crt_event_loop_group_options_set_max_threads($elg_options, (int)$max_threads); + } + + /** + * @param object Pointer to event_loop_group_options, {@see event_loop_group_options_new} * @return object Pointer to the new event loop group */ - function event_loop_group_new(int $num_threads) { - return self::$impl->aws_crt_event_loop_group_new($num_threads); + function event_loop_group_new($options) { + return self::$impl->aws_crt_event_loop_group_new($options); } /** diff --git a/src/AWS/CRT/IO/EventLoopGroup.php b/src/AWS/CRT/IO/EventLoopGroup.php index cccf919..30c350f 100644 --- a/src/AWS/CRT/IO/EventLoopGroup.php +++ b/src/AWS/CRT/IO/EventLoopGroup.php @@ -15,7 +15,7 @@ final class EventLoopGroup extends NativeResource { static function defaults() { return array( - 'num_threads' => 0, + 'max_threads' => 0, ); } @@ -24,7 +24,10 @@ final class EventLoopGroup extends NativeResource { if (count($options) == 0) { $options = self::defaults(); } - $this->acquire(self::$crt->event_loop_group_new($options['num_threads'])); + $elg_options = self::$crt->event_loop_group_options_new(); + self::$crt->event_loop_group_options_set_max_threads($elg_options, $options['max_threads']); + $this->acquire(self::$crt->event_loop_group_new($elg_options)); + self::$crt->event_loop_group_options_release($elg_options); } function __destruct() { diff --git a/src/AWS/CRT/Internal/Extension.php b/src/AWS/CRT/Internal/Extension.php index 0defbc5..78a5f59 100644 --- a/src/AWS/CRT/Internal/Extension.php +++ b/src/AWS/CRT/Internal/Extension.php @@ -20,7 +20,7 @@ final class Extension { * same name with the supplied arguments. Argument type hinting and checking * occurs at the CRT wrapper. */ - function __call(string $name, $args) { + function __call($name, $args) { return call_user_func_array($name, $args); } }