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.

139 lines
3.8 KiB

  1. #include <ruby.h>
  2. /* Remove global macros defined in Ruby's win32.h */
  3. #ifdef write
  4. # undef write
  5. #endif
  6. #ifdef read
  7. # undef read
  8. #endif
  9. /* Ruby 1.7 defines NUM2LL(), LL2NUM() and ULL2NUM() macros */
  10. #ifndef NUM2LL
  11. #define NUM2LL(x) NUM2LONG((x))
  12. #endif
  13. #ifndef LL2NUM
  14. #define LL2NUM(x) INT2NUM((long) (x))
  15. #endif
  16. #ifndef ULL2NUM
  17. #define ULL2NUM(x) UINT2NUM((unsigned long) (x))
  18. #endif
  19. /* Ruby 1.7 doesn't (yet) define NUM2ULL() */
  20. #ifndef NUM2ULL
  21. #ifdef HAVE_LONG_LONG
  22. #define NUM2ULL(x) rb_num2ull((x))
  23. #else
  24. #define NUM2ULL(x) NUM2ULONG(x)
  25. #endif
  26. #endif
  27. /* RSTRING_LEN, etc are new in Ruby 1.9, but ->ptr and ->len no longer work */
  28. /* Define these for older versions so we can just write code the new way */
  29. #ifndef RSTRING_LEN
  30. # define RSTRING_LEN(x) RSTRING(x)->len
  31. #endif
  32. #ifndef RSTRING_PTR
  33. # define RSTRING_PTR(x) RSTRING(x)->ptr
  34. #endif
  35. #ifndef RSTRING_END
  36. # define RSTRING_END(x) (RSTRING_PTR(x) + RSTRING_LEN(x))
  37. #endif
  38. #ifndef RARRAY_LEN
  39. # define RARRAY_LEN(x) RARRAY(x)->len
  40. #endif
  41. #ifndef RARRAY_PTR
  42. # define RARRAY_PTR(x) RARRAY(x)->ptr
  43. #endif
  44. #ifndef RFLOAT_VALUE
  45. # define RFLOAT_VALUE(x) RFLOAT(x)->value
  46. #endif
  47. #ifndef DOUBLE2NUM
  48. # define DOUBLE2NUM(x) rb_float_new(x)
  49. #endif
  50. #ifndef RHASH_TBL
  51. # define RHASH_TBL(x) (RHASH(x)->tbl)
  52. #endif
  53. #ifndef RHASH_ITER_LEV
  54. # define RHASH_ITER_LEV(x) (RHASH(x)->iter_lev)
  55. #endif
  56. #ifndef RHASH_IFNONE
  57. # define RHASH_IFNONE(x) (RHASH(x)->ifnone)
  58. #endif
  59. #ifndef RHASH_SIZE
  60. # define RHASH_SIZE(x) (RHASH(x)->tbl->num_entries)
  61. #endif
  62. #ifndef RHASH_EMPTY_P
  63. # define RHASH_EMPTY_P(x) (RHASH_SIZE(x) == 0)
  64. #endif
  65. #ifndef RSTRUCT_LEN
  66. # define RSTRUCT_LEN(x) RSTRUCT(x)->len
  67. #endif
  68. #ifndef RSTRUCT_PTR
  69. # define RSTRUCT_PTR(x) RSTRUCT(x)->ptr
  70. #endif
  71. /*
  72. * Need to be very careful about how these macros are defined, especially
  73. * when compiling C++ code or C code with an ANSI C compiler.
  74. *
  75. * VALUEFUNC(f) is a macro used to typecast a C function that implements
  76. * a Ruby method so that it can be passed as an argument to API functions
  77. * like rb_define_method() and rb_define_singleton_method().
  78. *
  79. * VOIDFUNC(f) is a macro used to typecast a C function that implements
  80. * either the "mark" or "free" stuff for a Ruby Data object, so that it
  81. * can be passed as an argument to API functions like Data_Wrap_Struct()
  82. * and Data_Make_Struct().
  83. */
  84. #ifdef __cplusplus
  85. # ifndef RUBY_METHOD_FUNC /* These definitions should work for Ruby 1.4.6 */
  86. # define PROTECTFUNC(f) ((VALUE (*)()) f)
  87. # define VALUEFUNC(f) ((VALUE (*)()) f)
  88. # define VOIDFUNC(f) ((void (*)()) f)
  89. # else
  90. # ifndef ANYARGS /* These definitions should work for Ruby 1.6 */
  91. # define PROTECTFUNC(f) ((VALUE (*)()) f)
  92. # define VALUEFUNC(f) ((VALUE (*)()) f)
  93. # define VOIDFUNC(f) ((RUBY_DATA_FUNC) f)
  94. # else /* These definitions should work for Ruby 1.7+ */
  95. # define PROTECTFUNC(f) ((VALUE (*)(VALUE)) f)
  96. # define VALUEFUNC(f) ((VALUE (*)(ANYARGS)) f)
  97. # define VOIDFUNC(f) ((RUBY_DATA_FUNC) f)
  98. # endif
  99. # endif
  100. #else
  101. # define VALUEFUNC(f) (f)
  102. # define VOIDFUNC(f) (f)
  103. #endif
  104. /* Don't use for expressions have side effect */
  105. #ifndef RB_STRING_VALUE
  106. #define RB_STRING_VALUE(s) (TYPE(s) == T_STRING ? (s) : (*(volatile VALUE *)&(s) = rb_str_to_str(s)))
  107. #endif
  108. #ifndef StringValue
  109. #define StringValue(s) RB_STRING_VALUE(s)
  110. #endif
  111. #ifndef StringValuePtr
  112. #define StringValuePtr(s) RSTRING_PTR(RB_STRING_VALUE(s))
  113. #endif
  114. #ifndef StringValueLen
  115. #define StringValueLen(s) RSTRING_LEN(RB_STRING_VALUE(s))
  116. #endif
  117. #ifndef SafeStringValue
  118. #define SafeStringValue(v) do {\
  119. StringValue(v);\
  120. rb_check_safe_str(v);\
  121. } while (0)
  122. #endif
  123. #ifndef HAVE_RB_DEFINE_ALLOC_FUNC
  124. #define rb_define_alloc_func(klass, func) rb_define_singleton_method((klass), "new", VALUEFUNC((func)), -1)
  125. #define rb_undef_alloc_func(klass) rb_undef_method(CLASS_OF((klass)), "new")
  126. #endif
  127. static VALUE _mSWIG = Qnil;