Skip to content

Commit 2132126

Browse files
committed
Revert "TL parsing by vkext"
This reverts commit 5aa3078.
1 parent 58359ea commit 2132126

7 files changed

Lines changed: 23 additions & 202 deletions

File tree

vkext/vk_zend.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -226,24 +226,6 @@ static zend_always_inline void vk_zend_update_public_property_long(zval *object,
226226
#endif
227227
}
228228

229-
static zend_always_inline void vk_zend_call_known_instance_method(zval *object,
230-
const char * name, size_t name_len, zval *retval_ptr,
231-
uint32_t param_count, zval *params) {
232-
zend_object* zobj = Z_OBJ_P(object);
233-
zend_string* method_name = zend_string_init(name, name_len, 0);
234-
zend_function* fun = Z_OBJ_HANDLER_P(object, get_method)(&zobj, method_name, 0);
235-
zend_string_release(method_name);
236-
if (!fun) {
237-
return; // retval stays UNDEF
238-
}
239-
#if PHP_MAJOR_VERSION >= 8
240-
zend_call_known_instance_method(fun, zobj, retval_ptr, param_count, params);
241-
#else
242-
// TODO - this branch is not tested yet
243-
zend_call_known_instance_method(fun, object, retval_ptr, param_count, params);
244-
#endif
245-
}
246-
247229
#define ZAPI_TO_PP(az) (&(az))
248230
#define ZP_TO_API_P(az) (az)
249231
#define SMART_STRDATA(ss) ((ss).s)

vkext/vkext-rpc-req-error.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,13 @@ void tl::RpcReqError::tl_fetch() {
6868
}
6969

7070
void RpcError::try_fetch() {
71-
int op = tl_lookup_int();
71+
int op = tl_parse_int();
7272
if (op == TL_REQ_RESULT_HEADER) {
73-
(void)tl_parse_int(); // skip op
7473
flags = tl_parse_int();
7574
header.emplace().tl_fetch(flags);
76-
op = tl_lookup_int();
75+
op = tl_parse_int();
7776
}
7877
if (op == TL_RPC_REQ_ERROR) {
79-
(void)tl_parse_int(); // skip op
8078
error.emplace().tl_fetch();
8179
}
8280
}

vkext/vkext-rpc-tl-serialization.cpp

Lines changed: 18 additions & 167 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ static zval *create_php_instance(const char *class_name) {
532532
return ci;
533533
}
534534

535-
static zval *make_query_result_or_error(zval *r, const vkext_rpc::tl::RpcReqError &error, const vkext_rpc::tl::RpcReqResultExtra *header = nullptr, int extra_flags = 0);
535+
static zval *make_query_result_or_error(zval **r, const vkext_rpc::tl::RpcReqError &error, const vkext_rpc::tl::RpcReqResultExtra *header = nullptr, int extra_flags = 0);
536536

537537
/**
538538
* This function extracts ORIGINAL tl name from given php class name.
@@ -924,36 +924,6 @@ inline void tl_debug(const char *s __attribute__((unused)), int n __attribute__(
924924

925925
/* {{{ Interface functions */
926926

