Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
lstring.h File Reference
#include "lgc.h"
#include "lobject.h"
#include "lstate.h"

Go to the source code of this file.

Macros

#define MEMERRMSG   "not enough memory"
 
#define sizelstring(l)   (offsetof(TString, contents) + ((l) + 1) * sizeof(char))
 
#define luaS_newliteral(L, s)
 
#define isreserved(s)   ((s)->tt == LUA_VSHRSTR && (s)->extra > 0)
 
#define eqshrstr(a, b)   check_exp((a)->tt == LUA_VSHRSTR, (a) == (b))
 

Functions

LUAI_FUNC unsigned int luaS_hash (const char *str, size_t l, unsigned int seed)
 
LUAI_FUNC unsigned int luaS_hashlongstr (TString *ts)
 
LUAI_FUNC int luaS_eqlngstr (TString *a, TString *b)
 
LUAI_FUNC void luaS_resize (lua_State *L, int newsize)
 
LUAI_FUNC void luaS_clearcache (global_State *g)
 
LUAI_FUNC void luaS_init (lua_State *L)
 
LUAI_FUNC void luaS_remove (lua_State *L, TString *ts)
 
LUAI_FUNC UdataluaS_newudata (lua_State *L, size_t s, int nuvalue)
 
LUAI_FUNC TStringluaS_newlstr (lua_State *L, const char *str, size_t l)
 
LUAI_FUNC TStringluaS_new (lua_State *L, const char *str)
 
LUAI_FUNC TStringluaS_createlngstrobj (lua_State *L, size_t l)
 

Macro Definition Documentation

◆ eqshrstr

#define eqshrstr ( a,
b )   check_exp((a)->tt == LUA_VSHRSTR, (a) == (b))

Definition at line 41 of file lua-5.4.3/src/lstring.h.

◆ isreserved

#define isreserved ( s)    ((s)->tt == LUA_VSHRSTR && (s)->extra > 0)

Definition at line 35 of file lua-5.4.3/src/lstring.h.

◆ luaS_newliteral

#define luaS_newliteral ( L,
s )
Value:
(luaS_newlstr(L, "" s, \
(sizeof(s)/sizeof(char))-1))
LUAI_FUNC TString * luaS_newlstr(lua_State *L, const char *str, size_t l)
CURL_EXTERN CURLMcode curl_socket_t s
Definition multi.h:318

Definition at line 28 of file lua-5.4.3/src/lstring.h.

28#define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \
29 (sizeof(s)/sizeof(char))-1))

◆ MEMERRMSG

#define MEMERRMSG   "not enough memory"

Definition at line 19 of file lua-5.4.3/src/lstring.h.

◆ sizelstring

#define sizelstring ( l)    (offsetof(TString, contents) + ((l) + 1) * sizeof(char))

Definition at line 26 of file lua-5.4.3/src/lstring.h.

Function Documentation

◆ luaS_clearcache()

LUAI_FUNC void luaS_clearcache ( global_State * g)

Definition at line 103 of file lua-5.3.6/src/lstring.c.

103 {
104 int i, j;
105 for (i = 0; i < STRCACHE_N; i++)
106 for (j = 0; j < STRCACHE_M; j++) {
107 if (iswhite(g->strcache[i][j])) /* will entry be collected? */
108 g->strcache[i][j] = g->memerrmsg; /* replace it with something fixed */
109 }
110}
#define iswhite(x)
#define STRCACHE_M
#define STRCACHE_N
TString * strcache[STRCACHE_N][STRCACHE_M]

References iswhite, global_State::memerrmsg, global_State::strcache, STRCACHE_M, and STRCACHE_N.

Referenced by atomic(), and atomic().

◆ luaS_createlngstrobj()

LUAI_FUNC TString * luaS_createlngstrobj ( lua_State * L,
size_t l )

Definition at line 147 of file lua-5.3.6/src/lstring.c.

147 {
148 TString *ts = createstrobj(L, l, LUA_TLNGSTR, G(L)->seed);
149 ts->u.lnglen = l;
150 return ts;
151}
#define G(L)
#define LUA_TLNGSTR
static TString * createstrobj(lua_State *L, size_t l, int tag, unsigned int h)
union TString::@70 u

References createstrobj(), createstrobj(), G, TString::lnglen, LUA_TLNGSTR, LUA_VLNGSTR, and TString::u.

Referenced by LoadString(), loadStringN(), luaS_newlstr(), and luaV_concat().

◆ luaS_eqlngstr()

LUAI_FUNC int luaS_eqlngstr ( TString * a,
TString * b )

Definition at line 33 of file lua-5.2.4/src/lstring.c.

33 {
34 size_t len = a->tsv.len;
35 lua_assert(a->tsv.tt == LUA_TLNGSTR && b->tsv.tt == LUA_TLNGSTR);
36 return (a == b) || /* same instance or... */
37 ((len == b->tsv.len) && /* equal length and ... */
38 (memcmp(getstr(a), getstr(b), len) == 0)); /* equal contents */
39}
#define lua_assert(c)
#define getstr(ts)
struct TString::@46 tsv

