Commit | Line | Data |
---|---|---|
1bbd0b84 | 1 | /* classes: src_files |
2b829bbb | 2 | * Copyright (C) 1995,1997,1998,2000,2001, 2006 Free Software Foundation, Inc. |
0f2d19dd | 3 | * |
73be1d9e MV |
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. | |
c22adbeb | 8 | * |
73be1d9e MV |
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. | |
c22adbeb | 13 | * |
73be1d9e MV |
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 | |
92205699 | 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
73be1d9e | 17 | */ |
0f2d19dd | 18 | |
1bbd0b84 GB |
19 | |
20 | ||
0f2d19dd | 21 | \f |
0261dfae RB |
22 | #if HAVE_CONFIG_H |
23 | # include <config.h> | |
24 | #endif | |
0f2d19dd | 25 | |
a0599745 MD |
26 | #include "libguile/_scm.h" |
27 | #include "libguile/ports.h" | |
28 | #include "libguile/smob.h" | |
20e6290e | 29 | |
a0599745 | 30 | #include "libguile/mallocs.h" |
20e6290e | 31 | |
0f2d19dd | 32 | #ifdef HAVE_MALLOC_H |
95b88819 | 33 | #include <malloc.h> |
0f2d19dd JB |
34 | #endif |
35 | #ifdef HAVE_UNISTD_H | |
95b88819 | 36 | #include <unistd.h> |
0f2d19dd JB |
37 | #endif |
38 | ||
39 | ||
40 | \f | |
92c2555f | 41 | scm_t_bits scm_tc16_malloc; |
0f2d19dd | 42 | |
1cc91f1b | 43 | |
1be6b49c | 44 | static size_t |
e841c3e0 | 45 | malloc_free (SCM ptr) |
0f2d19dd JB |
46 | { |
47 | if (SCM_MALLOCDATA (ptr)) | |
48 | free (SCM_MALLOCDATA (ptr)); | |
49 | return 0; | |
50 | } | |
51 | ||
1cc91f1b | 52 | |
0f2d19dd | 53 | static int |
e81d98ec | 54 | malloc_print (SCM exp, SCM port, scm_print_state *pstate SCM_UNUSED) |
0f2d19dd | 55 | { |
b7f3516f | 56 | scm_puts("#<malloc ", port); |
0345e278 | 57 | scm_uintprint (SCM_SMOB_DATA (exp), 16, port); |
b7f3516f | 58 | scm_putc('>', port); |
0f2d19dd JB |
59 | return 1; |
60 | } | |
61 | ||
62 | \f | |
0f2d19dd | 63 | SCM |
1be6b49c | 64 | scm_malloc_obj (size_t n) |
0f2d19dd | 65 | { |
67329a9e | 66 | scm_t_bits mem = n ? (scm_t_bits) scm_gc_malloc (n, "malloc smob") : 0; |
0f2d19dd | 67 | if (n && !mem) |
216eedfc | 68 | return SCM_BOOL_F; |
23a62151 | 69 | SCM_RETURN_NEWSMOB (scm_tc16_malloc, mem); |
0f2d19dd JB |
70 | } |
71 | ||
72 | ||
73 | \f | |
0f2d19dd JB |
74 | void |
75 | scm_init_mallocs () | |
0f2d19dd | 76 | { |
e841c3e0 KN |
77 | scm_tc16_malloc = scm_make_smob_type ("malloc", 0); |
78 | scm_set_smob_free (scm_tc16_malloc, malloc_free); | |
79 | scm_set_smob_print (scm_tc16_malloc, malloc_print); | |
0f2d19dd | 80 | } |
89e00824 ML |
81 | |
82 | /* | |
83 | Local Variables: | |
84 | c-file-style: "gnu" | |
85 | End: | |
86 | */ |