Skip to content

Commit 633e5fb

Browse files
committed
fix issue cloudwu#331
1 parent c1c5cd3 commit 633e5fb

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

3rd/lua/lstring.c

+12-15
Original file line numberDiff line numberDiff line change
@@ -252,36 +252,33 @@ struct shrmap {
252252
int n;
253253
};
254254

255-
static struct shrmap *SSM = NULL;
255+
static struct shrmap SSM;
256256

257257
LUA_API void
258258
luaS_initshr() {
259-
struct shrmap * s = malloc(sizeof(*s));
260-
memset(s, 0, sizeof(*s));
259+
struct shrmap * s = &SSM;
261260
int i;
262261
for (i=0;i<SHRSTR_SLOT;i++) {
263262
rwlock_init(&s->h[i].lock);
264263
}
265-
SSM = s;
266264
}
267265

268266
LUA_API void
269267
luaS_exitshr() {
270268
int i;
271269
for (i=0;i<SHRSTR_SLOT;i++) {
272-
TString *str = SSM->h[i].str;
270+
TString *str = SSM.h[i].str;
273271
while (str) {
274272
TString * next = str->u.hnext;
275273
free(str);
276274
str = next;
277275
}
278276
}
279-
free(SSM);
280277
}
281278

282279
static TString *
283280
query_string(unsigned int h, const char *str, lu_byte l) {
284-
struct shrmap_slot *s = &SSM->h[HASH_NODE(h)];
281+
struct shrmap_slot *s = &SSM.h[HASH_NODE(h)];
285282
rwlock_rlock(&s->lock);
286283
TString *ts = s->str;
287284
while (ts) {
@@ -299,7 +296,7 @@ query_string(unsigned int h, const char *str, lu_byte l) {
299296
static TString *
300297
query_ptr(TString *t) {
301298
unsigned int h = t->hash;
302-
struct shrmap_slot *s = &SSM->h[HASH_NODE(h)];
299+
struct shrmap_slot *s = &SSM.h[HASH_NODE(h)];
303300
rwlock_rlock(&s->lock);
304301
TString *ts = s->str;
305302
while (ts) {
@@ -326,7 +323,7 @@ new_string(unsigned int h, const char *str, lu_byte l) {
326323
static TString *
327324
add_string(unsigned int h, const char *str, lu_byte l) {
328325
TString * tmp = new_string(h, str, l);
329-
struct shrmap_slot *s = &SSM->h[HASH_NODE(h)];
326+
struct shrmap_slot *s = &SSM.h[HASH_NODE(h)];
330327
rwlock_wlock(&s->lock);
331328
TString *ts = s->str;
332329
while (ts) {
@@ -366,9 +363,9 @@ internshrstr (lua_State *L, const char *str, size_t l) {
366363
ts = query_string(h0, str, l);
367364
if (ts)
368365
return ts;
369-
// If SSM->n greate than 0, add it to SSM
370-
if (SSM->n > 0) {
371-
ATOM_DEC(&SSM->n);
366+
// If SSM.n greate than 0, add it to SSM
367+
if (SSM.n > 0) {
368+
ATOM_DEC(&SSM.n);
372369
return add_string(h0, str, l);
373370
}
374371
// Else add it to global state (local)
@@ -377,7 +374,7 @@ internshrstr (lua_State *L, const char *str, size_t l) {
377374

378375
LUA_API void
379376
luaS_expandshr(int n) {
380-
ATOM_ADD(&SSM->n, n);
377+
ATOM_ADD(&SSM.n, n);
381378
}
382379

383380
LUAI_FUNC TString *
@@ -430,7 +427,7 @@ luaS_shrinfo(lua_State *L) {
430427
int i;
431428
int len = 0;
432429
for (i=0;i<SHRSTR_SLOT;i++) {
433-
struct shrmap_slot *s = &SSM->h[i];
430+
struct shrmap_slot *s = &SSM.h[i];
434431
getslot(s, &tmp);
435432
len += tmp.len;
436433
if (tmp.len > total.len) {
@@ -441,6 +438,6 @@ luaS_shrinfo(lua_State *L) {
441438
lua_pushinteger(L, len);
442439
lua_pushinteger(L, total.size);
443440
lua_pushinteger(L, total.len);
444-
lua_pushinteger(L, SSM->n);
441+
lua_pushinteger(L, SSM.n);
445442
return 4;
446443
}

0 commit comments

Comments
 (0)