javaprims.h (_Jv_Utf8Const): Change struct to a class, with private fields and access...
[gcc.git] / libjava / gcj / cni.h
1 // gcj/cni.h -*- c++ -*-
2 // This file describes the Compiled Native Interface, CNI.
3 // It provides a nicer interface to many of the things in gcj/javaprims.h.
4
5 /* Copyright (C) 1998, 1999, 2002 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 "C" void _Jv_InitClass (jclass);
24 extern "C" void *_Jv_AllocBytes (jsize size) __attribute__((__malloc__));
25
26 extern inline void
27 JvInitClass (jclass cls)
28 {
29 return _Jv_InitClass (cls);
30 }
31
32 extern inline void *
33 JvAllocBytes (jsize sz)
34 {
35 return _Jv_AllocBytes (sz);
36 }
37
38 extern inline jstring
39 JvAllocString (jsize sz)
40 {
41 return _Jv_AllocString (sz);
42 }
43
44 extern inline jstring
45 JvNewString (const jchar *chars, jsize len)
46 {
47 return _Jv_NewString (chars, len);
48 }
49
50 extern inline jstring
51 JvNewStringLatin1 (const char *bytes, jsize len)
52 {
53 return _Jv_NewStringLatin1 (bytes, len);
54 }
55
56 extern inline jstring
57 JvNewStringLatin1 (const char *bytes)
58 {
59 return _Jv_NewStringLatin1 (bytes, strlen (bytes));
60 }
61
62 extern inline jchar *
63 _Jv_GetStringChars (jstring str)
64 {
65 return (jchar*)((char*) str->data + str->boffset);
66 }
67
68 extern inline jchar*
69 JvGetStringChars (jstring str)
70 {
71 return _Jv_GetStringChars (str);
72 }
73
74 extern inline jsize
75 JvGetStringUTFLength (jstring string)
76 {
77 return _Jv_GetStringUTFLength (string);
78 }
79
80 extern inline jsize
81 JvGetStringUTFRegion (jstring str, jsize start, jsize len, char *buf)
82 {
83 return _Jv_GetStringUTFRegion (str, start, len, buf);
84 }
85
86 extern inline jstring
87 JvNewStringUTF (const char *bytes)
88 {
89 return _Jv_NewStringUTF (bytes);
90 }
91
92 class JvSynchronize
93 {
94 private:
95 jobject obj;
96 public:
97 JvSynchronize (const jobject &o) : obj (o)
98 { _Jv_MonitorEnter (obj); }
99 ~JvSynchronize ()
100 { _Jv_MonitorExit (obj); }
101 };
102
103 /* Call malloc, but throw exception if insufficient memory. */
104 extern inline void *
105 JvMalloc (jsize size)
106 {
107 return _Jv_Malloc (size);
108 }
109
110 extern inline void
111 JvFree (void *ptr)
112 {
113 return _Jv_Free (ptr);
114 }
115
116 extern inline jint
117 JvCreateJavaVM (void* vm_args)
118 {
119 return _Jv_CreateJavaVM (vm_args);
120 }
121
122 extern inline java::lang::Thread*
123 JvAttachCurrentThread (jstring name, java::lang::ThreadGroup* group)
124 {
125 return _Jv_AttachCurrentThread (name, group);
126 }
127
128 extern inline java::lang::Thread*
129 JvAttachCurrentThreadAsDaemon (jstring name, java::lang::ThreadGroup* group)
130 {
131 return _Jv_AttachCurrentThreadAsDaemon (name, group);
132 }
133
134 extern inline jint
135 JvDetachCurrentThread (void)
136 {
137 return _Jv_DetachCurrentThread ();
138 }
139 #endif /* __GCJ_CNI_H__ */