Commit | Line | Data |
---|---|---|
1bbd0b84 GB |
1 | /* classes: src_files |
2 | * Copyright (C) 1995, 1997, 1998 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 | ||
25 | #include <stdio.h> | |
26 | #include "_scm.h" | |
20e6290e JB |
27 | #include "genio.h" |
28 | #include "smob.h" | |
29 | ||
0f2d19dd | 30 | #include "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 | |
41 | ||
42 | ||
1cc91f1b | 43 | |
0f2d19dd | 44 | static scm_sizet |
1bbd0b84 | 45 | fmalloc(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 |
1bbd0b84 | 54 | prinmalloc (SCM exp,SCM port,scm_print_state *pstate) |
0f2d19dd | 55 | { |
b7f3516f | 56 | scm_puts("#<malloc ", port); |
0f2d19dd | 57 | scm_intprint(SCM_CDR(exp), 16, port); |
b7f3516f | 58 | scm_putc('>', port); |
0f2d19dd JB |
59 | return 1; |
60 | } | |
61 | ||
62 | \f | |
63 | int scm_tc16_malloc; | |
0f2d19dd JB |
64 | \f |
65 | ||
1cc91f1b | 66 | |
0f2d19dd JB |
67 | SCM |
68 | scm_malloc_obj (n) | |
69 | scm_sizet n; | |
0f2d19dd | 70 | { |
0f2d19dd JB |
71 | SCM mem; |
72 | ||
0f2d19dd JB |
73 | mem = (n |
74 | ? (SCM)malloc (n) | |
75 | : 0); | |
76 | if (n && !mem) | |
77 | { | |
78 | SCM_ALLOW_INTS; | |
79 | return SCM_BOOL_F; | |
80 | } | |
23a62151 | 81 | SCM_RETURN_NEWSMOB (scm_tc16_malloc, mem); |
0f2d19dd JB |
82 | } |
83 | ||
84 | ||
85 | \f | |
1cc91f1b | 86 | |
0f2d19dd JB |
87 | void |
88 | scm_init_mallocs () | |
0f2d19dd | 89 | { |
23a62151 MD |
90 | scm_tc16_malloc = scm_make_smob_type_mfpe ("malloc", 0, |
91 | NULL, fmalloc, prinmalloc, NULL); | |
0f2d19dd | 92 | } |