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 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)   luaM_reallocv(L, (b), n, 0, sizeof((b)[0]))
 
#define luaM_malloc(L, s)   luaM_realloc_(L, NULL, 0, (s))
 
#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_newobject(L, tag, s)   luaM_realloc_(L, NULL, tag, (s))
 
#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 l_noret luaM_toobig (lua_State *L)
 
LUAI_FUNC void * luaM_realloc_ (lua_State *L, void *block, size_t oldsize, size_t size)
 
LUAI_FUNC void * luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elem, int limit, const char *what)
 

Macro Definition Documentation

◆ luaM_free

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

Definition at line 30 of file lua-5.2.4/src/lmem.h.

◆ luaM_freearray

#define luaM_freearray ( L,
b,
n )   luaM_reallocv(L, (b), n, 0, sizeof((b)[0]))

Definition at line 31 of file lua-5.2.4/src/lmem.h.

◆ luaM_freemem

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

Definition at line 29 of file lua-5.2.4/src/lmem.h.

◆ 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 *what)

Definition at line 40 of file lua-5.2.4/src/lmem.h.

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

◆ luaM_malloc

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

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

◆ luaM_new

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

Definition at line 34 of file lua-5.2.4/src/lmem.h.

◆ luaM_newobject

#define luaM_newobject ( L,
tag,
s )   luaM_realloc_(L, NULL, tag, (s))

Definition at line 38 of file lua-5.2.4/src/lmem.h.

Referenced by lua_newthread(), luaC_newobj(), and luaC_newobj().

◆ luaM_newvector

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

Definition at line 35 of file lua-5.2.4/src/lmem.h.

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

◆ luaM_reallocv

#define luaM_reallocv ( L,
b,
on,
n,
e )
Value:
(cast(void, \
(cast(size_t, (n)+1) > MAX_SIZET/(e)) ? (luaM_toobig(L), 0) : 0), \
luaM_realloc_(L, (b), (on)*(e), (n)*(e)))
#define MAX_SIZET
LUAI_FUNC l_noret luaM_toobig(lua_State *L)
LUAI_FUNC void * luaM_realloc_(lua_State *L, void *block, size_t oldsize, size_t size)

Definition at line 24 of file lua-5.2.4/src/lmem.h.

24#define luaM_reallocv(L,b,on,n,e) \
25 (cast(void, \
26 (cast(size_t, (n)+1) > MAX_SIZET/(e)) ? (luaM_toobig(L), 0) : 0), \
27 luaM_realloc_(L, (b), (on)*(e), (n)*(e)))

◆ luaM_reallocvector

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

Definition at line 44 of file lua-5.2.4/src/lmem.h.

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

Function Documentation

◆ luaM_growaux_()

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

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 l_noret 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}