Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
4.2 KiB

  1. /* -----------------------------------------------------------------------------
  2. * See the LICENSE file for information on copyright, usage and redistribution
  3. * of SWIG, and the README file for authors - http://www.swig.org/release.html.
  4. *
  5. * javahead.swg
  6. *
  7. * Java support code
  8. * ----------------------------------------------------------------------------- */
  9. /* JNI function calls require different calling conventions for C and C++. These JCALL macros are used so
  10. * that the same typemaps can be used for generating code for both C and C++. The SWIG preprocessor can expand
  11. * the macros thereby generating the correct calling convention. It is thus essential that all typemaps that
  12. * use the macros are not within %{ %} brackets as they won't be run through the SWIG preprocessor. */
  13. #ifdef __cplusplus
  14. # define JCALL0(func, jenv) jenv->func()
  15. # define JCALL1(func, jenv, ar1) jenv->func(ar1)
  16. # define JCALL2(func, jenv, ar1, ar2) jenv->func(ar1, ar2)
  17. # define JCALL3(func, jenv, ar1, ar2, ar3) jenv->func(ar1, ar2, ar3)
  18. # define JCALL4(func, jenv, ar1, ar2, ar3, ar4) jenv->func(ar1, ar2, ar3, ar4)
  19. # define JCALL5(func, jenv, ar1, ar2, ar3, ar4, ar5) jenv->func(ar1, ar2, ar3, ar4, ar5)
  20. # define JCALL6(func, jenv, ar1, ar2, ar3, ar4, ar5, ar6) jenv->func(ar1, ar2, ar3, ar4, ar5, ar6)
  21. # define JCALL7(func, jenv, ar1, ar2, ar3, ar4, ar5, ar6, ar7) jenv->func(ar1, ar2, ar3, ar4, ar5, ar6, ar7)
  22. #else
  23. # define JCALL0(func, jenv) (*jenv)->func(jenv)
  24. # define JCALL1(func, jenv, ar1) (*jenv)->func(jenv, ar1)
  25. # define JCALL2(func, jenv, ar1, ar2) (*jenv)->func(jenv, ar1, ar2)
  26. # define JCALL3(func, jenv, ar1, ar2, ar3) (*jenv)->func(jenv, ar1, ar2, ar3)
  27. # define JCALL4(func, jenv, ar1, ar2, ar3, ar4) (*jenv)->func(jenv, ar1, ar2, ar3, ar4)
  28. # define JCALL5(func, jenv, ar1, ar2, ar3, ar4, ar5) (*jenv)->func(jenv, ar1, ar2, ar3, ar4, ar5)
  29. # define JCALL6(func, jenv, ar1, ar2, ar3, ar4, ar5, ar6) (*jenv)->func(jenv, ar1, ar2, ar3, ar4, ar5, ar6)
  30. # define JCALL7(func, jenv, ar1, ar2, ar3, ar4, ar5, ar6, ar7) (*jenv)->func(jenv, ar1, ar2, ar3, ar4, ar5, ar6, ar7)
  31. #endif
  32. %insert(runtime) %{
  33. /* Fix for jlong on some versions of gcc on Windows */
  34. #if defined(__GNUC__) && !defined(__INTELC__)
  35. typedef long long __int64;
  36. #endif
  37. /* Fix for jlong on 64-bit x86 Solaris */
  38. #if defined(__x86_64)
  39. # ifdef _LP64
  40. # undef _LP64
  41. # endif
  42. #endif
  43. #include <jni.h>
  44. #include <stdlib.h>
  45. #include <string.h>
  46. %}
  47. %insert(runtime) %{
  48. /* Support for throwing Java exceptions */
  49. typedef enum {
  50. SWIG_JavaOutOfMemoryError = 1,
  51. SWIG_JavaIOException,
  52. SWIG_JavaRuntimeException,
  53. SWIG_JavaIndexOutOfBoundsException,
  54. SWIG_JavaArithmeticException,
  55. SWIG_JavaIllegalArgumentException,
  56. SWIG_JavaNullPointerException,
  57. SWIG_JavaDirectorPureVirtual,
  58. SWIG_JavaUnknownError
  59. } SWIG_JavaExceptionCodes;
  60. typedef struct {
  61. SWIG_JavaExceptionCodes code;
  62. const char *java_exception;
  63. } SWIG_JavaExceptions_t;
  64. %}
  65. %insert(runtime) {
  66. static void SWIGUNUSED SWIG_JavaThrowException(JNIEnv *jenv, SWIG_JavaExceptionCodes code, const char *msg) {
  67. jclass excep;
  68. static const SWIG_JavaExceptions_t java_exceptions[] = {
  69. { SWIG_JavaOutOfMemoryError, "java/lang/OutOfMemoryError" },
  70. { SWIG_JavaIOException, "java/io/IOException" },
  71. { SWIG_JavaRuntimeException, "java/lang/RuntimeException" },
  72. { SWIG_JavaIndexOutOfBoundsException, "java/lang/IndexOutOfBoundsException" },
  73. { SWIG_JavaArithmeticException, "java/lang/ArithmeticException" },
  74. { SWIG_JavaIllegalArgumentException, "java/lang/IllegalArgumentException" },
  75. { SWIG_JavaNullPointerException, "java/lang/NullPointerException" },
  76. { SWIG_JavaDirectorPureVirtual, "java/lang/RuntimeException" },
  77. { SWIG_JavaUnknownError, "java/lang/UnknownError" },
  78. { (SWIG_JavaExceptionCodes)0, "java/lang/UnknownError" } };
  79. const SWIG_JavaExceptions_t *except_ptr = java_exceptions;
  80. while (except_ptr->code != code && except_ptr->code)
  81. except_ptr++;
  82. JCALL0(ExceptionClear, jenv);
  83. excep = JCALL1(FindClass, jenv, except_ptr->java_exception);
  84. if (excep)
  85. JCALL2(ThrowNew, jenv, excep, msg);
  86. }
  87. }
  88. %insert(runtime) %{
  89. /* Contract support */
  90. #define SWIG_contract_assert(nullreturn, expr, msg) if (!(expr)) {SWIG_JavaThrowException(jenv, SWIG_JavaIllegalArgumentException, msg); return nullreturn; } else
  91. %}