- 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 b535cf5aaca536575f421f7f45b486c643b78224..9d99bc9aa239c9d371d520e70cb6b518d0116f15 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 ef687d4eb175ab8fe739d28bf40db8aa42a68b67..131d7189685bff857b45697b55375c90d166f16e 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 1a5980e18b92c690576032474b0d92debe397d7e..edc18a0499d549d1a7c026afd1e25c51e36aef2c 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 fc039f824fb1e5226cdc0ccf0da2e87681ddc9e1..b40ef8992457e8a9833cf8e23c6324676aa4682c 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 3ea2b844dcb1ccbadfacb7c16641a7a9ad5f9ce1..3880fc4debc8c2fb09bd3d73faf285a0b47c2b3b 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 a1dfb97d259cb41ad64f6211b46dc54158cc37df..5ba031185fb7511817b1fb5840145388cea9e21e 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 5e94bf38f14c5324052a5cf1b57c02517f5e1072..8c416b9b906df9f99574aa6d219887a7812df2ab 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 8195dadc67885fa17185ae4c3e93a14b45b3843f..a85e81755efa0e0caf97ff76d5c82958ed6540a2 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 e40884b9b9052b54447ddc39c7d34b2fa145353f..8996166fad6f060faaf09e66a088dcfc91f3e4c1 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
 }