Merge branch 'master' into boehm-demers-weiser-gc
[bpt/guile.git] / libguile / mallocs.c
1 /* classes: src_files
2 * Copyright (C) 1995,1997,1998,2000,2001, 2006 Free Software Foundation, Inc.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library 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 GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19
20
21 \f
22 #ifdef HAVE_CONFIG_H
23 # include <config.h>
24 #endif
25
26 #include "libguile/_scm.h"
27 #include "libguile/ports.h"
28 #include "libguile/smob.h"
29
30 #include "libguile/mallocs.h"
31
32 #ifdef HAVE_MALLOC_H
33 #include <malloc.h>
34 #endif
35 #ifdef HAVE_UNISTD_H
36 #include <unistd.h>
37 #endif
38
39
40 \f
41 scm_t_bits scm_tc16_malloc;
42
43
44
45 static int
46 malloc_print (SCM exp, SCM port, scm_print_state *pstate SCM_UNUSED)
47 {
48 scm_puts("#<malloc ", port);
49 scm_uintprint (SCM_SMOB_DATA (exp), 16, port);
50 scm_putc('>', port);
51 return 1;
52 }
53
54 \f
55 SCM
56 scm_malloc_obj (size_t n)
57 {
58 scm_t_bits mem = n ? (scm_t_bits) scm_gc_malloc (n, "malloc smob") : 0;
59 if (n && !mem)
60 return SCM_BOOL_F;
61 SCM_RETURN_NEWSMOB (scm_tc16_malloc, mem);
62 }
63
64
65 \f
66 void
67 scm_init_mallocs ()
68 {
69 scm_tc16_malloc = scm_make_smob_type ("malloc", 0);
70 scm_set_smob_print (scm_tc16_malloc, malloc_print);
71 }
72
73 /*
74 Local Variables:
75 c-file-style: "gnu"
76 End:
77 */