Skip to content

Commit

Permalink
Merge pull request #374 from openswoole/master
Browse files Browse the repository at this point in the history
Merge
  • Loading branch information
doubaokun authored Dec 31, 2024
2 parents 53f9cfd + db650be commit eb5455d
Show file tree
Hide file tree
Showing 57 changed files with 191 additions and 1,921 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ jobs:
# files: ./coverage.info
# fail_ci_if_error: true

- name: Publish Core Test Results
if: always()
uses: EnricoMi/publish-unit-test-result-action@v1
with:
check_name: Core Test Results
files: core-tests/test-result.xml
# - name: Publish Core Test Results
# if: always()
# uses: EnricoMi/publish-unit-test-result-action@v1
# with:
# check_name: Core Test Results
# files: core-tests/test-result.xml
34 changes: 17 additions & 17 deletions .github/workflows/ext.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@ jobs:
--enable-openssl --enable-cares --enable-debug-log &&
make clean && make -j$(sysctl -n hw.ncpu)

build-centos:
runs-on: ubuntu-latest
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
container: 'centos:latest'
steps:
- uses: actions/checkout@v4
- name: fix-repo
run: sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-Linux-* &&
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=https://vault.centos.org|g' /etc/yum.repos.d/CentOS-Linux-*
- name: install-deps
run: yum update -y && yum install -y gcc gcc-c++ make c-ares-devel php-devel curl php-curl libcurl-devel openssl-devel postgresql-devel
- name: phpize
run: phpize
- name: build
run: ./configure --enable-sockets --enable-mysqlnd --enable-http2 --enable-hook-curl
--enable-openssl --enable-cares --with-postgres --enable-debug-log &&
make clean && make -j$(sysctl -n hw.ncpu)
# build-centos:
# runs-on: ubuntu-latest
# if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
# container: 'centos:latest'
# steps:
# - uses: actions/checkout@v4
# - name: fix-repo
# run: sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-Linux-* &&
# sed -i 's|#baseurl=http://mirror.centos.org|baseurl=https://vault.centos.org|g' /etc/yum.repos.d/CentOS-Linux-*
# - name: install-deps
# run: yum update -y && yum install -y gcc gcc-c++ make c-ares-devel php-devel curl php-curl libcurl-devel openssl-devel postgresql-devel
# - name: phpize
# run: phpize
# - name: build
# run: ./configure --enable-sockets --enable-mysqlnd --enable-http2 --enable-hook-curl
# --enable-openssl --enable-cares --with-postgres --enable-debug-log &&
# make clean && make -j$(sysctl -n hw.ncpu)

build-macos-latest:
runs-on: macos-latest
Expand Down
42 changes: 21 additions & 21 deletions .github/workflows/test-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,27 @@ jobs:
${{runner.workspace}}/ext-openswoole/ci/route.sh
env:
PHP_VERSION: "${{ matrix.php }}"
- name: Upload Unit Test Results
if: always()
uses: actions/upload-artifact@v4
with:
name: PHP ${{ matrix.php }}
path: tests/test-results.xml
# - name: Upload Unit Test Results
# if: always()
# uses: actions/upload-artifact@v4
# with:
# name: PHP ${{ matrix.php }}
# path: tests/test-results.xml

publish-test-results:
name: "Publish PHP Unit Tests Results"
needs: test-linux
runs-on: ubuntu-latest
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
# publish-test-results:
# name: "Publish PHP Unit Tests Results"
# needs: test-linux
# runs-on: ubuntu-latest
# if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name

steps:
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
# steps:
# - name: Download Artifacts
# uses: actions/download-artifact@v4
# with:
# path: artifacts

- name: Publish PHP Test Results
uses: EnricoMi/publish-unit-test-result-action@v1
with:
check_name: PHP Test Results
files: artifacts/**/*.xml
# - name: Publish PHP Test Results
# uses: EnricoMi/publish-unit-test-result-action@v1
# with:
# check_name: PHP Test Results
# files: artifacts/**/*.xml
4 changes: 4 additions & 0 deletions ci/route.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ __CURRENT__=`pwd`
__DIR__=$(cd "$(dirname "$0")";pwd)

export DOCKER_COMPOSE_VERSION="1.21.0"

export PHP_VERSION=${PHP_VERSION:-${1:-"8.2"}}
export CI_BRANCH=${CI_BRANCH:-${2:-"master"}}

