mirror of
https://github.com/awslabs/aws-crt-php.git
synced 2026-08-17 17:47:12 +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,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 */
|
||||
|
||||
Reference in New Issue
Block a user