Commit | Line | Data |
---|---|---|
0f2d19dd JB |
1 | /* classes: src_files */ |
2 | ||
3 | /* Copyright (C) 1995 Free Software Foundation, Inc. | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation; either version 2, or (at your option) | |
8 | * any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with this software; see the file COPYING. If not, write to | |
17 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
18 | */ | |
19 | ||
20 | \f | |
21 | ||
22 | #include <stdio.h> | |
23 | #include "_scm.h" | |
24 | #include "mallocs.h" | |
25 | #ifdef HAVE_MALLOC_H | |
26 | #include "malloc.h" | |
27 | #endif | |
28 | #ifdef HAVE_UNISTD_H | |
29 | #include "unistd.h" | |
30 | #endif | |
31 | ||
32 | ||
33 | \f | |
34 | ||
35 | ||
36 | #ifdef __STDC__ | |
37 | static scm_sizet | |
38 | fmalloc(SCM ptr) | |
39 | #else | |
40 | static scm_sizet | |
41 | fmalloc(ptr) | |
42 | SCM ptr; | |
43 | #endif | |
44 | { | |
45 | if (SCM_MALLOCDATA (ptr)) | |
46 | free (SCM_MALLOCDATA (ptr)); | |
47 | return 0; | |
48 | } | |
49 | ||
50 | #ifdef __STDC__ | |
51 | static int | |
52 | prinmalloc (SCM exp, SCM port, int writing) | |
53 | #else | |
54 | static int | |
55 | prinmalloc (exp, port, writing) | |
56 | SCM exp; | |
57 | SCM port; | |
58 | int writing; | |
59 | #endif | |
60 | { | |
61 | scm_gen_puts(scm_regular_string, "#<malloc ", port); | |
62 | scm_intprint(SCM_CDR(exp), 16, port); | |
63 | scm_gen_putc('>', port); | |
64 | return 1; | |
65 | } | |
66 | ||
67 | \f | |
68 | int scm_tc16_malloc; | |
69 | static scm_smobfuns mallocsmob = {scm_mark0, fmalloc, prinmalloc, 0}; | |
70 | ||
71 | \f | |
72 | ||
73 | #ifdef __STDC__ | |
74 | SCM | |
75 | scm_malloc_obj (scm_sizet n) | |
76 | #else | |
77 | SCM | |
78 | scm_malloc_obj (n) | |
79 | scm_sizet n; | |
80 | #endif | |
81 | { | |
82 | SCM answer; | |
83 | SCM mem; | |
84 | ||
85 | SCM_NEWCELL (answer); | |
86 | SCM_DEFER_INTS; | |
87 | mem = (n | |
88 | ? (SCM)malloc (n) | |
89 | : 0); | |
90 | if (n && !mem) | |
91 | { | |
92 | SCM_ALLOW_INTS; | |
93 | return SCM_BOOL_F; | |
94 | } | |
95 | SCM_CDR (answer) = mem; | |
96 | SCM_CAR (answer) = scm_tc16_malloc; | |
97 | SCM_ALLOW_INTS; | |
98 | return answer; | |
99 | } | |
100 | ||
101 | ||
102 | \f | |
103 | #ifdef __STDC__ | |
104 | void | |
105 | scm_init_mallocs (void) | |
106 | #else | |
107 | void | |
108 | scm_init_mallocs () | |
109 | #endif | |
110 | { | |
111 | scm_tc16_malloc = scm_newsmob (&mallocsmob); | |
112 | } | |
113 |