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.

154 lines
3.6 KiB

  1. /* -----------------------------------------------------------------------------
  2. * error manipulation
  3. * ----------------------------------------------------------------------------- */
  4. /* Define some additional error types */
  5. #define SWIG_ObjectPreviouslyDeletedError -100
  6. /* Define custom exceptions for errors that do not map to existing Ruby
  7. exceptions. Note this only works for C++ since a global cannot be
  8. initialized by a funtion in C. For C, fallback to rb_eRuntimeError.*/
  9. SWIGINTERN VALUE
  10. getNullReferenceError(void) {
  11. static int init = 0;
  12. static VALUE rb_eNullReferenceError ;
  13. if (!init) {
  14. init = 1;
  15. rb_eNullReferenceError = rb_define_class("NullReferenceError", rb_eRuntimeError);
  16. }
  17. return rb_eNullReferenceError;
  18. }
  19. SWIGINTERN VALUE
  20. getObjectPreviouslyDeletedError(void) {
  21. static int init = 0;
  22. static VALUE rb_eObjectPreviouslyDeleted ;
  23. if (!init) {
  24. init = 1;
  25. rb_eObjectPreviouslyDeleted = rb_define_class("ObjectPreviouslyDeleted", rb_eRuntimeError);
  26. }
  27. return rb_eObjectPreviouslyDeleted;
  28. }
  29. SWIGINTERN VALUE
  30. SWIG_Ruby_ErrorType(int SWIG_code) {
  31. VALUE type;
  32. switch (SWIG_code) {
  33. case SWIG_MemoryError:
  34. type = rb_eNoMemError;
  35. break;
  36. case SWIG_IOError:
  37. type = rb_eIOError;
  38. break;
  39. case SWIG_RuntimeError:
  40. type = rb_eRuntimeError;
  41. break;
  42. case SWIG_IndexError:
  43. type = rb_eIndexError;
  44. break;
  45. case SWIG_TypeError:
  46. type = rb_eTypeError;
  47. break;
  48. case SWIG_DivisionByZero:
  49. type = rb_eZeroDivError;
  50. break;
  51. case SWIG_OverflowError:
  52. type = rb_eRangeError;
  53. break;
  54. case SWIG_SyntaxError:
  55. type = rb_eSyntaxError;
  56. break;
  57. case SWIG_ValueError:
  58. type = rb_eArgError;
  59. break;
  60. case SWIG_SystemError:
  61. type = rb_eFatal;
  62. break;
  63. case SWIG_AttributeError:
  64. type = rb_eRuntimeError;
  65. break;
  66. case SWIG_NullReferenceError:
  67. type = getNullReferenceError();
  68. break;
  69. case SWIG_ObjectPreviouslyDeletedError:
  70. type = getObjectPreviouslyDeletedError();
  71. break;
  72. case SWIG_UnknownError:
  73. type = rb_eRuntimeError;
  74. break;
  75. default:
  76. type = rb_eRuntimeError;
  77. }
  78. return type;
  79. }
  80. /* This function is called when a user inputs a wrong argument to
  81. a method.
  82. */
  83. SWIGINTERN
  84. const char* Ruby_Format_TypeError( const char* msg,
  85. const char* type,
  86. const char* name,
  87. const int argn,
  88. VALUE input )
  89. {
  90. char buf[128];
  91. VALUE str;
  92. VALUE asStr;
  93. if ( msg && *msg )
  94. {
  95. str = rb_str_new2(msg);
  96. }
  97. else
  98. {
  99. str = rb_str_new(NULL, 0);
  100. }
  101. str = rb_str_cat2( str, "Expected argument " );
  102. sprintf( buf, "%d of type ", argn-1 );
  103. str = rb_str_cat2( str, buf );
  104. str = rb_str_cat2( str, type );
  105. str = rb_str_cat2( str, ", but got " );
  106. str = rb_str_cat2( str, rb_obj_classname(input) );
  107. str = rb_str_cat2( str, " " );
  108. asStr = rb_inspect(input);
  109. if ( RSTRING_LEN(asStr) > 30 )
  110. {
  111. str = rb_str_cat( str, StringValuePtr(asStr), 30 );
  112. str = rb_str_cat2( str, "..." );
  113. }
  114. else
  115. {
  116. str = rb_str_append( str, asStr );
  117. }
  118. if ( name )
  119. {
  120. str = rb_str_cat2( str, "\n\tin SWIG method '" );
  121. str = rb_str_cat2( str, name );
  122. str = rb_str_cat2( str, "'" );
  123. }
  124. return StringValuePtr( str );
  125. }
  126. /* This function is called when an overloaded method fails */
  127. SWIGINTERN
  128. void Ruby_Format_OverloadedError(
  129. const int argc,
  130. const int maxargs,
  131. const char* method,
  132. const char* prototypes
  133. )
  134. {
  135. const char* msg = "Wrong # of arguments";
  136. if ( argc <= maxargs ) msg = "Wrong arguments";
  137. rb_raise(rb_eArgError,"%s for overloaded method '%s'.\n"
  138. "Possible C/C++ prototypes are:\n%s",
  139. msg, method, prototypes);
  140. }