From a87b039c6d02c48476f9771a861c30022aee27bc Mon Sep 17 00:00:00 2001 From: Cloud Wu Date: Sat, 10 Oct 2020 19:19:33 +0800 Subject: [PATCH] use new lua userdata api --- lualib-src/ltls.c | 6 +++--- lualib-src/lua-bson.c | 8 ++++---- lualib-src/lua-crypt.c | 12 ++++++------ lualib-src/lua-datasheet.c | 2 +- lualib-src/lua-debugchannel.c | 2 +- lualib-src/lua-netpack.c | 4 ++-- lualib-src/lua-sharedata.c | 8 ++++---- lualib-src/lua-sharetable.c | 2 +- lualib-src/lua-socket.c | 4 ++-- lualib-src/lua-stm.c | 4 ++-- 10 files changed, 26 insertions(+), 26 deletions(-) diff --git a/lualib-src/ltls.c b/lualib-src/ltls.c index 9d352de7..6da40c48 100644 --- a/lualib-src/ltls.c +++ b/lualib-src/ltls.c @@ -317,7 +317,7 @@ _lctx_ciphers(lua_State* L) { static int lnew_ctx(lua_State* L) { - struct ssl_ctx* ctx_p = (struct ssl_ctx*)lua_newuserdata(L, sizeof(*ctx_p)); + struct ssl_ctx* ctx_p = (struct ssl_ctx*)lua_newuserdatauv(L, sizeof(*ctx_p), 0); ctx_p->ctx = SSL_CTX_new(SSLv23_method()); if(!ctx_p->ctx) { unsigned int err = ERR_get_error(); @@ -345,12 +345,12 @@ lnew_ctx(lua_State* L) { static int lnew_tls(lua_State* L) { - struct tls_context* tls_p = (struct tls_context*)lua_newuserdata(L, sizeof(*tls_p)); + struct tls_context* tls_p = (struct tls_context*)lua_newuserdatauv(L, sizeof(*tls_p), 1); tls_p->is_close = false; const char* method = luaL_optstring(L, 1, "nil"); struct ssl_ctx* ctx_p = _check_sslctx(L, 2); lua_pushvalue(L, 2); - lua_setuservalue(L, -2); // set ssl_ctx associated to tls_context + lua_setiuservalue(L, -2, 1); // set ssl_ctx associated to tls_context if(strcmp(method, "client") == 0) { _init_client_context(L, tls_p, ctx_p); diff --git a/lualib-src/lua-bson.c b/lualib-src/lua-bson.c index 6fca5623..808ca0f7 100644 --- a/lualib-src/lua-bson.c +++ b/lualib-src/lua-bson.c @@ -818,7 +818,7 @@ lmakeindex(lua_State *L) { lua_rawset(L,-3); } } - lua_setuservalue(L,1); + lua_setiuservalue(L,1,1); lua_settop(L,1); return 1; @@ -862,7 +862,7 @@ replace_object(lua_State *L, int type, struct bson * bs) { static int lreplace(lua_State *L) { - lua_getuservalue(L,1); + lua_getiuservalue(L,1,1); if (!lua_istable(L,-1)) { return luaL_error(L, "call makeindex first"); } @@ -954,7 +954,7 @@ encode_bson(lua_State *L) { } else { pack_simple_dict(L, b, 0); } - void * ud = lua_newuserdata(L, b->size); + void * ud = lua_newuserdatauv(L, b->size, 1); memcpy(ud, b->ptr, b->size); return 1; } @@ -984,7 +984,7 @@ encode_bson_byorder(lua_State *L) { lua_settop(L, --n); pack_ordered_dict(L, b, n, 0); lua_settop(L,0); - void * ud = lua_newuserdata(L, b->size); + void * ud = lua_newuserdatauv(L, b->size, 1); memcpy(ud, b->ptr, b->size); return 1; } diff --git a/lualib-src/lua-crypt.c b/lualib-src/lua-crypt.c index 77ba7c40..0e4d06cf 100644 --- a/lualib-src/lua-crypt.c +++ b/lualib-src/lua-crypt.c @@ -470,7 +470,7 @@ ldesencode(lua_State *L) { uint8_t tmp[SMALL_CHUNK]; uint8_t *buffer = tmp; if (chunksz > SMALL_CHUNK) { - buffer = lua_newuserdata(L, chunksz); + buffer = lua_newuserdatauv(L, chunksz, 0); } int i; for (i=0;i<(int)textsz-7;i+=8) { @@ -503,7 +503,7 @@ ldesdecode(lua_State *L) { uint8_t tmp[SMALL_CHUNK]; uint8_t *buffer = tmp; if (textsz > SMALL_CHUNK) { - buffer = lua_newuserdata(L, textsz); + buffer = lua_newuserdatauv(L, textsz, 0); } for (i=0;i SMALL_CHUNK/2) { - buffer = lua_newuserdata(L, sz * 2); + buffer = lua_newuserdatauv(L, sz * 2, 0); } int i; for (i=0;i SMALL_CHUNK*2) { - buffer = lua_newuserdata(L, sz / 2); + buffer = lua_newuserdatauv(L, sz / 2, 0); } int i; for (i=0;i SMALL_CHUNK) { - buffer = lua_newuserdata(L, encode_sz); + buffer = lua_newuserdatauv(L, encode_sz, 0); } int i,j; j=0; @@ -953,7 +953,7 @@ lb64decode(lua_State *L) { char tmp[SMALL_CHUNK]; char *buffer = tmp; if (decode_sz > SMALL_CHUNK) { - buffer = lua_newuserdata(L, decode_sz); + buffer = lua_newuserdatauv(L, decode_sz, 0); } int i,j; int output = 0; diff --git a/lualib-src/lua-datasheet.c b/lualib-src/lua-datasheet.c index 57e56764..c2b219db 100644 --- a/lualib-src/lua-datasheet.c +++ b/lualib-src/lua-datasheet.c @@ -68,7 +68,7 @@ create_proxy(lua_State *L, const void *data, int index) { // NODECACHE, table, PROXYCACHE lua_pushvalue(L, -2); // NODECACHE, table, PROXYCACHE, table - struct proxy * p = lua_newuserdata(L, sizeof(struct proxy)); + struct proxy * p = lua_newuserdatauv(L, sizeof(struct proxy), 0); // NODECACHE, table, PROXYCACHE, table, proxy p->data = data; p->index = index; diff --git a/lualib-src/lua-debugchannel.c b/lualib-src/lua-debugchannel.c index 7f83c9e9..bfaf3d23 100644 --- a/lualib-src/lua-debugchannel.c +++ b/lualib-src/lua-debugchannel.c @@ -152,7 +152,7 @@ new_channel(lua_State *L, struct channel *c) { luaL_error(L, "new channel failed"); // never go here } - struct channel_box * cb = lua_newuserdata(L, sizeof(*cb)); + struct channel_box * cb = lua_newuserdatauv(L, sizeof(*cb), 0); cb->c = c; if (luaL_newmetatable(L, METANAME)) { luaL_Reg l[]={ diff --git a/lualib-src/lua-netpack.c b/lualib-src/lua-netpack.c index 7f9a7b64..ac84972d 100644 --- a/lualib-src/lua-netpack.c +++ b/lualib-src/lua-netpack.c @@ -117,7 +117,7 @@ static struct queue * get_queue(lua_State *L) { struct queue *q = lua_touserdata(L,1); if (q == NULL) { - q = lua_newuserdata(L, sizeof(struct queue)); + q = lua_newuserdatauv(L, sizeof(struct queue), 0); q->cap = QUEUESIZE; q->head = 0; q->tail = 0; @@ -132,7 +132,7 @@ get_queue(lua_State *L) { static void expand_queue(lua_State *L, struct queue *q) { - struct queue *nq = lua_newuserdata(L, sizeof(struct queue) + q->cap * sizeof(struct netpack)); + struct queue *nq = lua_newuserdatauv(L, sizeof(struct queue) + q->cap * sizeof(struct netpack), 0); nq->cap = q->cap + QUEUESIZE; nq->head = 0; nq->tail = q->cap; diff --git a/lualib-src/lua-sharedata.c b/lualib-src/lua-sharedata.c index 7f8cdead..e96bf407 100644 --- a/lualib-src/lua-sharedata.c +++ b/lualib-src/lua-sharedata.c @@ -381,7 +381,7 @@ convert_stringmap(struct context *ctx, struct table *tbl) { lua_checkstack(L, ctx->string_index + LUA_MINSTACK); lua_settop(L, ctx->string_index + 1); lua_pushvalue(L, 1); - struct state * s = lua_newuserdata(L, sizeof(*s)); + struct state * s = lua_newuserdatauv(L, sizeof(*s), 1); s->dirty = 0; s->ref = 0; s->root = tbl; @@ -678,7 +678,7 @@ lboxconf(lua_State *L) { struct state * s = lua_touserdata(tbl->L, 1); ATOM_INC(&s->ref); - struct ctrl * c = lua_newuserdata(L, sizeof(*c)); + struct ctrl * c = lua_newuserdatauv(L, sizeof(*c), 1); c->root = tbl; c->update = NULL; if (luaL_newmetatable(L, "confctrl")) { @@ -742,7 +742,7 @@ lneedupdate(lua_State *L) { struct ctrl * c = lua_touserdata(L, 1); if (c->update) { lua_pushlightuserdata(L, c->update); - lua_getuservalue(L, 1); + lua_getiuservalue(L, 1, 1); return 2; } return 0; @@ -759,7 +759,7 @@ lupdate(lua_State *L) { return luaL_error(L, "You should update a new object"); } lua_settop(L, 3); - lua_setuservalue(L, 1); + lua_setiuservalue(L, 1, 1); c->update = n; return 0; diff --git a/lualib-src/lua-sharetable.c b/lualib-src/lua-sharetable.c index d74d1e3a..185a5e85 100644 --- a/lualib-src/lua-sharetable.c +++ b/lualib-src/lua-sharetable.c @@ -151,7 +151,7 @@ get_size(lua_State *L) { static int box_state(lua_State *L, lua_State *mL) { - struct state_ud *ud = (struct state_ud *)lua_newuserdata(L, sizeof(*ud)); + struct state_ud *ud = (struct state_ud *)lua_newuserdatauv(L, sizeof(*ud), 0); ud->L = mL; if (luaL_newmetatable(L, "BOXMATRIXSTATE")) { lua_pushvalue(L, -1); diff --git a/lualib-src/lua-socket.c b/lualib-src/lua-socket.c index ed9a226b..593dd7ad 100644 --- a/lualib-src/lua-socket.c +++ b/lualib-src/lua-socket.c @@ -53,7 +53,7 @@ lfreepool(lua_State *L) { static int lnewpool(lua_State *L, int sz) { - struct buffer_node * pool = lua_newuserdata(L, sizeof(struct buffer_node) * sz); + struct buffer_node * pool = lua_newuserdatauv(L, sizeof(struct buffer_node) * sz, 0); int i; for (i=0;isize = 0; sb->offset = 0; sb->head = NULL; diff --git a/lualib-src/lua-stm.c b/lualib-src/lua-stm.c index 3089594b..ecfa1e57 100644 --- a/lualib-src/lua-stm.c +++ b/lualib-src/lua-stm.c @@ -140,7 +140,7 @@ lnewwriter(lua_State *L) { msg = skynet_malloc(sz); memcpy(msg, tmp, sz); } - struct boxstm * box = lua_newuserdata(L, sizeof(*box)); + struct boxstm * box = lua_newuserdatauv(L, sizeof(*box), 0); box->obj = stm_new(msg,sz); lua_pushvalue(L, lua_upvalueindex(1)); lua_setmetatable(L, -2); @@ -182,7 +182,7 @@ struct boxreader { static int lnewreader(lua_State *L) { - struct boxreader * box = lua_newuserdata(L, sizeof(*box)); + struct boxreader * box = lua_newuserdatauv(L, sizeof(*box), 0); box->obj = lua_touserdata(L, 1); box->lastcopy = NULL; lua_pushvalue(L, lua_upvalueindex(1));