- fix a load of issues with inheritance and cloning
authorMichael Wallner <mike@php.net>
Mon, 21 Aug 2006 07:16:16 +0000 (07:16 +0000)
committerMichael Wallner <mike@php.net>
Mon, 21 Aug 2006 07:16:16 +0000 (07:16 +0000)
http_deflatestream_object.c
http_inflatestream_object.c
http_message_object.c
http_request_object.c
package2.xml
php_http.h
tests/HttpMessage_003.phpt
tests/HttpRequestPool_002.phpt
tests/HttpRequest_006.phpt

index b535cf5..9d99bc9 100644 (file)
@@ -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)
index ef687d4..131d718 100644 (file)
@@ -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)
index 1a5980e..edc18a0 100644 (file)
@@ -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)
index fc039f8..b40ef89 100644 (file)
@@ -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);
        
index 3ea2b84..3880fc4 100644 (file)
@@ -28,9 +28,9 @@ support. Parallel requests are available for PHP 5 and greater.
   <email>mike@php.net</email>
   <active>yes</active>
  </lead>
- <date>2006-08-18</date>
+ <date>2006-08-00</date>
  <version>
-  <release>1.2.0</release>
+  <release>1.2.1</release>
   <api>1.2.0</api>
  </version>
  <stability>
@@ -39,10 +39,8 @@ support. Parallel requests are available for PHP 5 and greater.
  </stability>
  <license>BSD, revised</license>
  <notes><![CDATA[
-+ Improved response performance (HttpResponse, http_send API)
-* Fixed http_parse_cookie() allowed_extras and flags parameters
-* Added http_build_cookie() function
-* Fixed configuration with shared dependencies
+* Fixed issues with inheritance and cloning of HttpDeflateStream, HttpInflateStream and HttpMessage
+  (Extending classes lose default properties on instantiation; Complex members ignored during cloning)
 ]]></notes>
  <contents>
   <dir name="/">
index a1dfb97..5ba0311 100644 (file)
@@ -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"
index 5e94bf3..8c416b9 100644 (file)
@@ -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
 }
index 8195dad..a85e817 100644 (file)
@@ -4,6 +4,10 @@ extending HttpRequestPool
 <?php
 include 'skip.inc';
 checkcls('HttpRequestPool');
+checkurl('ch.php.net');
+checkurl('at.php.net');
+checkurl('de.php.net');
+checkurl('www.php.net');
 ?>
 --FILE--
 <?php
index e40884b..8996166 100644 (file)
@@ -24,20 +24,6 @@ echo "Done\n";
 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) ""
-  ["headers:protected"]=>
-  array(6) {
-    %s
-  }
   ["body:protected"]=>
   string(309) "string(294) "<?xml version="1.0" encoding="iso-8859-1"?>
 <methodCall>
@@ -59,26 +45,26 @@ object(HttpMessage)#%d (%d) {
 </methodCall>
 "
 "
-  ["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) "<?xml version="1.0" encoding="iso-8859-1"?>
 <methodCall>
@@ -100,26 +86,26 @@ object(HttpMessage)#%d (%d) {
 </methodCall>
 "
 "
-  ["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) "<?xml version="1.0" encoding="iso-8859-1"?>
 <methodCall>
@@ -141,6 +127,20 @@ object(HttpMessage)#%d (%d) {
 </methodCall>
 "
 "
+  ["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
 }