Skip to content

Commit

Permalink
perf(ubus): use ligh userdata instead of userdata for alloc defered r…
Browse files Browse the repository at this point in the history
…equest.

Signed-off-by: Jianhui Zhao <zhaojh329@gmail.com>
  • Loading branch information
zhaojh329 committed Apr 12, 2024
1 parent 3a073cb commit ace2943
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions ubus.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,10 +459,14 @@ static int ubus_method_handler(struct ubus_context *ctx, struct ubus_object *obj
{
struct eco_ubus_context *c = container_of(ctx, struct eco_ubus_context, ctx);
struct eco_ubus_object *o = container_of(obj, struct eco_ubus_object, object);
struct ubus_request_data *new_req;
struct ubus_request_data *dreq;
lua_State *L = c->eco->L;
int rv = 0;

dreq = malloc(sizeof(struct ubus_request_data));
if (!dreq)
luaL_error(L, "no mem");

lua_settop(L, 0);

lua_pushnil(L);
Expand All @@ -479,8 +483,9 @@ static int ubus_method_handler(struct ubus_context *ctx, struct ubus_object *obj
lua_replace(L, -6);
lua_settop(L, -5);

new_req = lua_newuserdata(L, sizeof(struct ubus_request_data));
ubus_defer_request(ctx, req, new_req);
ubus_defer_request(ctx, req, dreq);

lua_pushlightuserdata(L, dreq);

blob_to_lua_table(L, blob_data(msg), blob_len(msg), false);

Expand Down Expand Up @@ -655,6 +660,7 @@ static int lua_ubus_complete_deferred_request(lua_State *L)
int ret = luaL_checkinteger(L, 3);

ubus_complete_deferred_request(&ctx->ctx, req, ret);
free(req);

return 0;
}
Expand Down

0 comments on commit ace2943

Please sign in to comment.