Skip to content

Commit 6660e1c

Browse files
hrissandenisichh
authored andcommitted
fetch_get_pos in all runtimes (#1507)
1 parent 3e2b881 commit 6660e1c

File tree

12 files changed

+44
-2
lines changed

12 files changed

+44
-2
lines changed

builtin-functions/kphp-full/_functions.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,8 @@ function fetch_memcache_value () ::: mixed;
914914
function fetch_eof () ::: bool;
915915
/** @kphp-extern-func-info can_throw */
916916
function fetch_end () ::: bool;
917+
/** @kphp-extern-func-info */
918+
function fetch_get_pos () ::: int;
917919

918920
/** @kphp-extern-func-info can_throw */
919921
function fetch_lookup_int () ::: int;

builtin-functions/kphp-light/stdlib/rpc.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ function fetch_string () ::: string;
8585
/** @kphp-extern-func-info can_throw */
8686
function fetch_string2 () ::: string;
8787

88+
/** @kphp-extern-func-info */
89+
function fetch_get_pos () ::: int;
90+
8891
function store_int ($v ::: int) ::: bool;
8992
function store_byte ($v ::: int) ::: bool;
9093
function store_long ($v ::: int) ::: bool;

runtime-light/stdlib/rpc/rpc-api.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ inline string f$fetch_string2() noexcept {
182182
return {};
183183
}
184184

185+
inline int64_t f$fetch_get_pos() noexcept {
186+
return static_cast<int64_t>(RpcServerInstanceState::get().tl_fetcher.pos());
187+
}
188+
185189
inline void f$fetch_raw_vector_double(array<double>& vector, int64_t num_elems) noexcept {
186190
auto& tl_fetcher{RpcServerInstanceState::get().tl_fetcher};
187191
const auto len_bytes{sizeof(double) * num_elems};

runtime/rpc.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,10 @@ bool f$fetch_end() {
483483
return true;
484484
}
485485

486+
int64_t f$fetch_get_pos() {
487+
return rpc_get_pos();
488+
}
489+
486490
C$RpcConnection::C$RpcConnection(int32_t host_num, int32_t port, int32_t timeout_ms, int32_t actor_id, int32_t connect_timeout, int32_t reconnect_timeout)
487491
: host_num(host_num),
488492
port(port),

runtime/rpc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ bool f$fetch_eof();
107107

108108
bool f$fetch_end();
109109

110+
int64_t f$fetch_get_pos();
111+
110112
void f$fetch_raw_vector_double(array<double>& out, int64_t n_elems);
111113

112114
void estimate_and_flush_overflow(size_t& bytes_sent);

vkext/vkext-rpc.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3112,6 +3112,14 @@ void php_rpc_fetch_end(INTERNAL_FUNCTION_PARAMETERS) { /* {{{ */
31123112

31133113
/* }}} */
31143114

3115+
void php_rpc_fetch_get_pos(INTERNAL_FUNCTION_PARAMETERS) { /* {{{ */
3116+
char *error = 0;
3117+
int value = do_rpc_fetch_get_pos(&error);
3118+
RETURN_LONG (value); // do not overcomplicate, any wrong state has position 0
3119+
}
3120+
3121+
/* }}} */
3122+
31153123
void php_rpc_queue_create(INTERNAL_FUNCTION_PARAMETERS) { /* {{{ */
31163124
ADD_CNT (parse);
31173125
START_TIMER (parse);

vkext/vkext-rpc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ void php_rpc_fetch_float(INTERNAL_FUNCTION_PARAMETERS);
182182
void php_rpc_fetch_string(INTERNAL_FUNCTION_PARAMETERS);
183183
void php_rpc_fetch_string2(INTERNAL_FUNCTION_PARAMETERS);
184184
void php_rpc_fetch_end(INTERNAL_FUNCTION_PARAMETERS);
185+
void php_rpc_fetch_get_pos(INTERNAL_FUNCTION_PARAMETERS);
185186

186187
void php_rpc_fetch_lookup_int(INTERNAL_FUNCTION_PARAMETERS);
187188
void php_rpc_fetch_lookup_data(INTERNAL_FUNCTION_PARAMETERS);

vkext/vkext-tl-parse.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,8 @@ int tl_parse_save_pos() {
119119
if (error) {
120120
tl_set_error(error);
121121
return 0;
122-
} else {
123-
return r;
124122
}
123+
return r;
125124
}
126125

127126
int tl_parse_restore_pos(int pos) {

vkext/vkext.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,13 @@ PHP_FUNCTION (fetch_eof) {
965965
END_TIMER(total);
966966
}
967967

968+
PHP_FUNCTION (fetch_get_pos) {
969+
ADD_CNT(total);
970+
START_TIMER(total);
971+
php_rpc_fetch_get_pos(INTERNAL_FUNCTION_PARAM_PASSTHRU);
972+
END_TIMER(total);
973+
}
974+
968975
PHP_FUNCTION (rpc_queue_create) {
969976
ADD_CNT(total);
970977
START_TIMER(total);

vkext/vkext.stub.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ function fetch_eof() : bool {
195195
return false;
196196
}
197197

198+
function fetch_get_pos() : int {
199+
return 0;
200+
}
201+
198202
/**
199203
* @return int|false
200204
*/

0 commit comments

Comments
 (0)