Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
lstring.c File Reference
#include <string.h>
#include "lua.h"
#include "lmem.h"
#include "lobject.h"
#include "lstate.h"
#include "lstring.h"

Go to the source code of this file.

Macros

#define lstring_c
 
#define LUA_CORE
 
#define LUAI_HASHLIMIT   5
 

Functions

int luaS_eqlngstr (TString *a, TString *b)
 
int luaS_eqstr (TString *a, TString *b)
 
unsigned int luaS_hash (const char *str, size_t l, unsigned int seed)
 
void luaS_resize (lua_State *L, int newsize)
 
static TStringcreatestrobj (lua_State *L, const char *str, size_t l, int tag, unsigned int h, GCObject **list)
 
static TStringnewshrstr (lua_State *L, const char *str, size_t l, unsigned int h)
 
static TStringinternshrstr (lua_State *L, const char *str, size_t l)
 
TStringluaS_newlstr (lua_State *L, const char *str, size_t l)
 
TStringluaS_new (lua_State *L, const char *str)
 
UdataluaS_newudata (lua_State *L, size_t s, Table *e)
 

Macro Definition Documentation

◆ lstring_c

#define lstring_c

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

◆ LUA_CORE

#define LUA_CORE

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

◆ LUAI_HASHLIMIT

#define LUAI_HASHLIMIT   5

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

Referenced by luaS_hash().

Function Documentation

◆ createstrobj()

static TString * createstrobj ( lua_State * L,
const char * str,
size_t l,
int tag,
unsigned int h,
GCObject ** list )
static

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

99 {
100 TString *ts;
101 size_t totalsize; /* total size of TString object */
102 totalsize = sizeof(TString) + ((l + 1) * sizeof(char));
103 ts = &luaC_newobj(L, tag, totalsize, list, 0)->ts;
104 ts->tsv.len = l;
105 ts->tsv.hash = h;
106 ts->tsv.extra = 0;
107 memcpy(ts+1, str, l*sizeof(char));
108 ((char *)(ts+1))[l] = '\0'; /* ending 0 */
109 return ts;
110}
union TString TString
GCObject * luaC_newobj(lua_State *L, int tt, size_t sz, GCObject **list, int offset)
union TString ts
unsigned int hash
struct TString::@46 tsv

References TString::extra, TString::hash, TString::len, luaC_newobj(), GCObject::ts, and TString::tsv.

Referenced by luaS_newlstr(), and newshrstr().

◆ internshrstr()

static TString * internshrstr ( lua_State * L,
const char * str,
size_t l )
static

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

133 {
134 GCObject *o;
135 global_State *g = G(L);
136 unsigned int h = luaS_hash(str, l, g->seed);
137 for (o = g->strt.hash[lmod(h, g->strt.size)];
138 o != NULL;
139 o = gch(o)->next) {
140 TString *ts = rawgco2ts(o);
141 if (h == ts->tsv.hash &&
142 l == ts->tsv.len &&
143 (memcmp(str, getstr(ts), l * sizeof(char)) == 0)) {
144 if (isdead(G(L), o)) /* string is dead (but was not collected yet)? */
145 changewhite(o); /* resurrect it */
146 return ts;
147 }
148 }
149 return newshrstr(L, str, l, h); /* not found; create a new string */
150}
#define NULL
Definition gmacros.h:924
#define changewhite(x)
#define isdead(g, v)
#define lmod(s, size)
#define getstr(ts)
#define G(L)
#define rawgco2ts(o)
#define gch(o)
unsigned int luaS_hash(const char *str, size_t l, unsigned int seed)
static TString * newshrstr(lua_State *L, const char *str, size_t l, unsigned int h)

References changewhite, G, gch, getstr, TString::hash, stringtable::hash, isdead, TString::len, lmod, luaS_hash(), newshrstr(), NULL, rawgco2ts, global_State::seed, stringtable::size, global_State::strt, and TString::tsv.

Referenced by luaS_newlstr().

◆ luaS_eqlngstr()

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 LUA_TLNGSTR

References getstr, TString::len, lua_assert, LUA_TLNGSTR, and TString::tsv.

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

◆ luaS_eqstr()

int luaS_eqstr ( TString * a,
TString * b )

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

45 {
46 return (a->tsv.tt == b->tsv.tt) &&
47 (a->tsv.tt == LUA_TSHRSTR ? eqshrstr(a, b) : luaS_eqlngstr(a, b));
48}
#define LUA_TSHRSTR
int luaS_eqlngstr(TString *a, TString *b)
#define eqshrstr(a, b)

References eqshrstr, LUA_TSHRSTR, luaS_eqlngstr(), and TString::tsv.

Referenced by checkrepeated(), closegoto(), findgotos(), findlabel(), searchupvalue(), and searchvar().

