aboutsummaryrefslogtreecommitdiff
path: root/lmem.h
diff options
context:
space:
mode:
Diffstat (limited to 'lmem.h')
-rw-r--r--lmem.h14
1 files changed, 8 insertions, 6 deletions
diff --git a/lmem.h b/lmem.h
index e98aabdb..f87c9132 100644
--- a/lmem.h
+++ b/lmem.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lmem.h,v 1.45 2017/12/07 18:59:52 roberto Exp roberto $ 2** $Id: lmem.h,v 1.46 2017/12/08 17:28:25 roberto Exp roberto $
3** Interface to Memory Manager 3** Interface to Memory Manager
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -29,7 +29,7 @@
29** avoiding this warning but also this optimization.) 29** avoiding this warning but also this optimization.)
30*/ 30*/
31#define luaM_testsize(n,e) \ 31#define luaM_testsize(n,e) \
32 (sizeof(n) >= sizeof(size_t) && cast(size_t, (n)) + 1 > MAX_SIZET/(e)) 32 (sizeof(n) >= sizeof(size_t) && cast_sizet((n)) + 1 > MAX_SIZET/(e))
33 33
34#define luaM_checksize(L,n,e) \ 34#define luaM_checksize(L,n,e) \
35 (luaM_testsize(n,e) ? luaM_toobig(L) : cast_void(0)) 35 (luaM_testsize(n,e) ? luaM_toobig(L) : cast_void(0))
@@ -42,13 +42,15 @@
42** 'int' or 'unsigned int' and that 'int' is not larger than 'size_t'.) 42** 'int' or 'unsigned int' and that 'int' is not larger than 'size_t'.)
43*/ 43*/
44#define luaM_limitN(n,t) \ 44#define luaM_limitN(n,t) \
45 ((cast(size_t, n) > MAX_SIZET/sizeof(t)) ? (MAX_SIZET/sizeof(t)) : (n)) 45 ((cast_sizet(n) <= MAX_SIZET/sizeof(t)) ? (n) : \
46 cast_uint((MAX_SIZET/sizeof(t))))
47
46 48
47/* 49/*
48** Arrays of chars do not need any test 50** Arrays of chars do not need any test
49*/ 51*/
50#define luaM_reallocvchar(L,b,on,n) \ 52#define luaM_reallocvchar(L,b,on,n) \
51 cast(char *, luaM_saferealloc_(L, (b), (on)*sizeof(char), (n)*sizeof(char))) 53 cast_charp(luaM_saferealloc_(L, (b), (on)*sizeof(char), (n)*sizeof(char)))
52 54
53#define luaM_freemem(L, b, s) luaM_free_(L, (b), (s)) 55#define luaM_freemem(L, b, s) luaM_free_(L, (b), (s))
54#define luaM_free(L, b) luaM_free_(L, (b), sizeof(*(b))) 56#define luaM_free(L, b) luaM_free_(L, (b), sizeof(*(b)))
@@ -66,8 +68,8 @@
66 luaM_limitN(limit,t),e))) 68 luaM_limitN(limit,t),e)))
67 69
68#define luaM_reallocvector(L, v,oldn,n,t) \ 70#define luaM_reallocvector(L, v,oldn,n,t) \
69 (cast(t *, luaM_realloc_(L, v, cast(size_t, oldn) * sizeof(t), \ 71 (cast(t *, luaM_realloc_(L, v, cast_sizet(oldn) * sizeof(t), \
70 cast(size_t, n) * sizeof(t)))) 72 cast_sizet(n) * sizeof(t))))
71 73
72#define luaM_shrinkvector(L,v,size,fs,t) \ 74#define luaM_shrinkvector(L,v,size,fs,t) \
73 ((v)=cast(t *, luaM_shrinkvector_(L, v, &(size), fs, sizeof(t)))) 75 ((v)=cast(t *, luaM_shrinkvector_(L, v, &(size), fs, sizeof(t))))