*** empty log message ***
[bpt/guile.git] / libguile / mallocs.c
CommitLineData
0f2d19dd
JB
1/* classes: src_files */
2
7dc6e754 3/* Copyright (C) 1995, 1997, 1998 Free Software Foundation, Inc.
0f2d19dd
JB
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this software; see the file COPYING. If not, write to
82892bed
JB
17 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307 USA */
0f2d19dd
JB
19
20\f
21
22#include <stdio.h>
23#include "_scm.h"
20e6290e
JB
24#include "genio.h"
25#include "smob.h"
26
0f2d19dd 27#include "mallocs.h"
20e6290e 28
0f2d19dd 29#ifdef HAVE_MALLOC_H
95b88819 30#include <malloc.h>
0f2d19dd
JB
31#endif
32#ifdef HAVE_UNISTD_H
95b88819 33#include <unistd.h>
0f2d19dd
JB
34#endif
35
36
37\f
38
39
1cc91f1b
JB
40
41static scm_sizet fmalloc SCM_P ((SCM ptr));
42
0f2d19dd
JB
43static scm_sizet
44fmalloc(ptr)
45 SCM ptr;
0f2d19dd
JB
46{
47 if (SCM_MALLOCDATA (ptr))
48 free (SCM_MALLOCDATA (ptr));
49 return 0;
50}
51
1cc91f1b
JB
52
53static int prinmalloc SCM_P ((SCM exp, SCM port, scm_print_state *pstate));
54
0f2d19dd 55static int
9882ea19 56prinmalloc (exp, port, pstate)
0f2d19dd
JB
57 SCM exp;
58 SCM port;
9882ea19 59 scm_print_state *pstate;
0f2d19dd 60{
b7f3516f 61 scm_puts("#<malloc ", port);
0f2d19dd 62 scm_intprint(SCM_CDR(exp), 16, port);
b7f3516f 63 scm_putc('>', port);
0f2d19dd
JB
64 return 1;
65}
66
67\f
68int scm_tc16_malloc;
0f2d19dd
JB
69\f
70
1cc91f1b 71
0f2d19dd
JB
72SCM
73scm_malloc_obj (n)
74 scm_sizet n;
0f2d19dd 75{
0f2d19dd
JB
76 SCM mem;
77
0f2d19dd
JB
78 mem = (n
79 ? (SCM)malloc (n)
80 : 0);
81 if (n && !mem)
82 {
83 SCM_ALLOW_INTS;
84 return SCM_BOOL_F;
85 }
23a62151 86 SCM_RETURN_NEWSMOB (scm_tc16_malloc, mem);
0f2d19dd
JB
87}
88
89
90\f
1cc91f1b 91
0f2d19dd
JB
92void
93scm_init_mallocs ()
0f2d19dd 94{
23a62151
MD
95 scm_tc16_malloc = scm_make_smob_type_mfpe ("malloc", 0,
96 NULL, fmalloc, prinmalloc, NULL);
0f2d19dd 97}