* src/vmcore/linker.c (build_display_inner): Use MNEW instead of malloc.
[cacao.git] / src / vm / package.c
1 /* src/vm/package.c - Java boot-package functions
2
3    Copyright (C) 2007, 2008
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
8    This program is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2, or (at
11    your option) any later version.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23 */
24
25
26 #include "config.h"
27
28 #include <stdint.h>
29
30 #include "toolbox/list.h"
31
32 #include "mm/memory.h"
33
34 #include "native/jni.h"
35
36 #include "native/include/java_lang_String.h"
37
38 #include "vm/package.h"
39 #include "vm/stringlocal.h"
40
41 #include "vmcore/options.h"
42 #include "vmcore/utf8.h"
43
44
45 /* internal property structure ************************************************/
46
47 typedef struct list_package_entry_t list_package_entry_t;
48
49 struct list_package_entry_t {
50 /*      java_string_t *packagename; */
51         utf           *packagename;
52         listnode_t     linkage;
53 };
54
55
56 /* global variables ***********************************************************/
57
58 static list_t *list_package = NULL;
59
60
61 /* package_init ****************************************************************
62
63    Initialize the package list.
64
65 *******************************************************************************/
66
67 void package_init(void)
68 {
69         TRACESUBSYSTEMINITIALIZATION("package_init");
70
71         /* create the properties list */
72
73         list_package = list_create(OFFSET(list_package_entry_t, linkage));
74 }
75
76
77 /* package_add *****************************************************************
78
79    Add a package to the boot-package list.
80
81    IN:
82        packagename....package name as Java string
83
84 *******************************************************************************/
85
86 /* void package_add(java_handle_t *packagename) */
87 void package_add(utf *packagename)
88 {
89 /*      java_string_t        *s; */
90         list_package_entry_t *lpe;
91
92         /* Intern the Java string to get a unique address. */
93
94 /*      s = javastring_intern(packagename); */
95
96         /* Check if the package is already stored. */
97
98         if (package_find(packagename) != NULL)
99                 return;
100
101         /* Add the package. */
102
103 #if !defined(NDEBUG)
104         if (opt_DebugPackage) {
105                 log_start();
106                 log_print("[package_add: packagename=");
107                 utf_display_printable_ascii(packagename);
108                 log_print("]");
109                 log_finish();
110         }
111 #endif
112
113         lpe = NEW(list_package_entry_t);
114
115         lpe->packagename = packagename;
116
117         list_add_last(list_package, lpe);
118 }
119
120
121 /* package_find ****************************************************************
122
123    Find a package in the list.
124
125    IN:
126        packagename....package name as Java string
127
128    OUT:
129        package name as Java string
130
131 *******************************************************************************/
132
133 /* java_handle_t *package_find(java_handle_t *packagename) */
134 utf *package_find(utf *packagename)
135 {
136 /*      java_string_t        *s; */
137         list_t               *l;
138         list_package_entry_t *lpe;
139
140         /* Intern the Java string to get a unique address. */
141
142 /*      s = javastring_intern(packagename); */
143
144         /* For convenience. */
145
146         l = list_package;
147
148         for (lpe = list_first(l); lpe != NULL; lpe = list_next(l, lpe)) {
149 /*              if (lpe->packagename == s) */
150                 if (lpe->packagename == packagename)
151                         return lpe->packagename;
152         }
153
154         return NULL;
155 }
156
157
158 /*
159  * These are local overrides for various environment variables in Emacs.
160  * Please do not remove this and leave it at the end of the file, where
161  * Emacs will automagically detect them.
162  * ---------------------------------------------------------------------
163  * Local variables:
164  * mode: c
165  * indent-tabs-mode: t
166  * c-basic-offset: 4
167  * tab-width: 4
168  * End:
169  * vim:noexpandtab:sw=4:ts=4:
170  */