X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=http_message_object.c;h=c642754c73641b81bf4182bee3a71d25ebc7f658;hb=7904ebbfd747d11f0821d2b2712600ab07a36ff6;hp=ad4d8277ef02d829f0c9878288ebee4937689efa;hpb=778163476c4500a8554c35c68dfc9c0cd33f82f8;p=m6w6%2Fext-http diff --git a/http_message_object.c b/http_message_object.c index ad4d827..c642754 100644 --- a/http_message_object.c +++ b/http_message_object.c @@ -209,6 +209,56 @@ PHP_MINIT_FUNCTION(http_message_object) return SUCCESS; } +void _http_message_object_reverse(zval *this_ptr, zval *return_value TSRMLS_DC) +{ + int i; + getObject(http_message_object, obj); + + /* count */ + http_message_count(i, obj->message); + + if (i > 1) { + zval o; + zend_object_value *ovalues = NULL; + http_message_object **objects = NULL; + int last = i - 1; + + objects = ecalloc(i, sizeof(http_message_object *)); + ovalues = ecalloc(i, sizeof(zend_object_value)); + + /* we are the first message */ + objects[0] = obj; + ovalues[0] = getThis()->value.obj; + + /* fetch parents */ + INIT_PZVAL(&o); + o.type = IS_OBJECT; + for (i = 1; obj->parent.handle; ++i) { + o.value.obj = obj->parent; + ovalues[i] = o.value.obj; + objects[i] = obj = zend_object_store_get_object(&o TSRMLS_CC); + } + + /* reorder parents */ + for (last = --i; i; --i) { + objects[i]->message->parent = objects[i-1]->message; + objects[i]->parent = ovalues[i-1]; + } + objects[0]->message->parent = NULL; + objects[0]->parent.handle = 0; + objects[0]->parent.handlers = NULL; + + /* add ref (why?) */ + Z_OBJ_ADDREF_P(getThis()); + RETVAL_OBJVAL(ovalues[last], 1); + + efree(objects); + efree(ovalues); + } else { + RETURN_ZVAL(getThis(), 1, 0); + } +} + void _http_message_object_prepend_ex(zval *this_ptr, zval *prepend, zend_bool top TSRMLS_DC) { zval m; @@ -1382,53 +1432,8 @@ PHP_METHOD(HttpMessage, prepend) */ PHP_METHOD(HttpMessage, reverse) { - int i; - getObject(http_message_object, obj); - - NO_ARGS; - - /* count */ - http_message_count(i, obj->message); - - if (i > 1) { - zval o; - zend_object_value *ovalues = NULL; - http_message_object **objects = NULL; - int last = i - 1; - - objects = ecalloc(i, sizeof(http_message_object *)); - ovalues = ecalloc(i, sizeof(zend_object_value)); - - /* we are the first message */ - objects[0] = obj; - ovalues[0] = getThis()->value.obj; - - /* fetch parents */ - INIT_PZVAL(&o); - o.type = IS_OBJECT; - for (i = 1; obj->parent.handle; ++i) { - o.value.obj = obj->parent; - ovalues[i] = o.value.obj; - objects[i] = obj = zend_object_store_get_object(&o TSRMLS_CC); - } - - /* reorder parents */ - for (last = --i; i; --i) { - objects[i]->message->parent = objects[i-1]->message; - objects[i]->parent = ovalues[i-1]; - } - objects[0]->message->parent = NULL; - objects[0]->parent.handle = 0; - objects[0]->parent.handlers = NULL; - - /* add ref (why?) */ - Z_OBJ_ADDREF_P(getThis()); - RETVAL_OBJVAL(ovalues[last], 1); - - efree(objects); - efree(ovalues); - } else { - RETURN_ZVAL(getThis(), 1, 0); + NO_ARGS { + http_message_object_reverse(getThis(), return_value); } } /* }}} */