* fixing concept of phpstr dtor/free
authorMichael Wallner <mike@php.net>
Mon, 21 Mar 2005 19:33:38 +0000 (19:33 +0000)
committerMichael Wallner <mike@php.net>
Mon, 21 Mar 2005 19:33:38 +0000 (19:33 +0000)
# so, how to typedef a struct for the php4 build :-?

http.c
http_api.c
http_curl_api.c
http_functions.c
http_methods.c
phpstr/phpstr.c
phpstr/phpstr.h

diff --git a/http.c b/http.c
index 930e179a13a572c9acfbb88d8aaa3f029bf8102b..e0f61fc893f027a1525a185a5e81444e5180da1b 100644 (file)
--- 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;
index 1a1dfead13c9c035a655a79d312662c90605a94f..ff7468d066626358a5423a856b0ac9f75935f29b 100644 (file)
@@ -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);
index 371f39fb3b0832bd7ddd1b537f48222a37d31d9a..7f0638f08f14815f35f5ec333be584262f51c83f 100644 (file)
@@ -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
  */
-
index bf3fab60a99111b9d96670808625bb4094dac54e..05f6b7ee14a7bed0ee15a8bfedcfb3450b0629d9 100644 (file)
@@ -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();
        }
 
index ded27ff88ee5313b10fcb2b020ee1f320ee5cb9f..d22ae96e912c00c050ef0cc7f3c55492e9805ab9 100644 (file)
@@ -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));
                }
        }
 
index 999230005bdf15c94d40e84cb8f511ae40678bcf..af090fa02d16aadb2d1139e9c3f3ba9e168d7175 100644 (file)
@@ -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);
        }
 }
index dc103e132a70a5e4110e340b488d5d8fcca4f97b..50d9c283c14616a619ce72ee1cf93131dc4f4a67 100644 (file)
 #      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