927-
// returns 0 if no typedStore was found, otherwise returns allocated ZVAL with fetcher instance
928-
bool store_function2(VK_ZVAL_API_P arr, zval *fetcher) {
929-
ADD_CNT(store_function2)
930-
START_TIMER(store_function2)
931-
assert(arr);
932-
if (Z_TYPE_P(arr) != IS_OBJECT) {
933-
END_TIMER(store_function2)
934-
return false;
935-
}
936-
vk_zend_call_known_instance_method(arr, "typedStore", strlen("typedStore"), fetcher, 0, NULL);
937-
if (EG(exception)) {
938-
// This behavior is consistent with old code, in this case, query_one will return qid 0
939-
fprintf(stderr, "typedStore exception\n");
940-
_zend_object* old_exception = EG(exception);
941-
EG(exception) = NULL;
942-
OBJ_RELEASE(old_exception);
943-
END_TIMER(store_function2)
944-
return false;
945-
}
946-
if (Z_TYPE_P(fetcher) != IS_OBJECT) { // returned null or function not found
947-
fprintf(stderr, "typedStore fetcher type is %d\n", Z_TYPE_P(fetcher));
948-
END_TIMER(store_function2)
949-
return false;
950-
}
951-
// when using fetcher, tl_current_function_name will not be accessed. But we set it anyway in case we forgot something.
952-
tl_current_function_name = "typedStore";
953-
END_TIMER(store_function2)
954-
return true;
955-
}
956-
957927
struct tl_tree *store_function(VK_ZVAL_API_P arr) {
958928
ADD_CNT(store_function)
959929
START_TIMER(store_function)
@@ -1064,7 +1034,7 @@ struct tl_tree *store_function(VK_ZVAL_API_P arr) {
10641034
return reinterpret_cast<tl_tree *>(res);
10651035
}
10661036

1067-
zval *fetch_function(struct tl_tree *T) {
1037+
zval **fetch_function(struct tl_tree *T) {
10681038
ADD_CNT(fetch_function)
10691039
START_TIMER(fetch_function)
10701040
#ifdef VLOG
@@ -1087,10 +1057,10 @@ zval *fetch_function(struct tl_tree *T) {
10871057
vkext_rpc::RpcError rpc_error;
10881058
rpc_error.try_fetch();
10891059
if (rpc_error.error.has_value()) {
1090-
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);
1060+
*_arr = make_query_result_or_error(NULL, rpc_error.error.value(), rpc_error.header.has_value() ? &rpc_error.header.value() : nullptr, rpc_error.flags);
10911061
DEC_REF (T);
10921062
END_TIMER(fetch_function)
1093-
return ret;
1063+
return _arr;
10941064
}
10951065
tl_parse_restore_pos(pos);
10961066

@@ -1108,55 +1078,28 @@ zval *fetch_function(struct tl_tree *T) {
11081078
VK_ALLOC_INIT_ZVAL(*_arr);
11091079
ZVAL_BOOL (*_arr, 1);
11101080
}
1111-
return *_arr;
1081+
return _arr;
11121082
} else {
11131083
if (*_arr) {
11141084
zval_dtor (*_arr);
11151085
}
11161086
*_arr = make_query_result_or_error(NULL, {TL_ERROR_RESPONSE_SYNTAX, "Can't parse response"});
1117-
return *_arr;
1087+
return _arr;
11181088
}
11191089
}
11201090

11211091
void _extra_dec_ref(struct rpc_query *q) {
1122-
if (!q->extra_free) {
1123-
return;
1124-
}
1125-
q->extra_free = 0;
1126-
total_tl_working--;
11271092
if (q->extra) {
1128-
DEC_REF (q->extra);
1129-
q->extra = 0;
1093+
total_tl_working--;
11301094
}
1131-
zval_ptr_dtor(&q->fetcher);
1095+
DEC_REF (q->extra);
1096+
q->extra = 0;
1097+
q->extra_free = 0;
11321098
}
11331099

11341100
struct rpc_query *vk_rpc_tl_query_one_impl(struct rpc_connection *c, double timeout, VK_ZVAL_API_P arr, int ignore_answer) {
11351101
do_rpc_clean();
11361102
START_TIMER (tmp);
1137-
zval fetcher;
1138-
ZVAL_NULL(&fetcher);
1139-
bool fetcher_found = store_function2(arr, &fetcher);
1140-
END_TIMER (tmp);
1141-
if (fetcher_found) {
1142-
struct rpc_query *q;
1143-
if (!(q = do_rpc_send_noflush(c, timeout, ignore_answer))) {
1144-
zval_ptr_dtor(&fetcher);
1145-
vkext_error(VKEXT_ERROR_NETWORK, "Can't send packet");
1146-
return 0;
1147-
}
1148-
if (q == (struct rpc_query *)1) { // answer is ignored
1149-
assert (ignore_answer);
1150-
zval_ptr_dtor(&fetcher);
1151-
return q;
1152-
}
1153-
assert (!ignore_answer);
1154-
ZVAL_COPY_VALUE(&q->fetcher, &fetcher);
1155-
q->extra_free = _extra_dec_ref;
1156-
total_tl_working++;
1157-
return q;
1158-
}
1159-
START_TIMER (tmp);
11601103
void *res = store_function(arr);
11611104
END_TIMER (tmp);
11621105
if (!res) {
@@ -1175,23 +1118,15 @@ struct rpc_query *vk_rpc_tl_query_one_impl(struct rpc_connection *c, double time
11751118
}
11761119
assert (!ignore_answer);
11771120
q->extra = res;
1178-
ZVAL_NULL(&q->fetcher);
11791121
q->extra_free = _extra_dec_ref;
11801122
total_tl_working++;
11811123
return q;
11821124
}
11831125

1184-
zval *fetch_function2(zval *fetcher);
1185-
1186-
zval *vk_rpc_tl_query_result_one_impl(struct tl_tree *T, zval *fetcher) {
1126+
zval **vk_rpc_tl_query_result_one_impl(struct tl_tree *T) {
11871127
tl_parse_init();
11881128
START_TIMER (tmp);
1189-
zval *r = NULL;
1190-
if (T) {
1191-
r = fetch_function(T);
1192-
}else{
1193-
r = fetch_function2(fetcher);
1194-
}
1129+
zval **r = fetch_function(T);
11951130
//fprintf(stderr, "~~~~ after fetch:\n");
11961131
//php_debug_zval_dump(*r, 1);
11971132
END_TIMER (tmp);
@@ -1417,79 +1352,9 @@ static zval *convert_rpc_extra_header_to_php_repr(const vkext_rpc::tl::RpcReqRes
14171352
return res;
14181353
}
14191354

1420-
zval *fetch_function2(zval *fetcher) {
1421-
ADD_CNT(fetch_function2)
1422-
START_TIMER(fetch_function2)
1423-
1424-
assert(fetcher);
1425-
assert(Z_TYPE_P(fetcher) == IS_OBJECT);
1426-
1427-
vkext_rpc::RpcError rpc_error;
1428-
rpc_error.try_fetch();
1429-
if (rpc_error.error.has_value()) {
1430-
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);
1431-
END_TIMER(fetch_function2)
1432-
return ret;
1433-
}
1434-
1435-
zval* return_value;
1436-
VK_ALLOC_INIT_ZVAL(return_value);
1437-
ZVAL_UNDEF(return_value);
1438-
vk_zend_call_known_instance_method(fetcher, "typedFetch", strlen("typedFetch"), return_value, 0, NULL);
1439-
if (EG(exception)) {
1440-
efree(return_value); // it is UNDEF
1441-
1442-
_zend_object * old_exception = EG(exception);
1443-
EG(exception) = NULL;
1444-
1445-
zval exception_zval;
1446-
ZVAL_OBJ(&exception_zval, old_exception);
1447-
1448-
zval *message;
1449-
VK_ALLOC_INIT_ZVAL(message);
1450-
ZVAL_UNDEF(message);
1451-
vk_zend_call_known_instance_method(&exception_zval, "getMessage", strlen("getMessage"), message, 0, NULL);
1452-
// fprintf(stderr, "getMessage after call %d\n", Z_TYPE(message));
1453-
assert(Z_TYPE_P(message) == IS_STRING);
1454-
1455-
OBJ_RELEASE(old_exception);
1456-
1457-
zval *_err = create_php_instance(reqResult_error_class_name);
1458-
1459-
vk_zend_update_public_property_nod(_err, "error", message);
1460-
1461-
// vk_zend_update_public_property_string(_err, "error", "hren");
1462-
vk_zend_update_public_property_long(_err, "error_code", -1000);
1463-
END_TIMER(fetch_function2)
1464-
return _err;
1465-
}
1466-
fprintf(stderr, "typedFetch after call %d\n", Z_TYPE_P(return_value));
1467-
if (Z_TYPE_P(return_value) != IS_OBJECT) { // should be never, but that is user code
1468-
zval *_err = create_php_instance(reqResult_error_class_name);
1469-
vk_zend_update_public_property_string(_err, "error", "fetcher->typedFetch() did not return object, as expected");
1470-
vk_zend_update_public_property_long(_err, "error_code", -1000);
1471-
END_TIMER(fetch_function2)
1472-
return _err;
1473-
}
1474-
if (rpc_error.header.has_value()) {
1475-
zval *wrapped_err = create_php_instance(reqResult_header_class_name);
1476-
zval *header_php_repr = convert_rpc_extra_header_to_php_repr(rpc_error.header.value());
1477-
1478-
set_field_int(&wrapped_err, rpc_error.flags, "flags", -1);
1479-
set_field(&wrapped_err, header_php_repr, "extra", -1);
1480-
set_field(&wrapped_err, return_value, "result", -1);
1481-
END_TIMER(fetch_function2)
1482-
return wrapped_err;
1483-
}
1484-
zval *wrapped_err = create_php_instance(reqResult_underscore_class_name);
1485-
set_field(&wrapped_err, return_value, "result", -1);
1486-
END_TIMER(fetch_function2)
1487-
return wrapped_err;
1488-
}
1489-
1490-
static zval *make_query_result_or_error(zval *r, const vkext_rpc::tl::RpcReqError &error, const vkext_rpc::tl::RpcReqResultExtra *header, int extra_flags) {
1355+
static zval *make_query_result_or_error(zval **r, const vkext_rpc::tl::RpcReqError &error, const vkext_rpc::tl::RpcReqResultExtra *header, int extra_flags) {
14911356
if (r) {
1492-
return r;
1357+
return *r;
14931358
}
14941359
zval *_err;
14951360
switch (typed_mode) {
@@ -1539,22 +1404,13 @@ void vk_rpc_tl_query_result_impl(struct rpc_queue *Q, double timeout, zval **r)
15391404
}
15401405
struct rpc_query *q = rpc_query_get(qid);
15411406
tl_tree *T = reinterpret_cast<tl_tree *>(q->extra);
1542-
zval fetcher;
1543-
ZVAL_COPY(&fetcher, &q->fetcher);
15441407
tl_current_function_name = q->fun_name;
1545-
if (T) {
1546-
INC_REF (T);
1547-
}
1408+
INC_REF (T);
15481409

15491410
if (do_rpc_get_and_parse(qid, timeout - precise_now) < 0) {
1550-
// TODO - most likely. leak here (of both T and fetcher).
1551-
// But it is difficult to simulate this situation, so
1552-
// we decided to keep leak to avoid double delete in case we
1553-
// failed to completely understand this code.
15541411
continue;
15551412
}
1556-
zval *res = make_query_result_or_error(vk_rpc_tl_query_result_one_impl(T, &fetcher), {TL_ERROR_RESPONSE_NOT_FOUND, "Response not found, probably timed out"});
1557-
zval_ptr_dtor(&fetcher);
1413+
zval *res = make_query_result_or_error(vk_rpc_tl_query_result_one_impl(T), {TL_ERROR_RESPONSE_NOT_FOUND, "Response not found, probably timed out"});
15581414
vk_add_index_zval_nod (*r, qid, res);
15591415
}
15601416
}
@@ -1585,19 +1441,14 @@ void vk_rpc_tl_query_result_one(INTERNAL_FUNCTION_PARAMETERS) {
15851441
double timeout = (argc < 2) ? q->timeout : precise_now + parse_zend_double(VK_ZVAL_ARRAY_TO_API_P(z[1]));
15861442
END_TIMER (parse);
15871443
auto *T = reinterpret_cast<tl_tree *>(q->extra);
1588-
zval fetcher;
1589-
ZVAL_COPY(&fetcher, &q->fetcher);
1590-
if (T) {
1591-
INC_REF (T);
1592-
}
1444+
INC_REF (T);
15931445
if (do_rpc_get_and_parse(qid, timeout - precise_now) < 0) {
15941446
zval *r = make_query_result_or_error(NULL, {TL_ERROR_RESPONSE_NOT_FOUND, "Response not found, probably timed out"});
15951447
RETVAL_ZVAL(r, false, true);
15961448
efree(r);
15971449
return;
15981450
}
1599-
zval *r = make_query_result_or_error(vk_rpc_tl_query_result_one_impl(T, &fetcher), {TL_ERROR_RESPONSE_NOT_FOUND, "Response not found, probably timed out"});
1600-
zval_ptr_dtor(&fetcher);
1451+
zval *r = make_query_result_or_error(vk_rpc_tl_query_result_one_impl(T), {TL_ERROR_RESPONSE_NOT_FOUND, "Response not found, probably timed out"});
16011452
RETVAL_ZVAL(r, false, true);
16021453
efree(r);
16031454
}

vkext/vkext-rpc.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,9 @@ static struct rpc_query *rpc_query_alloc(double timeout) {
854854
q->qid = qid;
855855
q->start_time = precise_now;
856856
q->timeout = timeout;
857-
q->fun_name = tl_current_function_name;
857+
if (tl_current_function_name) {
858+
q->fun_name = tl_current_function_name;
859+
}
858860
/* ADD_CNT(tree_insert);
859861
START_TICKS(tree_insert);
860862
query_tree = tree_insert_query (query_tree, q, lrand48 ());

vkext/vkext-rpc.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ struct rpc_query {
113113
int answer_len;
114114
enum query_status status;
115115
void *extra;
116-
zval fetcher; // set if extra == NULL
117116
void (*extra_free)(struct rpc_query *);
118117
const char *fun_name;
119118
};
@@ -304,9 +303,7 @@ struct stats {
304303
DECLARE_STAT(store);
305304
DECLARE_STAT(fetch);
306305
DECLARE_STAT(store_function);
307-
DECLARE_STAT(store_function2);
308306
DECLARE_STAT(fetch_function);
309-
DECLARE_STAT(fetch_function2);
310307
DECLARE_STAT(crc32);
311308
DECLARE_STAT(tree_insert);
312309
DECLARE_STAT(total);

vkext/vkext-tl-parse.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,6 @@ int tl_parse_int() {
2727
return do_rpc_fetch_int(&tl.error);
2828
}
2929

30-
int tl_lookup_int() {
31-
if (tl.error) {
32-
return -1;
33-
}
34-
return do_rpc_lookup_int(&tl.error);
35-
}
36-
3730
long long tl_parse_long() {
3831
if (tl.error) {
3932
return -1;
@@ -97,7 +90,6 @@ std::string tl_parse_string() {
9790
return res;
9891
}
9992
res.assign(s);
100-
free(s);
10193
return res;
10294
}
10395

vkext/vkext-tl-parse.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
void tl_parse_init();
1111
int tl_parse_int();
12-
int tl_lookup_int();
1312
long long tl_parse_long();
1413
double tl_parse_double();
1514
float tl_parse_float();

0 commit comments

Comments
 (0)