modify upstream makefile to allow hardening build flags to apply
[debian/yforth] / memall.c
1 /* yForth? - A Forth interpreter written in ANSI C
2  * Copyright (C) 2012 Luca Padovani
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  * ------------------------------------------------------------------------
17  * Module name: memall.c
18  * Abstract:    Memory allocation word set
19  */
20
21 #include <string.h>
22 #include <malloc.h>
23 #include "yforth.h"
24 #include "core.h"
25 #include "coree.h"
26
27 /**************************************************************************/
28 /* WORDS ******************************************************************/
29 /**************************************************************************/
30
31 void _allocate() {
32     register void *addr = malloc(*sp);
33     if (addr == NULL) *sp = 0;
34     else *sp = (Cell) addr;
35     *--sp = FFLAG(addr == NULL);
36 }
37
38 void _free() {
39     free((void *) *sp);
40     *sp = FFLAG(0);
41 }
42
43 void _resize() {
44     register void *addr = realloc((void *) sp[1], sp[0]);
45     if (addr == NULL) sp[1] = 0;
46     else sp[1] = (Cell) addr;
47     *sp = FFLAG(addr == NULL);
48 }
49
50