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.

298 lines
8.1 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. * php4.swg
  6. *
  7. * PHP4 configuration file
  8. * ----------------------------------------------------------------------------- */
  9. %runtime "swigrun.swg" // Common C API type-checking code
  10. %runtime "php4run.swg" // Php4 runtime functions
  11. %include <php4init.swg> // Php4 initialization routine.
  12. %include <globalvar.i> // Global variables.
  13. %include <const.i>
  14. // use %init %{ "/*code goes here*/ " %}
  15. // or %minit %{ "/* code goes here*/ " %} to
  16. // insert code in the PHP_MINIT_FUNCTION
  17. #define %minit %insert("init")
  18. // use %rinit %{ "/* code goes here*/ " %} to
  19. // insert code in the PHP_RINIT_FUNCTION
  20. #define %rinit %insert("rinit")
  21. // use %shutdown %{ " /*code goes here*/ " %} to
  22. // insert code in the PHP_MSHUTDOWN_FUNCTION
  23. #define %shutdown %insert("shutdown")
  24. #define %mshutdown %insert("shutdown")
  25. // use %rshutdown %{ " /*code goes here*/" %} to
  26. // insert code in the PHP_RSHUTDOWN_FUNCTION
  27. #define %rshutdown %insert("rshutdown")
  28. /* Typemaps for input parameters by value */
  29. %include <utils.i>
  30. %pass_by_val(bool,CONVERT_BOOL_IN);
  31. %pass_by_val(size_t, CONVERT_INT_IN);
  32. %pass_by_val(enum SWIGTYPE, CONVERT_INT_IN);
  33. %pass_by_val(signed int, CONVERT_INT_IN);
  34. %pass_by_val(int,CONVERT_INT_IN);
  35. %pass_by_val(unsigned int,CONVERT_INT_IN);
  36. %pass_by_val(signed short, CONVERT_INT_IN);
  37. %pass_by_val(short,CONVERT_INT_IN);
  38. %pass_by_val(unsigned short, CONVERT_INT_IN);
  39. %pass_by_val(signed long, CONVERT_INT_IN);
  40. %pass_by_val(long, CONVERT_INT_IN);
  41. %pass_by_val(unsigned long, CONVERT_INT_IN);
  42. %pass_by_val(signed char, CONVERT_INT_IN);
  43. %pass_by_val(char, CONVERT_CHAR_IN);
  44. %pass_by_val(unsigned char, CONVERT_INT_IN);
  45. %pass_by_val(float, CONVERT_FLOAT_IN);
  46. %pass_by_val(double, CONVERT_FLOAT_IN);
  47. %pass_by_val(char *, CONVERT_STRING_IN);
  48. // char array can be in/out, though the passed string may not be big enough...
  49. // so we have to size it
  50. %typemap(in) char[ANY]
  51. {
  52. convert_to_string_ex($input);
  53. $1 = ($1_ltype) Z_STRVAL_PP($input);
  54. }
  55. /* Object passed by value. Convert to a pointer */
  56. %typemap(in) SWIGTYPE ($&1_ltype tmp)
  57. {
  58. if(SWIG_ConvertPtr(*$input, (void **) &tmp, $&1_descriptor, 0) < 0 || tmp == NULL) {
  59. SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor");
  60. }
  61. $1 = *tmp;
  62. }
  63. %typemap(in) SWIGTYPE *,
  64. SWIGTYPE []
  65. {
  66. if(SWIG_ConvertPtr(*$input, (void **) &$1, $1_descriptor, 0) < 0) {
  67. SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor");
  68. }
  69. }
  70. %typemap(in) SWIGTYPE &
  71. {
  72. if(SWIG_ConvertPtr(*$input, (void **) &$1, $1_descriptor, 0) < 0 || $1 == NULL) {
  73. SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor");
  74. }
  75. }
  76. %typemap(in) SWIGTYPE *DISOWN
  77. {
  78. if(SWIG_ConvertPtr(*$input, (void **) &$1, $1_descriptor, SWIG_POINTER_DISOWN ) < 0) {
  79. SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor");
  80. }
  81. }
  82. %typemap(argout) SWIGTYPE *,
  83. SWIGTYPE [],
  84. SWIGTYPE&;
  85. %typemap(in) void *
  86. {
  87. if(SWIG_ConvertPtr(*$input, (void **) &$1, 0, 0) < 0) {
  88. /* Allow NULL from php for void* */
  89. if ((*$input)->type==IS_NULL) $1=0;
  90. else
  91. SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor");
  92. }
  93. }
  94. /* Special case when void* is passed by reference so it can be made to point
  95. to opaque api structs */
  96. %typemap(in) void ** ($*1_ltype ptr, int force),
  97. void *& ($*1_ltype ptr, int force)
  98. {
  99. /* If they pass NULL by reference, make it into a void*
  100. This bit should go in arginit if arginit support init-ing scripting args */
  101. if(SWIG_ConvertPtr(*$input, (void **) &$1, $1_descriptor, 0) < 0) {
  102. /* So... we didn't get a ref or ptr, but we'll accept NULL by reference */
  103. if (!((*$input)->type==IS_NULL && PZVAL_IS_REF(*$input))) {
  104. /* wasn't a pre/ref/thing, OR anything like an int thing */
  105. SWIG_PHP_Error(E_ERROR, "Type error in argument $arg of $symname.");
  106. }
  107. }
  108. force=0;
  109. if (arg1==NULL) {
  110. #ifdef __cplusplus
  111. ptr=new $*1_ltype;
  112. #else
  113. ptr=($*1_ltype) calloc(1,sizeof($*1_ltype));
  114. #endif
  115. $1=&ptr;
  116. /* have to passback arg$arg too */
  117. force=1;
  118. }
  119. }
  120. %typemap(argout) void **,
  121. void *&
  122. {
  123. if (force$argnum) {
  124. SWIG_SetPointerZval( *$input, (void*) ptr$argnum, $*1_descriptor, 1);
  125. }
  126. }
  127. /* Typemap for output values */
  128. %typemap(out) int,
  129. unsigned int,
  130. short,
  131. unsigned short,
  132. long,
  133. unsigned long,
  134. signed char,
  135. unsigned char,
  136. bool,
  137. size_t,
  138. enum SWIGTYPE
  139. {
  140. ZVAL_LONG(return_value,$1);
  141. }
  142. %typemap(out) bool
  143. {
  144. ZVAL_BOOL(return_value,($1)?1:0);
  145. }
  146. %typemap(out) float,
  147. double
  148. {
  149. ZVAL_DOUBLE(return_value,$1);
  150. }
  151. %typemap(out) char
  152. {
  153. ZVAL_STRINGL(return_value,&$1, 1, 1);
  154. }
  155. %typemap(out) char *,
  156. char []
  157. {
  158. if(!$1) {
  159. ZVAL_NULL(return_value);
  160. } else {
  161. ZVAL_STRING(return_value,$1, 1);
  162. }
  163. }
  164. %typemap(out) SWIGTYPE *,
  165. SWIGTYPE [],
  166. SWIGTYPE &
  167. {
  168. SWIG_SetPointerZval(return_value, (void *)$1, $1_descriptor, $owner);
  169. }
  170. %typemap(out) SWIGTYPE *DYNAMIC,
  171. SWIGTYPE &DYNAMIC
  172. {
  173. swig_type_info *ty = SWIG_TypeDynamicCast($1_descriptor, (void **) &$1);
  174. SWIG_SetPointerZval(return_value, (void *)$1, ty, $owner);
  175. }
  176. %typemap(out) SWIGTYPE
  177. #ifdef __cplusplus
  178. {
  179. $&1_ltype resultobj = new $1_ltype(($1_ltype &) $1);
  180. SWIG_SetPointerZval(return_value, (void *)resultobj, $&1_descriptor, 1);
  181. }
  182. #else
  183. {
  184. $&1_ltype resultobj = ($&1_ltype) emalloc(sizeof($1_type));
  185. memmove(resultobj, &$1, sizeof($1_type));
  186. SWIG_SetPointerZval(return_value, (void *)resultobj, $&1_descriptor, 1);
  187. }
  188. #endif
  189. %typemap(out) void "";
  190. %typemap(out) char [ANY]
  191. {
  192. RETVAL_STRINGL($1,$1_dim0,1);
  193. }
  194. // This typecheck does hard checking for proper argument type. If you want
  195. // an argument to be converted from a different PHP type, you must convert
  196. // it yourself before passing it (e.g. (string)4.7 or (int)"6").
  197. %define %php_typecheck(_type,_prec,is)
  198. %typemap(typecheck,precedence=_prec) _type
  199. " $1 = (Z_TYPE_PP($input) == is); "
  200. %enddef
  201. %php_typecheck(int,SWIG_TYPECHECK_INTEGER,IS_LONG)
  202. %php_typecheck(unsigned int,SWIG_TYPECHECK_UINT32,IS_LONG)
  203. %php_typecheck(short,SWIG_TYPECHECK_INT16,IS_LONG)
  204. %php_typecheck(unsigned short,SWIG_TYPECHECK_UINT16,IS_LONG)
  205. %php_typecheck(long,SWIG_TYPECHECK_INT64,IS_LONG)
  206. %php_typecheck(unsigned long,SWIG_TYPECHECK_UINT64,IS_LONG)
  207. %php_typecheck(signed char,SWIG_TYPECHECK_INT8,IS_LONG)
  208. %php_typecheck(unsigned char,SWIG_TYPECHECK_UINT8,IS_LONG)
  209. %php_typecheck(size_t,SWIG_TYPECHECK_INT16,IS_LONG)
  210. %php_typecheck(enum SWIGTYPE,SWIG_TYPECHECK_INT8,IS_LONG)
  211. %php_typecheck(bool,SWIG_TYPECHECK_BOOL,IS_BOOL)
  212. %php_typecheck(char,SWIG_TYPECHECK_CHAR,IS_STRING)
  213. %php_typecheck(char *,SWIG_TYPECHECK_STRING,IS_STRING)
  214. %php_typecheck(char [],SWIG_TYPECHECK_STRING,IS_STRING)
  215. %php_typecheck(float,SWIG_TYPECHECK_FLOAT,IS_DOUBLE)
  216. %php_typecheck(double,SWIG_TYPECHECK_BOOL,IS_DOUBLE)
  217. %typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE
  218. " /* typecheck SWIGTYPE */ "
  219. %typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *,
  220. SWIGTYPE [],
  221. SWIGTYPE &
  222. {
  223. void *tmp;
  224. _v = (SWIG_ConvertPtr( *$input, (void**)&tmp, $1_descriptor, 0) >= 0);
  225. }
  226. %typecheck(SWIG_TYPECHECK_VOIDPTR) void *
  227. " /* typecheck void * */ "
  228. /* Exception handling */
  229. %typemap(throws) int,
  230. long,
  231. short,
  232. unsigned int,
  233. unsigned long,
  234. unsigned short {
  235. char error_msg[256];
  236. sprintf(error_msg, "C++ $1_type exception thrown, value: %d", $1);
  237. SWIG_PHP_Error(E_ERROR, error_msg);
  238. }
  239. %typemap(throws) SWIGTYPE, SWIGTYPE &, SWIGTYPE *, SWIGTYPE [], SWIGTYPE [ANY] %{
  240. (void)$1;
  241. SWIG_PHP_Error(E_ERROR, "C++ $1_type exception thrown");
  242. %}
  243. %typemap(throws) char * %{
  244. SWIG_PHP_Error(E_ERROR, (char *)$1);
  245. %}
  246. /* php keywords */
  247. %include <php4kw.swg>