mirror of
https://github.com/awslabs/aws-crt-php.git
synced 2026-08-18 01:57:13 +00:00
Added aws_error* functions to native extension (#12)
* Added aws_crt_error_str and test, removed awscrt_version test function * Added aws_crt_error_name * Added aws_crt_error_debug_str * Use PHP's own tools to generate arginfo * Only re-generate arginfo on php7+ * Added a definition for ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX for php5 * Ignore generated files for clang-format
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
# ignore generated files
|
||||
ext/api.h
|
||||
ext/*_arginfo.h
|
||||
src/api.h
|
||||
@@ -15,4 +15,4 @@ jobs:
|
||||
uses: DoozyX/[email protected]
|
||||
with:
|
||||
# List of extensions to check
|
||||
extensions: c,h
|
||||
extensions: c
|
||||
|
||||
+17
-6
@@ -3,6 +3,7 @@ BUILD_DIR=$(shell pwd)/build
|
||||
DEPS_DIR=$(BUILD_DIR)/deps
|
||||
INT_DIR=$(BUILD_DIR)/install
|
||||
INSTALL_DIR=$(shell pwd)
|
||||
AT_LEAST_PHP7=$(shell expr `php --version | head -1 | cut -f 2 -d' '` \>= 7)
|
||||
|
||||
CMAKE = cmake3
|
||||
ifeq (, $(shell which cmake3))
|
||||
@@ -26,7 +27,6 @@ $(INT_DIR)/lib/libcrypto.a: $(DEPS_DIR)/openssl
|
||||
mkdir -p $(INT_DIR)/lib
|
||||
ln -s $(INT_DIR)/lib64/libcrypto.a $(INT_DIR)/lib/libcrypto.a || true
|
||||
|
||||
|
||||
CMAKE_CONFIGURE = $(CMAKE) -DCMAKE_INSTALL_PREFIX=$(INT_DIR) -DCMAKE_PREFIX_PATH=$(INT_DIR) -DBUILD_TESTING=OFF
|
||||
CMAKE_BUILD = $(CMAKE) --build
|
||||
CMAKE_BUILD_TYPE ?= RelWithDebInfo
|
||||
@@ -52,15 +52,26 @@ $(BUILD_DIR)/aws-crt-ffi-static/libaws-crt-ffi.a: $(BUILD_DIR)/aws-crt-ffi-stati
|
||||
extension: ext/crt.lo
|
||||
|
||||
# Force the crt object target to depend on the CRT static library
|
||||
ext/crt.lo: $(BUILD_DIR)/aws-crt-ffi-static/libaws-crt-ffi.a ext/api.h
|
||||
ext/crt.lo: $(BUILD_DIR)/aws-crt-ffi-static/libaws-crt-ffi.a ext/api.h ext/awscrt_arginfo.h
|
||||
|
||||
ifeq ($(AT_LEAST_PHP7),1)
|
||||
GEN_STUB=build/gen_stub.php
|
||||
# generate awscrt_arginfo.h
|
||||
ext/awscrt_arginfo.h: ext/awscrt.stub.php $(GEN_STUB)
|
||||
php $(GEN_STUB) ext/awscrt.stub.php
|
||||
|
||||
# borrow the gen_stub script from PHP's build process
|
||||
$(GEN_STUB):
|
||||
curl -o $(GEN_STUB) -sSL https://raw.githubusercontent.com/php/php-src/bbb86ba7e2fe8ae365294d1834c6a392570a9dcd/build/gen_stub.php
|
||||
endif
|
||||
|
||||
# transform/install api.h from FFI lib
|
||||
$(INSTALL_DIR)/src/api.h: crt/aws-crt-ffi/src/api.h
|
||||
cat crt/aws-crt-ffi/src/api.h | grep -v AWS_EXTERN_C | sed -e 's/AWS_CRT_API //' | grep -ve '^#' > $(INSTALL_DIR)/src/api.h
|
||||
src/api.h: crt/aws-crt-ffi/src/api.h
|
||||
cat crt/aws-crt-ffi/src/api.h | grep -v AWS_EXTERN_C | sed -e 's/AWS_CRT_API //' | grep -ve '^#' > src/api.h
|
||||
|
||||
# install api.h to ext/ as well
|
||||
ext/api.h : $(INSTALL_DIR)/src/api.h
|
||||
cp -v $(INSTALL_DIR)/src/api.h ext/api.h
|
||||
ext/api.h : src/api.h
|
||||
cp -v src/api.h ext/api.h
|
||||
|
||||
# FFI target
|
||||
ffi: src/libaws-crt-ffi.so
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
/** @generate-class-entries */
|
||||
|
||||
function aws_crt_last_error(): int {}
|
||||
|
||||
function aws_crt_error_name(int $error_code): string {}
|
||||
|
||||
function aws_crt_error_str(int $error_code): string {}
|
||||
|
||||
function aws_crt_error_debug_str(int $error_code): string {}
|
||||
@@ -0,0 +1,28 @@
|
||||
/* This is a generated file, edit the .stub.php file instead.
|
||||
* Stub hash: a629a07df494f8ae6563949b2819c833e9d73f9a */
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_last_error, 0, 0, IS_LONG, 0)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_aws_crt_error_name, 0, 1, IS_STRING, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, error_code, IS_LONG, 0)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
#define arginfo_aws_crt_error_str arginfo_aws_crt_error_name
|
||||
|
||||
#define arginfo_aws_crt_error_debug_str arginfo_aws_crt_error_name
|
||||
|
||||
|
||||
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);
|
||||
|
||||
|
||||
static const zend_function_entry ext_functions[] = {
|
||||
ZEND_FE(aws_crt_last_error, arginfo_aws_crt_last_error)
|
||||
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_END
|
||||
};
|
||||
@@ -8,6 +8,8 @@
|
||||
|
||||
#include "api.h"
|
||||
|
||||
#include "awscrt_arginfo.h"
|
||||
|
||||
ZEND_DECLARE_MODULE_GLOBALS(awscrt);
|
||||
|
||||
PHP_INI_BEGIN()
|
||||
@@ -41,34 +43,48 @@ static PHP_GINIT_FUNCTION(awscrt) {
|
||||
awscrt_globals->log_level = 0;
|
||||
}
|
||||
|
||||
/* awscrt_version */
|
||||
ZEND_BEGIN_ARG_INFO(awscrt_version_arginfo, 0)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
PHP_FUNCTION(awscrt_version) {
|
||||
static const char *version = "1.0.0-dev";
|
||||
AWS_RETURN_STRING(version);
|
||||
}
|
||||
|
||||
/* aws_crt_last_error() */
|
||||
ZEND_BEGIN_ARG_INFO(aws_crt_last_error_arginfo, 0)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
PHP_FUNCTION(aws_crt_last_error) {
|
||||
RETURN_LONG(aws_crt_last_error());
|
||||
}
|
||||
|
||||
/* clang-format off */
|
||||
const zend_function_entry awscrt_functions[] = {
|
||||
PHP_FE(awscrt_version, awscrt_version_arginfo)
|
||||
PHP_FE(aws_crt_last_error, aws_crt_last_error_arginfo)
|
||||
PHP_FE_END
|
||||
};
|
||||
/* aws_crt_error_str(int error_code) */
|
||||
PHP_FUNCTION(aws_crt_error_str) {
|
||||
zend_ulong error_code = 0;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &error_code) == FAILURE) {
|
||||
RETURN_NULL();
|
||||
}
|
||||
|
||||
AWS_RETURN_STRING(aws_crt_error_str(error_code));
|
||||
}
|
||||
|
||||
/* aws_crt_error_name(int error_code) */
|
||||
PHP_FUNCTION(aws_crt_error_name) {
|
||||
zend_ulong error_code = 0;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &error_code) == FAILURE) {
|
||||
RETURN_NULL();
|
||||
}
|
||||
|
||||
AWS_RETURN_STRING(aws_crt_error_name(error_code));
|
||||
}
|
||||
|
||||
/* aws_crt_error_debug_str(int error_code) */
|
||||
PHP_FUNCTION(aws_crt_error_debug_str) {
|
||||
zend_ulong error_code = 0;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &error_code) == FAILURE) {
|
||||
RETURN_NULL();
|
||||
}
|
||||
|
||||
AWS_RETURN_STRING(aws_crt_error_debug_str(error_code));
|
||||
}
|
||||
|
||||
zend_module_entry awscrt_module_entry = {
|
||||
STANDARD_MODULE_HEADER,
|
||||
"awscrt",
|
||||
awscrt_functions, /* functions */
|
||||
ext_functions, /* functions */
|
||||
PHP_MINIT(awscrt),
|
||||
PHP_MSHUTDOWN(awscrt),
|
||||
NULL, /* RINIT */
|
||||
@@ -79,9 +95,8 @@ zend_module_entry awscrt_module_entry = {
|
||||
PHP_GINIT(awscrt),
|
||||
NULL, /* GSHUTDOWN */
|
||||
NULL, /* RPOSTSHUTDOWN */
|
||||
STANDARD_MODULE_PROPERTIES_EX};
|
||||
|
||||
/* clang-format on */
|
||||
STANDARD_MODULE_PROPERTIES_EX,
|
||||
};
|
||||
|
||||
#ifdef COMPILE_DL_AWSCRT
|
||||
ZEND_GET_MODULE(awscrt)
|
||||
|
||||
@@ -34,6 +34,13 @@ ZEND_EXTERN_MODULE_GLOBALS(awscrt)
|
||||
# define AWS_RETURN_STRING(s) RETURN_STRING(s)
|
||||
#else
|
||||
# define AWS_RETURN_STRING(s) RETURN_STRING(s, 1)
|
||||
/* definitions for ZEND API macros taken from PHP7 and backported to 5.6 */
|
||||
# define ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, allow_null) \
|
||||
static const zend_arg_info name[] = {{NULL, 0, NULL, required_num_args, return_reference, 0, 0},
|
||||
|
||||
/* PHP5 doesn't really handle type hints well, so elide them */
|
||||
# define ZEND_ARG_TYPE_INFO(pass_by_ref, name, type_hint, allow_null) \
|
||||
{#name, sizeof(#name) - 1, NULL, 0, 0, pass_by_ref, allow_null, 0},
|
||||
#endif
|
||||
|
||||
#endif /* PHP_AWS_CRT_H */
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ if NOT type $CLANG_FORMAT 2> /dev/null ; then
|
||||
fi
|
||||
|
||||
FAIL=0
|
||||
SOURCE_FILES=`find ext -type f \( -name '*.h' -o -name '*.c' \)`
|
||||
SOURCE_FILES=`find src ext -type f \( -name '*.h' -o -name '*.c' \)`
|
||||
for i in $SOURCE_FILES
|
||||
do
|
||||
$CLANG_FORMAT -output-replacements-xml $i | grep -c "<replacement " > /dev/null
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
--TEST--
|
||||
aws_crt_error_debug_str
|
||||
--SKIPIF--
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . '/skipif.inc');
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . '/common.inc');
|
||||
|
||||
echo aws_crt_error_debug_str(0);
|
||||
?>
|
||||
--EXPECT--
|
||||
aws-c-common: AWS_ERROR_SUCCESS, Success.
|
||||
@@ -0,0 +1,14 @@
|
||||
--TEST--
|
||||
aws_crt_error_name
|
||||
--SKIPIF--
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . '/skipif.inc');
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . '/common.inc');
|
||||
|
||||
echo aws_crt_error_name(0);
|
||||
?>
|
||||
--EXPECT--
|
||||
AWS_ERROR_SUCCESS
|
||||
@@ -1,5 +1,5 @@
|
||||
--TEST--
|
||||
Version: Simple function call
|
||||
aws_crt_error_str
|
||||
--SKIPIF--
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . '/skipif.inc');
|
||||
@@ -8,7 +8,7 @@ require_once(dirname(__FILE__) . '/skipif.inc');
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . '/common.inc');
|
||||
|
||||
echo awscrt_version();
|
||||
echo aws_crt_error_str(0);
|
||||
?>
|
||||
--EXPECT--
|
||||
1.0.0-dev
|
||||
Success.
|
||||
Reference in New Issue
Block a user