{
php_http_client_object_t *o = PHP_HTTP_OBJ(object, NULL);
+ PTR_FREE(o->gc);
+
php_http_client_free(&o->client);
php_http_object_method_dtor(&o->notify);
php_http_object_method_free(&o->update);
return &php_http_client_object_new_ex(ce, NULL)->zo;
}
+static HashTable *php_http_client_object_get_gc(zval *object, zval **table, int *n)
+{
+ php_http_client_object_t *obj = PHP_HTTP_OBJ(NULL, object);
+ zend_llist_element *el = NULL;
+ HashTable *props = Z_OBJPROP_P(object);
+ uint32_t count = zend_hash_num_elements(props) + zend_llist_count(&obj->client->responses) + zend_llist_count(&obj->client->requests);
+ zval *val;
+
+ *n = 0;
+ *table = obj->gc = erealloc(obj->gc, sizeof(zval) * count);
+
+ for (el = obj->client->responses.head; el; el = el->next) {
+ php_http_message_object_t *response_obj = *(php_http_message_object_t **) el->data;
+ ZVAL_OBJ(&obj->gc[(*n)++], &response_obj->zo);
+ }
+
+ for (el = obj->client->requests.head; el; el = el->next) {
+ php_http_client_enqueue_t *q = *(php_http_client_enqueue_t **) el->data;
+ php_http_message_object_t *request_obj = q->opaque; /* FIXME */
+ ZVAL_OBJ(&obj->gc[(*n)++], &request_obj->zo);
+ }
+
+ ZEND_HASH_FOREACH_VAL(props, val)
+ {
+ ZVAL_COPY_VALUE(&obj->gc[(*n)++], val);
+ }
+ ZEND_HASH_FOREACH_END();
+
+ return NULL;
+}
+
static void handle_history(zval *zclient, php_http_message_t *request, php_http_message_t *response)
{
zval new_hist, old_hist_tmp, *old_hist = zend_read_property(php_http_client_class_entry, zclient, ZEND_STRL("history"), 0, &old_hist_tmp);
*response = NULL;
msg_obj = php_http_message_object_new_ex(php_http_get_client_response_class_entry(), msg);
- ZVAL_OBJ(&zresponse, &msg_obj->zo);
+ ZVAL_OBJECT(&zresponse, &msg_obj->zo, 1);
ZVAL_OBJECT(&zrequest, &((php_http_message_object_t *) e->opaque)->zo, 1);
php_http_message_object_prepend(&zresponse, &zrequest, 1);
zend_update_property(php_http_get_client_response_class_entry(), &zresponse, ZEND_STRL("transferInfo"), &info);
zval_ptr_dtor(&info);
- Z_ADDREF(zresponse);
zend_llist_add_element(&client->responses, &msg_obj);
if (e->closure.fci.size) {
{
php_http_message_object_t *msg_obj = *(php_http_message_object_t **) data;
- zend_objects_store_del(&msg_obj->zo);
+ zend_object_release(&msg_obj->zo);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_construct, 0, 0, 0)
{
php_http_message_object_t *msg_obj = e->opaque;
- zend_objects_store_del(&msg_obj->zo);
+ zend_object_release(&msg_obj->zo);
zend_hash_destroy(e->options);
FREE_HASHTABLE(e->options);
if (e->closure.fci.size) {
zval_ptr_dtor(&e->closure.fci.function_name);
if (e->closure.fci.object) {
- zend_objects_store_del(e->closure.fci.object);
+ zend_object_release(e->closure.fci.object);
}
}
}
php_http_client_object_handlers.offset = XtOffsetOf(php_http_client_object_t, zo);
php_http_client_object_handlers.free_obj = php_http_client_object_free;
php_http_client_object_handlers.clone_obj = NULL;
+ php_http_client_object_handlers.get_gc = php_http_client_object_get_gc;
zend_declare_property_null(php_http_client_class_entry, ZEND_STRL("observers"), ZEND_ACC_PRIVATE);
zend_declare_property_null(php_http_client_class_entry, ZEND_STRL("options"), ZEND_ACC_PROTECTED);
zend_declare_property_null(php_http_client_class_entry, ZEND_STRL("history"), ZEND_ACC_PROTECTED);
php_http_object_method_t *update;
php_http_object_method_t notify;
long iterator;
+ zval *gc;
zend_object zo;
} php_http_client_object_t;
static size_t php_http_curle_read_callback(void *data, size_t len, size_t n, void *ctx)
{
- php_http_message_body_t *body = ctx;
+ php_stream *s = php_http_message_body_stream(ctx);
- if (body && body->res) {
- php_stream *s = php_http_message_body_stream(body);
-
- if (s) {
- return php_stream_read(s, data, len * n);
- } else abort();
+ if (s) {
+ return php_stream_read(s, data, len * n);
}
return 0;
}
copy = temp = php_http_message_init(to, 0, php_http_message_body_copy(from->body, NULL));
php_http_message_set_info(temp, &info);
- zend_hash_copy(&temp->hdrs, &from->hdrs, (copy_ctor_func_t) zval_add_ref);
+ array_copy(&from->hdrs, &temp->hdrs);
if (parents) while (from->parent) {
info.type = from->parent->type;
php_http_message_object_t *parent_obj = PHP_HTTP_OBJ(NULL, value);
if (obj->message->parent) {
- zend_objects_store_del(&obj->parent->zo);
+ zend_object_release(&obj->parent->zo);
}
Z_ADDREF_P(value);
obj->parent = parent_obj;
body_obj->body = php_http_message_body_init(NULL, NULL);
}
if (msg_obj->body) {
- zend_objects_store_del(&msg_obj->body->zo);
+ zend_object_release(&msg_obj->body->zo);
}
if (msg_obj->message) {
php_http_message_body_free(&msg_obj->message->body);
{
php_http_message_object_t *o = PHP_HTTP_OBJ(object, NULL);
+ PTR_FREE(o->gc);
+
if (!Z_ISUNDEF(o->iterator)) {
zval_ptr_dtor(&o->iterator);
ZVAL_UNDEF(&o->iterator);
o->message = NULL;
}
if (o->parent) {
- if (GC_REFCOUNT(&o->parent->zo) == 1) {
- zend_objects_store_del(&o->parent->zo);
- }
- zend_objects_store_del(&o->parent->zo);
+ zend_object_release(&o->parent->zo);
o->parent = NULL;
}
if (o->body) {
- if (GC_REFCOUNT(&o->body->zo) == 1) {
- zend_objects_store_del(&o->body->zo);
- }
- zend_objects_store_del(&o->body->zo);
+ zend_object_release(&o->body->zo);
o->body = NULL;
}
zend_object_std_dtor(object);
return props;
}
+static HashTable *php_http_message_object_get_gc(zval *object, zval **table, int *n)
+{
+ php_http_message_object_t *obj = PHP_HTTP_OBJ(NULL, object);
+ HashTable *props = Z_OBJPROP_P(object);
+ uint32_t count = 2 + zend_hash_num_elements(props);
+ zval *val;
+
+ *n = 0;
+ *table = obj->gc = erealloc(obj->gc, count * sizeof(zval));
+
+ if (obj->body) {
+ ZVAL_OBJ(&obj->gc[(*n)++], &obj->body->zo);
+ }
+ if (obj->parent) {
+ ZVAL_OBJ(&obj->gc[(*n)++], &obj->parent->zo);
+ }
+
+ ZEND_HASH_FOREACH_VAL(props, val)
+ {
+ ZVAL_COPY_VALUE(&obj->gc[(*n)++], val);
+ }
+ ZEND_HASH_FOREACH_END();
+
+ return NULL;
+}
+
ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage___construct, 0, 0, 0)
ZEND_ARG_INFO(0, message)
ZEND_ARG_INFO(0, greedy)
php_http_message_object_handlers.write_property = php_http_message_object_write_prop;
php_http_message_object_handlers.get_debug_info = php_http_message_object_get_debug_info;
php_http_message_object_handlers.get_property_ptr_ptr = NULL;
+ php_http_message_object_handlers.get_gc = php_http_message_object_get_gc;
zend_class_implements(php_http_message_class_entry, 3, spl_ce_Countable, zend_ce_serializable, zend_ce_iterator);
php_http_message_t *message;
struct php_http_message_object *parent;
php_http_message_body_object_t *body;
- zval iterator;
+ zval iterator, *gc;
zend_object zo;
} php_http_message_object_t;
body->res = stream->res;
++GC_REFCOUNT(body->res);
} else {
- stream = php_stream_temp_create(TEMP_STREAM_DEFAULT, 0xffff);
- body->res = stream->res;
+ body->res = php_stream_temp_create(TEMP_STREAM_DEFAULT, 0xffff)->res;
}
- php_stream_auto_cleanup(stream);
if (body_ptr) {
*body_ptr = body;
php_http_message_body_t *body = *body_ptr;
if (!--body->refcount) {
- zend_list_delete(body->res);
PTR_FREE(body->boundary);
efree(body);
}
zend_object_std_init(&o->zo, php_http_message_body_class_entry);
object_properties_init(&o->zo, ce);
+ o->gc = emalloc(sizeof(zval));
+
if (body) {
o->body = body;
+ php_stream_to_zval(php_http_message_body_stream(o->body), o->gc);
+
}
o->zo.handlers = &php_http_message_body_object_handlers;
return &new_obj->zo;
}
+static HashTable *php_http_message_body_object_get_gc(zval *object, zval **table, int *n)
+{
+ php_http_message_body_object_t *obj = PHP_HTTP_OBJ(NULL, object);
+ HashTable *props = Z_OBJPROP_P(object);
+ uint32_t count = zend_hash_num_elements(props);
+
+ *n = 1;
+ if (count) {
+ zval *val;
+
+ obj->gc = erealloc(obj->gc, (*n + count) * sizeof(zval));
+
+ ZEND_HASH_FOREACH_VAL(props, val)
+ {
+ ZVAL_COPY_VALUE(&obj->gc[(*n)++], val);
+ }
+ ZEND_HASH_FOREACH_END();
+ }
+ *table = obj->gc;
+
+ return NULL;
+}
+
void php_http_message_body_object_free(zend_object *object)
{
php_http_message_body_object_t *obj = PHP_HTTP_OBJ(object, NULL);
+ PTR_FREE(obj->gc);
php_http_message_body_free(&obj->body);
zend_object_std_dtor(object);
}
do { \
if (!obj->body) { \
obj->body = php_http_message_body_init(NULL, NULL); \
+ php_stream_to_zval(php_http_message_body_stream(obj->body), obj->gc); \
} \
} while(0)
php_http_message_body_free(&obj->body);
}
obj->body = php_http_message_body_init(NULL, stream);
+ php_stream_to_zval(stream, obj->gc);
}
}
php_stream *s = php_stream_memory_open(0, us_str, us_len);
obj->body = php_http_message_body_init(NULL, s);
+ php_stream_to_zval(s, obj->gc);
}
}
PHP_HTTP_MESSAGE_BODY_OBJECT_INIT(obj);
- ++GC_REFCOUNT(obj->body->res);
- RETVAL_RES(obj->body->res);
+ php_stream_to_zval(php_http_message_body_stream(obj->body), return_value);
+ Z_ADDREF_P(return_value);
}
}
php_http_message_body_object_handlers.offset = XtOffsetOf(php_http_message_body_object_t, zo);
php_http_message_body_object_handlers.clone_obj = php_http_message_body_object_clone;
php_http_message_body_object_handlers.free_obj = php_http_message_body_object_free;
+ php_http_message_body_object_handlers.get_gc = php_http_message_body_object_get_gc;
zend_class_implements(php_http_message_body_class_entry, 1, zend_ce_serializable);
return SUCCESS;
static inline php_stream *php_http_message_body_stream(php_http_message_body_t *body)
{
- return body->res->ptr;
+ return body && body->res ? body->res->ptr : NULL;
+}
+
+static inline zend_resource *php_http_message_body_resource(php_http_message_body_t *body)
+{
+ return body ? body->res : NULL;
}
typedef struct php_http_message_body_object {
php_http_message_body_t *body;
+ zval *gc;
zend_object zo;
} php_http_message_body_object_t;