box: introduce c_func_iproto_multireturn in compat
With this option enabled (new), the multiresults returned by a stored C function via iproto aren't wrapped in the additional msgpack array (old). Due to new behaviour some renames are performed: * `port_c_dump_msgpack()` -> `port_c_dump_msgpack_wrapped()`, since this is dump format with additional msgpack array encoded. * `port_c_dump_msgpack16()` -> `port_c_dump_msgpack()`, since this format is now the default new format of a msgpack dump. The behaviour of the C port msgpack dumping depends on the `c_func_iproto_multireturn` option: * uses `port_c_dump_msgpack()` if set to true (new), * uses `port_c_dump_msgpack_wrapped()` otherwise (old). Needed for #4799 @TarantoolBot document Title: Document `c_func_iproto_multireturn` compat option Please create a documentation page for the new compat option: https://tarantool.io/compat/c_func_iproto_multireturn In the new behaviour, the multiresults returned by a stored C function via iproto aren't wrapped in the additional msgpack array (old). ``` tarantool> compat.c_func_iproto_multireturn = 'old' --- ... tarantool> net_box.connect(box.cfg.listen):call('myclib.cfunc') --- - [true, -1] ... tarantool> compat.c_func_iproto_multireturn = 'new' --- ... tarantool> net_box.connect(box.cfg.listen):call('myclib.cfunc') --- - true - -1 ... ``` The new behaviour is consistent with the local call of the function via `box.func`: ``` tarantool> box.func['myclib.cfunc']:call() --- - true - -1 ... ``` Assume you have a stored C function that returns values like the following: ```c char *position = mp_encode_bool(buffer, true); box_return_mp(ctx, buffer, position); /* ... */ position = mp_encode_int(buffer, -1); box_return_mp(ctx, buffer, position); ``` If you want to preserve the format of the returned array for your C functions, when the `c_func_iproto_multireturn` option is set to "new", you should add the additional wrapping, like the following: ```c char *position = mp_encode_array(buffer_with_results, n_results); position = mp_encode_bool(position, true); /* ... */ position = mp_encode_int(position, -1); box_return_mp(ctx, buffer_with_results, position); ``` The amount of `box_return_mp()` calls indicates the number of values to be returned. Also, you should update its usage via `box.func` if there is any.
Showing
- changelogs/unreleased/gh-4799-consistent-c-functions-calls.md 5 additions, 0 deletions...gelogs/unreleased/gh-4799-consistent-c-functions-calls.md
- src/box/port.c 27 additions, 6 deletionssrc/box/port.c
- src/box/port.h 9 additions, 0 deletionssrc/box/port.h
- src/box/sql/port.c 1 addition, 1 deletionsrc/box/sql/port.c
- src/lua/compat.lua 14 additions, 0 deletionssrc/lua/compat.lua
- test/box-luatest/CMakeLists.txt 3 additions, 0 deletionstest/box-luatest/CMakeLists.txt
- test/box-luatest/gh_4799_fix_c_stored_functions_call.c 17 additions, 0 deletionstest/box-luatest/gh_4799_fix_c_stored_functions_call.c
- test/box-luatest/gh_4799_fix_c_stored_functions_call_test.lua 52 additions, 0 deletions.../box-luatest/gh_4799_fix_c_stored_functions_call_test.lua
Loading
Please register or sign in to comment