cni.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. /* Copyright (C) 1998, 1999, 2002 Free Software Foundation
  5. This file is part of libgcj.
  6. This software is copyrighted work licensed under the terms of the
  7. Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
  8. details. */
  9. #ifndef __GCJ_CNI_H__
  10. #define __GCJ_CNI_H__
  11. #include <java/lang/Object.h>
  12. #include <java/lang/Class.h>
  13. #include <gcj/array.h>
  14. #include <gcj/javaprims.h>
  15. #include <string.h>
  16. extern "C" void _Jv_InitClass (jclass);
  17. extern "C" void *_Jv_AllocBytes (jsize size) __attribute__((__malloc__));
  18. extern inline void
  19. JvInitClass (jclass cls)
  20. {
  21. return _Jv_InitClass (cls);
  22. }
  23. extern inline void *
  24. JvAllocBytes (jsize sz)
  25. {
  26. return _Jv_AllocBytes (sz);
  27. }
  28. extern inline jstring
  29. JvAllocString (jsize sz)
  30. {
  31. return _Jv_AllocString (sz);
  32. }
  33. extern inline jstring
  34. JvNewString (const jchar *chars, jsize len)
  35. {
  36. return _Jv_NewString (chars, len);
  37. }
  38. extern inline jstring
  39. JvNewStringLatin1 (const char *bytes, jsize len)
  40. {
  41. return _Jv_NewStringLatin1 (bytes, len);
  42. }
  43. extern inline jstring
  44. JvNewStringLatin1 (const char *bytes)
  45. {
  46. return _Jv_NewStringLatin1 (bytes, strlen (bytes));
  47. }
  48. extern inline jchar *
  49. _Jv_GetStringChars (jstring str)
  50. {
  51. return (jchar*)((char*) str->data + str->boffset);
  52. }
  53. extern inline jchar*
  54. JvGetStringChars (jstring str)
  55. {
  56. return _Jv_GetStringChars (str);
  57. }
  58. extern inline jsize
  59. JvGetStringUTFLength (jstring string)
  60. {
  61. return _Jv_GetStringUTFLength (string);
  62. }
  63. extern inline jsize
  64. JvGetStringUTFRegion (jstring str, jsize start, jsize len, char *buf)
  65. {
  66. return _Jv_GetStringUTFRegion (str, start, len, buf);
  67. }
  68. extern inline jstring
  69. JvNewStringUTF (const char *bytes)
  70. {
  71. return _Jv_NewStringUTF (bytes);
  72. }
  73. class JvSynchronize
  74. {
  75. private:
  76. jobject obj;
  77. public:
  78. JvSynchronize (const jobject &o) : obj (o)
  79. { _Jv_MonitorEnter (obj); }
  80. ~JvSynchronize ()
  81. { _Jv_MonitorExit (obj); }
  82. };
  83. /* Call malloc, but throw exception if insufficient memory. */
  84. extern inline void *
  85. JvMalloc (jsize size)
  86. {
  87. return _Jv_Malloc (size);
  88. }
  89. extern inline void *
  90. JvRealloc (void *ptr, jsize size)
  91. {
  92. return _Jv_Realloc (ptr, size);
  93. }
  94. extern inline void
  95. JvFree (void *ptr)
  96. {
  97. return _Jv_Free (ptr);
  98. }
  99. typedef struct _Jv_VMOption JvVMOption;
  100. typedef struct _Jv_VMInitArgs JvVMInitArgs;
  101. extern inline jint
  102. JvCreateJavaVM (JvVMInitArgs* vm_args)
  103. {
  104. return _Jv_CreateJavaVM (vm_args);
  105. }
  106. extern inline java::lang::Thread*
  107. JvAttachCurrentThread (jstring name, java::lang::ThreadGroup* group)
  108. {
  109. return _Jv_AttachCurrentThread (name, group);
  110. }
  111. extern inline java::lang::Thread*
  112. JvAttachCurrentThreadAsDaemon (jstring name, java::lang::ThreadGroup* group)
  113. {
  114. return _Jv_AttachCurrentThreadAsDaemon (name, group);
  115. }
  116. extern inline jint
  117. JvDetachCurrentThread (void)
  118. {
  119. return _Jv_DetachCurrentThread ();
  120. }
  121. #endif /* __GCJ_CNI_H__ */