[Tarantool-patches] [PATCH v10 2/4] module_cache: move module handling into own subsystem

Cyrill Gorcunov gorcunov at gmail.com
Mon Nov 16 17:41:57 MSK 2020


On Thu, Nov 12, 2020 at 11:54:01PM +0100, Vladislav Shpilevoy wrote:
> > +
> > +/**
> > + * Find a path to a module using Lua's package.cpath.
> > + */
> > +static int
> > +module_find(struct module_find_ctx *ctx)
> > +{
> 
> 2. In the original code the function took package name and
> path, which was way more clear than a ctx. Which in the
> old code was constructed inside of this function.
> 
> But you somewhy moved it to the caller code, to module_load(),
> which creates the ctx just to call module_find(), and never
> uses it again. So what was the point? I honestly do not
> understand.

Some more details on this function. Previously we have

static int
module_find(const char *package, const char *package_end, char *path,
	    size_t path_len)
{
	struct module_find_ctx ctx = { package, package_end, path, path_len };
	lua_State *L = tarantool_L;
	int top = lua_gettop(L);
	if (luaT_cpcall(L, luaT_module_find, &ctx) != 0) {
	...
}

The caller provides *all* 4 parameters which are then packed into
module_find_ctx and sent to luaT_cpcall. The luaT_cpcall extracts
them and fills the @path inside.

Thus instead of passing module_find_ctx right from the point where
path[] and path_len are allocated (ie just one argument) we pass
4 instead, for absolutely no reason. So bloody ugly :( I simply
fixed it since I'm reworking this code.

If you prefer I can do such transition as a separate patch before
moving code into new place.


More information about the Tarantool-patches mailing list