• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3  * Version: NPL 1.1/GPL 2.0/LGPL 2.1
4  *
5  * The contents of this file are subject to the Netscape Public License
6  * Version 1.1 (the "License"); you may not use this file except in
7  * compliance with the License. You may obtain a copy of the License at
8  * http://www.mozilla.org/NPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12  * for the specific language governing rights and limitations under the
13  * License.
14  *
15  * The Original Code is mozilla.org code.
16  *
17  * The Initial Developer of the Original Code is
18  * Netscape Communications Corporation.
19  * Portions created by the Initial Developer are Copyright (C) 1998
20  * the Initial Developer. All Rights Reserved.
21  *
22  * Contributor(s):
23  *
24  * Alternatively, the contents of this file may be used under the terms of
25  * either the GNU General Public License Version 2 or later (the "GPL"), or
26  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27  * in which case the provisions of the GPL or the LGPL are applicable instead
28  * of those above. If you wish to allow use of your version of this file only
29  * under the terms of either the GPL or the LGPL, and not to allow others to
30  * use your version of this file under the terms of the NPL, indicate your
31  * decision by deleting the provisions above and replace them with the notice
32  * and other provisions required by the GPL or the LGPL. If you do not delete
33  * the provisions above, a recipient may use your version of this file under
34  * the terms of any one of the NPL, the GPL or the LGPL.
35  *
36  * ***** END LICENSE BLOCK ***** */
37 
38 /*******************************************************************************
39  * Java Runtime Interface
40  ******************************************************************************/
41 
42 #ifndef JRITYPES_H
43 #define JRITYPES_H
44 
45 #include "jri_md.h"
46 #include "jni.h"
47 #include <stddef.h>
48 #include <stdlib.h>
49 #include <stdarg.h>
50 
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54 
55 /*******************************************************************************
56  * Types
57  ******************************************************************************/
58 
59 struct JRIEnvInterface;
60 
61 typedef void*		JRIRef;
62 typedef void*		JRIGlobalRef;
63 
64 typedef jint		JRIFieldID;
65 typedef jint		JRIMethodID;
66 
67 /* synonyms: */
68 typedef JRIGlobalRef	jglobal;
69 
70 typedef union JRIValue {
71 	jbool			z;
72 	jbyte			b;
73 	jchar			c;
74 	jshort			s;
75 	jint			i;
76 	jlong			l;
77 	jfloat			f;
78 	jdouble			d;
79 	jref			r;
80 } JRIValue;
81 
82 typedef enum JRIBoolean {
83     JRIFalse		= 0,
84     JRITrue			= 1
85 } JRIBoolean;
86 
87 typedef enum JRIConstant {
88 	JRIUninitialized	= -1
89 } JRIConstant;
90 
91 /* convenience types (these must be distinct struct types for c++ overloading): */
92 #if 0	/* now in jni.h */
93 typedef struct jbooleanArrayStruct*		jbooleanArray;
94 typedef struct jbyteArrayStruct*		jbyteArray;
95 typedef struct jcharArrayStruct*		jcharArray;
96 typedef struct jshortArrayStruct*		jshortArray;
97 typedef struct jintArrayStruct*			jintArray;
98 typedef struct jlongArrayStruct*		jlongArray;
99 typedef struct jfloatArrayStruct*		jfloatArray;
100 typedef struct jdoubleArrayStruct*		jdoubleArray;
101 typedef struct jobjectArrayStruct*		jobjectArray;
102 #endif
103 typedef struct jstringArrayStruct*		jstringArray;
104 typedef struct jarrayArrayStruct*		jarrayArray;
105 
106 #define JRIConstructorMethodName	"<init>"
107 
108 /*******************************************************************************
109  * Signature Construction Macros
110  ******************************************************************************/
111 
112 /*
113 ** These macros can be used to construct signature strings. Hopefully their names
114 ** are a little easier to remember than the single character they correspond to.
115 ** For example, to specify the signature of the method:
116 **
117 **	public int read(byte b[], int off, int len);
118 **
119 ** you could write something like this in C:
120 **
121 **	char* readSig = JRISigMethod(JRISigArray(JRISigByte)
122 **								 JRISigInt
123 **								 JRISigInt) JRISigInt;
124 **
125 ** Of course, don't put commas between the types.
126 */
127 #define JRISigArray(T)		"[" T
128 #define JRISigByte			"B"
129 #define JRISigChar			"C"
130 #define JRISigClass(name)	"L" name ";"
131 #define JRISigFloat			"F"
132 #define JRISigDouble		"D"
133 #define JRISigMethod(args)	"(" args ")"
134 #define JRISigNoArgs		""
135 #define JRISigInt			"I"
136 #define JRISigLong			"J"
137 #define JRISigShort			"S"
138 #define JRISigVoid			"V"
139 #define JRISigBoolean		"Z"
140 
141 /*******************************************************************************
142  * Environments
143  ******************************************************************************/
144 
145 extern JRI_PUBLIC_API(const struct JRIEnvInterface**)
146 JRI_GetCurrentEnv(void);
147 
148 /*******************************************************************************
149  * Specific Scalar Array Types
150  ******************************************************************************/
151 
152 /*
153 ** The JRI Native Method Interface does not support boolean arrays. This
154 ** is to allow Java runtime implementations to optimize boolean array
155 ** storage. Using the ScalarArray operations on boolean arrays is bound
156 ** to fail, so convert any boolean arrays to byte arrays in Java before
157 ** passing them to a native method.
158 */
159 
160 #define JRI_NewByteArray(env, length, initialValues)	\
161 	JRI_NewScalarArray(env, length, JRISigByte, (jbyte*)(initialValues))
162 #define JRI_GetByteArrayLength(env, array)	\
163 	JRI_GetScalarArrayLength(env, array)
164 #define JRI_GetByteArrayElements(env, array)	\
165 	JRI_GetScalarArrayElements(env, array)
166 
167 #define JRI_NewCharArray(env, length, initialValues)	\
168 	JRI_NewScalarArray(env, ((length) * sizeof(jchar)), JRISigChar, (jbyte*)(initialValues))
169 #define JRI_GetCharArrayLength(env, array)	\
170 	JRI_GetScalarArrayLength(env, array)
171 #define JRI_GetCharArrayElements(env, array)		   \
172 	((jchar*)JRI_GetScalarArrayElements(env, array))
173 
174 #define JRI_NewShortArray(env, length, initialValues)	\
175 	JRI_NewScalarArray(env, ((length) * sizeof(jshort)), JRISigShort, (jbyte*)(initialValues))
176 #define JRI_GetShortArrayLength(env, array)	\
177 	JRI_GetScalarArrayLength(env, array)
178 #define JRI_GetShortArrayElements(env, array)		   \
179 	((jshort*)JRI_GetScalarArrayElements(env, array))
180 
181 #define JRI_NewIntArray(env, length, initialValues)	\
182 	JRI_NewScalarArray(env, ((length) * sizeof(jint)), JRISigInt, (jbyte*)(initialValues))
183 #define JRI_GetIntArrayLength(env, array)	\
184 	JRI_GetScalarArrayLength(env, array)
185 #define JRI_GetIntArrayElements(env, array)		   \
186 	((jint*)JRI_GetScalarArrayElements(env, array))
187 
188 #define JRI_NewLongArray(env, length, initialValues)	\
189 	JRI_NewScalarArray(env, ((length) * sizeof(jlong)), JRISigLong, (jbyte*)(initialValues))
190 #define JRI_GetLongArrayLength(env, array)	\
191 	JRI_GetScalarArrayLength(env, array)
192 #define JRI_GetLongArrayElements(env, array)		   \
193 	((jlong*)JRI_GetScalarArrayElements(env, array))
194 
195 #define JRI_NewFloatArray(env, length, initialValues)	\
196 	JRI_NewScalarArray(env, ((length) * sizeof(jfloat)), JRISigFloat, (jbyte*)(initialValues))
197 #define JRI_GetFloatArrayLength(env, array)	\
198 	JRI_GetScalarArrayLength(env, array)
199 #define JRI_GetFloatArrayElements(env, array)		   \
200 	((jfloat*)JRI_GetScalarArrayElements(env, array))
201 
202 #define JRI_NewDoubleArray(env, length, initialValues)	\
203 	JRI_NewScalarArray(env, ((length) * sizeof(jdouble)), JRISigDouble, (jbyte*)(initialValues))
204 #define JRI_GetDoubleArrayLength(env, array)	\
205 	JRI_GetScalarArrayLength(env, array)
206 #define JRI_GetDoubleArrayElements(env, array)		   \
207 	((jdouble*)JRI_GetScalarArrayElements(env, array))
208 
209 /******************************************************************************/
210 /*
211 ** JDK Stuff -- This stuff is still needed while we're using the JDK
212 ** dynamic linking strategy to call native methods.
213 */
214 
215 typedef union JRI_JDK_stack_item {
216     /* Non pointer items */
217     jint           i;
218     jfloat         f;
219     jint           o;
220     /* Pointer items */
221     void          *h;
222     void          *p;
223     unsigned char *addr;
224 #ifdef IS_64
225     double         d;
226     long           l;		/* == 64bits! */
227 #endif
228 } JRI_JDK_stack_item;
229 
230 typedef union JRI_JDK_Java8Str {
231     jint x[2];
232     jdouble d;
233     jlong l;
234     void *p;
235     float f;
236 } JRI_JDK_Java8;
237 
238 /******************************************************************************/
239 #ifdef __cplusplus
240 }
241 #endif
242 #endif /* JRITYPES_H */
243 /******************************************************************************/
244