Skip to content

Commit 6bcfb08

Browse files
committed
gbuteyko/vkext_upload_crash_4
1 parent 7f6e8eb commit 6bcfb08

3 files changed

Lines changed: 82 additions & 3 deletions

File tree

vkext/vkext-rpc-tl-serialization.cpp

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,7 @@ bool store_function2(VK_ZVAL_API_P arr, zval *fetcher) {
955955
// when using fetcher, tl_current_function_name will not be accessed. But we set it anyway in case we forgot something.
956956
tl_current_function_name = "typedStore";
957957
END_TIMER(store_function2)
958-
return false;
958+
return true;
959959
}
960960

961961
struct tl_tree *store_function(VK_ZVAL_API_P arr) {
@@ -1184,10 +1184,17 @@ struct rpc_query *vk_rpc_tl_query_one_impl(struct rpc_connection *c, double time
11841184
return q;
11851185
}
11861186

1187+
zval *fetch_function2(zval *fetcher);
1188+
11871189
zval *vk_rpc_tl_query_result_one_impl(struct tl_tree *T, zval *fetcher) {
11881190
tl_parse_init();
11891191
START_TIMER (tmp);
1190-
zval *r = fetch_function(T);
1192+
zval *r = NULL;
1193+
if (T) {
1194+
r = fetch_function(T);
1195+
}else{
1196+
r = fetch_function2(fetcher);
1197+
}
11911198
//fprintf(stderr, "~~~~ after fetch:\n");
11921199
//php_debug_zval_dump(*r, 1);
11931200
END_TIMER (tmp);
@@ -1413,6 +1420,77 @@ static zval *convert_rpc_extra_header_to_php_repr(const vkext_rpc::tl::RpcReqRes
14131420
return res;
14141421
}
14151422

1423+
zval *fetch_function2(zval *fetcher) {
1424+
ADD_CNT(fetch_function2)
1425+
START_TIMER(fetch_function2)
1426+
1427+
assert(fetcher);
1428+
assert(Z_TYPE_P(fetcher) == IS_OBJECT);
1429+
1430+
vkext_rpc::RpcError rpc_error;
1431+
rpc_error.try_fetch();
1432+
if (rpc_error.error.has_value()) {
1433+
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);
1434+
END_TIMER(fetch_function2)
1435+
return ret;
1436+
}
1437+
1438+
zval* return_value;
1439+
VK_ALLOC_INIT_ZVAL(return_value);
1440+
ZVAL_UNDEF(return_value);
1441+
vk_zend_call_known_instance_method(fetcher, "typedFetch", strlen("typedFetch"), return_value, 0, NULL);
1442+
if (EG(exception)) {
1443+
efree(return_value); // it is UNDEF
1444+
1445+
_zend_object * old_exception = EG(exception);
1446+
EG(exception) = NULL;
1447+
1448+
zval exception_zval;
1449+
ZVAL_OBJ(&exception_zval, old_exception);
1450+
1451+
zval *message;
1452+
VK_ALLOC_INIT_ZVAL(message);
1453+
ZVAL_UNDEF(message);
1454+
vk_zend_call_known_instance_method(&exception_zval, "getMessage", strlen("getMessage"), message, 0, NULL);
1455+
// fprintf(stderr, "getMessage after call %d\n", Z_TYPE(message));
1456+
assert(Z_TYPE_P(message) == IS_STRING);
1457+
1458+
OBJ_RELEASE(old_exception);
1459+
1460+
zval *_err = create_php_instance(reqResult_error_class_name);
1461+
1462+
vk_zend_update_public_property_nod(_err, "error", message);
1463+
1464+
// vk_zend_update_public_property_string(_err, "error", "hren");
1465+
vk_zend_update_public_property_long(_err, "error_code", -1000);
1466+
END_TIMER(fetch_function2)
1467+
return _err;
1468+
}
1469+
// TODO - will remove later when everything works
1470+
// fprintf(stderr, "typedFetch after call %d\n", Z_TYPE_P(return_value));
1471+
if (Z_TYPE_P(return_value) != IS_OBJECT) { // should be never, but that is user code
1472+
zval *_err = create_php_instance(reqResult_error_class_name);
1473+
vk_zend_update_public_property_string(_err, "error", "fetcher->typedFetch() did not return object, as expected");
1474+
vk_zend_update_public_property_long(_err, "error_code", -1000);
1475+
END_TIMER(fetch_function2)
1476+
return _err;
1477+
}
1478+
if (rpc_error.header.has_value()) {
1479+
zval *wrapped_err = create_php_instance(reqResult_header_class_name);
1480+
zval *header_php_repr = convert_rpc_extra_header_to_php_repr(rpc_error.header.value());
1481+
1482+
set_field_int(&wrapped_err, rpc_error.flags, "flags", -1);
1483+
set_field(&wrapped_err, header_php_repr, "extra", -1);
1484+
set_field(&wrapped_err, return_value, "result", -1);
1485+
END_TIMER(fetch_function2)
1486+
return wrapped_err;
1487+
}
1488+
zval *wrapped_err = create_php_instance(reqResult_underscore_class_name);
1489+
set_field(&wrapped_err, return_value, "result", -1);
1490+
END_TIMER(fetch_function2)
1491+
return wrapped_err;
1492+
}
1493+
14161494
static zval *make_query_result_or_error(zval *r, const vkext_rpc::tl::RpcReqError &error, const vkext_rpc::tl::RpcReqResultExtra *header, int extra_flags) {
14171495
if (r) {
14181496
return r;

vkext/vkext-rpc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ struct stats {
306306
DECLARE_STAT(store_function);
307307
DECLARE_STAT(store_function2);
308308
DECLARE_STAT(fetch_function);
309+
DECLARE_STAT(fetch_function2);
309310
DECLARE_STAT(crc32);
310311
DECLARE_STAT(tree_insert);
311312
DECLARE_STAT(total);

vkext/vkext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#include "vkext/vk_zend.h"
99

10-
#define VKEXT_VERSION "1.02-upload-crash-3"
10+
#define VKEXT_VERSION "1.02-upload-crash-4"
1111

1212
#define VKEXT_NAME "vk_extension"
1313

0 commit comments

Comments
 (0)