OSDN Git Service

sjlj jumbo patch
[pf3gnuchains/gcc-fork.git] / libjava / gcj / cni.h
1 // gcj/cni.h -*- c++ -*-
2 // This file describes the Cygnus Native Interface, CNI.
3 // It provides a nicer interface to many of the things in gcj/javaprims.h.
4
5 /* Copyright (C) 1998, 1999  Cygnus Solutions
6
7    This file is part of libgcj.
8
9 This software is copyrighted work licensed under the terms of the
10 Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
11 details.  */
12
13 #ifndef __GCJ_CNI_H__
14 #define __GCJ_CNI_H__
15
16 #include <java/lang/Object.h>
17 #include <java/lang/Class.h>
18
19 #include <gcj/array.h>
20
21 extern inline jobject
22 JvAllocObject (jclass cls)
23 {
24   return _Jv_AllocObject (cls, cls->size());
25 }
26
27 extern inline jobject
28 JvAllocObject (jclass cls, jsize sz)
29 {
30   return _Jv_AllocObject (cls, sz);
31 }
32
33 extern "C" jstring _Jv_NewStringUTF (const char *bytes);
34 extern "C" void _Jv_InitClass (jclass);
35
36 extern inline void
37 JvInitClass (jclass cls)
38 {
39   return _Jv_InitClass (cls);
40 }
41
42 extern inline jstring
43 JvAllocString (jsize sz)
44 {
45   return _Jv_AllocString (sz);
46 }
47
48 extern inline jstring
49 JvNewString (const jchar *chars, jsize len)
50 {
51   return _Jv_NewString (chars, len);
52 }
53
54 extern inline jstring
55 JvNewStringLatin1 (const char *bytes, jsize len)
56 {
57   return _Jv_NewStringLatin1 (bytes, len);
58 }
59
60 extern inline jstring
61 JvNewStringLatin1 (const char *bytes)
62 {
63   return _Jv_NewStringLatin1 (bytes, strlen (bytes));
64 }
65
66 extern inline jchar *
67 _Jv_GetStringChars (jstring str)
68 {
69   return (jchar*)((char*) str->data + str->boffset);
70 }
71
72 extern inline jchar*
73 JvGetStringChars (jstring str)
74 {
75   return _Jv_GetStringChars (str);
76 }
77
78 extern inline jsize
79 JvGetStringUTFLength (jstring string)
80 {
81   return _Jv_GetStringUTFLength (string);
82 }
83
84 extern inline jsize
85 JvGetStringUTFRegion (jstring str, jsize start, jsize len, char *buf) 
86
87   return _Jv_GetStringUTFRegion (str, start, len, buf); 
88
89
90 extern inline jstring
91 JvNewStringUTF (const char *bytes)
92 {
93   return _Jv_NewStringUTF (bytes);
94 }
95
96 extern class _Jv_PrimClass _Jv_byteClass, _Jv_shortClass, _Jv_intClass,
97   _Jv_longClass, _Jv_booleanClass, _Jv_charClass, _Jv_floatClass,
98   _Jv_doubleClass, _Jv_voidClass;
99 #define JvPrimClass(TYPE) ((jclass) & _Jv_##TYPE##Class)
100
101 class JvSynchronize
102 {
103 private:
104   jobject obj;
105 public:
106   JvSynchronize (const jobject &o) : obj (o)
107     { _Jv_MonitorEnter (obj); }
108   ~JvSynchronize ()
109     { _Jv_MonitorExit (obj); }
110 };
111
112 #ifdef SJLJ_EXCEPTIONS
113 #define _Jv_Throw _Jv_Sjlj_Throw
114 #endif
115
116 // Throw some exception.
117 extern void JvThrow (jobject obj) __attribute__ ((__noreturn__));
118 extern inline void
119 JvThrow (jobject obj)
120 {
121   _Jv_Throw ((void *) obj);
122 }
123
124 /* Call malloc, but throw exception if insufficient memory. */
125 extern inline void *
126 JvMalloc (jsize size)
127 {
128   return _Jv_Malloc (size);
129 }
130
131 extern inline void
132 JvFree (void *ptr)
133 {
134   return _Jv_Free (ptr);
135 }
136 #endif /* __GCJ_CNI_H__ */