misc/liblua/lmem.h
author koda
Sat, 09 Mar 2013 00:57:09 +0100
changeset 8702 a28966180a29
parent 2812 0a24853de796
child 10017 de822cd3df3a
permissions -rw-r--r--
have fpc work in the right directory instead of passing the full path of the main module (avoids having full paths in debug build backtraces for the first module only)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2812
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     1
/*
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     2
** $Id: lmem.h,v 1.31.1.1 2007/12/27 13:02:25 roberto Exp $
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     3
** Interface to Memory Manager
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     4
** See Copyright Notice in lua.h
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     5
*/
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     6
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     7
#ifndef lmem_h
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     8
#define lmem_h
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
     9
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    10
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    11
#include <stddef.h>
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    12
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    13
#include "llimits.h"
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    14
#include "lua.h"
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    15
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    16
#define MEMERRMSG	"not enough memory"
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    17
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    18
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    19
#define luaM_reallocv(L,b,on,n,e) \
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    20
	((cast(size_t, (n)+1) <= MAX_SIZET/(e)) ?  /* +1 to avoid warnings */ \
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    21
		luaM_realloc_(L, (b), (on)*(e), (n)*(e)) : \
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    22
		luaM_toobig(L))
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    23
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    24
#define luaM_freemem(L, b, s)	luaM_realloc_(L, (b), (s), 0)
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    25
#define luaM_free(L, b)		luaM_realloc_(L, (b), sizeof(*(b)), 0)
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    26
#define luaM_freearray(L, b, n, t)   luaM_reallocv(L, (b), n, 0, sizeof(t))
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    27
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    28
#define luaM_malloc(L,t)	luaM_realloc_(L, NULL, 0, (t))
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    29
#define luaM_new(L,t)		cast(t *, luaM_malloc(L, sizeof(t)))
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    30
#define luaM_newvector(L,n,t) \
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    31
		cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t)))
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    32
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    33
#define luaM_growvector(L,v,nelems,size,t,limit,e) \
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    34
          if ((nelems)+1 > (size)) \
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    35
            ((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e)))
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    36
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    37
#define luaM_reallocvector(L, v,oldn,n,t) \
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    38
   ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t))))
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    39
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    40
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    41
LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize,
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    42
                                                          size_t size);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    43
LUAI_FUNC void *luaM_toobig (lua_State *L);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    44
LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size,
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    45
                               size_t size_elem, int limit,
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    46
                               const char *errormsg);
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    47
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    48
#endif
0a24853de796 add liblua to sources for macosx
koda
parents:
diff changeset
    49