[Tarantool-patches] [PATCH v21 5/6] box: implement box.lib module

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Tue Apr 13 01:08:49 MSK 2021


Hi! Thanks for the patch!

Consider the diff below:

====================
@@ -413,17 +413,13 @@ lbox_module_load_func(struct lua_State *L)
 	}
 
 	/*
-	 * Functions are bound to a module symbols, thus
-	 * since the hash is global it should be unique
-	 * per module. The symbol (function name) is the
-	 * last part of the hash key.
-	 *
-	 * Make sure there is enough space for key,
-	 * path and formatting.
+	 * Functions are bound to a module symbols, thus since the hash is
+	 * global it should be unique per module.
+	 * Make sure there is enough space for key, and formatting.
 	 */
-	char key[PATH_MAX + max_sym_len + 32];
-	snprintf(key, sizeof(key), "%p.%s.%s",
-		 m, m->package, sym);
+	char key[max_sym_len + 32];
+	int bytes = snprintf(key, sizeof(key), "%p.%s", m, sym) + 1;
+	assert(bytes <= (int)sizeof(key));
 	size_t len = strlen(key);
 
 	struct box_module_func *cf = cache_find(key, len);
====================

You don't need any of the 'm' object attributes in the hash if
the 'm' pointer is already included. It is unique. There can't be
2 objects with the same pointer in the memory.


More information about the Tarantool-patches mailing list