Smob-related creanup.
[bpt/guile.git] / libguile / mallocs.c
1 /* classes: src_files
2 * Copyright (C) 1995, 1997, 1998, 2000 Free Software Foundation, Inc.
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 2, or (at your option)
7 * 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 software; see the file COPYING. If not, write to
16 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
17 * Boston, MA 02111-1307 USA */
18
19 /* Software engineering face-lift by Greg J. Badros, 11-Dec-1999,
20 gjb@cs.washington.edu, http://www.cs.washington.edu/homes/gjb */
21
22
23 \f
24
25 #include <stdio.h>
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_bits_t scm_tc16_malloc;
42
43
44 static scm_sizet
45 malloc_free (SCM ptr)
46 {
47 if (SCM_MALLOCDATA (ptr))
48 free (SCM_MALLOCDATA (ptr));
49 return 0;
50 }
51
52
53 static int
54 malloc_print (SCM exp, SCM port, scm_print_state *pstate)
55 {
56 scm_puts("#<malloc ", port);
57 scm_intprint (SCM_CELL_WORD_1 (exp), 16, port);
58 scm_putc('>', port);
59 return 1;
60 }
61
62 \f
63 SCM
64 scm_malloc_obj (scm_sizet n)
65 {
66 scm_bits_t mem = n ? (scm_bits_t) malloc (n) : 0;
67 if (n && !mem)
68 {
69 SCM_ALLOW_INTS;
70 return SCM_BOOL_F;
71 }
72 SCM_RETURN_NEWSMOB (scm_tc16_malloc, mem);
73 }
74
75
76 \f
77 void
78 scm_init_mallocs ()
79 {
80 scm_tc16_malloc = scm_make_smob_type ("malloc", 0);
81 scm_set_smob_free (scm_tc16_malloc, malloc_free);
82 scm_set_smob_print (scm_tc16_malloc, malloc_print);
83 }
84
85 /*
86 Local Variables:
87 c-file-style: "gnu"
88 End:
89 */