]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
lua module framework: reduce usage of void *data
authorVladimír Čunát <vladimir.cunat@nic.cz>
Tue, 9 Apr 2019 07:34:35 +0000 (09:34 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Thu, 13 Jun 2019 13:03:15 +0000 (15:03 +0200)
Theoretically a lua module could have used them, but I see no motivation
for that, as they have much more convenient ways inside lua.

daemon/ffimodule.c
lib/layer.h

index bd766f200892a431c3b93761e2d45a7adb1a0526..24f6aaccdc29a278b728b147e28fe87d6537befa 100644 (file)
@@ -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 */
 
index 56f6bd15e285cf34edef27588ce64e1d646e66e5..0085e068384087983f8139f10dafd77aeb963a98 100644 (file)
@@ -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. */