OSDN Git Service

1dacbd0810da46c58619fe12164cdd1401ff40f3
[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  Free Software Foundation
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 #include <string.h>
22
23 extern inline jobject
24 JvAllocObject (jclass cls)
25 {
26   return _Jv_AllocObject (cls, cls->size());
27 }
28
29 extern inline jobject
30 JvAllocObject (jclass cls, jsize sz)
31 {
32   return _Jv_AllocObject (cls, sz);
33 }
34
35 extern "C" jstring _Jv_NewStringUTF (const char *bytes);
36 extern "C" void _Jv_InitClass (jclass);
37
38 extern inline void
39 JvInitClass (jclass cls)
40 {
41   return _Jv_InitClass (cls);
42 }
43
44 extern inline jstring
45 JvAllocString (jsize sz)
46 {
47   return _Jv_AllocString (sz);
48 }
49
50 extern inline jstring
51 JvNewString (const jchar *chars, jsize len)
52 {
53   return _Jv_NewString (chars, len);
54 }
55
56 extern inline jstring
57 JvNewStringLatin1 (const char *bytes, jsize len)
58 {
59   return _Jv_NewStringLatin1 (bytes, len);
60 }
61
62 extern inline jstring
63 JvNewStringLatin1 (const char *bytes)
64 {
65   return _Jv_NewStringLatin1 (bytes, strlen (bytes));
66 }
67
68 extern inline jchar *
69 _Jv_GetStringChars (jstring str)
70 {
71   return (jchar*)((char*) str->data + str->boffset);
72 }
73
74 extern inline jchar*
75 JvGetStringChars (jstring str)
76 {
77   return _Jv_GetStringChars (str);
78 }
79
80 extern inline jsize
81 JvGetStringUTFLength (jstring string)
82 {
83   return _Jv_GetStringUTFLength (string);
84 }
85
86 extern inline jsize
87 JvGetStringUTFRegion (jstring str, jsize start, jsize len, char *buf) 
88
89   return _Jv_GetStringUTFRegion (str, start, len, buf); 
90
91
92 extern inline jstring
93 JvNewStringUTF (const char *bytes)
94 {
95   return _Jv_NewStringUTF (bytes);
96 }
97
98 class JvSynchronize
99 {
100 private:
101   jobject obj;
102 public:
103   JvSynchronize (const jobject &o) : obj (o)
104     { _Jv_MonitorEnter (obj); }
105   ~JvSynchronize ()
106     { _Jv_MonitorExit (obj); }
107 };
108
109 #ifdef SJLJ_EXCEPTIONS
110 #define _Jv_Throw _Jv_Sjlj_Throw
111 #endif
112
113 // Throw some exception.
114 extern void JvThrow (jobject obj) __attribute__ ((__noreturn__));
115 extern inline void
116 JvThrow (jobject obj)
117 {
118   _Jv_Throw ((void *) obj);
119 }
120
121 /* Call malloc, but throw exception if insufficient memory. */
122 extern inline void *
123 JvMalloc (jsize size)
124 {
125   return _Jv_Malloc (size);
126 }
127
128 extern inline void
129 JvFree (void *ptr)
130 {
131   return _Jv_Free (ptr);
132 }
133 #endif /* __GCJ_CNI_H__ */