From: Michael Wallner Date: Thu, 8 Feb 2018 15:48:04 +0000 (+0100) Subject: compat with master X-Git-Tag: RELEASE_3_2_0_RC1~43 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=fb9ddae6fe52e50c21559a8986e2cddcb09e3751;p=m6w6%2Fext-http compat with master --- diff --git a/src/php_http_client.c b/src/php_http_client.c index cedc239..b7cf2b9 100644 --- a/src/php_http_client.c +++ b/src/php_http_client.c @@ -711,7 +711,7 @@ static PHP_METHOD(HttpClient, enqueue) if (fci.size) { Z_TRY_ADDREF(fci.function_name); if (fci.object) { - ++GC_REFCOUNT(fci.object); + GC_ADDREF(fci.object); } } @@ -781,7 +781,7 @@ static PHP_METHOD(HttpClient, requeue) if (fci.size) { Z_TRY_ADDREF(fci.function_name); if (fci.object) { - ++GC_REFCOUNT(fci.object); + GC_ADDREF(fci.object); } } diff --git a/src/php_http_env_response.c b/src/php_http_env_response.c index 3a5a8e8..7406857 100644 --- a/src/php_http_env_response.c +++ b/src/php_http_env_response.c @@ -848,7 +848,7 @@ static ZEND_RESULT_CODE php_http_env_response_stream_init(php_http_env_response_ ctx = ecalloc(1, sizeof(*ctx)); ctx->stream = init_arg; - ++GC_REFCOUNT(ctx->stream->res); + GC_ADDREF(ctx->stream->res); ZEND_INIT_SYMTABLE(&ctx->header); php_http_version_init(&ctx->version, 1, 1); php_stream_set_option(ctx->stream, PHP_STREAM_OPTION_WRITE_BUFFER, PHP_STREAM_BUFFER_FULL, &buffer_size); diff --git a/src/php_http_message_body.c b/src/php_http_message_body.c index e630176..a6abfcd 100644 --- a/src/php_http_message_body.c +++ b/src/php_http_message_body.c @@ -40,13 +40,13 @@ php_http_message_body_t *php_http_message_body_init(php_http_message_body_t **bo php_http_message_body_addref(body); return body; } - + body = ecalloc(1, sizeof(php_http_message_body_t)); body->refcount = 1; if (stream) { body->res = stream->res; - ++GC_REFCOUNT(body->res); + GC_ADDREF(body->res); } else { body->res = php_stream_temp_create(TEMP_STREAM_DEFAULT, 0xffff)->res; } @@ -339,8 +339,8 @@ static ZEND_RESULT_CODE add_recursive_fields(php_http_message_body_t *body, cons zval *val; php_http_arrkey_t key; - if (!ZEND_HASH_GET_APPLY_COUNT(fields)) { - ZEND_HASH_INC_APPLY_COUNT(fields); + if (!HT_IS_RECURSIVE(fields)) { + HT_PROTECT_RECURSION(fields); ZEND_HASH_FOREACH_KEY_VAL_IND(fields, key.h, key.key, val) { char *str = format_key(&key, name); @@ -348,18 +348,18 @@ static ZEND_RESULT_CODE add_recursive_fields(php_http_message_body_t *body, cons if (Z_TYPE_P(val) != IS_ARRAY && Z_TYPE_P(val) != IS_OBJECT) { if (SUCCESS != add_recursive_field_value(body, str, val)) { efree(str); - ZEND_HASH_DEC_APPLY_COUNT(fields); + HT_UNPROTECT_RECURSION(fields); return FAILURE; } } else if (SUCCESS != add_recursive_fields(body, str, HASH_OF(val))) { efree(str); - ZEND_HASH_DEC_APPLY_COUNT(fields); + HT_UNPROTECT_RECURSION(fields); return FAILURE; } efree(str); } ZEND_HASH_FOREACH_END(); - ZEND_HASH_DEC_APPLY_COUNT(fields); + HT_UNPROTECT_RECURSION(fields); } return SUCCESS; @@ -377,8 +377,8 @@ static ZEND_RESULT_CODE add_recursive_files(php_http_message_body_t *body, const zval *val; php_http_arrkey_t key; - if (!ZEND_HASH_GET_APPLY_COUNT(files)) { - ZEND_HASH_INC_APPLY_COUNT(files); + if (!HT_IS_RECURSIVE(files)) { + HT_PROTECT_RECURSION(files); ZEND_HASH_FOREACH_KEY_VAL_IND(files, key.h, key.key, val) { if (Z_TYPE_P(val) == IS_ARRAY || Z_TYPE_P(val) == IS_OBJECT) { @@ -386,14 +386,14 @@ static ZEND_RESULT_CODE add_recursive_files(php_http_message_body_t *body, const if (SUCCESS != add_recursive_files(body, str, HASH_OF(val))) { efree(str); - ZEND_HASH_DEC_APPLY_COUNT(files); + HT_UNPROTECT_RECURSION(files); return FAILURE; } efree(str); } } ZEND_HASH_FOREACH_END(); - ZEND_HASH_DEC_APPLY_COUNT(files); + HT_UNPROTECT_RECURSION(files); } return SUCCESS; } else { diff --git a/src/php_http_misc.h b/src/php_http_misc.h index ae3359c..02e1b46 100644 --- a/src/php_http_misc.h +++ b/src/php_http_misc.h @@ -144,6 +144,32 @@ static inline const char *php_http_locate_bin_eol(const char *bin, size_t len, i # define HASH_OF(p) ((HashTable*)(Z_TYPE_P(p)==IS_ARRAY ? Z_ARRVAL_P(p) : ((Z_TYPE_P(p)==IS_OBJECT ? Z_OBJ_HT_P(p)->get_properties((p)) : NULL)))) #endif +#ifndef GC_SET_REFCOUNT +# define GC_SET_REFCOUNT(gc, rc) GC_REFCOUNT(gc) = rc +#endif +#ifndef GC_ADDREF +# define GC_ADDREF(gc) ++GC_REFCOUNT(gc) +#endif +#ifndef GC_DELREF +# define GC_DELREF(gc) --GC_REFCOUNT(gc) +#endif + +#ifdef ZEND_HASH_GET_APPLY_COUNT +# define HT_IS_RECURSIVE(ht) (ZEND_HASH_GET_APPLY_COUNT(ht) > 0) +#else +# define HT_IS_RECURSIVE(ht) GC_IS_RECURSIVE(ht) +#endif +#ifdef ZEND_HASH_INC_APPLY_COUNT +# define HT_PROTECT_RECURSION(ht) ZEND_HASH_INC_APPLY_COUNT(ht) +#else +# define HT_PROTECT_RECURSION(ht) GC_PROTECT_RECURSION(ht) +#endif +#ifdef ZEND_HASH_DEC_APPLY_COUNT +# define HT_UNPROTECT_RECURSION ZEND_HASH_DEC_APPLY_COUNT(ht) +#else +# define HT_UNPROTECT_RECURSION(ht) GC_UNPROTECT_RECURSION(ht) +#endif + static inline void *PHP_HTTP_OBJ(zend_object *zo, zval *zv) { if (!zo) { @@ -161,7 +187,7 @@ static inline zend_string *php_http_cs2zs(char *s, size_t l) str->len = l; str->h = 0; - GC_REFCOUNT(str) = 1; + GC_SET_REFCOUNT(str, 1); GC_TYPE_INFO(str) = IS_STRING; return str; diff --git a/src/php_http_object.c b/src/php_http_object.c index e42998e..2d09860 100644 --- a/src/php_http_object.c +++ b/src/php_http_object.c @@ -66,7 +66,9 @@ php_http_object_method_t *php_http_object_method_init(php_http_object_method_t * cb->fci.size = sizeof(cb->fci); ZVAL_STRINGL(&cb->fci.function_name, method_str, method_len); +#if PHP_VERSION_ID < 70300 cb->fcc.initialized = 1; +#endif cb->fcc.calling_scope = cb->fcc.called_scope = Z_OBJCE_P(zobject); cb->fcc.function_handler = Z_OBJ_HT_P(zobject)->get_method(&Z_OBJ_P(zobject), Z_STR(cb->fci.function_name), NULL); diff --git a/src/php_http_params.c b/src/php_http_params.c index 9b40cfe..5ba191f 100644 --- a/src/php_http_params.c +++ b/src/php_http_params.c @@ -200,8 +200,8 @@ static void prepare_dimension(php_http_buffer_t *buf, php_http_buffer_t *keybuf, zval *val; php_http_buffer_t prefix; - if (!ZEND_HASH_GET_APPLY_COUNT(ht)) { - ZEND_HASH_INC_APPLY_COUNT(ht); + if (!HT_IS_RECURSIVE(ht)) { + HT_PROTECT_RECURSION(ht); php_http_buffer_init(&prefix); php_http_buffer_append(&prefix, keybuf->data, keybuf->used); @@ -235,7 +235,7 @@ static void prepare_dimension(php_http_buffer_t *buf, php_http_buffer_t *keybuf, php_http_buffer_cut(&prefix, keybuf->used, prefix.used - keybuf->used); } ZEND_HASH_FOREACH_END(); - ZEND_HASH_DEC_APPLY_COUNT(ht); + HT_UNPROTECT_RECURSION(ht); php_http_buffer_dtor(&prefix); } diff --git a/src/php_http_url.c b/src/php_http_url.c index 0e3b2ee..65cc3d8 100644 --- a/src/php_http_url.c +++ b/src/php_http_url.c @@ -40,7 +40,7 @@ static inline char *localhostname(void) { char hostname[1024] = {0}; - + #if PHP_WIN32 if (SUCCESS == gethostname(hostname, lenof(hostname))) { return estrdup(hostname); @@ -188,9 +188,9 @@ php_http_url_t *php_http_url_mod(const php_http_url_t *old_url, const php_http_u if (!(flags & PHP_HTTP_URL_STRIP_PASS)) { url_copy(pass); } - + url_copy(host); - + if (!(flags & PHP_HTTP_URL_STRIP_PORT)) { url(buf)->port = url_isset(new_url, port) ? new_url->port : ((old_url) ? old_url->port : 0); } @@ -199,14 +199,14 @@ php_http_url_t *php_http_url_mod(const php_http_url_t *old_url, const php_http_u if ((flags & PHP_HTTP_URL_JOIN_PATH) && url_isset(old_url, path) && url_isset(new_url, path) && *new_url->path != '/') { size_t old_path_len = strlen(old_url->path), new_path_len = strlen(new_url->path); char *path = ecalloc(1, old_path_len + new_path_len + 1 + 1); - + strcat(path, old_url->path); if (path[old_path_len - 1] != '/') { php_dirname(path, old_path_len); strcat(path, "/"); } strcat(path, new_url->path); - + url(buf)->path = &buf.data[buf.used]; if (path[0] != '/') { url_append(&buf, php_http_buffer_append(&buf, "/", 1)); @@ -235,16 +235,16 @@ php_http_url_t *php_http_url_mod(const php_http_url_t *old_url, const php_http_u if (!(flags & PHP_HTTP_URL_STRIP_QUERY)) { if ((flags & PHP_HTTP_URL_JOIN_QUERY) && url_isset(new_url, query) && url_isset(old_url, query)) { zval qarr, qstr; - + array_init(&qarr); - + ZVAL_STRING(&qstr, old_url->query); php_http_querystring_update(&qarr, &qstr, NULL); zval_ptr_dtor(&qstr); ZVAL_STRING(&qstr, new_url->query); php_http_querystring_update(&qarr, &qstr, NULL); zval_ptr_dtor(&qstr); - + ZVAL_NULL(&qstr); php_http_querystring_update(&qarr, NULL, &qstr); @@ -261,7 +261,7 @@ php_http_url_t *php_http_url_mod(const php_http_url_t *old_url, const php_http_u if (!(flags & PHP_HTTP_URL_STRIP_FRAGMENT)) { url_copy(fragment); } - + /* done with copy & combine & strip */ if (flags & PHP_HTTP_URL_FROM_ENV) { @@ -274,13 +274,13 @@ php_http_url_t *php_http_url_mod(const php_http_url_t *old_url, const php_http_u && url(buf)->path && url(buf)->path[0] && url(buf)->path[1]) { char *ptr, *end = url(buf)->path + strlen(url(buf)->path) + 1; - + for (ptr = strchr(url(buf)->path, '/'); ptr; ptr = strchr(ptr, '/')) { switch (ptr[1]) { case '/': memmove(&ptr[1], &ptr[2], end - &ptr[2]); break; - + case '.': switch (ptr[2]) { case '\0': @@ -328,7 +328,7 @@ php_http_url_t *php_http_url_mod(const php_http_url_t *old_url, const php_http_u url(buf)->port = 0; } } - + return url(buf); } @@ -1810,7 +1810,9 @@ php_http_url_t *php_http_url_parse(const char *str, size_t len, unsigned flags) state->maxlen = maxlen; if (!parse_scheme(state)) { - php_error_docref(NULL, E_WARNING, "Failed to parse URL scheme: '%s'", state->ptr); + if (!(flags & PHP_HTTP_URL_SILENT_ERRORS)) { + php_error_docref(NULL, E_WARNING, "Failed to parse URL scheme: '%s'", state->ptr); + } efree(state); return NULL; } @@ -1821,13 +1823,17 @@ php_http_url_t *php_http_url_parse(const char *str, size_t len, unsigned flags) } if (!parse_query(state)) { - php_error_docref(NULL, E_WARNING, "Failed to parse URL query: '%s'", state->ptr); + if (!(flags & PHP_HTTP_URL_SILENT_ERRORS)) { + php_error_docref(NULL, E_WARNING, "Failed to parse URL query: '%s'", state->ptr); + } efree(state); return NULL; } if (!parse_fragment(state)) { - php_error_docref(NULL, E_WARNING, "Failed to parse URL fragment: '%s'", state->ptr); + if (!(flags & PHP_HTTP_URL_SILENT_ERRORS)) { + php_error_docref(NULL, E_WARNING, "Failed to parse URL fragment: '%s'", state->ptr); + } efree(state); return NULL; } @@ -1896,9 +1902,7 @@ PHP_METHOD(HttpUrl, __construct) flags |= PHP_HTTP_URL_FROM_ENV; } - if (flags & PHP_HTTP_URL_SILENT_ERRORS) { - zend_replace_error_handling(EH_SUPPRESS, NULL, &zeh); - } else if (flags & PHP_HTTP_URL_IGNORE_ERRORS) { + if (flags & (PHP_HTTP_URL_SILENT_ERRORS|PHP_HTTP_URL_IGNORE_ERRORS)) { zend_replace_error_handling(EH_NORMAL, NULL, &zeh); } else { zend_replace_error_handling(EH_THROW, php_http_get_exception_bad_url_class_entry(), &zeh); @@ -1950,9 +1954,7 @@ PHP_METHOD(HttpUrl, mod) php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "z!|l", &new_url, &flags), invalid_arg, return); - if (flags & PHP_HTTP_URL_SILENT_ERRORS) { - zend_replace_error_handling(EH_SUPPRESS, NULL, &zeh); - } else if (flags & PHP_HTTP_URL_IGNORE_ERRORS) { + if (flags & (PHP_HTTP_URL_SILENT_ERRORS|PHP_HTTP_URL_IGNORE_ERRORS)) { zend_replace_error_handling(EH_NORMAL, NULL, &zeh); } else { zend_replace_error_handling(EH_THROW, php_http_get_exception_bad_url_class_entry(), &zeh);