Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 2 additions & 137 deletions vkext/vkext-rpc-tl-serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -924,39 +924,6 @@ inline void tl_debug(const char *s __attribute__((unused)), int n __attribute__(

/* {{{ Interface functions */

// returns 0 if no typedStore was found, otherwise returns allocated ZVAL with fetcher instance
bool store_function2(VK_ZVAL_API_P arr, zval *fetcher) {
ADD_CNT(store_function2)
START_TIMER(store_function2)
assert(arr);
if (Z_TYPE_P(arr) != IS_OBJECT) {
END_TIMER(store_function2)
return false;
}
vk_zend_call_known_instance_method(arr, "typedStore", strlen("typedStore"), fetcher, 0, NULL);
if (EG(exception)) {
// This behavior is consistent with old code, in this case, query_one will return qid 0
fprintf(stderr, "typedStore exception\n");
_zend_object* old_exception = EG(exception);
EG(exception) = NULL;
OBJ_RELEASE(old_exception);
END_TIMER(store_function2)
return false;
}
if (Z_TYPE_P(fetcher) != IS_OBJECT) {
// returned null or function not found (undef) or function returned something unexpected
if (Z_TYPE_P(fetcher) != IS_NULL) {
fprintf(stderr, "typedStore fetcher unexpected type is %d\n", Z_TYPE_P(fetcher));
}
END_TIMER(store_function2)
return false;
}
// when using fetcher, tl_current_function_name will not be accessed. But we set it anyway in case we forgot something.
tl_current_function_name = "typedStore";
END_TIMER(store_function2)
return true;
}

struct tl_tree *store_function(VK_ZVAL_API_P arr) {
ADD_CNT(store_function)
START_TIMER(store_function)
Expand Down Expand Up @@ -1116,8 +1083,7 @@ zval *fetch_function(struct tl_tree *T) {
if (*_arr) {
zval_dtor (*_arr);
}
*_arr = make_query_result_or_error(NULL, {TL_ERROR_RESPONSE_SYNTAX, "Can't parse response"});
return *_arr;
return make_query_result_or_error(NULL, {TL_ERROR_RESPONSE_SYNTAX, "Can't parse response"});
}
}

Expand All @@ -1137,29 +1103,6 @@ void _extra_dec_ref(struct rpc_query *q) {
struct rpc_query *vk_rpc_tl_query_one_impl(struct rpc_connection *c, double timeout, VK_ZVAL_API_P arr, int ignore_answer) {
do_rpc_clean();
START_TIMER (tmp);
zval fetcher;
ZVAL_NULL(&fetcher);
bool fetcher_found = store_function2(arr, &fetcher);
END_TIMER (tmp);
if (fetcher_found) {
struct rpc_query *q;
if (!(q = do_rpc_send_noflush(c, timeout, ignore_answer))) {
zval_ptr_dtor(&fetcher);
vkext_error(VKEXT_ERROR_NETWORK, "Can't send packet");
return 0;
}
if (q == (struct rpc_query *)1) { // answer is ignored
assert (ignore_answer);
zval_ptr_dtor(&fetcher);
return q;
}
assert (!ignore_answer);
ZVAL_COPY_VALUE(&q->fetcher, &fetcher);
q->extra_free = _extra_dec_ref;
total_tl_working++;
return q;
}
START_TIMER (tmp);
void *res = store_function(arr);
END_TIMER (tmp);
if (!res) {
Expand All @@ -1184,17 +1127,10 @@ struct rpc_query *vk_rpc_tl_query_one_impl(struct rpc_connection *c, double time
return q;
}

zval *fetch_function2(zval *fetcher);

zval *vk_rpc_tl_query_result_one_impl(struct tl_tree *T, zval *fetcher) {
tl_parse_init();
START_TIMER (tmp);
zval *r = NULL;
if (T) {
r = fetch_function(T);
}else{
r = fetch_function2(fetcher);
}
zval *r = fetch_function(T);
//fprintf(stderr, "~~~~ after fetch:\n");
//php_debug_zval_dump(*r, 1);
END_TIMER (tmp);
Expand Down Expand Up @@ -1420,77 +1356,6 @@ static zval *convert_rpc_extra_header_to_php_repr(const vkext_rpc::tl::RpcReqRes
return res;
}

zval *fetch_function2(zval *fetcher) {
ADD_CNT(fetch_function2)
START_TIMER(fetch_function2)

assert(fetcher);
assert(Z_TYPE_P(fetcher) == IS_OBJECT);

vkext_rpc::RpcError rpc_error;
rpc_error.try_fetch();
if (rpc_error.error.has_value()) {
zval *ret = make_query_result_or_error(NULL, rpc_error.error.value(), rpc_error.header.has_value() ? &rpc_error.header.value() : nullptr, rpc_error.flags);
END_TIMER(fetch_function2)
return ret;
}

zval* return_value;
VK_ALLOC_INIT_ZVAL(return_value);
ZVAL_UNDEF(return_value);
vk_zend_call_known_instance_method(fetcher, "typedFetch", strlen("typedFetch"), return_value, 0, NULL);
if (EG(exception)) {
efree(return_value); // it is UNDEF

_zend_object * old_exception = EG(exception);
EG(exception) = NULL;

zval exception_zval;
ZVAL_OBJ(&exception_zval, old_exception);

zval *message;
VK_ALLOC_INIT_ZVAL(message);
ZVAL_UNDEF(message);
vk_zend_call_known_instance_method(&exception_zval, "getMessage", strlen("getMessage"), message, 0, NULL);
// fprintf(stderr, "getMessage after call %d\n", Z_TYPE(message));
assert(Z_TYPE_P(message) == IS_STRING);

OBJ_RELEASE(old_exception);

zval *_err = create_php_instance(reqResult_error_class_name);

vk_zend_update_public_property_nod(_err, "error", message);

// vk_zend_update_public_property_string(_err, "error", "hren");
vk_zend_update_public_property_long(_err, "error_code", -1000);
END_TIMER(fetch_function2)
return _err;
}
// TODO - will remove later when everything works
// fprintf(stderr, "typedFetch after call %d\n", Z_TYPE_P(return_value));
if (Z_TYPE_P(return_value) != IS_OBJECT) { // should be never, but that is user code
zval *_err = create_php_instance(reqResult_error_class_name);
vk_zend_update_public_property_string(_err, "error", "fetcher->typedFetch() did not return object, as expected");
vk_zend_update_public_property_long(_err, "error_code", -1000);
END_TIMER(fetch_function2)
return _err;
}
if (rpc_error.header.has_value()) {
zval *wrapped_err = create_php_instance(reqResult_header_class_name);
zval *header_php_repr = convert_rpc_extra_header_to_php_repr(rpc_error.header.value());

set_field_int(&wrapped_err, rpc_error.flags, "flags", -1);
set_field(&wrapped_err, header_php_repr, "extra", -1);
set_field(&wrapped_err, return_value, "result", -1);
END_TIMER(fetch_function2)
return wrapped_err;
}
zval *wrapped_err = create_php_instance(reqResult_underscore_class_name);
set_field(&wrapped_err, return_value, "result", -1);
END_TIMER(fetch_function2)
return wrapped_err;
}

static zval *make_query_result_or_error(zval *r, const vkext_rpc::tl::RpcReqError &error, const vkext_rpc::tl::RpcReqResultExtra *header, int extra_flags) {
if (r) {
return r;
Expand Down
2 changes: 0 additions & 2 deletions vkext/vkext-rpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,7 @@ struct stats {
DECLARE_STAT(store);
DECLARE_STAT(fetch);
DECLARE_STAT(store_function);
DECLARE_STAT(store_function2);
DECLARE_STAT(fetch_function);
DECLARE_STAT(fetch_function2);
DECLARE_STAT(crc32);
DECLARE_STAT(tree_insert);
DECLARE_STAT(total);
Expand Down
2 changes: 1 addition & 1 deletion vkext/vkext.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "vkext/vk_zend.h"

#define VKEXT_VERSION "1.02"
#define VKEXT_VERSION "1.02-upload-crash-2"

#define VKEXT_NAME "vk_extension"

Expand Down
Loading