References getstr, TString::len, TString::lnglen, lua_assert, LUA_TLNGSTR, LUA_VLNGSTR, TString::tsv, and TString::u.

Referenced by equalkey(), luaS_eqstr(), luaV_equalobj(), and luaV_equalobj_().

◆ luaS_hash()

LUAI_FUNC unsigned int luaS_hash ( const char * str,
size_t l,
unsigned int seed )

Definition at line 51 of file lua-5.2.4/src/lstring.c.

51 {
52 unsigned int h = seed ^ cast(unsigned int, l);
53 size_t l1;
54 size_t step = (l >> LUAI_HASHLIMIT) + 1;
55 for (l1 = l; l1 >= step; l1 -= step)
56 h = h ^ ((h<<5) + (h>>2) + cast_byte(str[l1 - 1]));
57 return h;
58}
#define cast_byte(i)
#define cast(t, exp)
#define LUAI_HASHLIMIT

References cast, cast_byte, cast_uint, and LUAI_HASHLIMIT.

Referenced by internshrstr(), internshrstr(), internshrstr(), luai_makeseed(), luaS_hashlongstr(), mainposition(), makeseed(), and makeseed().

◆ luaS_hashlongstr()

LUAI_FUNC unsigned int luaS_hashlongstr ( TString * ts)

Definition at line 58 of file lua-5.3.6/src/lstring.c.

58 {
59 lua_assert(ts->tt == LUA_TLNGSTR);
60 if (ts->extra == 0) { /* no hash? */
61 ts->hash = luaS_hash(getstr(ts), ts->u.lnglen, ts->hash);
62 ts->extra = 1; /* now it has its hash */
63 }
64 return ts->hash;
65}
unsigned int luaS_hash(const char *str, size_t l, unsigned int seed)
unsigned int hash

References TString::extra, getstr, TString::hash, TString::lnglen, lua_assert, LUA_TLNGSTR, LUA_VLNGSTR, luaS_hash(), and TString::u.

Referenced by mainposition(), and mainposition().

◆ luaS_init()

LUAI_FUNC void luaS_init ( lua_State * L)

Definition at line 116 of file lua-5.3.6/src/lstring.c.

116 {
117 global_State *g = G(L);
118 int i, j;
119 luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */
120 /* pre-create memory-error message */
122 luaC_fix(L, obj2gco(g->memerrmsg)); /* it should never be collected */
123 for (i = 0; i < STRCACHE_N; i++) /* fill cache with valid strings */
124 for (j = 0; j < STRCACHE_M; j++)
125 g->strcache[i][j] = g->memerrmsg;
126}
#define MINSTRTABSIZE
#define obj2gco(v)
#define luaS_newliteral(L, s)
void luaC_fix(lua_State *L, GCObject *o)
#define MEMERRMSG
void luaS_resize(lua_State *L, int newsize)

References G, stringtable::hash, luaC_fix(), luaM_newvector, luaS_newliteral, luaS_resize(), global_State::memerrmsg, MEMERRMSG, MINSTRTABSIZE, obj2gco, stringtable::size, global_State::strcache, STRCACHE_M, STRCACHE_N, and tablerehash().

Referenced by f_luaopen(), and f_luaopen().

◆ luaS_new()

LUAI_FUNC TString * luaS_new ( lua_State * L,
const char * str )

Definition at line 170 of file lua-5.2.4/src/lstring.c.

170 {
171 return luaS_newlstr(L, str, strlen(str));
172}
TString * luaS_newlstr(lua_State *L, const char *str, size_t l)

References G, getstr, luaS_newlstr(), point2uint, STRCACHE_M, and STRCACHE_N.

◆ luaS_newlstr()

LUAI_FUNC TString * luaS_newlstr ( lua_State * L,
const char * str,
size_t l )

Definition at line 75 of file lua-5.1.5/src/lstring.c.

75 {
76 GCObject *o;
77 unsigned int h = cast(unsigned int, l); /* seed */
78 size_t step = (l>>5)+1; /* if string is too long, don't hash all its chars */
79 size_t l1;
80 for (l1=l; l1>=step; l1-=step) /* compute hash */
81 h = h ^ ((h<<5)+(h>>2)+cast(unsigned char, str[l1-1]));
82 for (o = G(L)->strt.hash[lmod(h, G(L)->strt.size)];
83 o != NULL;
84 o = o->gch.next) {
85 TString *ts = rawgco2ts(o);
86 if (ts->tsv.len == l && (memcmp(str, getstr(ts), l) == 0)) {
87 /* string may be dead */
88 if (isdead(G(L), o)) changewhite(o);
89 return ts;
90 }
91 }
92 return newlstr(L, str, l, h); /* not found */
93}
#define NULL
Definition gmacros.h:924
#define changewhite(x)
#define isdead(g, v)
#define lmod(s, size)
#define rawgco2ts(o)
static TString * newlstr(lua_State *L, const char *str, size_t l, unsigned int h)

