From: Michael Wallner Date: Mon, 19 Sep 2005 15:07:59 +0000 (+0000) Subject: - initialize local zvals used as HashTable containers X-Git-Tag: RELEASE_0_14_0~18 X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=commitdiff_plain;h=bb1f32fd5d06b9b9ace6517c177b0fe58c9ff57c;ds=inline - initialize local zvals used as HashTable containers - added another function missing in WONKY (zend_update_property_stringl) - added PHP4 compile fix (RETVAL_ZVAL) - ditch warnings --- diff --git a/http_api.c b/http_api.c index f59a7d0..abc2c9b 100644 --- a/http_api.c +++ b/http_api.c @@ -85,7 +85,7 @@ STATUS _http_parse_key_list(const char *list, HashTable *items, char separator, int vallen = 0, keylen = 0, done = 0; zval array; - Z_ARRVAL(array) = items; + INIT_ZARR(array, items); if (!(val = strchr(list, '='))) { return FAILURE; diff --git a/http_headers_api.c b/http_headers_api.c index e320f46..4f255fe 100644 --- a/http_headers_api.c +++ b/http_headers_api.c @@ -331,7 +331,10 @@ PHP_HTTP_API STATUS _http_parse_headers_ex(const char *header, HashTable *header size_t header_len; zval array; + INIT_PZVAL(&array); + Z_TYPE_P(array) = IS_ARRAY; Z_ARRVAL(array) = headers; + if (body) { header_len = body - header; } else { @@ -341,7 +344,7 @@ PHP_HTTP_API STATUS _http_parse_headers_ex(const char *header, HashTable *header while (header_len >= (size_t) (line - begin)) { int value_len = 0; - + /* note: valgrind may choke on that -- should be safe though */ switch (*line++) { case ':': diff --git a/http_info_api.c b/http_info_api.c index a6b1213..0e9b648 100644 --- a/http_info_api.c +++ b/http_info_api.c @@ -32,7 +32,8 @@ ZEND_EXTERN_MODULE_GLOBALS(http); PHP_HTTP_API void _http_info_default_callback(void **nothing, HashTable **headers, http_info *info TSRMLS_DC) { zval array; - Z_ARRVAL(array) = *headers; + + INIT_ZARR(array, *headers); switch (info->type) { diff --git a/http_message_api.c b/http_message_api.c index 15fa449..36b3098 100644 --- a/http_message_api.c +++ b/http_message_api.c @@ -312,8 +312,7 @@ PHP_HTTP_API void _http_message_tostruct_recursive(http_message *msg, zval *obj zval strct; zval *headers; - Z_TYPE(strct) = IS_ARRAY; - Z_ARRVAL(strct) = HASH_OF(obj); + INIT_ZARR(strct, HASH_OF(obj)); add_assoc_long(&strct, "type", msg->type); add_assoc_double(&strct, "httpVersion", msg->http.version); @@ -394,6 +393,8 @@ PHP_HTTP_API STATUS _http_message_send(http_message *message TSRMLS_DC) char *uri = NULL; zval **zhost, options, headers; + INIT_PZVAL(&options); + INIT_PZVAL(&headers); array_init(&options); array_init(&headers); zend_hash_copy(Z_ARRVAL(headers), &message->hdrs, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *)); diff --git a/http_message_object.c b/http_message_object.c index b187f55..cd64d31 100644 --- a/http_message_object.c +++ b/http_message_object.c @@ -409,7 +409,7 @@ static HashTable *_http_message_object_get_props(zval *object TSRMLS_DC) zval array; \ char *m_prop_name; \ int m_prop_len; \ - Z_ARRVAL(array) = OBJ_PROP(obj); \ + INIT_ZARR(array, OBJ_PROP(obj)); \ zend_mangle_property_name(&m_prop_name, &m_prop_len, "*", 1, name, lenof(name), 1); \ add_assoc_ ##ptype## _ex(&array, m_prop_name, sizeof(name)+4, val); \ } @@ -419,7 +419,7 @@ static HashTable *_http_message_object_get_props(zval *object TSRMLS_DC) zval array; \ char *m_prop_name; \ int m_prop_len; \ - Z_ARRVAL(array) = OBJ_PROP(obj); \ + INIT_ZARR(array, OBJ_PROP(obj)); \ zend_mangle_property_name(&m_prop_name, &m_prop_len, "*", 1, name, lenof(name), 1); \ add_assoc_stringl_ex(&array, m_prop_name, sizeof(name)+4, val, len, 1); \ } @@ -557,7 +557,7 @@ PHP_METHOD(HttpMessage, getHeaders) zval headers; getObject(http_message_object, obj); - Z_ARRVAL(headers) = &obj->message->hdrs; + INIT_ZARR(headers, &obj->message->hdrs); array_init(return_value); array_copy(&headers, return_value); } @@ -578,7 +578,7 @@ PHP_METHOD(HttpMessage, setHeaders) } zend_hash_clean(&obj->message->hdrs); - Z_ARRVAL(old_headers) = &obj->message->hdrs; + INIT_ZARR(old_headers, &obj->message->hdrs); array_copy(new_headers, &old_headers); } /* }}} */ @@ -597,7 +597,7 @@ PHP_METHOD(HttpMessage, addHeaders) return; } - Z_ARRVAL(old_headers) = &obj->message->hdrs; + INIT_ZARR(old_headers, &obj->message->hdrs); if (append) { array_append(new_headers, &old_headers); } else { diff --git a/http_request_api.c b/http_request_api.c index eb2906b..8b195f8 100644 --- a/http_request_api.c +++ b/http_request_api.c @@ -685,7 +685,7 @@ PHP_HTTP_API STATUS _http_request_exec(CURL *ch, HashTable *info, phpstr *respon PHP_HTTP_API void _http_request_info(CURL *ch, HashTable *info TSRMLS_DC) { zval array; - Z_ARRVAL(array) = info; + INIT_ZARR(array, info); HTTP_CURL_INFO(EFFECTIVE_URL); #if LIBCURL_VERSION_NUM >= 0x070a07 diff --git a/http_request_method_api.c b/http_request_method_api.c index 57636d0..28365f7 100644 --- a/http_request_method_api.c +++ b/http_request_method_api.c @@ -167,7 +167,7 @@ PHP_HTTP_API unsigned long _http_request_method_register(const char *method_name } method[method_len] = '\0'; - Z_ARRVAL(array) = &HTTP_G(request).methods.custom; + INIT_ZARR(array, &HTTP_G(request).methods.custom); add_next_index_stringl(&array, method, method_len, 0); method_len = spprintf(&http_method, 0, "HTTP_METH_%s", method); diff --git a/http_request_object.c b/http_request_object.c index 0a6c5d1..f1f2551 100644 --- a/http_request_object.c +++ b/http_request_object.c @@ -344,6 +344,7 @@ static inline void _http_request_object_declare_default_properties(TSRMLS_D) DCL_PROP(PUBLIC, bool, recordHistory, 1); +#ifndef WONKY /* * Request Method Constants */ @@ -388,6 +389,7 @@ static inline void _http_request_object_declare_default_properties(TSRMLS_D) DCL_CONST(long, "AUTH_NTLM", CURLAUTH_NTLM); DCL_CONST(long, "AUTH_ANY", CURLAUTH_ANY); # endif /* LIBCURL_VERSION_NUM */ +#endif /* WONKY */ } void _http_request_object_free(zend_object *object TSRMLS_DC) diff --git a/http_response_object.c b/http_response_object.c index 7de10dc..ba1ae40 100644 --- a/http_response_object.c +++ b/http_response_object.c @@ -237,10 +237,11 @@ static inline void _http_response_object_declare_default_properties(TSRMLS_D) DCL_STATIC_PROP(PROTECTED, long, bufferSize, HTTP_SENDBUF_SIZE); DCL_STATIC_PROP(PROTECTED, double, throttleDelay, 0.0); +#ifndef WONKY DCL_CONST(long, "ETAG_MD5", HTTP_ETAG_MD5); DCL_CONST(long, "ETAG_SHA1", HTTP_ETAG_SHA1); -#ifdef HTTP_HAVE_MHASH +# ifdef HTTP_HAVE_MHASH { int l, i, c = mhash_count(); @@ -254,7 +255,8 @@ static inline void _http_response_object_declare_default_properties(TSRMLS_D) } } } -#endif +# endif /* HTTP_HAVE_MHASH */ +#endif /* WONKY */ } static void _http_grab_response_headers(void *data, void *arg TSRMLS_DC) @@ -880,7 +882,7 @@ PHP_METHOD(HttpResponse, getFile) */ PHP_METHOD(HttpResponse, send) { - zval *sent, *headers; + zval *sent; zend_bool clean_ob = 1; if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &clean_ob)) { diff --git a/missing.c b/missing.c index 7febedf..9d9b941 100644 --- a/missing.c +++ b/missing.c @@ -47,6 +47,18 @@ void zend_update_property_bool(zend_class_entry *scope, zval *object, char *name ZVAL_BOOL(tmp, value); zend_update_property(scope, object, name, name_length, tmp TSRMLS_CC); } + +void zend_update_property_stringl(zend_class_entry *scope, zval *object, char *name, int name_length, char *value, int value_len TSRMLS_DC) +{ + zval *tmp; + + ALLOC_ZVAL(tmp); + tmp->is_ref = 0; + tmp->refcount = 0; + ZVAL_STRINGL(tmp, value, value_len, 1); + zend_update_property(scope, object, name, name_length, tmp TSRMLS_CC); +} + #endif /* diff --git a/missing.h b/missing.h index d1f53e5..e76b078 100644 --- a/missing.h +++ b/missing.h @@ -30,6 +30,8 @@ extern void zend_update_property_double(zend_class_entry *scope, zval *object, c extern int zend_declare_property_bool(zend_class_entry *ce, char *name, int name_length, long value, int access_type TSRMLS_DC); extern void zend_update_property_bool(zend_class_entry *scope, zval *object, char *name, int name_length, long value TSRMLS_DC); + +extern void zend_update_property_stringl(zend_class_entry *scope, zval *object, char *name, int name_length, char *value, int value_len TSRMLS_DC); #endif #endif diff --git a/php_http_std_defs.h b/php_http_std_defs.h index c212d30..ce42260 100644 --- a/php_http_std_defs.h +++ b/php_http_std_defs.h @@ -52,6 +52,13 @@ typedef int STATUS; } #endif +#define INIT_ZARR(zv, ht) \ + { \ + INIT_PZVAL(&(zv)); \ + Z_TYPE(zv) = IS_ARRAY; \ + Z_ARRVAL(zv) = (ht); \ + } + /* return bool (v == SUCCESS) */ #define RETVAL_SUCCESS(v) RETVAL_BOOL(SUCCESS == (v)) #define RETURN_SUCCESS(v) RETURN_BOOL(SUCCESS == (v)) @@ -366,6 +373,31 @@ typedef int STATUS; # endif #endif +#ifndef ZVAL_ZVAL +#define ZVAL_ZVAL(z, zv, copy, dtor) { \ + int is_ref, refcount; \ + is_ref = (z)->is_ref; \ + refcount = (z)->refcount; \ + *(z) = *(zv); \ + if (copy) { \ + zval_copy_ctor(z); \ + } \ + if (dtor) { \ + if (!copy) { \ + ZVAL_NULL(zv); \ + } \ + zval_ptr_dtor(&zv); \ + } \ + (z)->is_ref = is_ref; \ + (z)->refcount = refcount; \ + } +#endif +#ifndef RETVAL_ZVAL +#define RETVAL_ZVAL(zv, copy, dtor) ZVAL_ZVAL(return_value, zv, copy, dtor) +#endif +#ifndef RETURN_ZVAL +#define RETURN_ZVAL(zv, copy, dtor) { RETVAL_ZVAL(zv, copy, dtor); return; } +#endif #endif /* PHP_HTTP_STD_DEFS_H */