Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/sys/contrib/openzfs/module/lua/lmem.h
48383 views
1
// SPDX-License-Identifier: MIT
2
/*
3
** $Id: lmem.h,v 1.40.1.1 2013/04/12 18:48:47 roberto Exp $
4
** Interface to Memory Manager
5
** See Copyright Notice in lua.h
6
*/
7
8
#ifndef lmem_h
9
#define lmem_h
10
11
12
#include "llimits.h"
13
#include <sys/lua/lua.h>
14
15
16
/*
17
** This macro avoids the runtime division MAX_SIZET/(e), as 'e' is
18
** always constant.
19
** The macro is somewhat complex to avoid warnings:
20
** +1 avoids warnings of "comparison has constant result";
21
** cast to 'void' avoids warnings of "value unused".
22
*/
23
#define luaM_reallocv(L,b,on,n,e) \
24
(cast(void, \
25
(cast(size_t, (n)+1) > MAX_SIZET/(e)) ? (luaM_toobig(L), 0) : 0), \
26
luaM_realloc_(L, (b), (on)*(e), (n)*(e)))
27
28
#define luaM_freemem(L, b, s) luaM_realloc_(L, (b), (s), 0)
29
#define luaM_free(L, b) luaM_realloc_(L, (b), sizeof(*(b)), 0)
30
#define luaM_freearray(L, b, n) luaM_reallocv(L, (b), n, 0, sizeof((b)[0]))
31
32
#define luaM_malloc(L,s) luaM_realloc_(L, NULL, 0, (s))
33
#define luaM_new(L,t) cast(t *, luaM_malloc(L, sizeof(t)))
34
#define luaM_newvector(L,n,t) \
35
cast(t *, luaM_reallocv(L, NULL, 0, n, sizeof(t)))
36
37
#define luaM_newobject(L,tag,s) luaM_realloc_(L, NULL, tag, (s))
38
39
#define luaM_growvector(L,v,nelems,size,t,limit,e) \
40
if ((nelems)+1 > (size)) \
41
((v)=cast(t *, luaM_growaux_(L,v,&(size),sizeof(t),limit,e)))
42
43
#define luaM_reallocvector(L, v,oldn,n,t) \
44
((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t))))
45
46
LUAI_FUNC l_noret luaM_toobig (lua_State *L);
47
48
/* not to be called directly */
49
LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize,
50
size_t size);
51
LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size,
52
size_t size_elem, int limit,
53
const char *what);
54
55
#endif
56
57