cvs: pecl /http http.c http_api.c http_curl_api.c http_functions.c http_methods.c /http/phpstr phpstr.c phpstr.h
| From: | Michael Wallner | Date: | Mon, 21 Mar 2005 19:33:38 +0000 |
| Subject: | cvs: pecl /http http.c http_api.c http_curl_api.c http_functions.c http_methods.c /http/phpstr phpstr.c phpstr.h | ||
| Groups: | php.pecl.cvs | ||
| Request: | Send a blank email to pecl-cvs+get-2875@lists.php.net to get a copy of this message | ||
mike Mon Mar 21 14:33:38 2005 EDT
Modified files:
/pecl/http http.c http_api.c http_curl_api.c http_functions.c
http_methods.c
/pecl/http/phpstr phpstr.c phpstr.h
Log:
* fixing concept of phpstr dtor/free
# so, how to typedef a struct for the php4 build :-?
http://cvs.php.net/diff.php/pecl/http/http.c?r1=1.55&r2=1.56&ty=u Index: pecl/http/http.c diff -u pecl/http/http.c:1.55 pecl/http/http.c:1.56 --- pecl/http/http.c:1.55 Sun Mar 20 12:27:21 2005 +++ pecl/http/http.c Mon Mar 21 14:33:37 2005 @@ -13,7 +13,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: http.c,v 1.55 2005/03/20 17:27:21 mike Exp $ */ +/* $Id: http.c,v 1.56 2005/03/21 19:33:37 mike Exp $ */ #ifdef HAVE_CONFIG_H @@ -485,7 +485,7 @@ { 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 @@ } #ifdef HTTP_HAVE_CURL - //phpstr_free(&HTTP_G(curlbuf)); + phpstr_dtor(&HTTP_G(curlbuf)); #endif return SUCCESS; http://cvs.php.net/diff.php/pecl/http/http_api.c?r1=1.64&r2=1.65&ty=u Index: pecl/http/http_api.c diff -u pecl/http/http_api.c:1.64 pecl/http/http_api.c:1.65 --- pecl/http/http_api.c:1.64 Sun Mar 20 12:30:56 2005 +++ pecl/http/http_api.c Mon Mar 21 14:33:37 2005 @@ -13,7 +13,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: http_api.c,v 1.64 2005/03/20 17:30:56 mike Exp $ */ +/* $Id: http_api.c,v 1.65 2005/03/21 19:33:37 mike Exp $ */ #ifdef HAVE_CONFIG_H # include "config.h" @@ -1387,7 +1387,7 @@ /* }}} */ /* {{{ 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 @@ 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 @@ ulong idx; zval **zdata = NULL, *copyzval; - if (!ht) { + if (!ht || !formstr) { return FAILURE; } @@ -1766,7 +1766,7 @@ *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); http://cvs.php.net/diff.php/pecl/http/http_curl_api.c?r1=1.21&r2=1.22&ty=u Index: pecl/http/http_curl_api.c diff -u pecl/http/http_curl_api.c:1.21 pecl/http/http_curl_api.c:1.22 --- pecl/http/http_curl_api.c:1.21 Sun Mar 20 12:33:59 2005 +++ pecl/http/http_curl_api.c Mon Mar 21 14:33:37 2005 @@ -13,7 +13,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: http_curl_api.c,v 1.21 2005/03/20 17:33:59 mike Exp $ */ +/* $Id: http_curl_api.c,v 1.22 2005/03/21 19:33:37 mike Exp $ */ #ifdef HAVE_CONFIG_H # include "config.h" @@ -72,7 +72,7 @@ } #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 @@ 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 @@ status = http_post_data_ex(ch, URL, encoded, encoded_len, options, info, data, data_len); efree(encoded); - + return status; } /* }}} */ @@ -548,4 +548,3 @@ * vim600: noet sw=4 ts=4 fdm=marker * vim<600: noet sw=4 ts=4 */ - http://cvs.php.net/diff.php/pecl/http/http_functions.c?r1=1.14&r2=1.15&ty=u Index: pecl/http/http_functions.c diff -u pecl/http/http_functions.c:1.14 pecl/http/http_functions.c:1.15 --- pecl/http/http_functions.c:1.14 Sun Mar 20 12:36:16 2005 +++ pecl/http/http_functions.c Mon Mar 21 14:33:37 2005 @@ -13,7 +13,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: http_functions.c,v 1.14 2005/03/20 17:36:16 mike Exp $ */ +/* $Id: http_functions.c,v 1.15 2005/03/21 19:33:37 mike Exp $ */ #ifdef HAVE_CONFIG_H # include "config.h" @@ -975,11 +975,12 @@ } 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(); } http://cvs.php.net/diff.php/pecl/http/http_methods.c?r1=1.14&r2=1.15&ty=u Index: pecl/http/http_methods.c diff -u pecl/http/http_methods.c:1.14 pecl/http/http_methods.c:1.15 --- pecl/http/http_methods.c:1.14 Sun Mar 20 12:35:40 2005 +++ pecl/http/http_methods.c Mon Mar 21 14:33:37 2005 @@ -13,7 +13,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: http_methods.c,v 1.14 2005/03/20 17:35:40 mike Exp $ */ +/* $Id: http_methods.c,v 1.15 2005/03/21 19:33:37 mike Exp $ */ #ifdef HAVE_CONFIG_H # include "config.h" @@ -478,7 +478,7 @@ 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)); } } http://cvs.php.net/diff.php/pecl/http/phpstr/phpstr.c?r1=1.1&r2=1.2&ty=u Index: pecl/http/phpstr/phpstr.c diff -u pecl/http/phpstr/phpstr.c:1.1 pecl/http/phpstr/phpstr.c:1.2 --- pecl/http/phpstr/phpstr.c:1.1 Sun Mar 20 12:31:41 2005 +++ pecl/http/phpstr/phpstr.c Mon Mar 21 14:33:38 2005 @@ -1,11 +1,11 @@ -/* $Id: phpstr.c,v 1.1 2005/03/20 17:31:41 mike Exp $ */ +/* $Id: phpstr.c,v 1.2 2005/03/21 19:33:38 mike Exp $ */ #include "php.h" #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 @@ 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 void phpstr_free(phpstr *buf) +PHPSTR_API void phpstr_dtor(phpstr *buf) { if (buf->data) { efree(buf->data); @@ -240,10 +240,10 @@ 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); } } http://cvs.php.net/diff.php/pecl/http/phpstr/phpstr.h?r1=1.1&r2=1.2&ty=u Index: pecl/http/phpstr/phpstr.h diff -u pecl/http/phpstr/phpstr.h:1.1 pecl/http/phpstr/phpstr.h:1.2 --- pecl/http/phpstr/phpstr.h:1.1 Sun Mar 20 12:31:41 2005 +++ pecl/http/phpstr/phpstr.h Mon Mar 21 14:33:38 2005 @@ -1,5 +1,5 @@ -/* $Id: phpstr.h,v 1.1 2005/03/20 17:31:41 mike Exp $ */ +/* $Id: phpstr.h,v 1.2 2005/03/21 19:33:38 mike Exp $ */ #ifndef _PHPSTR_H_ #define _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 @@ 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 *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 @@ /* 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
http://cvs.php.net/diff.php/pecl/http/http.c?r1=1.55&r2=1.56&ty=u Index: pecl/http/http.c diff -u pecl/http/http.c:1.55 pecl/http/http.c:1.56 --- pecl/http/http.c:1.55 Sun Mar 20 12:27:21 2005 +++ pecl/http/http.c Mon Mar 21 14:33:37 2005 @@ -13,7 +13,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: http.c,v 1.55 2005/03/20 17:27:21 mike Exp $ */ +/* $Id: http.c,v 1.56 2005/03/21 19:33:37 mike Exp $ */ #ifdef HAVE_CONFIG_H @@ -485,7 +485,7 @@ { 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 @@ } #ifdef HTTP_HAVE_CURL - //phpstr_free(&HTTP_G(curlbuf)); + phpstr_dtor(&HTTP_G(curlbuf)); #endif return SUCCESS; http://cvs.php.net/diff.php/pecl/http/http_api.c?r1=1.64&r2=1.65&ty=u Index: pecl/http/http_api.c diff -u pecl/http/http_api.c:1.64 pecl/http/http_api.c:1.65 --- pecl/http/http_api.c:1.64 Sun Mar 20 12:30:56 2005 +++ pecl/http/http_api.c Mon Mar 21 14:33:37 2005 @@ -13,7 +13,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: http_api.c,v 1.64 2005/03/20 17:30:56 mike Exp $ */ +/* $Id: http_api.c,v 1.65 2005/03/21 19:33:37 mike Exp $ */ #ifdef HAVE_CONFIG_H # include "config.h" @@ -1387,7 +1387,7 @@ /* }}} */ /* {{{ 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 @@ 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 @@ ulong idx; zval **zdata = NULL, *copyzval; - if (!ht) { + if (!ht || !formstr) { return FAILURE; } @@ -1766,7 +1766,7 @@ *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); http://cvs.php.net/diff.php/pecl/http/http_curl_api.c?r1=1.21&r2=1.22&ty=u Index: pecl/http/http_curl_api.c diff -u pecl/http/http_curl_api.c:1.21 pecl/http/http_curl_api.c:1.22 --- pecl/http/http_curl_api.c:1.21 Sun Mar 20 12:33:59 2005 +++ pecl/http/http_curl_api.c Mon Mar 21 14:33:37 2005 @@ -13,7 +13,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: http_curl_api.c,v 1.21 2005/03/20 17:33:59 mike Exp $ */ +/* $Id: http_curl_api.c,v 1.22 2005/03/21 19:33:37 mike Exp $ */ #ifdef HAVE_CONFIG_H # include "config.h" @@ -72,7 +72,7 @@ } #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 @@ 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 @@ status = http_post_data_ex(ch, URL, encoded, encoded_len, options, info, data, data_len); efree(encoded); - + return status; } /* }}} */ @@ -548,4 +548,3 @@ * vim600: noet sw=4 ts=4 fdm=marker * vim<600: noet sw=4 ts=4 */ - http://cvs.php.net/diff.php/pecl/http/http_functions.c?r1=1.14&r2=1.15&ty=u Index: pecl/http/http_functions.c diff -u pecl/http/http_functions.c:1.14 pecl/http/http_functions.c:1.15 --- pecl/http/http_functions.c:1.14 Sun Mar 20 12:36:16 2005 +++ pecl/http/http_functions.c Mon Mar 21 14:33:37 2005 @@ -13,7 +13,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: http_functions.c,v 1.14 2005/03/20 17:36:16 mike Exp $ */ +/* $Id: http_functions.c,v 1.15 2005/03/21 19:33:37 mike Exp $ */ #ifdef HAVE_CONFIG_H # include "config.h" @@ -975,11 +975,12 @@ } 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(); } http://cvs.php.net/diff.php/pecl/http/http_methods.c?r1=1.14&r2=1.15&ty=u Index: pecl/http/http_methods.c diff -u pecl/http/http_methods.c:1.14 pecl/http/http_methods.c:1.15 --- pecl/http/http_methods.c:1.14 Sun Mar 20 12:35:40 2005 +++ pecl/http/http_methods.c Mon Mar 21 14:33:37 2005 @@ -13,7 +13,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: http_methods.c,v 1.14 2005/03/20 17:35:40 mike Exp $ */ +/* $Id: http_methods.c,v 1.15 2005/03/21 19:33:37 mike Exp $ */ #ifdef HAVE_CONFIG_H # include "config.h" @@ -478,7 +478,7 @@ 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)); } } http://cvs.php.net/diff.php/pecl/http/phpstr/phpstr.c?r1=1.1&r2=1.2&ty=u Index: pecl/http/phpstr/phpstr.c diff -u pecl/http/phpstr/phpstr.c:1.1 pecl/http/phpstr/phpstr.c:1.2 --- pecl/http/phpstr/phpstr.c:1.1 Sun Mar 20 12:31:41 2005 +++ pecl/http/phpstr/phpstr.c Mon Mar 21 14:33:38 2005 @@ -1,11 +1,11 @@ -/* $Id: phpstr.c,v 1.1 2005/03/20 17:31:41 mike Exp $ */ +/* $Id: phpstr.c,v 1.2 2005/03/21 19:33:38 mike Exp $ */ #include "php.h" #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 @@ 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 void phpstr_free(phpstr *buf) +PHPSTR_API void phpstr_dtor(phpstr *buf) { if (buf->data) { efree(buf->data); @@ -240,10 +240,10 @@ 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); } } http://cvs.php.net/diff.php/pecl/http/phpstr/phpstr.h?r1=1.1&r2=1.2&ty=u Index: pecl/http/phpstr/phpstr.h diff -u pecl/http/phpstr/phpstr.h:1.1 pecl/http/phpstr/phpstr.h:1.2 --- pecl/http/phpstr/phpstr.h:1.1 Sun Mar 20 12:31:41 2005 +++ pecl/http/phpstr/phpstr.h Mon Mar 21 14:33:38 2005 @@ -1,5 +1,5 @@ -/* $Id: phpstr.h,v 1.1 2005/03/20 17:31:41 mike Exp $ */ +/* $Id: phpstr.h,v 1.2 2005/03/21 19:33:38 mike Exp $ */ #ifndef _PHPSTR_H_ #define _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 @@ 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 *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 @@ /* 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