Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
lmem.h File Reference
#include <stddef.h>
#include "llimits.h"
#include "lua.h"

Go to the source code of this file.

Macros

#define MEMERRMSG   "not enough memory"
 
#define luaM_reallocv(L, b, on, n, e)
 
#define luaM_freemem(L, b, s)   luaM_realloc_(L, (b), (s), 0)
 
#define luaM_free(L, b)   luaM_realloc_(L, (b), sizeof(*(b)), 0)
 
#define luaM_freearray(L, b, n, t)   luaM_reallocv(L, (b), n, 0, sizeof(t))
 
#define luaM_malloc(L, t)   luaM_realloc_(L, NULL, 0, (t))
 
#define luaM_new(L, t)   cast(t *, luaM_malloc(L, sizeof(t)))
 
#define luaM_newvector(L, n, t)    cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t)))
 
#define luaM_growvector(L, v, nelems, size, t, limit, e)
 
#define luaM_reallocvector(L, v, oldn, n, t)    ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t))))
 

Functions

LUAI_FUNC void * luaM_realloc_ (lua_State *L, void *block, size_t oldsize, size_t size)
 
LUAI_FUNC void * luaM_toobig (lua_State *L)
 
LUAI_FUNC void * luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elem, int limit, const char *errormsg)
 

Macro Definition Documentation

◆ luaM_free

#define luaM_free ( L,
b )   luaM_realloc_(L, (b), sizeof(*(b)), 0)

◆ luaM_freearray

◆ luaM_freemem

#define luaM_freemem ( L,
b,
s )   luaM_realloc_(L, (b), (s), 0)

◆ luaM_growvector

#define luaM_growvector ( L,
v,
nelems,
size,
t,
limit,
e )
Value:
if ((nelems)+1 > (size)) \
((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e)))
#define cast(t, exp)
LUAI_FUNC void * luaM_growaux_(lua_State *L, void *block, int *size, size_t size_elem, int limit, const char *errormsg)

Definition at line 33 of file lua-5.1.5/src/lmem.h.

33#define luaM_growvector(L,v,nelems,size,t,limit,e) \
34 if ((nelems)+1 > (size)) \
35 ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e)))

Referenced by addk(), addk(), addk(), addk(), addprototype(), addprototype(), addprototype(), allocupvalue(), indexupvalue(), luaK_code(), luaK_code(), luaK_code(), luaK_code(), new_localvar(), new_localvar(), new_localvar(), newlabelentry(), newlabelentry(), newlabelentry(), newupvalue(), newupvalue(), pushclosure(), registerlocalvar(), registerlocalvar(), registerlocalvar(), registerlocalvar(), and savelineinfo().

◆ luaM_malloc

#define luaM_malloc ( L,
t )   luaM_realloc_(L, NULL, 0, (t))

◆ luaM_new

#define luaM_new ( L,
t )   cast(t *, luaM_malloc(L, sizeof(t)))

◆ luaM_newvector

#define luaM_newvector ( L,
n,
t )    cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t)))

◆ luaM_reallocv

#define luaM_reallocv ( L,
b,
on,
n,
e )
Value:
((cast(size_t, (n)+1) <= MAX_SIZET/(e)) ? /* +1 to avoid warnings */ \
luaM_realloc_(L, (b), (on)*(e), (n)*(e)) : \
#define MAX_SIZET
LUAI_FUNC void * luaM_toobig(lua_State *L)

Definition at line 19 of file lua-5.1.5/src/lmem.h.

19#define luaM_reallocv(L,b,on,n,e) \
20 ((cast(size_t, (n)+1) <= MAX_SIZET/(e)) ? /* +1 to avoid warnings */ \
21 luaM_realloc_(L, (b), (on)*(e), (n)*(e)) : \
22 luaM_toobig(L))

Referenced by luaM_growaux_(), and luaM_growaux_().

◆ luaM_reallocvector

#define luaM_reallocvector ( L,
v,
oldn,
n,
t )    ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t))))

Definition at line 37 of file lua-5.1.5/src/lmem.h.

37#define luaM_reallocvector(L, v,oldn,n,t) \
38 ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t))))

Referenced by close_func(), close_func(), close_func(), luaD_reallocCI(), luaD_reallocstack(), luaD_reallocstack(), luaH_resize(), luaH_resize(), luaH_resize(), luaS_resize(), luaS_resize(), resize(), setarrayvector(), setarrayvector(), and setarrayvector().

◆ MEMERRMSG

#define MEMERRMSG   "not enough memory"

Definition at line 16 of file lua-5.1.5/src/lmem.h.

Referenced by f_luaopen(), luaD_seterrorobj(), and luaS_init().

Function Documentation

◆ luaM_growaux_()

LUAI_FUNC void * luaM_growaux_ ( lua_State * L,
void * block,
int * size,
size_t size_elem,
int limit,
const char * errormsg )

Definition at line 46 of file lua-5.1.5/src/lmem.c.

47 {
48 void *newblock;
49 int newsize;
50 if (*size >= limit/2) { /* cannot double it? */
51 if (*size >= limit) /* cannot grow even a little? */
52 luaG_runerror(L, errormsg);
53 newsize = limit; /* still have at least one free place */
54 }
55 else {
56 newsize = (*size)*2;
57 if (newsize < MINSIZEARRAY)
58 newsize = MINSIZEARRAY; /* minimum size */
59 }
60 newblock = luaM_reallocv(L, block, *size, newsize, size_elems);
61 *size = newsize; /* update only when everything else is OK */
62 return newblock;
63}
void luaG_runerror(lua_State *L, const char *fmt,...)
#define MINSIZEARRAY
#define luaM_reallocv(L, b, on, n, e)
static void block(LexState *ls)

◆ luaM_realloc_()

LUAI_FUNC void * luaM_realloc_ ( lua_State * L,
void * block,
size_t oldsize,
size_t size )

Definition at line 76 of file lua-5.1.5/src/lmem.c.

76 {
77 global_State *g = G(L);
78 lua_assert((osize == 0) == (block == NULL));
79 block = (*g->frealloc)(g->ud, block, osize, nsize);
80 if (block == NULL && nsize > 0)
82 lua_assert((nsize == 0) == (block == NULL));
83 g->totalbytes = (g->totalbytes - osize) + nsize;
84 return block;
85}
#define NULL
Definition gmacros.h:924
void luaD_throw(lua_State *L, int errcode)
#define lua_assert(c)
#define G(L)
#define LUA_ERRMEM

◆ luaM_toobig()

LUAI_FUNC void * luaM_toobig ( lua_State * L)

Definition at line 66 of file lua-5.1.5/src/lmem.c.

66 {
67 luaG_runerror(L, "memory allocation error: block too big");
68 return NULL; /* to avoid warnings */
69}