diff options
author | Vladimír Čunát <vladimir.cunat@nic.cz> | 2016-11-08 17:02:43 +0100 |
---|---|---|
committer | Vladimír Čunát <vladimir.cunat@nic.cz> | 2016-11-08 18:12:23 +0100 |
commit | cc47973e392f3f7494821ae8ccaaa563bfa64694 (patch) | |
tree | 3fbde9a5199bd7255d96a58b3f8b315d4ca154af /daemon/ffimodule.c | |
parent | layer: rename knot_ identifiers that are private now (diff) | |
download | knot-resolver-cc47973e392f3f7494821ae8ccaaa563bfa64694.tar.xz knot-resolver-cc47973e392f3f7494821ae8ccaaa563bfa64694.zip |
layer: refactor and better describe the API
- The API and ABI for modules changes slightly (details below).
KR_MODULE_API is bumped to avoid loading incompatible code.
We have bumped libkres ABIVER since the last release 1.1.1,
so leaving that one intact.
- Make KR_STATE_YIELD not reuse 0 value anymore.
It's easy to e.g. return kr_ok() by mistake.
- struct kr_layer_t:
* ::mm was unused, uninitialized, etc.
* Make ::state an int, as it was everywhere else.
* void *data was ugly and always containing struct kr_request *
- struct kr_layer_api:
* Drop the void* parameter from ::begin, as it was only used
for the request which is available as ctx->req anyway
(formerly ctx->data).
* Drop ::fail. It wasn't even called. Modules can watch for
KR_STATE_FAIL in ::finish.
- Document the apparent meaning of the layer interface, deduced mainly
from the way it's used in the code. Caveats:
* enum knot_layer_state handling seems to assume that it holds exactly
one of the possibilities at a time. The cookie module does NOT
follow that (intentionally), apparently depending on the exact
implementation of the handling at that moment. It feels fragile.
* I was unable to deduce a plausible description of when ::reset is
called. It's practically unused in modules, too.
Diffstat (limited to 'daemon/ffimodule.c')
-rw-r--r-- | daemon/ffimodule.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/daemon/ffimodule.c b/daemon/ffimodule.c index 65410a36..af7e46da 100644 --- a/daemon/ffimodule.c +++ b/daemon/ffimodule.c @@ -146,23 +146,23 @@ static int l_ffi_deinit(struct kr_module *module) lua_rawgeti(L, LUA_REGISTRYINDEX, cb_slot[SLOT_ ## slot]); \ lua_pushnumber(L, ctx->state) -static int l_ffi_layer_begin(kr_layer_t *ctx, void *module_param) +static int l_ffi_layer_begin(kr_layer_t *ctx) { LAYER_FFI_CALL(ctx, begin); - lua_pushlightuserdata(L, ctx->data); + lua_pushlightuserdata(L, ctx->req); return l_ffi_call(L, 2); } static int l_ffi_layer_reset(kr_layer_t *ctx) { LAYER_FFI_CALL(ctx, reset); - lua_pushlightuserdata(L, ctx->data); + lua_pushlightuserdata(L, ctx->req); return l_ffi_call(L, 2); } static int l_ffi_layer_finish(kr_layer_t *ctx) { - struct kr_request *req = ctx->data; + struct kr_request *req = ctx->req; LAYER_FFI_CALL(ctx, finish); lua_pushlightuserdata(L, req); lua_pushlightuserdata(L, req->answer); @@ -175,7 +175,7 @@ static int l_ffi_layer_consume(kr_layer_t *ctx, knot_pkt_t *pkt) return ctx->state; /* Already failed, skip */ } LAYER_FFI_CALL(ctx, consume); - lua_pushlightuserdata(L, ctx->data); + lua_pushlightuserdata(L, ctx->req); lua_pushlightuserdata(L, pkt); return l_ffi_call(L, 3); } @@ -186,7 +186,7 @@ static int l_ffi_layer_produce(kr_layer_t *ctx, knot_pkt_t *pkt) return ctx->state; /* Already failed or done, skip */ } LAYER_FFI_CALL(ctx, produce); - lua_pushlightuserdata(L, ctx->data); + lua_pushlightuserdata(L, ctx->req); lua_pushlightuserdata(L, pkt); return l_ffi_call(L, 3); } |