◆ luaS_hash()

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, and LUAI_HASHLIMIT.

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

◆ luaS_new()

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 luaS_newlstr().

◆ luaS_newlstr()

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

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

156 {
157 if (l <= LUAI_MAXSHORTLEN) /* short string? */
158 return internshrstr(L, str, l);
159 else {
160 if (l + 1 > (MAX_SIZET - sizeof(TString))/sizeof(char))
161 luaM_toobig(L);
162 return createstrobj(L, str, l, LUA_TLNGSTR, G(L)->seed, NULL);
163 }
164}
#define MAX_SIZET
void * luaM_toobig(lua_State *L)
static TString * internshrstr(lua_State *L, const char *str, size_t l)
static TString * createstrobj(lua_State *L, const char *str, size_t l, int tag, unsigned int h, GCObject **list)
#define LUAI_MAXSHORTLEN

References createstrobj(), G, internshrstr(), LUA_TLNGSTR, LUAI_MAXSHORTLEN, luaM_toobig(), MAX_SIZET, and NULL.

Referenced by luaS_new().

◆ luaS_newudata()

Udata * luaS_newudata ( lua_State * L,
size_t s,
Table * e )

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

175 {
176 Udata *u;
177 if (s > MAX_SIZET - sizeof(Udata))
178 luaM_toobig(L);
179 u = &luaC_newobj(L, LUA_TUSERDATA, sizeof(Udata) + s, NULL, 0)->u;
180 u->uv.len = s;
181 u->uv.metatable = NULL;
182 u->uv.env = e;
183 return u;
184}
#define LUA_TUSERDATA
CURL_EXTERN CURLMcode curl_socket_t s
Definition multi.h:318
struct Udata::@47 uv
struct Table * env
struct Table * metatable

References Udata::env, Udata::len, LUA_TUSERDATA, luaC_newobj(), luaM_toobig(), MAX_SIZET, Udata::metatable, NULL, s, GCObject::u, and Udata::uv.

◆ luaS_resize()

void luaS_resize ( lua_State * L,
int newsize )

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

64 {
65 int i;
66 stringtable *tb = &G(L)->strt;
67 /* cannot resize while GC is traversing strings */
69 if (newsize > tb->size) {
70 luaM_reallocvector(L, tb->hash, tb->size, newsize, GCObject *);
71 for (i = tb->size; i < newsize; i++) tb->hash[i] = NULL;
72 }
73 /* rehash */
74 for (i=0; i<tb->size; i++) {
75 GCObject *p = tb->hash[i];
76 tb->hash[i] = NULL;
77 while (p) { /* for each node in the list */
78 GCObject *next = gch(p)->next; /* save next */
79 unsigned int h = lmod(gco2ts(p)->hash, newsize); /* new position */
80 gch(p)->next = tb->hash[h]; /* chain it */
81 tb->hash[h] = p;
82 resetoldbit(p); /* see MOVE OLD rule */
83 p = next;
84 }
85 }
86 if (newsize < tb->size) {
87 /* shrinking slice must be empty */
88 lua_assert(tb->hash[newsize] == NULL && tb->hash[tb->size - 1] == NULL);
89 luaM_reallocvector(L, tb->hash, tb->size, newsize, GCObject *);
90 }
91 tb->size = newsize;
92}
#define GCSsweepstring
#define bitmask(b)
#define next(ls)
#define luaM_reallocvector(L, v, oldn, n, t)
#define gco2ts(o)
void luaC_runtilstate(lua_State *L, int statesmask)
#define resetoldbit(o)

References bitmask, G, gch, gco2ts, GCSsweepstring, stringtable::hash, lmod, lua_assert, luaC_runtilstate(), luaM_reallocvector, next, NULL, resetoldbit, and stringtable::size.

Referenced by newshrstr().

◆ newshrstr()

static TString * newshrstr ( lua_State * L,
const char * str,
size_t l,
unsigned int h )
static

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

117 {
118 GCObject **list; /* (pointer to) list where it will be inserted */
119 stringtable *tb = &G(L)->strt;
120 TString *s;
121 if (tb->nuse >= cast(lu_int32, tb->size) && tb->size <= MAX_INT/2)
122 luaS_resize(L, tb->size*2); /* too crowded */
123 list = &tb->hash[lmod(h, tb->size)];
124 s = createstrobj(L, str, l, LUA_TSHRSTR, h, list);
125 tb->nuse++;
126 return s;
127}
LUAI_UINT32 lu_int32
#define MAX_INT
void luaS_resize(lua_State *L, int newsize)

References cast, createstrobj(), G, stringtable::hash, lmod, LUA_TSHRSTR, luaS_resize(), MAX_INT, stringtable::nuse, s, and stringtable::size.

Referenced by internshrstr().