diff --git a/doc/user/stored-procedures.xml b/doc/user/stored-procedures.xml index c59fb6b45c33e727b9136646e879ab59e7cdb381..5beb1691d4f756ff07808116032dabd725cac658 100644 --- a/doc/user/stored-procedures.xml +++ b/doc/user/stored-procedures.xml @@ -732,11 +732,14 @@ lua box.dostring('local f = function(key) t=box.select(0, 0, key); if t ~= nil t </term> <listitem> <para> - Generate 128-bit (16 bytes) unique id. + Generate 128-bit (16 bytes) unique id. The id + is returned in binary form. </para> <para> - Require <emphasis>libuuid</emphasis> to be - installed. + Requires <emphasis>libuuid</emphasis> library to be + installed. The library is loaded in runtime, + and if the library is not available, this + function returns an error. </para> </listitem> </varlistentry> @@ -758,23 +761,6 @@ lua box.dostring('local f = function(key) t=box.select(0, 0, key); if t ~= nil t </programlisting> </listitem> </varlistentry> - <varlistentry> - <term> - <emphasis role="lua">box.uuid_is_loaded()</emphasis> - </term> - <listitem> - <para> - Check if <emphasis>libuuid</emphasis> is available - and loaded. - </para> - <bridgehead renderas="sect4">Example</bridgehead> - <programlisting> - lua box.uuid_is_loaded() - --- - - 1 - ... - </programlisting> - </listitem> </variablelist> <variablelist> diff --git a/mod/box/CMakeLists.txt b/mod/box/CMakeLists.txt index a6d811e45940b81f65c64e11d6bc5822b20bb82b..185e2f4cf6ef8406f31d603ce3fb8ca5d0bbe3c7 100644 --- a/mod/box/CMakeLists.txt +++ b/mod/box/CMakeLists.txt @@ -2,7 +2,6 @@ if (TARGET_OS_DARWIN) set(module_link_flags "-pagezero_size 10000 -image_base 100000000") endif() - add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/mod/box/memcached-grammar.m WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} COMMAND ${RAGEL} -G2 mod/box/memcached-grammar.rl diff --git a/mod/box/box_lua_uuid.h b/mod/box/box_lua_uuid.h index c2fbb0ba6b60644c5fae33c4f19b081d8549f249..2bd9bd75388d22533f5cb7decac7e12ff6cbe0d6 100644 --- a/mod/box/box_lua_uuid.h +++ b/mod/box/box_lua_uuid.h @@ -1,9 +1,39 @@ -#ifndef __BOX_LUA_UUID_H__ -#define __BOX_LUA_UUID_H__ +#ifndef INCLUDES_TARANTOOL_MOD_BOX_LUA_UUID_H +#define INCLUDES_TARANTOOL_MOD_BOX_LUA_UUID_H +/* + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * 1. Redistributions of source code must retain the above + * copyright notice, this list of conditions and the + * following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ struct lua_State; -int lbox_uuid(struct lua_State *L); -int lbox_uuid_hex(struct lua_State *L); +int +lbox_uuid(struct lua_State *L); +int +lbox_uuid_hex(struct lua_State *L); -#endif /* __BOX_LUA_UUID_H__ */ +#endif /* INCLUDES_TARANTOOL_MOD_BOX_LUA_UUID_H */ diff --git a/mod/box/box_lua_uuid.m b/mod/box/box_lua_uuid.m index bb0ceadc9dca452585c37dae8593a3f7636ecc1f..16c281061680374802d90b77bb196346a47590fa 100644 --- a/mod/box/box_lua_uuid.m +++ b/mod/box/box_lua_uuid.m @@ -1,45 +1,75 @@ +/* + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * 1. Redistributions of source code must retain the above + * copyright notice, this list of conditions and the + * following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ +#include "box_lua_uuid.h" + #include <stdio.h> #include <string.h> #include <dlfcn.h> #include <alloca.h> -#include "box_lua_uuid.h" #include "lua.h" #include "lauxlib.h" #include "lualib.h" - -/* libuuid API */ +/** libuuid API */ typedef unsigned char uuid_t[16]; static void (*uuid_generate)(uuid_t uuid); +/** box functions */ +typedef int(*box_function)(struct lua_State *L); -/* box functions */ -typedef int(*box_foo)(struct lua_State *L); - - -static int lbox_uuid_load_and_call(lua_State *L); -static int lbox_uuid_hex_load_and_call(lua_State *L); +static int +lbox_uuid_load_and_call(lua_State *L); +static int +lbox_uuid_hex_load_and_call(lua_State *L); /* functions that are called after library is loaded */ -static int lbox_uuid_loaded(struct lua_State *L); -static int lbox_uuid_hex_loaded(struct lua_State *L); - -static box_foo - _lbox_uuid = lbox_uuid_load_and_call, - _lbox_uuid_hex = lbox_uuid_hex_load_and_call -; - +static int +lbox_uuid_loaded(struct lua_State *L); +static int +lbox_uuid_hex_loaded(struct lua_State *L); + +/** + * We load libuuid on first call to a box.uuid* + * function. Once the library is loaded, + * we reset function pointers and do not attempt + * to load it again. + */ +static box_function _lbox_uuid = lbox_uuid_load_and_call; +static box_function _lbox_uuid_hex = lbox_uuid_hex_load_and_call; + +static int +loaddl_and_call(struct lua_State *L, box_function f) +{ - -static int loaddl_and_call(struct lua_State *L, box_foo f, int raise) { - void *libuuid = dlopen("libuuid.so.1", RTLD_LAZY); - if (!libuuid) { - if (raise) - return luaL_error(L, "box.uuid(): %s", dlerror()); - else - return 0; - } + if (!libuuid) + return luaL_error(L, "box.uuid(): %s", dlerror()); uuid_generate = dlsym(libuuid, "uuid_generate"); if (!uuid_generate) { @@ -48,10 +78,7 @@ static int loaddl_and_call(struct lua_State *L, box_foo f, int raise) { char *sdl_error = alloca(strlen(dl_error) + 1); strcpy(sdl_error, dl_error); dlclose(libuuid); - if (raise) - return luaL_error(L, "box.uuid(): %s", sdl_error); - else - return 0; + return luaL_error(L, "box.uuid(): %s", sdl_error); } _lbox_uuid = lbox_uuid_loaded; @@ -59,8 +86,10 @@ static int loaddl_and_call(struct lua_State *L, box_foo f, int raise) { return f(L); } - -static int lbox_uuid_loaded(struct lua_State *L) { +/** Generate uuid (libuuid is loaded). */ +static int +lbox_uuid_loaded(struct lua_State *L) +{ uuid_t uuid; uuid_generate(uuid); @@ -68,12 +97,15 @@ static int lbox_uuid_loaded(struct lua_State *L) { return 1; } -static int lbox_uuid_hex_loaded(struct lua_State *L) { +/** Generate uuid hex (libuuid is loaded). */ +static int +lbox_uuid_hex_loaded(struct lua_State *L) +{ unsigned i; char uuid_hex[ sizeof(uuid_t) * 2 + 1 ]; uuid_t uuid; - + uuid_generate(uuid); for (i = 0; i < sizeof(uuid_t); i++) @@ -83,21 +115,25 @@ static int lbox_uuid_hex_loaded(struct lua_State *L) { return 1; } - -static int lbox_uuid_load_and_call(lua_State *L) { - return loaddl_and_call(L, lbox_uuid_loaded, 1); +static int +lbox_uuid_load_and_call(lua_State *L) +{ + return loaddl_and_call(L, lbox_uuid_loaded); } -static int lbox_uuid_hex_load_and_call(lua_State *L) { - return loaddl_and_call(L, lbox_uuid_hex_loaded, 1); +static int +lbox_uuid_hex_load_and_call(lua_State *L) +{ + return loaddl_and_call(L, lbox_uuid_hex_loaded); } - -int lbox_uuid(struct lua_State *L) { +int +lbox_uuid(struct lua_State *L) +{ return _lbox_uuid(L); } -int lbox_uuid_hex(struct lua_State *L) { +int lbox_uuid_hex(struct lua_State *L) +{ return _lbox_uuid_hex(L); } - diff --git a/test/box/lua.test b/test/box/lua.test index a31a1e17ebee1e394d728095d98fe0731f9208da..1efa74501939728373c563b65ef4e5b48ae2492e 100644 --- a/test/box/lua.test +++ b/test/box/lua.test @@ -534,4 +534,3 @@ exec admin "lua box.dostring('abc=2')" exec admin "lua box.dostring('return abc')" exec admin "lua box.dostring('return ...', 1, 2, 3)" - diff --git a/test/lib/test_suite.py b/test/lib/test_suite.py index c9bb178b37a468e0ddd8c8f2b6473314da1186fe..4b8a82dd6e40ee319a04841dab26665608991ff8 100644 --- a/test/lib/test_suite.py +++ b/test/lib/test_suite.py @@ -71,7 +71,7 @@ def print_tail_n(filename, num_lines): class Test: """An individual test file. A test object can run itself and remembers completion state of the run. - + If file <test_name>.skipcond is exists it will be executed before test and if it sets self.skip to True value the test will be skipped. """