From: Vladimír Čunát Date: Tue, 9 Apr 2019 07:34:35 +0000 (+0200) Subject: lua module framework: reduce usage of void *data X-Git-Tag: v4.1.0~21^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1902ba0f6dfe1726264400ebd5be90957578ec79;p=thirdparty%2Fknot-resolver.git lua module framework: reduce usage of void *data Theoretically a lua module could have used them, but I see no motivation for that, as they have much more convenient ways inside lua. --- diff --git a/daemon/ffimodule.c b/daemon/ffimodule.c index bd766f200..24f6aaccd 100644 --- a/daemon/ffimodule.c +++ b/daemon/ffimodule.c @@ -112,8 +112,7 @@ static int l_ffi_deinit(struct kr_module *module) const int ret = l_ffi_modcb(L, module); lua_pop(L, 1); /* the module's table */ - /* Free the layer API wrapper (unconst it) */ - kr_layer_api_t* api = module->data; + const kr_layer_api_t *api = module->layer; if (!api) { return ret; } @@ -123,7 +122,7 @@ static int l_ffi_deinit(struct kr_module *module) luaL_unref(L, LUA_REGISTRYINDEX, api->cb_slots[si]); } } - free(api); + free_const(api); return ret; } @@ -264,7 +263,6 @@ static kr_layer_api_t *l_ffi_layer_create(lua_State *L, struct kr_module *module LAYER_REGISTER(L, api, checkout); LAYER_REGISTER(L, api, answer_finalize); LAYER_REGISTER(L, api, reset); - api->data = module; } return api; } @@ -293,8 +291,6 @@ int ffimodule_register_lua(struct engine *engine, struct kr_module *module, cons lua_getfield(L, -1, "layer"); if (!lua_isnil(L, -1)) { module->layer = l_ffi_layer_create(L, module); - /* most likely not needed, but compatibility for now */ - module->data = (void *)module->layer; } lua_pop(L, 1); /* .layer table */ diff --git a/lib/layer.h b/lib/layer.h index 56f6bd15e..0085e0683 100644 --- a/lib/layer.h +++ b/lib/layer.h @@ -95,8 +95,7 @@ struct kr_layer_api { * Last chance to affect what will get into the answer, including EDNS.*/ int (*answer_finalize)(kr_layer_t *ctx); - /** The module can store anything in here. - * In lua case we store kr_module pointer. */ + /** The C module can store anything in here. */ void *data; /** Internal to ./daemon/ffimodule.c. */