Change Guile license to LGPLv3+
[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 License
6 * as published by the Free Software Foundation; either version 3 of
7 * the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful, but
10 * 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
17 * 02110-1301 USA
18 */
19
20
21
22 \f
23 #ifdef HAVE_CONFIG_H
24 # include <config.h>
25 #endif
26
27 #include "libguile/_scm.h"
28 #include "libguile/ports.h"
29 #include "libguile/smob.h"
30
31 #include "libguile/mallocs.h"
32
33 #ifdef HAVE_MALLOC_H
34 #include <malloc.h>
35 #endif
36 #ifdef HAVE_UNISTD_H
37 #include <unistd.h>
38 #endif
39
40
41 \f
42 scm_t_bits scm_tc16_malloc;
43
44
45 static size_t
46 malloc_free (SCM ptr)
47 {
48 if (SCM_MALLOCDATA (ptr))
49 free (SCM_MALLOCDATA (ptr));
50 return 0;
51 }
52
53
54 static int
55 malloc_print (SCM exp, SCM port, scm_print_state *pstate SCM_UNUSED)
56 {
57 scm_puts("#<malloc ", port);
58 scm_uintprint (SCM_SMOB_DATA (exp), 16, port);
59 scm_putc('>', port);
60 return 1;
61 }
62
63 \f
64 SCM
65 scm_malloc_obj (size_t n)
66 {
67 scm_t_bits mem = n ? (scm_t_bits) scm_gc_malloc (n, "malloc smob") : 0;
68 if (n && !mem)
69 return SCM_BOOL_F;
70 SCM_RETURN_NEWSMOB (scm_tc16_malloc, mem);
71 }
72
73
74 \f
75 void
76 scm_init_mallocs ()
77 {
78 scm_tc16_malloc = scm_make_smob_type ("malloc", 0);
79 scm_set_smob_free (scm_tc16_malloc, malloc_free);
80 scm_set_smob_print (scm_tc16_malloc, malloc_print);
81 }
82
83 /*
84 Local Variables:
85 c-file-style: "gnu"
86 End:
87 */