References cast, changewhite, createstrobj(), G, GCObject::gch, getstr, internshrstr(), internshrstr(), internshrstr(), isdead, TString::len, lmod, LUA_TLNGSTR, LUAI_MAXSHORTLEN, luaM_toobig(), luaS_createlngstrobj(), MAX_SIZE, MAX_SIZET, newlstr(), NULL, rawgco2ts, and TString::tsv.

Referenced by LoadString(), LoadString(), LoadString(), loadStringN(), lua_concat(), lua_pushlstring(), luaK_numberK(), luaO_pushvfstring(), luaO_tostring(), luaO_tostring(), luaS_new(), luaV_concat(), luaV_concat(), luaV_tostring(), luaX_newstring(), pushstr(), pushstr(), and pushstr().

◆ luaS_newudata()

LUAI_FUNC Udata * luaS_newudata ( lua_State * L,
size_t s,
int nuvalue )

Definition at line 258 of file lua-5.4.3/src/lstring.c.

258 {
259 Udata *u;
260 int i;
261 GCObject *o;
262 if (l_unlikely(s > MAX_SIZE - udatamemoffset(nuvalue)))
263 luaM_toobig(L);
264 o = luaC_newobj(L, LUA_VUSERDATA, sizeudata(nuvalue, s));
265 u = gco2u(o);
266 u->len = s;
267 u->nuvalue = nuvalue;
268 u->metatable = NULL;
269 for (i = 0; i < nuvalue; i++)
270 setnilvalue(&u->uv[i].uv);
271 return u;
272}
void * luaM_toobig(lua_State *L)
#define setnilvalue(obj)
#define gco2u(o)
#define sizeudata(u)
GCObject * luaC_newobj(lua_State *L, int tt, size_t sz, GCObject **list, int offset)
#define MAX_SIZE
#define udatamemoffset(nuv)
#define LUA_VUSERDATA
struct Udata::@47 uv
struct Table * metatable
unsigned short nuvalue

References gco2u, Udata::len, LUA_VUSERDATA, luaC_newobj(), luaM_toobig(), MAX_SIZE, Udata::metatable, NULL, Udata::nuvalue, s, setnilvalue, sizeudata, udatamemoffset, and Udata::uv.

◆ luaS_remove()

LUAI_FUNC void luaS_remove ( lua_State * L,
TString * ts )

Definition at line 154 of file lua-5.3.6/src/lstring.c.

154 {
155 stringtable *tb = &G(L)->strt;
156 TString **p = &tb->hash[lmod(ts->hash, tb->size)];
157 while (*p != ts) /* find previous element */
158 p = &(*p)->u.hnext;
159 *p = (*p)->u.hnext; /* remove element from its list */
160 tb->nuse--;
161}
struct TString * hnext

References G, TString::hash, stringtable::hash, TString::hnext, lmod, stringtable::nuse, stringtable::size, and TString::u.

Referenced by freeobj(), and freeobj().

◆ luaS_resize()

LUAI_FUNC void luaS_resize ( lua_State * L,
int newsize )

Definition at line 22 of file lua-5.1.5/src/lstring.c.

22 {
23 GCObject **newhash;
24 stringtable *tb;
25 int i;
26 if (G(L)->gcstate == GCSsweepstring)
27 return; /* cannot resize during GC traverse */
28 newhash = luaM_newvector(L, newsize, GCObject *);
29 tb = &G(L)->strt;
30 for (i=0; i<newsize; i++) newhash[i] = NULL;
31 /* rehash */
32 for (i=0; i<tb->size; i++) {
33 GCObject *p = tb->hash[i];
34 while (p) { /* for each node in the list */
35 GCObject *next = p->gch.next; /* save next */
36 unsigned int h = gco2ts(p)->hash;
37 int h1 = lmod(h, newsize); /* new position */
38 lua_assert(cast_int(h%newsize) == lmod(h, newsize));
39 p->gch.next = newhash[h1]; /* chain it */
40 newhash[h1] = p;
41 p = next;
42 }
43 }
44 luaM_freearray(L, tb->hash, tb->size, TString *);
45 tb->size = newsize;
46 tb->hash = newhash;
47}
#define GCSsweepstring
#define next(ls)
#define cast_int(i)
#define luaM_freearray(L, b, n, t)
#define luaM_newvector(L, n, t)
#define gco2ts(o)

References bitmask, cast_int, G, GCObject::gch, gch, gco2ts, GCSsweepstring, TString::hash, stringtable::hash, TString::hnext, lmod, lua_assert, luaC_runtilstate(), luaM_freearray, luaM_newvector, luaM_reallocvector, next, NULL, resetoldbit, stringtable::size, tablerehash(), and TString::u.

Referenced by checkSizes(), checkSizes(), checkSizes(), checkSizes(), f_luaopen(), f_luaopen(), growstrtab(), internshrstr(), luaS_init(), newlstr(), and newshrstr().