[ -z "${CI_BRANCH}" ] && export CI_BRANCH="master"
[ -z "${CI_BUILD_DIR}" ] && export CI_BUILD_DIR=$(cd "$(dirname "$0")";cd ../;pwd)
if [ "${CI_BRANCH}" = "alpine" ]; then
Expand Down
3 changes: 2 additions & 1 deletion config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,8 @@ AC_COMPILE_IFELSE([
)
AC_MSG_RESULT([$CLANG])

AC_PROG_CC_C99
AC_PROG_CC
CFLAGS="$CFLAGS -std=c99"

AC_CANONICAL_HOST

Expand Down
17 changes: 1 addition & 16 deletions ext-src/php_swoole.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,26 +160,11 @@ static void php_swoole_init_globals(zend_openswoole_globals *openswoole_globals)

void php_swoole_register_shutdown_function(const char *function) {
php_shutdown_function_entry shutdown_function_entry;
#if PHP_VERSION_ID >= 80100
zval function_name;
ZVAL_STRING(&function_name, function);
zend_fcall_info_init(
&function_name, 0, &shutdown_function_entry.fci, &shutdown_function_entry.fci_cache, NULL, NULL);
register_user_shutdown_function(Z_STRVAL(function_name), Z_STRLEN(function_name), &shutdown_function_entry);
#else
zval *function_name;
#if PHP_VERSION_ID >= 80000
shutdown_function_entry.arg_count = 0;
shutdown_function_entry.arguments = NULL;
function_name = &shutdown_function_entry.function_name;
#else
shutdown_function_entry.arg_count = 1;
shutdown_function_entry.arguments = (zval *) safe_emalloc(sizeof(zval), 1, 0);
function_name = &shutdown_function_entry.arguments[0];
#endif
ZVAL_STRING(function_name, function);
register_user_shutdown_function(Z_STRVAL_P(function_name), Z_STRLEN_P(function_name), &shutdown_function_entry);
#endif
}

void php_swoole_set_global_option(HashTable *vht) {
Expand Down Expand Up @@ -1198,7 +1183,7 @@ PHP_MINIT_FUNCTION(openswoole) {
SwooleG.dns_cache_refresh_time = 60;

// enable pcre.jit and use swoole extension on MacOS will lead to coredump, disable it temporarily
#if defined(PHP_PCRE_VERSION) && defined(HAVE_PCRE_JIT_SUPPORT) && PHP_VERSION_ID >= 70300 && __MACH__ && \
#if defined(PHP_PCRE_VERSION) && defined(HAVE_PCRE_JIT_SUPPORT) && __MACH__ && \
!defined(SW_DEBUG)
PCRE_G(jit) = 0;
#endif
Expand Down
6 changes: 0 additions & 6 deletions ext-src/php_swoole_coroutine.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ struct PHPContext {
zend_vm_stack vm_stack;
size_t vm_stack_page_size;
zend_execute_data *execute_data;
#if PHP_VERSION_ID >= 80000
uint32_t jit_trace_num;
#endif
#ifdef ZEND_CHECK_STACK_LIMIT
void *stack_base;
void *stack_limit;
Expand All @@ -64,10 +62,6 @@ struct PHPContext {
zend_class_entry *exception_class;
zend_object *exception;
zend_output_globals *output_ptr;
#if PHP_VERSION_ID < 80100
/* for array_walk non-reentrancy */
zend::Function *array_walk_fci;
#endif
/* for error control `@` */
bool in_silence;
bool enable_scheduler;
Expand Down
17 changes: 0 additions & 17 deletions ext-src/php_swoole_cxx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,8 @@ SW_API zend_string **sw_zend_known_strings = nullptr;

//----------------------------------Swoole known string------------------------------------

#if PHP_VERSION_ID < 80000
typedef zval zend_source_string_t;
#else
typedef zend_string zend_source_string_t;
#endif

#if PHP_VERSION_ID < 80200
static zend_op_array *swoole_compile_string(zend_source_string_t *source_string, ZEND_STR_CONST char *filename);

// for compatibly with dis_eval
static zend_op_array *(*old_compile_string)(zend_source_string_t *source_string, ZEND_STR_CONST char *filename);

static zend_op_array *swoole_compile_string(zend_source_string_t *source_string, ZEND_STR_CONST char *filename) {
zend_op_array *opa = old_compile_string(source_string, filename);
opa->type = ZEND_USER_FUNCTION;
return opa;
}
#else
static zend_op_array *swoole_compile_string(zend_source_string_t *source_string,
ZEND_STR_CONST char *filename,
zend_compile_position position);
Expand All @@ -45,7 +29,6 @@ static zend_op_array *swoole_compile_string(zend_source_string_t *source_string,
opa->type = ZEND_USER_FUNCTION;
return opa;
}
#endif

namespace zend {
bool eval(const std::string &code, std::string const &filename) {
Expand Down
4 changes: 0 additions & 4 deletions ext-src/php_swoole_cxx.h
Original file line number Diff line number Diff line change
Expand Up @@ -443,11 +443,7 @@ static inline void assign_zend_string_by_val(zval *zdata, char *addr, size_t len
ZVAL_STR(zdata, zstr);
}

#if PHP_VERSION_ID < 80000
#define ZEND_STR_CONST
#else
#define ZEND_STR_CONST const
#endif

#ifndef ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX
#define ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, allow_null) \
Expand Down
75 changes: 3 additions & 72 deletions ext-src/php_swoole_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ extern PHPAPI int php_array_merge(zend_array *dest, zend_array *src);
#define SWOOLE_SOCKETS_SUPPORT
#endif

#if PHP_VERSION_ID < 70200
#error "require PHP version 7.2 or later"
#if PHP_VERSION_ID < 80200
#error "require PHP version 8.2 or later"
#endif

#if defined(ZTS) && defined(SW_USE_THREAD_CONTEXT)
Expand Down Expand Up @@ -377,22 +377,12 @@ zend_bool php_swoole_signal_isset_handler(int signo);
/*}}}*/

/* PHP 8 compatibility macro {{{*/
#if PHP_VERSION_ID < 80000
#define sw_zend7_object zval
#define SW_Z7_OBJ_P(object) Z_OBJ_P(object)
#define SW_Z8_OBJ_P(zobj) zobj
#else
#define sw_zend7_object zend_object
#define SW_Z7_OBJ_P(object) object
#define SW_Z8_OBJ_P(zobj) Z_OBJ_P(zobj)
#endif
/*}}}*/

#if PHP_VERSION_ID < 70400
typedef size_t php_stream_size_t;
#else
typedef ssize_t php_stream_size_t;
#endif

/* PHP 7 wrapper functions / macros */

Expand All @@ -406,18 +396,8 @@ typedef ssize_t php_stream_size_t;
(ptr) = &(val); \
} while (0)

#if PHP_VERSION_ID < 80000
#define SW_ZVAL_SOCKET(return_value, result) \
ZVAL_RES(return_value, zend_register_resource((void *) (result), php_sockets_le_socket()))
#else
#define SW_ZVAL_SOCKET(return_value, result) ZVAL_OBJ(return_value, &result->std)
#endif

#if PHP_VERSION_ID < 80000
#define SW_Z_SOCKET_P(zsocket) (php_socket *) zend_fetch_resource_ex(zsocket, nullptr, php_sockets_le_socket())
#else
#define SW_Z_SOCKET_P(zsocket) Z_SOCKET_P(zsocket)
#endif

#ifndef ZVAL_IS_BOOL
static sw_inline zend_bool ZVAL_IS_BOOL(zval *v) {
Expand Down Expand Up @@ -613,13 +593,7 @@ static sw_inline void add_assoc_ulong_safe(zval *arg, const char *key, zend_ulon
} \
} while (0)

#if PHP_VERSION_ID < 80100
#define SW_SET_CLASS_NOT_SERIALIZABLE(module) \
module##_ce->serialize = zend_class_serialize_deny; \
module##_ce->unserialize = zend_class_unserialize_deny;
#else
#define SW_SET_CLASS_NOT_SERIALIZABLE(module) module##_ce->ce_flags |= ZEND_ACC_NOT_SERIALIZABLE;
#endif

#define sw_zend_class_clone_deny NULL
#define SW_SET_CLASS_CLONEABLE(module, _clone_obj) module##_handlers.clone_obj = _clone_obj
Expand Down Expand Up @@ -690,25 +664,9 @@ static sw_inline int sw_zend_register_class_alias(const char *name, size_t name_

zend_string *_interned_name = zend_new_interned_string(_name);

#if PHP_VERSION_ID >= 70300
return zend_register_class_alias_ex(ZSTR_VAL(_interned_name), ZSTR_LEN(_interned_name), ce, 1);
#else
return zend_register_class_alias_ex(ZSTR_VAL(_interned_name), ZSTR_LEN(_interned_name), ce);
#endif
}

#if PHP_VERSION_ID < 70300
/* Allocates object type and zeros it, but not the properties.
* Properties MUST be initialized using object_properties_init(). */
static zend_always_inline void *zend_object_alloc(size_t obj_size, zend_class_entry *ce) {
void *obj = emalloc(obj_size + zend_object_properties_size(ce));
/* Subtraction of sizeof(zval) is necessary, because zend_object_properties_size() may be
* -sizeof(zval), if the object has no properties. */
memset(obj, 0, obj_size - sizeof(zval));
return obj;
}
#endif

static sw_inline zend_object *sw_zend_create_object(zend_class_entry *ce, zend_object_handlers *handlers) {
zend_object *object = (zend_object *) zend_object_alloc(sizeof(zend_object), ce);
zend_object_std_init(object, ce);
Expand All @@ -733,21 +691,6 @@ static sw_inline zend_object *sw_zend_create_object_deny(zend_class_entry *ce) {
return object;
}

#if PHP_VERSION_ID < 80000
static sw_inline void sw_zend_class_unset_property_deny(zval *zobject, zval *zmember, void **cache_slot) {
zend_class_entry *ce = Z_OBJCE_P(zobject);
while (ce->parent) {
ce = ce->parent;
}
SW_ASSERT(ce->type == ZEND_INTERNAL_CLASS);
if (EXPECTED(zend_hash_find(&ce->properties_info, Z_STR_P(zmember)))) {
zend_throw_error(
NULL, "Property %s of class %s cannot be unset", Z_STRVAL_P(zmember), SW_Z_OBJCE_NAME_VAL_P(zobject));
return;
}
std_object_handlers.unset_property(zobject, zmember, cache_slot);
}
#else
static sw_inline void sw_zend_class_unset_property_deny(zend_object *object, zend_string *member, void **cache_slot) {
zend_class_entry *ce = object->ce;
while (ce->parent) {
Expand All @@ -760,7 +703,6 @@ static sw_inline void sw_zend_class_unset_property_deny(zend_object *object, zen
}
std_object_handlers.unset_property(object, member, cache_slot);
}
#endif

static sw_inline zval *sw_zend_read_property(zend_class_entry *ce, zval *obj, const char *s, int len, int silent) {
zval rv, *property = zend_read_property(ce, SW_Z8_OBJ_P(obj), s, len, silent, &rv);
Expand Down Expand Up @@ -873,12 +815,8 @@ static sw_inline zend_bool sw_zend_is_callable_at_frame(zval *zcallable,
char **error) {
zend_string *name;
zend_bool ret;
#if PHP_VERSION_ID < 80000
ret = zend_is_callable_ex(zcallable, zobject ? Z_OBJ_P(zobject) : NULL, check_flags, &name, fci_cache, error);
#else
ret = zend_is_callable_at_frame(zcallable, zobject ? Z_OBJ_P(zobject) : NULL, frame, check_flags, fci_cache, error);
name = zend_get_callable_name_ex(zcallable, zobject ? Z_OBJ_P(zobject) : NULL);
#endif
if (callable_name) {
*callable_name = estrndup(ZSTR_VAL(name), ZSTR_LEN(name));
}
Expand Down Expand Up @@ -921,11 +859,7 @@ static sw_inline int sw_zend_call_function_ex(
fci.retval = retval ? retval : &_retval;
fci.param_count = param_count;
fci.params = params;
#if PHP_VERSION_ID >= 80000
fci.named_params = NULL;
#else
fci.no_separation = 0;
#endif

ret = zend_call_function(&fci, fci_cache);

Expand Down Expand Up @@ -1038,10 +972,7 @@ static sw_inline char *php_swoole_url_encode(const char *value, size_t value_len
}

static sw_inline char *php_swoole_http_build_query(zval *zdata, size_t *length, smart_str *formstr) {
#if PHP_VERSION_ID < 80000
if (php_url_encode_hash_ex(
HASH_OF(zdata), formstr, NULL, 0, NULL, 0, NULL, 0, NULL, NULL, (int) PHP_QUERY_RFC1738) == FAILURE) {
#elif PHP_VERSION_ID < 80300
#if PHP_VERSION_ID < 80300
if (HASH_OF(zdata)) {
php_url_encode_hash_ex(HASH_OF(zdata), formstr, NULL, 0, NULL, 0, NULL, 0, NULL, NULL, (int) PHP_QUERY_RFC1738);
} else {
Expand Down
Loading

0 comments on commit eb5455d

Please sign in to comment.