[Tarantool-patches] [PATCH v12 3/8] module_cache: improve naming

Cyrill Gorcunov gorcunov at gmail.com
Mon Jan 18 23:35:51 MSK 2021


 - rename func_name to func_name_desc because
   it is not just a name but rather a name descriptor
   which includes symbol address

 - rename func_split_name to parse_func_name because
   the action of splitting name to parts is not what
   the function about, the function parses specification
   to fetch a descriptor

Part-of #4642

Signed-off-by: Cyrill Gorcunov <gorcunov at gmail.com>
---
 src/box/module_cache.c | 52 +++++++++++++++++++++---------------------
 1 file changed, 26 insertions(+), 26 deletions(-)

diff --git a/src/box/module_cache.c b/src/box/module_cache.c
index 9fe316807..8ae61a883 100644
--- a/src/box/module_cache.c
+++ b/src/box/module_cache.c
@@ -26,9 +26,9 @@
 static struct mh_strnptr_t *mod_hash = NULL;
 
 /**
- * Parsed symbol and package names.
+ * Function name descriptor: a symbol and a package.
  */
-struct func_name {
+struct func_name_desc {
 	/**
 	 * Null-terminated symbol name, e.g.
 	 * "func" for "mod.submod.func".
@@ -46,25 +46,25 @@ struct func_name {
 };
 
 /***
- * Split function name to symbol and package names.
+ * Parse function name into a name descriptor.
  *
  * For example, str = foo.bar.baz => sym = baz, package = foo.bar
  *
  * @param str function name, e.g. "module.submodule.function".
- * @param[out] name parsed symbol and a package name.
+ * @param[out] d parsed symbol and a package name.
  */
 static void
-func_split_name(const char *str, struct func_name *name)
+parse_func_name(const char *str, struct func_name_desc *d)
 {
-	name->package = str;
-	name->package_end = strrchr(str, '.');
-	if (name->package_end != NULL) {
+	d->package = str;
+	d->package_end = strrchr(str, '.');
+	if (d->package_end != NULL) {
 		/* module.submodule.function => module.submodule, function */
-		name->sym = name->package_end + 1; /* skip '.' */
+		d->sym = d->package_end + 1; /* skip '.' */
 	} else {
 		/* package == function => function, function */
-		name->sym = name->package;
-		name->package_end = str + strlen(str);
+		d->sym = d->package;
+		d->package_end = str + strlen(str);
 	}
 }
 
@@ -335,12 +335,12 @@ module_sym_load(struct module_sym *mod_sym)
 {
 	assert(mod_sym->addr == NULL);
 
-	struct func_name name;
-	func_split_name(mod_sym->name, &name);
+	struct func_name_desc d;
+	parse_func_name(mod_sym->name, &d);
 
-	struct module *module = module_cache_find(name.package, name.package_end);
+	struct module *module = module_cache_find(d.package, d.package_end);
 	if (module == NULL) {
-		module = module_load(name.package, name.package_end);
+		module = module_load(d.package, d.package_end);
 		if (module == NULL)
 			return -1;
 		if (module_cache_add(module) != 0) {
@@ -349,7 +349,7 @@ module_sym_load(struct module_sym *mod_sym)
 		}
 	}
 
-	mod_sym->addr = module_sym(module, name.sym);
+	mod_sym->addr = module_sym(module, d.sym);
 	if (mod_sym->addr == NULL)
 		return -1;
 
@@ -366,9 +366,9 @@ module_sym_unload(struct module_sym *mod_sym)
 
 	rlist_del(&mod_sym->item);
 	if (rlist_empty(&mod_sym->module->funcs_list)) {
-		struct func_name name;
-		func_split_name(mod_sym->name, &name);
-		module_cache_del(name.package, name.package_end);
+		struct func_name_desc d;
+		parse_func_name(mod_sym->name, &d);
+		module_cache_del(d.package, d.package_end);
 	}
 	module_gc(mod_sym->module);
 
@@ -439,13 +439,13 @@ module_reload(const char *package, const char *package_end,
 
 	struct module_sym *mod_sym, *tmp;
 	rlist_foreach_entry_safe(mod_sym, &old->funcs_list, item, tmp) {
-		struct func_name name;
-		func_split_name(mod_sym->name, &name);
+		struct func_name_desc d;
+		parse_func_name(mod_sym->name, &d);
 
-		mod_sym->addr = module_sym(new, name.sym);
+		mod_sym->addr = module_sym(new, d.sym);
 		if (mod_sym->addr == NULL) {
 			say_error("module: reload %s, symbol %s not found",
-				  package, name.sym);
+				  package, d.sym);
 			goto restore;
 		}
 
@@ -467,9 +467,9 @@ module_reload(const char *package, const char *package_end,
 	 * restore old functions.
 	 */
 	do {
-		struct func_name name;
-		func_split_name(mod_sym->name, &name);
-		mod_sym->addr = module_sym(old, name.sym);
+		struct func_name_desc d;
+		parse_func_name(mod_sym->name, &d);
+		mod_sym->addr = module_sym(old, d.sym);
 		if (mod_sym->addr == NULL) {
 			/*
 			 * Something strange was happen, an early loaden
-- 
2.29.2



More information about the Tarantool-patches mailing list