Skip to content
This repository was archived by the owner on Nov 28, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions binding/lua/pbc-lua.c
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,31 @@ _clear_gcobj(lua_State *L) {
return 0;
}

//kibernet
//手动调用该方法清除userdata的内存
static int
_clear_gcobj_manual(lua_State *L) {
struct gcobj * obj = (struct gcobj *)lua_touserdata(L,1);
int i;
for (i=0;i<obj->size_pat;i++) {
pbc_pattern_delete(obj->pat[i]);
}
for (i=0;i<obj->size_msg;i++) {
pbc_rmessage_delete(obj->msg[i]);
}
free(obj->pat);
free(obj->msg);

obj->size_pat = 0;
obj->cap_pat = 4;
obj->size_msg = 0;
obj->cap_msg = 4;
obj->pat = (struct pbc_pattern **)malloc(obj->cap_pat * sizeof(struct pbc_pattern *));
obj->msg = (struct pbc_rmessage **)malloc(obj->cap_msg * sizeof(struct pbc_rmessage *));

return 0;
}

static int
_gc(lua_State *L) {
struct gcobj * obj = (struct gcobj *)lua_newuserdata(L,sizeof(*obj));
Expand Down Expand Up @@ -1113,6 +1138,7 @@ luaopen_protobuf_c(lua_State *L) {
{"_last_error", _last_error },
{"_decode", _decode },
{"_gc", _gc },
{"_clear_gcobj_manual", _clear_gcobj_manual },
{"_add_pattern", _add_pattern },
{"_add_rmessage", _add_rmessage },
{"_env_enum_id", _env_enum_id},
Expand Down
4 changes: 4 additions & 0 deletions binding/lua/protobuf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -584,4 +584,8 @@ function extract(tbl)
end
end

function clear_gc_manual( )
c._clear_gcobj_manual(GC)
end

default=set_default
26 changes: 26 additions & 0 deletions binding/lua53/pbc-lua53.c
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,31 @@ _clear_gcobj(lua_State *L) {
return 0;
}

//kibernet
//手动调用该方法清除userdata的内存
static int
_clear_gcobj_manual(lua_State *L) {
struct gcobj * obj = (struct gcobj *)lua_touserdata(L,1);
int i;
for (i=0;i<obj->size_pat;i++) {
pbc_pattern_delete(obj->pat[i]);
}
for (i=0;i<obj->size_msg;i++) {
pbc_rmessage_delete(obj->msg[i]);
}
free(obj->pat);
free(obj->msg);

obj->size_pat = 0;
obj->cap_pat = 4;
obj->size_msg = 0;
obj->cap_msg = 4;
obj->pat = (struct pbc_pattern **)malloc(obj->cap_pat * sizeof(struct pbc_pattern *));
obj->msg = (struct pbc_rmessage **)malloc(obj->cap_msg * sizeof(struct pbc_rmessage *));

return 0;
}

static int
_gc(lua_State *L) {
struct gcobj * obj;
Expand Down Expand Up @@ -897,6 +922,7 @@ luaopen_protobuf_c(lua_State *L) {
{"_last_error", _last_error },
{"_decode", _decode },
{"_gc", _gc },
{"_clear_gcobj_manual", _clear_gcobj_manual },
{"_add_pattern", _add_pattern },
{"_add_rmessage", _add_rmessage },
{"_env_enum_id", _env_enum_id},
Expand Down
4 changes: 4 additions & 0 deletions binding/lua53/protobuf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,10 @@ function M.extract(tbl)
end
end

function clear_gc_manual( )
c._clear_gcobj_manual(GC)
end

M.default=set_default

return M