From 5ecd200ee2e3d887f0393948aec1914867e64293 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Mon, 21 Aug 2006 07:16:16 +0000 Subject: [PATCH] - fix a load of issues with inheritance and cloning --- http_deflatestream_object.c | 16 ++++--- http_inflatestream_object.c | 16 ++++--- http_message_object.c | 13 ++++-- http_request_object.c | 6 +-- package2.xml | 10 ++--- php_http.h | 2 +- tests/HttpMessage_003.phpt | 16 +++---- tests/HttpRequestPool_002.phpt | 4 ++ tests/HttpRequest_006.phpt | 76 +++++++++++++++++----------------- 9 files changed, 89 insertions(+), 70 deletions(-) diff --git a/http_deflatestream_object.c b/http_deflatestream_object.c index b535cf5..9d99bc9 100644 --- a/http_deflatestream_object.c +++ b/http_deflatestream_object.c @@ -101,7 +101,8 @@ zend_object_value _http_deflatestream_object_new_ex(zend_class_entry *ce, http_e } ALLOC_HASHTABLE(OBJ_PROP(o)); - zend_hash_init(OBJ_PROP(o), 0, NULL, ZVAL_PTR_DTOR, 0); + zend_hash_init(OBJ_PROP(o), zend_hash_num_elements(&ce->default_properties), NULL, ZVAL_PTR_DTOR, 0); + zend_hash_copy(OBJ_PROP(o), &ce->default_properties, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *)); ov.handle = putObject(http_deflatestream_object, o); ov.handlers = &http_deflatestream_object_handlers; @@ -112,14 +113,19 @@ zend_object_value _http_deflatestream_object_new_ex(zend_class_entry *ce, http_e zend_object_value _http_deflatestream_object_clone_obj(zval *this_ptr TSRMLS_DC) { http_encoding_stream *s; - getObject(http_deflatestream_object, obj); + zend_object_value new_ov; + http_deflatestream_object *new_obj = NULL; + getObject(http_deflatestream_object, old_obj); s = ecalloc(1, sizeof(http_encoding_stream)); - s->flags = obj->stream->flags; - deflateCopy(&s->stream, &obj->stream->stream); + s->flags = old_obj->stream->flags; + deflateCopy(&s->stream, &old_obj->stream->stream); s->stream.opaque = phpstr_dup(s->stream.opaque); - return http_deflatestream_object_new_ex(Z_OBJCE_P(this_ptr), s, NULL); + new_ov = http_deflatestream_object_new_ex(old_obj->zo.ce, s, &new_obj); + zend_objects_clone_members(&new_obj->zo, new_ov, &old_obj->zo, Z_OBJ_HANDLE_P(this_ptr) TSRMLS_CC); + + return new_ov; } void _http_deflatestream_object_free(zend_object *object TSRMLS_DC) diff --git a/http_inflatestream_object.c b/http_inflatestream_object.c index ef687d4..131d718 100644 --- a/http_inflatestream_object.c +++ b/http_inflatestream_object.c @@ -90,7 +90,8 @@ zend_object_value _http_inflatestream_object_new_ex(zend_class_entry *ce, http_e } ALLOC_HASHTABLE(OBJ_PROP(o)); - zend_hash_init(OBJ_PROP(o), 0, NULL, ZVAL_PTR_DTOR, 0); + zend_hash_init(OBJ_PROP(o), zend_hash_num_elements(&ce->default_properties), NULL, ZVAL_PTR_DTOR, 0); + zend_hash_copy(OBJ_PROP(o), &ce->default_properties, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *)); ov.handle = putObject(http_inflatestream_object, o); ov.handlers = &http_inflatestream_object_handlers; @@ -101,14 +102,19 @@ zend_object_value _http_inflatestream_object_new_ex(zend_class_entry *ce, http_e zend_object_value _http_inflatestream_object_clone_obj(zval *this_ptr TSRMLS_DC) { http_encoding_stream *s; - getObject(http_inflatestream_object, obj); + zend_object_value new_ov; + http_inflatestream_object *new_obj = NULL; + getObject(http_inflatestream_object, old_obj); s = ecalloc(1, sizeof(http_encoding_stream)); - s->flags = obj->stream->flags; - inflateCopy(&s->stream, &obj->stream->stream); + s->flags = old_obj->stream->flags; + inflateCopy(&s->stream, &old_obj->stream->stream); s->stream.opaque = phpstr_dup(s->stream.opaque); - return http_inflatestream_object_new_ex(Z_OBJCE_P(this_ptr), s, NULL); + new_ov = http_inflatestream_object_new_ex(old_obj->zo.ce, s, &new_obj); + zend_objects_clone_members(&new_obj->zo, new_ov, &old_obj->zo, Z_OBJ_HANDLE_P(this_ptr) TSRMLS_CC); + + return new_ov; } void _http_inflatestream_object_free(zend_object *object TSRMLS_DC) diff --git a/http_message_object.c b/http_message_object.c index 1a5980e..edc18a0 100644 --- a/http_message_object.c +++ b/http_message_object.c @@ -350,7 +350,8 @@ zend_object_value _http_message_object_new_ex(zend_class_entry *ce, http_message } ALLOC_HASHTABLE(OBJ_PROP(o)); - zend_hash_init(OBJ_PROP(o), 0, NULL, ZVAL_PTR_DTOR, 0); + zend_hash_init(OBJ_PROP(o), zend_hash_num_elements(&ce->default_properties), NULL, ZVAL_PTR_DTOR, 0); + zend_hash_copy(OBJ_PROP(o), &ce->default_properties, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *)); ov.handle = putObject(http_message_object, o); ov.handlers = &http_message_object_handlers; @@ -360,8 +361,14 @@ zend_object_value _http_message_object_new_ex(zend_class_entry *ce, http_message zend_object_value _http_message_object_clone_obj(zval *this_ptr TSRMLS_DC) { - getObject(http_message_object, obj); - return http_message_object_new_ex(Z_OBJCE_P(this_ptr), http_message_dup(obj->message), NULL); + zend_object_value new_ov; + http_message_object *new_obj = NULL; + getObject(http_message_object, old_obj); + + new_ov = http_message_object_new_ex(old_obj->zo.ce, http_message_dup(old_obj->message), &new_obj); + zend_objects_clone_members(&new_obj->zo, new_ov, &old_obj->zo, Z_OBJ_HANDLE_P(this_ptr) TSRMLS_CC); + + return new_ov; } void _http_message_object_free(zend_object *object TSRMLS_DC) diff --git a/http_request_object.c b/http_request_object.c index fc039f8..b40ef89 100644 --- a/http_request_object.c +++ b/http_request_object.c @@ -449,18 +449,16 @@ zend_object_value _http_request_object_new_ex(zend_class_entry *ce, CURL *ch, ht zend_object_value _http_request_object_clone_obj(zval *this_ptr TSRMLS_DC) { - zend_object *old_zo; zend_object_value new_ov; http_request_object *new_obj; getObject(http_request_object, old_obj); - old_zo = zend_objects_get_address(this_ptr TSRMLS_CC); - new_ov = http_request_object_new_ex(old_zo->ce, NULL, &new_obj); + new_ov = http_request_object_new_ex(old_obj->zo.ce, NULL, &new_obj); if (old_obj->request->ch) { http_curl_init_ex(curl_easy_duphandle(old_obj->request->ch), new_obj->request); } - zend_objects_clone_members(&new_obj->zo, new_ov, old_zo, Z_OBJ_HANDLE_P(this_ptr) TSRMLS_CC); + zend_objects_clone_members(&new_obj->zo, new_ov, &old_obj->zo, Z_OBJ_HANDLE_P(this_ptr) TSRMLS_CC); phpstr_append(&new_obj->request->conv.request, old_obj->request->conv.request.data, old_obj->request->conv.request.used); phpstr_append(&new_obj->request->conv.response, old_obj->request->conv.response.data, old_obj->request->conv.response.used); diff --git a/package2.xml b/package2.xml index 3ea2b84..3880fc4 100644 --- a/package2.xml +++ b/package2.xml @@ -28,9 +28,9 @@ support. Parallel requests are available for PHP 5 and greater. mike@php.net yes - 2006-08-18 + 2006-08-00 - 1.2.0 + 1.2.1 1.2.0 @@ -39,10 +39,8 @@ support. Parallel requests are available for PHP 5 and greater. BSD, revised diff --git a/php_http.h b/php_http.h index a1dfb97..5ba0311 100644 --- a/php_http.h +++ b/php_http.h @@ -15,7 +15,7 @@ #ifndef PHP_EXT_HTTP_H #define PHP_EXT_HTTP_H -#define PHP_EXT_HTTP_VERSION "1.2.0" +#define PHP_EXT_HTTP_VERSION "1.2.1dev" #ifdef HAVE_CONFIG_H # include "config.h" diff --git a/tests/HttpMessage_003.phpt b/tests/HttpMessage_003.phpt index 5e94bf3..8c416b9 100644 --- a/tests/HttpMessage_003.phpt +++ b/tests/HttpMessage_003.phpt @@ -46,23 +46,23 @@ X object(HttpMessage)#%d (%d) { ["type:protected"]=> int(2) - ["httpVersion:protected"]=> - float(1.1) - ["responseCode:protected"]=> - int(200) - ["responseStatus:protected"]=> - string(2) "Ok" + ["body:protected"]=> + string(0) "" ["requestMethod:protected"]=> string(0) "" ["requestUrl:protected"]=> string(0) "" + ["responseStatus:protected"]=> + string(2) "Ok" + ["responseCode:protected"]=> + int(200) + ["httpVersion:protected"]=> + float(1.1) ["headers:protected"]=> array(1) { ["Server"]=> string(9) "Funky/1.0" } - ["body:protected"]=> - string(0) "" ["parentMessage:protected"]=> NULL } diff --git a/tests/HttpRequestPool_002.phpt b/tests/HttpRequestPool_002.phpt index 8195dad..a85e817 100644 --- a/tests/HttpRequestPool_002.phpt +++ b/tests/HttpRequestPool_002.phpt @@ -4,6 +4,10 @@ extending HttpRequestPool --FILE-- int(2) - ["httpVersion:protected"]=> - float(1.1) - ["responseCode:protected"]=> - int(200) - ["responseStatus:protected"]=> - string(2) "OK" - ["requestMethod:protected"]=> - string(0) "" - ["requestUrl:protected"]=> - string(0) "" - ["headers:protected"]=> - array(6) { - %s - } ["body:protected"]=> string(309) "string(294) " @@ -59,26 +45,26 @@ object(HttpMessage)#%d (%d) { " " - ["parentMessage:protected"]=> - NULL -} -object(HttpMessage)#%d (%d) { - ["type:protected"]=> - int(2) - ["httpVersion:protected"]=> - float(1.1) - ["responseCode:protected"]=> - int(200) - ["responseStatus:protected"]=> - string(2) "OK" ["requestMethod:protected"]=> string(0) "" ["requestUrl:protected"]=> string(0) "" + ["responseStatus:protected"]=> + string(2) "OK" + ["responseCode:protected"]=> + int(200) + ["httpVersion:protected"]=> + float(1.1) ["headers:protected"]=> array(6) { %s } + ["parentMessage:protected"]=> + NULL +} +object(HttpMessage)#%d (%d) { + ["type:protected"]=> + int(2) ["body:protected"]=> string(309) "string(294) " @@ -100,26 +86,26 @@ object(HttpMessage)#%d (%d) { " " - ["parentMessage:protected"]=> - NULL -} -object(HttpMessage)#%d (%d) { - ["type:protected"]=> - int(2) - ["httpVersion:protected"]=> - float(1.1) - ["responseCode:protected"]=> - int(200) - ["responseStatus:protected"]=> - string(2) "OK" ["requestMethod:protected"]=> string(0) "" ["requestUrl:protected"]=> string(0) "" + ["responseStatus:protected"]=> + string(2) "OK" + ["responseCode:protected"]=> + int(200) + ["httpVersion:protected"]=> + float(1.1) ["headers:protected"]=> array(6) { %s } + ["parentMessage:protected"]=> + NULL +} +object(HttpMessage)#%d (%d) { + ["type:protected"]=> + int(2) ["body:protected"]=> string(309) "string(294) " @@ -141,6 +127,20 @@ object(HttpMessage)#%d (%d) { " " + ["requestMethod:protected"]=> + string(0) "" + ["requestUrl:protected"]=> + string(0) "" + ["responseStatus:protected"]=> + string(2) "OK" + ["responseCode:protected"]=> + int(200) + ["httpVersion:protected"]=> + float(1.1) + ["headers:protected"]=> + array(6) { + %s + } ["parentMessage:protected"]=> NULL } -- 2.30.2