* guile.texi: Commented out menu entry and inclusion of Tcl/Tk
[bpt/guile.git] / libguile / mallocs.c
CommitLineData
1bbd0b84 1/* classes: src_files
216eedfc 2 * Copyright (C) 1995,1997,1998,2000,2001 Free Software Foundation, Inc.
0f2d19dd
JB
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
82892bed
JB
16 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
17 * Boston, MA 02111-1307 USA */
0f2d19dd 18
1bbd0b84
GB
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
0f2d19dd
JB
23\f
24
a0599745
MD
25#include "libguile/_scm.h"
26#include "libguile/ports.h"
27#include "libguile/smob.h"
20e6290e 28
a0599745 29#include "libguile/mallocs.h"
20e6290e 30
0f2d19dd 31#ifdef HAVE_MALLOC_H
95b88819 32#include <malloc.h>
0f2d19dd
JB
33#endif
34#ifdef HAVE_UNISTD_H
95b88819 35#include <unistd.h>
0f2d19dd
JB
36#endif
37
38
39\f
e841c3e0 40scm_bits_t scm_tc16_malloc;
0f2d19dd 41
1cc91f1b 42
0f2d19dd 43static scm_sizet
e841c3e0 44malloc_free (SCM ptr)
0f2d19dd
JB
45{
46 if (SCM_MALLOCDATA (ptr))
47 free (SCM_MALLOCDATA (ptr));
48 return 0;
49}
50
1cc91f1b 51
0f2d19dd 52static int
e841c3e0 53malloc_print (SCM exp, SCM port, scm_print_state *pstate)
0f2d19dd 54{
b7f3516f 55 scm_puts("#<malloc ", port);
54778cd3 56 scm_intprint (SCM_CELL_WORD_1 (exp), 16, port);
b7f3516f 57 scm_putc('>', port);
0f2d19dd
JB
58 return 1;
59}
60
61\f
0f2d19dd 62SCM
6e8d25a6 63scm_malloc_obj (scm_sizet n)
0f2d19dd 64{
54778cd3 65 scm_bits_t mem = n ? (scm_bits_t) malloc (n) : 0;
0f2d19dd 66 if (n && !mem)
216eedfc 67 return SCM_BOOL_F;
23a62151 68 SCM_RETURN_NEWSMOB (scm_tc16_malloc, mem);
0f2d19dd
JB
69}
70
71
72\f
0f2d19dd
JB
73void
74scm_init_mallocs ()
0f2d19dd 75{
e841c3e0
KN
76 scm_tc16_malloc = scm_make_smob_type ("malloc", 0);
77 scm_set_smob_free (scm_tc16_malloc, malloc_free);
78 scm_set_smob_print (scm_tc16_malloc, malloc_print);
0f2d19dd 79}
89e00824
ML
80
81/*
82 Local Variables:
83 c-file-style: "gnu"
84 End:
85*/