From: Michael Wallner Date: Mon, 21 Mar 2005 19:33:38 +0000 (+0000) Subject: * fixing concept of phpstr dtor/free X-Git-Tag: RELEASE_0_7_0~19 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=af674f03c32f0f56b7f8c67e61c7e86b3ea23be5;p=m6w6%2Fext-http * fixing concept of phpstr dtor/free # so, how to typedef a struct for the php4 build :-? --- diff --git a/http.c b/http.c index 930e179..e0f61fc 100644 --- a/http.c +++ b/http.c @@ -485,7 +485,7 @@ PHP_MSHUTDOWN_FUNCTION(http) { UNREGISTER_INI_ENTRIES(); #ifdef HTTP_HAVE_CURL - //phpstr_free(&HTTP_G(curlbuf)); + phpstr_dtor(&HTTP_G(curlbuf)); curl_global_cleanup(); #endif return SUCCESS; @@ -518,7 +518,7 @@ PHP_RSHUTDOWN_FUNCTION(http) } #ifdef HTTP_HAVE_CURL - //phpstr_free(&HTTP_G(curlbuf)); + phpstr_dtor(&HTTP_G(curlbuf)); #endif return SUCCESS; diff --git a/http_api.c b/http_api.c index 1a1dfea..ff7468d 100644 --- a/http_api.c +++ b/http_api.c @@ -1387,7 +1387,7 @@ PHP_HTTP_API STATUS _http_send_stream_ex(php_stream *file, zend_bool close_strea /* }}} */ /* {{{ STATUS http_chunked_decode(char *, size_t, char **, size_t *) */ -PHP_HTTP_API STATUS _http_chunked_decode(const char *encoded, size_t encoded_len, +PHP_HTTP_API STATUS _http_chunked_decode(const char *encoded, size_t encoded_len, char **decoded, size_t *decoded_len TSRMLS_DC) { const char *e_ptr; @@ -1605,12 +1605,12 @@ PHP_HTTP_API STATUS _http_urlencode_hash_ex(HashTable *hash, zend_bool override_ if (SUCCESS != http_urlencode_hash_implementation(hash, qstr, arg_sep)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't encode query data"); - phpstr_dtor(qstr); + phpstr_free(qstr); return FAILURE; } phpstr_data(qstr, encoded_data, encoded_len); - phpstr_dtor(qstr); + phpstr_free(qstr); return SUCCESS; } @@ -1674,7 +1674,7 @@ PHP_HTTP_API STATUS _http_urlencode_hash_implementation_ex( ulong idx; zval **zdata = NULL, *copyzval; - if (!ht) { + if (!ht || !formstr) { return FAILURE; } @@ -1766,7 +1766,7 @@ PHP_HTTP_API STATUS _http_urlencode_hash_implementation_ex( *p = '\0'; } ht->nApplyCount++; - http_urlencode_hash_implementation_ex(HASH_OF(*zdata), formstr, arg_sep, + http_urlencode_hash_implementation_ex(HASH_OF(*zdata), formstr, arg_sep, NULL, 0, newprefix, newprefix_len, "]", 1, (Z_TYPE_PP(zdata) == IS_OBJECT ? *zdata : NULL)); ht->nApplyCount--; efree(newprefix); diff --git a/http_curl_api.c b/http_curl_api.c index 371f39f..7f0638f 100644 --- a/http_curl_api.c +++ b/http_curl_api.c @@ -72,7 +72,7 @@ ZEND_DECLARE_MODULE_GLOBALS(http) } #define http_curl_cleanup(ch, clean_curl) \ - phpstr_free(&HTTP_G(curlbuf)); \ + phpstr_dtor(&HTTP_G(curlbuf)); \ zend_llist_clean(&HTTP_G(to_free)); \ if (clean_curl) { \ curl_easy_cleanup(ch); \ @@ -298,7 +298,7 @@ static void _http_curl_setopts(CURL *ch, const char *url, HashTable *options TSR phpstr_fix(qstr); curl_easy_setopt(ch, CURLOPT_COOKIE, http_curl_copystr(qstr->data)); } - phpstr_dtor(qstr); + phpstr_free(qstr); } /* cookiestore */ @@ -512,7 +512,7 @@ PHP_HTTP_API STATUS _http_post_array_ex(CURL *ch, const char *URL, HashTable *po status = http_post_data_ex(ch, URL, encoded, encoded_len, options, info, data, data_len); efree(encoded); - + return status; } /* }}} */ @@ -548,4 +548,3 @@ PHP_HTTP_API STATUS _http_post_curldata_ex(CURL *ch, const char *URL, * vim600: noet sw=4 ts=4 fdm=marker * vim<600: noet sw=4 ts=4 */ - diff --git a/http_functions.c b/http_functions.c index bf3fab6..05f6b7e 100644 --- a/http_functions.c +++ b/http_functions.c @@ -975,11 +975,12 @@ PHP_FUNCTION(http_build_query) } if (SUCCESS != http_urlencode_hash_implementation_ex(HASH_OF(formdata), formstr, arg_sep, prefix, prefix_len, NULL, 0, NULL, 0, (Z_TYPE_P(formdata) == IS_OBJECT ? formdata : NULL) TSRMLS_CC)) { - phpstr_dtor(formstr); + phpstr_free(formstr); RETURN_FALSE; } if (!formstr->used) { + phpstr_free(formstr); RETURN_NULL(); } diff --git a/http_methods.c b/http_methods.c index ded27ff..d22ae96 100644 --- a/http_methods.c +++ b/http_methods.c @@ -478,7 +478,7 @@ PHP_METHOD(HttpResponse, send) zval *dispo_file = GET_PROP(obj, dispoFile); if (Z_STRLEN_P(dispo_file)) { zval *dispo_inline = GET_PROP(obj, dispoInline); - http_send_content_disposition(Z_STRVAL_P(dispo_file), Z_STRLEN_P(dispo_file), Z_LVAL_P(dispo_inline)); + http_send_content_disposition(Z_STRVAL_P(dispo_file), Z_STRLEN_P(dispo_file), (zend_bool) Z_LVAL_P(dispo_inline)); } } diff --git a/phpstr/phpstr.c b/phpstr/phpstr.c index 9992300..af090fa 100644 --- a/phpstr/phpstr.c +++ b/phpstr/phpstr.c @@ -5,7 +5,7 @@ #include "phpstr.h" #ifndef PHPSTR_DEFAULT_SIZE -#define PHPSTR_DEFAULT_SIZE 4096 +#define PHPSTR_DEFAULT_SIZE 256 #endif PHPSTR_API phpstr *phpstr_init_ex(phpstr *buf, size_t chunk_size, zend_bool pre_alloc) @@ -14,17 +14,17 @@ PHPSTR_API phpstr *phpstr_init_ex(phpstr *buf, size_t chunk_size, zend_bool pre_ buf = ecalloc(1, sizeof(phpstr)); } - buf->used = 0; buf->size = chunk_size > 0 ? chunk_size : PHPSTR_DEFAULT_SIZE; - buf->free = pre_alloc ? buf->size : 0; buf->data = pre_alloc ? emalloc(buf->size) : NULL; + buf->free = pre_alloc ? buf->size : 0; + buf->used = 0; return buf; } PHPSTR_API phpstr *phpstr_from_string_ex(phpstr *buf, char *string, size_t length) { - buf = phpstr_init(buf); + buf = phpstr_init(buf); phpstr_append(buf, string, length); return buf; } @@ -230,7 +230,7 @@ PHPSTR_API int phpstr_cmp(phpstr *left, phpstr *right) } } -PHPSTR_API void phpstr_free(phpstr *buf) +PHPSTR_API void phpstr_dtor(phpstr *buf) { if (buf->data) { efree(buf->data); @@ -240,10 +240,10 @@ PHPSTR_API void phpstr_free(phpstr *buf) buf->free = 0; } -PHPSTR_API void phpstr_dtor(phpstr *buf) +PHPSTR_API void phpstr_free(phpstr *buf) { if (buf) { - phpstr_free(buf); + phpstr_dtor(buf); efree(buf); } } diff --git a/phpstr/phpstr.h b/phpstr/phpstr.h index dc103e1..50d9c28 100644 --- a/phpstr/phpstr.h +++ b/phpstr/phpstr.h @@ -10,28 +10,29 @@ # define PHPSTR_API #endif -#define FREE_PHPSTR_PTR(STR) phpstr_dtor(STR) -#define FREE_PHPSTR_VAL(STR) phpstr_free(STR) +#define FREE_PHPSTR_PTR(STR) efree(STR) +#define FREE_PHPSTR_VAL(STR) phpstr_dtor(STR) +#define FREE_PHPSTR_ALL(STR) phpstr_free(STR) #define FREE_PHPSTR(free, STR) \ switch (free) \ { \ - case PHPSTR_FREE_VAL: phpstr_free(STR); break; \ - case PHPSTR_FREE_PTR: phpstr_dtor(STR); break; \ + case PHPSTR_FREE_PTR: efree(STR); break; \ + case PHPSTR_FREE_VAL: phpstr_dtor(STR); break; \ + case PHPSTR_FREE_ALL: phpstr_free(STR); break; \ case PHPSTR_FREE_NOT: break; \ default: break; \ } -#define RETURN_PHPSTR_PTR(STR) RETURN_PHPSTR((STR), PHPSTR_FREE_PTR) -#define RETURN_PHPSTR_VAL(STR) RETURN_PHPSTR((STR), PHPSTR_FREE_VAL) -#define RETURN_PHPSTR(STR, free) \ - RETVAL_PHPSTR((STR), (free)); \ +#define RETURN_PHPSTR_PTR(STR) RETURN_PHPSTR((STR), PHPSTR_FREE_PTR, 0) +#define RETURN_PHPSTR_VAL(STR) RETURN_PHPSTR(&(STR), PHPSTR_FREE_NOT, 0) +/* RETURN_PHPSTR(buf, PHPSTR_FREE_PTR, 0) */ +#define RETURN_PHPSTR(STR, free, dup) \ + RETVAL_PHPSTR((STR), (free), (dup)); \ return; -#define RETVAL_PHPSTR_PTR(STR) RETVAL_PHPSTR((STR), PHPSTR_FREE_PTR) -#define RETVAL_PHPSTR_VAL(STR) RETVAL_PHPSTR((STR), PHPSTR_FREE_VAL) -#define RETVAL_PHPSTR(STR, free) \ +#define RETVAL_PHPSTR(STR, free, dup) \ phpstr_fix(STR); \ - RETVAL_STRINGL((STR)->data, (STR)->used, 1); \ + RETVAL_STRINGL((STR)->data, (STR)->used, (dup)); \ FREE_PHPSTR((free), (STR)); struct _phpstr { @@ -44,11 +45,13 @@ typedef struct _phpstr phpstr; enum _phpstr_free { PHPSTR_FREE_NOT = 0, - PHPSTR_FREE_VAL = 1, /* phpstr_free() */ - PHPSTR_FREE_PTR = 2 /* phpstr_dtor() */ + PHPSTR_FREE_PTR, /* efree() */ + PHPSTR_FREE_VAL, /* phpstr_dtor() */ + PHPSTR_FREE_ALL /* phpstr_free() */ }; typedef enum _phpstr_free phpstr_free_t; +#define PHPSTR_ALL_FREE(STR) PHPSTR_FREE_ALL,(STR) #define PHPSTR_PTR_FREE(STR) PHPSTR_FREE_PTR,(STR) #define PHPSTR_VAL_FREE(STR) PHPSTR_FREE_VAL,(STR) #define PHPSTR_NOT_FREE(STR) PHPSTR_FREE_NOT,(STR) @@ -107,7 +110,7 @@ PHPSTR_API phpstr *phpstr_dup(const phpstr *buf); phpstr *final = phpstr_merge(3, PHPSTR_NOT_FREE(&keep), - PHPSTR_PTR_FREE(middle_ptr), + PHPSTR_ALL_FREE(middle_ptr), PHPSTR_VAL_FREE(&local); */ PHPSTR_API phpstr *phpstr_merge(unsigned argc, ...); @@ -117,13 +120,12 @@ PHPSTR_API phpstr *phpstr_merge_va(phpstr *buf, unsigned argc, va_list argv); /* sets a trailing NUL byte */ PHPSTR_API void phpstr_fix(phpstr *buf); -/* free a phpstr objects data (resets used and free) */ -PHPSTR_API void phpstr_free(phpstr *buf); - -/* free a phpstr object (calls phpstr_free, too) */ -#define phpstr_del(b) phpstr_dtor(b) +/* free a phpstr objects contents */ PHPSTR_API void phpstr_dtor(phpstr *buf); +/* free a phpstr object completely */ +PHPSTR_API void phpstr_free(phpstr *buf); + #endif