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.

444 lines
13 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. * rubyrun.swg
  6. *
  7. * This file contains the runtime support for Ruby modules
  8. * and includes code for managing global variables and pointer
  9. * type checking.
  10. * ----------------------------------------------------------------------------- */
  11. /* For backward compatibility only */
  12. #define SWIG_POINTER_EXCEPTION 0
  13. /* for raw pointers */
  14. #define SWIG_ConvertPtr(obj, pptr, type, flags) SWIG_Ruby_ConvertPtrAndOwn(obj, pptr, type, flags, 0)
  15. #define SWIG_ConvertPtrAndOwn(obj,pptr,type,flags,own) SWIG_Ruby_ConvertPtrAndOwn(obj, pptr, type, flags, own)
  16. #define SWIG_NewPointerObj(ptr, type, flags) SWIG_Ruby_NewPointerObj(ptr, type, flags)
  17. #define SWIG_AcquirePtr(ptr, own) SWIG_Ruby_AcquirePtr(ptr, own)
  18. #define swig_owntype ruby_owntype
  19. /* for raw packed data */
  20. #define SWIG_ConvertPacked(obj, ptr, sz, ty) SWIG_Ruby_ConvertPacked(obj, ptr, sz, ty, flags)
  21. #define SWIG_NewPackedObj(ptr, sz, type) SWIG_Ruby_NewPackedObj(ptr, sz, type)
  22. /* for class or struct pointers */
  23. #define SWIG_ConvertInstance(obj, pptr, type, flags) SWIG_ConvertPtr(obj, pptr, type, flags)
  24. #define SWIG_NewInstanceObj(ptr, type, flags) SWIG_NewPointerObj(ptr, type, flags)
  25. /* for C or C++ function pointers */
  26. #define SWIG_ConvertFunctionPtr(obj, pptr, type) SWIG_ConvertPtr(obj, pptr, type, 0)
  27. #define SWIG_NewFunctionPtrObj(ptr, type) SWIG_NewPointerObj(ptr, type, 0)
  28. /* for C++ member pointers, ie, member methods */
  29. #define SWIG_ConvertMember(obj, ptr, sz, ty) SWIG_Ruby_ConvertPacked(obj, ptr, sz, ty)
  30. #define SWIG_NewMemberObj(ptr, sz, type) SWIG_Ruby_NewPackedObj(ptr, sz, type)
  31. /* Runtime API */
  32. #define SWIG_GetModule(clientdata) SWIG_Ruby_GetModule()
  33. #define SWIG_SetModule(clientdata, pointer) SWIG_Ruby_SetModule(pointer)
  34. /* Error manipulation */
  35. #define SWIG_ErrorType(code) SWIG_Ruby_ErrorType(code)
  36. #define SWIG_Error(code, msg) rb_raise(SWIG_Ruby_ErrorType(code), msg)
  37. #define SWIG_fail goto fail
  38. /* Ruby-specific SWIG API */
  39. #define SWIG_InitRuntime() SWIG_Ruby_InitRuntime()
  40. #define SWIG_define_class(ty) SWIG_Ruby_define_class(ty)
  41. #define SWIG_NewClassInstance(value, ty) SWIG_Ruby_NewClassInstance(value, ty)
  42. #define SWIG_MangleStr(value) SWIG_Ruby_MangleStr(value)
  43. #define SWIG_CheckConvert(value, ty) SWIG_Ruby_CheckConvert(value, ty)
  44. #include "assert.h"
  45. /* -----------------------------------------------------------------------------
  46. * pointers/data manipulation
  47. * ----------------------------------------------------------------------------- */
  48. #ifdef __cplusplus
  49. extern "C" {
  50. #endif
  51. typedef struct {
  52. VALUE klass;
  53. VALUE mImpl;
  54. void (*mark)(void *);
  55. void (*destroy)(void *);
  56. int trackObjects;
  57. } swig_class;
  58. /* Global pointer used to keep some internal SWIG stuff */
  59. static VALUE _cSWIG_Pointer = Qnil;
  60. static VALUE swig_runtime_data_type_pointer = Qnil;
  61. /* Global IDs used to keep some internal SWIG stuff */
  62. static ID swig_arity_id = 0;
  63. static ID swig_call_id = 0;
  64. /*
  65. If your swig extension is to be run within an embedded ruby and has
  66. director callbacks, you should set -DRUBY_EMBEDDED during compilation.
  67. This will reset ruby's stack frame on each entry point from the main
  68. program the first time a virtual director function is invoked (in a
  69. non-recursive way).
  70. If this is not done, you run the risk of Ruby trashing the stack.
  71. */
  72. #ifdef RUBY_EMBEDDED
  73. # define SWIG_INIT_STACK \
  74. if ( !swig_virtual_calls ) { RUBY_INIT_STACK } \
  75. ++swig_virtual_calls;
  76. # define SWIG_RELEASE_STACK --swig_virtual_calls;
  77. # define Ruby_DirectorTypeMismatchException(x) \
  78. rb_raise( rb_eTypeError, x ); return c_result;
  79. static unsigned int swig_virtual_calls = 0;
  80. #else /* normal non-embedded extension */
  81. # define SWIG_INIT_STACK
  82. # define SWIG_RELEASE_STACK
  83. # define Ruby_DirectorTypeMismatchException(x) \
  84. throw Swig::DirectorTypeMismatchException( x );
  85. #endif /* RUBY_EMBEDDED */
  86. SWIGRUNTIME VALUE
  87. getExceptionClass(void) {
  88. static int init = 0;
  89. static VALUE rubyExceptionClass ;
  90. if (!init) {
  91. init = 1;
  92. rubyExceptionClass = rb_const_get(_mSWIG, rb_intern("Exception"));
  93. }
  94. return rubyExceptionClass;
  95. }
  96. /* This code checks to see if the Ruby object being raised as part
  97. of an exception inherits from the Ruby class Exception. If so,
  98. the object is simply returned. If not, then a new Ruby exception
  99. object is created and that will be returned to Ruby.*/
  100. SWIGRUNTIME VALUE
  101. SWIG_Ruby_ExceptionType(swig_type_info *desc, VALUE obj) {
  102. VALUE exceptionClass = getExceptionClass();
  103. if (rb_obj_is_kind_of(obj, exceptionClass)) {
  104. return obj;
  105. } else {
  106. return rb_exc_new3(rb_eRuntimeError, rb_obj_as_string(obj));
  107. }
  108. }
  109. /* Initialize Ruby runtime support */
  110. SWIGRUNTIME void
  111. SWIG_Ruby_InitRuntime(void)
  112. {
  113. if (_mSWIG == Qnil) {
  114. _mSWIG = rb_define_module("SWIG");
  115. swig_call_id = rb_intern("call");
  116. swig_arity_id = rb_intern("arity");
  117. }
  118. }
  119. /* Define Ruby class for C type */
  120. SWIGRUNTIME void
  121. SWIG_Ruby_define_class(swig_type_info *type)
  122. {
  123. VALUE klass;
  124. char *klass_name = (char *) malloc(4 + strlen(type->name) + 1);
  125. sprintf(klass_name, "TYPE%s", type->name);
  126. if (NIL_P(_cSWIG_Pointer)) {
  127. _cSWIG_Pointer = rb_define_class_under(_mSWIG, "Pointer", rb_cObject);
  128. rb_undef_method(CLASS_OF(_cSWIG_Pointer), "new");
  129. }
  130. klass = rb_define_class_under(_mSWIG, klass_name, _cSWIG_Pointer);
  131. free((void *) klass_name);
  132. }
  133. /* Create a new pointer object */
  134. SWIGRUNTIME VALUE
  135. SWIG_Ruby_NewPointerObj(void *ptr, swig_type_info *type, int flags)
  136. {
  137. int own = flags & SWIG_POINTER_OWN;
  138. int track;
  139. char *klass_name;
  140. swig_class *sklass;
  141. VALUE klass;
  142. VALUE obj;
  143. if (!ptr)
  144. return Qnil;
  145. if (type->clientdata) {
  146. sklass = (swig_class *) type->clientdata;
  147. /* Are we tracking this class and have we already returned this Ruby object? */
  148. track = sklass->trackObjects;
  149. if (track) {
  150. obj = SWIG_RubyInstanceFor(ptr);
  151. /* Check the object's type and make sure it has the correct type.
  152. It might not in cases where methods do things like
  153. downcast methods. */
  154. if (obj != Qnil) {
  155. VALUE value = rb_iv_get(obj, "@__swigtype__");
  156. char* type_name = RSTRING_PTR(value);
  157. if (strcmp(type->name, type_name) == 0) {
  158. return obj;
  159. }
  160. }
  161. }
  162. /* Create a new Ruby object */
  163. obj = Data_Wrap_Struct(sklass->klass, VOIDFUNC(sklass->mark),
  164. ( own ? VOIDFUNC(sklass->destroy) :
  165. (track ? VOIDFUNC(SWIG_RubyRemoveTracking) : 0 )
  166. ), ptr);
  167. /* If tracking is on for this class then track this object. */
  168. if (track) {
  169. SWIG_RubyAddTracking(ptr, obj);
  170. }
  171. } else {
  172. klass_name = (char *) malloc(4 + strlen(type->name) + 1);
  173. sprintf(klass_name, "TYPE%s", type->name);
  174. klass = rb_const_get(_mSWIG, rb_intern(klass_name));
  175. free((void *) klass_name);
  176. obj = Data_Wrap_Struct(klass, 0, 0, ptr);
  177. }
  178. rb_iv_set(obj, "@__swigtype__", rb_str_new2(type->name));
  179. return obj;
  180. }
  181. /* Create a new class instance (always owned) */
  182. SWIGRUNTIME VALUE
  183. SWIG_Ruby_NewClassInstance(VALUE klass, swig_type_info *type)
  184. {
  185. VALUE obj;
  186. swig_class *sklass = (swig_class *) type->clientdata;
  187. obj = Data_Wrap_Struct(klass, VOIDFUNC(sklass->mark), VOIDFUNC(sklass->destroy), 0);
  188. rb_iv_set(obj, "@__swigtype__", rb_str_new2(type->name));
  189. return obj;
  190. }
  191. /* Get type mangle from class name */
  192. SWIGRUNTIMEINLINE char *
  193. SWIG_Ruby_MangleStr(VALUE obj)
  194. {
  195. VALUE stype = rb_iv_get(obj, "@__swigtype__");
  196. return StringValuePtr(stype);
  197. }
  198. /* Acquire a pointer value */
  199. typedef void (*ruby_owntype)(void*);
  200. SWIGRUNTIME ruby_owntype
  201. SWIG_Ruby_AcquirePtr(VALUE obj, ruby_owntype own) {
  202. if (obj) {
  203. ruby_owntype oldown = RDATA(obj)->dfree;
  204. RDATA(obj)->dfree = own;
  205. return oldown;
  206. } else {
  207. return 0;
  208. }
  209. }
  210. /* Convert a pointer value */
  211. SWIGRUNTIME int
  212. SWIG_Ruby_ConvertPtrAndOwn(VALUE obj, void **ptr, swig_type_info *ty, int flags, ruby_owntype *own)
  213. {
  214. char *c;
  215. swig_cast_info *tc;
  216. void *vptr = 0;
  217. /* Grab the pointer */
  218. if (NIL_P(obj)) {
  219. *ptr = 0;
  220. return SWIG_OK;
  221. } else {
  222. if (TYPE(obj) != T_DATA) {
  223. return SWIG_ERROR;
  224. }
  225. Data_Get_Struct(obj, void, vptr);
  226. }
  227. if (own) *own = RDATA(obj)->dfree;
  228. /* Check to see if the input object is giving up ownership
  229. of the underlying C struct or C++ object. If so then we
  230. need to reset the destructor since the Ruby object no
  231. longer owns the underlying C++ object.*/
  232. if (flags & SWIG_POINTER_DISOWN) {
  233. /* Is tracking on for this class? */
  234. int track = 0;
  235. if (ty && ty->clientdata) {
  236. swig_class *sklass = (swig_class *) ty->clientdata;
  237. track = sklass->trackObjects;
  238. }
  239. if (track) {
  240. /* We are tracking objects for this class. Thus we change the destructor
  241. * to SWIG_RubyRemoveTracking. This allows us to
  242. * remove the mapping from the C++ to Ruby object
  243. * when the Ruby object is garbage collected. If we don't
  244. * do this, then it is possible we will return a reference
  245. * to a Ruby object that no longer exists thereby crashing Ruby. */
  246. RDATA(obj)->dfree = SWIG_RubyRemoveTracking;
  247. } else {
  248. RDATA(obj)->dfree = 0;
  249. }
  250. }
  251. /* Do type-checking if type info was provided */
  252. if (ty) {
  253. if (ty->clientdata) {
  254. if (rb_obj_is_kind_of(obj, ((swig_class *) (ty->clientdata))->klass)) {
  255. if (vptr == 0) {
  256. /* The object has already been deleted */
  257. return SWIG_ObjectPreviouslyDeletedError;
  258. }
  259. *ptr = vptr;
  260. return SWIG_OK;
  261. }
  262. }
  263. if ((c = SWIG_MangleStr(obj)) == NULL) {
  264. return SWIG_ERROR;
  265. }
  266. tc = SWIG_TypeCheck(c, ty);
  267. if (!tc) {
  268. return SWIG_ERROR;
  269. } else {
  270. int newmemory = 0;
  271. *ptr = SWIG_TypeCast(tc, vptr, &newmemory);
  272. assert(!newmemory); /* newmemory handling not yet implemented */
  273. }
  274. } else {
  275. *ptr = vptr;
  276. }
  277. return SWIG_OK;
  278. }
  279. /* Check convert */
  280. SWIGRUNTIMEINLINE int
  281. SWIG_Ruby_CheckConvert(VALUE obj, swig_type_info *ty)
  282. {
  283. char *c = SWIG_MangleStr(obj);
  284. if (!c) return 0;
  285. return SWIG_TypeCheck(c,ty) != 0;
  286. }
  287. SWIGRUNTIME VALUE
  288. SWIG_Ruby_NewPackedObj(void *ptr, int sz, swig_type_info *type) {
  289. char result[1024];
  290. char *r = result;
  291. if ((2*sz + 1 + strlen(type->name)) > 1000) return 0;
  292. *(r++) = '_';
  293. r = SWIG_PackData(r, ptr, sz);
  294. strcpy(r, type->name);
  295. return rb_str_new2(result);
  296. }
  297. /* Convert a packed value value */
  298. SWIGRUNTIME int
  299. SWIG_Ruby_ConvertPacked(VALUE obj, void *ptr, int sz, swig_type_info *ty) {
  300. swig_cast_info *tc;
  301. const char *c;
  302. if (TYPE(obj) != T_STRING) goto type_error;
  303. c = StringValuePtr(obj);
  304. /* Pointer values must start with leading underscore */
  305. if (*c != '_') goto type_error;
  306. c++;
  307. c = SWIG_UnpackData(c, ptr, sz);
  308. if (ty) {
  309. tc = SWIG_TypeCheck(c, ty);
  310. if (!tc) goto type_error;
  311. }
  312. return SWIG_OK;
  313. type_error:
  314. return SWIG_ERROR;
  315. }
  316. SWIGRUNTIME swig_module_info *
  317. SWIG_Ruby_GetModule(void)
  318. {
  319. VALUE pointer;
  320. swig_module_info *ret = 0;
  321. VALUE verbose = rb_gv_get("VERBOSE");
  322. /* temporarily disable warnings, since the pointer check causes warnings with 'ruby -w' */
  323. rb_gv_set("VERBOSE", Qfalse);
  324. /* first check if pointer already created */
  325. pointer = rb_gv_get("$swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME);
  326. if (pointer != Qnil) {
  327. Data_Get_Struct(pointer, swig_module_info, ret);
  328. }
  329. /* reinstate warnings */
  330. rb_gv_set("VERBOSE", verbose);
  331. return ret;
  332. }
  333. SWIGRUNTIME void
  334. SWIG_Ruby_SetModule(swig_module_info *pointer)
  335. {
  336. /* register a new class */
  337. VALUE cl = rb_define_class("swig_runtime_data", rb_cObject);
  338. /* create and store the structure pointer to a global variable */
  339. swig_runtime_data_type_pointer = Data_Wrap_Struct(cl, 0, 0, pointer);
  340. rb_define_readonly_variable("$swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME, &swig_runtime_data_type_pointer);
  341. }
  342. /* This function can be used to check whether a proc or method or similarly
  343. callable function has been passed. Usually used in a %typecheck, like:
  344. %typecheck(c_callback_t, precedence=SWIG_TYPECHECK_POINTER) {
  345. $result = SWIG_Ruby_isCallable( $input );
  346. }
  347. */
  348. SWIGINTERN
  349. int SWIG_Ruby_isCallable( VALUE proc )
  350. {
  351. if ( rb_respond_to( proc, swig_call_id ) == Qtrue )
  352. return 1;
  353. return 0;
  354. }
  355. /* This function can be used to check the arity (number of arguments)
  356. a proc or method can take. Usually used in a %typecheck.
  357. Valid arities will be that equal to minimal or those < 0
  358. which indicate a variable number of parameters at the end.
  359. */
  360. SWIGINTERN
  361. int SWIG_Ruby_arity( VALUE proc, int minimal )
  362. {
  363. if ( rb_respond_to( proc, swig_arity_id ) == Qtrue )
  364. {
  365. VALUE num = rb_funcall( proc, swig_arity_id, 0 );
  366. int arity = NUM2INT(num);
  367. if ( arity < 0 && (arity+1) < -minimal ) return 1;
  368. if ( arity == minimal ) return 1;
  369. return 1;
  370. }
  371. return 0;
  372. }
  373. #ifdef __cplusplus
  374. }
  375. #endif