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.

222 lines
7.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. * php4run.swg
  6. *
  7. * PHP4 runtime library
  8. * ----------------------------------------------------------------------------- */
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. #include "zend.h"
  13. #include "zend_API.h"
  14. #include "php.h"
  15. #ifdef ZEND_RAW_FENTRY
  16. /* ZEND_RAW_FENTRY was added somewhere between 5.2.0 and 5.2.3 */
  17. # define SWIG_ZEND_NAMED_FE(ZN, N, A) ZEND_RAW_FENTRY((char*)#ZN, N, A, 0)
  18. #else
  19. /* This causes warnings from GCC >= 4.2 (assigning a string literal to char*).
  20. * But this seems to be unavoidable without directly assuming knowledge of
  21. * the structure, which changed between PHP4 and PHP5. */
  22. # define SWIG_ZEND_NAMED_FE(ZN, N, A) ZEND_NAMED_FE(ZN, N, A)
  23. #endif
  24. #define SWIG_LONG_CONSTANT(N, V) zend_register_long_constant((char*)#N, sizeof(#N), V, CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC)
  25. #define SWIG_DOUBLE_CONSTANT(N, V) zend_register_double_constant((char*)#N, sizeof(#N), V, CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC)
  26. #define SWIG_STRING_CONSTANT(N, V) zend_register_stringl_constant((char*)#N, sizeof(#N), V, strlen(V), CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC)
  27. #define SWIG_CHAR_CONSTANT(N, V) do {\
  28. static char swig_char = (V);\
  29. zend_register_stringl_constant((char*)#N, sizeof(#N), &swig_char, 1, CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC);\
  30. } while (0)
  31. /* These TSRMLS_ stuff should already be defined now, but with older php under
  32. redhat are not... */
  33. #ifndef TSRMLS_D
  34. #define TSRMLS_D
  35. #endif
  36. #ifndef TSRMLS_DC
  37. #define TSRMLS_DC
  38. #endif
  39. #ifndef TSRMLS_C
  40. #define TSRMLS_C
  41. #endif
  42. #ifndef TSRMLS_CC
  43. #define TSRMLS_CC
  44. #endif
  45. #ifdef __cplusplus
  46. }
  47. #endif
  48. /* But in fact SWIG_ConvertPtr is the native interface for getting typed
  49. pointer values out of zvals. We need the TSRMLS_ macros for when we
  50. make PHP type calls later as we handle php resources */
  51. #define SWIG_ConvertPtr(obj,pp,type,flags) SWIG_ZTS_ConvertPtr(obj,pp,type,flags TSRMLS_CC)
  52. #define SWIG_fail goto fail
  53. static const char *default_error_msg = "Unknown error occurred";
  54. static int default_error_code = E_ERROR;
  55. #define SWIG_PHP_Arg_Error_Msg(argnum,extramsg) "Error in argument " #argnum " "#extramsg
  56. #define SWIG_PHP_Error(code,msg) do { SWIG_ErrorCode() = code; SWIG_ErrorMsg() = msg; SWIG_fail; } while (0)
  57. #define SWIG_contract_assert(expr,msg) \
  58. if (!(expr) ) { zend_printf("Contract Assert Failed %s\n",msg ); } else
  59. /* Standard SWIG API */
  60. #define SWIG_GetModule(clientdata) SWIG_Php4_GetModule()
  61. #define SWIG_SetModule(clientdata, pointer) SWIG_Php4_SetModule(pointer)
  62. /* used to wrap returned objects in so we know whether they are newobject
  63. and need freeing, or not */
  64. typedef struct _swig_object_wrapper {
  65. void * ptr;
  66. int newobject;
  67. } swig_object_wrapper;
  68. /* empty zend destructor for types without one */
  69. static ZEND_RSRC_DTOR_FUNC(SWIG_landfill) { (void)rsrc; }
  70. #define SWIG_SetPointerZval(a,b,c,d) SWIG_ZTS_SetPointerZval(a,b,c,d TSRMLS_CC)
  71. static void
  72. SWIG_ZTS_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject TSRMLS_DC) {
  73. swig_object_wrapper *value=NULL;
  74. /*
  75. * First test for Null pointers. Return those as PHP native NULL
  76. */
  77. if (!ptr ) {
  78. ZVAL_NULL(z);
  79. return;
  80. }
  81. if (type->clientdata) {
  82. if (! (*(int *)(type->clientdata)))
  83. zend_error(E_ERROR, "Type: %s failed to register with zend",type->name);
  84. value=(swig_object_wrapper *)emalloc(sizeof(swig_object_wrapper));
  85. value->ptr=ptr;
  86. value->newobject=newobject;
  87. ZEND_REGISTER_RESOURCE(z, value, *(int *)(type->clientdata));
  88. return;
  89. }
  90. zend_error(E_ERROR, "Type: %s not registered with zend",type->name);
  91. }
  92. /* This pointer conversion routine takes the native pointer p (along with
  93. its type name) and converts it by calling appropriate casting functions
  94. according to ty. The resultant pointer is returned, or NULL is returned
  95. if the pointer can't be cast.
  96. Sadly PHP has no API to find a type name from a type id, only from an
  97. instance of a resource of the type id, so we have to pass type_name as well.
  98. The two functions which might call this are:
  99. SWIG_ZTS_ConvertResourcePtr which gets the type name from the resource
  100. and the registered zend destructors for which we have one per type each
  101. with the type name hard wired in. */
  102. static void *
  103. SWIG_ZTS_ConvertResourceData(void * p, const char *type_name, swig_type_info *ty TSRMLS_DC) {
  104. swig_cast_info *tc;
  105. void *result = 0;
  106. if (!ty) {
  107. /* They don't care about the target type, so just pass on the pointer! */
  108. return p;
  109. }
  110. if (! type_name) {
  111. /* can't convert p to ptr type ty if we don't know what type p is */
  112. return NULL;
  113. }
  114. /* convert and cast p from type_name to ptr as ty. */
  115. tc = SWIG_TypeCheck(type_name, ty);
  116. if (tc) {
  117. int newmemory = 0;
  118. result = SWIG_TypeCast(tc, p, &newmemory);
  119. assert(!newmemory); /* newmemory handling not yet implemented */
  120. }
  121. return result;
  122. }
  123. /* This function returns a pointer of type ty by extracting the pointer
  124. and type info from the resource in z. z must be a resource.
  125. If it fails, NULL is returned.
  126. It uses SWIG_ZTS_ConvertResourceData to do the real work. */
  127. static void *
  128. SWIG_ZTS_ConvertResourcePtr(zval *z, swig_type_info *ty, int flags TSRMLS_DC) {
  129. swig_object_wrapper *value;
  130. void *p;
  131. int type;
  132. char *type_name;
  133. value = (swig_object_wrapper *) zend_list_find(z->value.lval, &type);
  134. if ( flags && SWIG_POINTER_DISOWN ) {
  135. value->newobject = 0;
  136. }
  137. p = value->ptr;
  138. if (type==-1) return NULL;
  139. type_name=zend_rsrc_list_get_rsrc_type(z->value.lval TSRMLS_CC);
  140. return SWIG_ZTS_ConvertResourceData(p, type_name, ty TSRMLS_CC);
  141. }
  142. /* We allow passing of a RESOURCE pointing to the object or an OBJECT whose
  143. _cPtr is a resource pointing to the object */
  144. static int
  145. SWIG_ZTS_ConvertPtr(zval *z, void **ptr, swig_type_info *ty, int flags TSRMLS_DC) {
  146. if (z == NULL) {
  147. *ptr = 0;
  148. return 0;
  149. }
  150. switch (z->type) {
  151. case IS_OBJECT: {
  152. zval ** _cPtr;
  153. if (zend_hash_find(HASH_OF(z),(char*)"_cPtr",sizeof("_cPtr"),(void**)&_cPtr)==SUCCESS) {
  154. if ((*_cPtr)->type==IS_RESOURCE) {
  155. *ptr = SWIG_ZTS_ConvertResourcePtr(*_cPtr, ty, flags TSRMLS_CC);
  156. return (*ptr == NULL ? -1 : 0);
  157. }
  158. }
  159. break;
  160. }
  161. case IS_RESOURCE:
  162. *ptr = SWIG_ZTS_ConvertResourcePtr(z, ty, flags TSRMLS_CC);
  163. return (*ptr == NULL ? -1 : 0);
  164. case IS_NULL:
  165. *ptr = 0;
  166. return 0;
  167. }
  168. return -1;
  169. }
  170. static char const_name[] = "swig_runtime_data_type_pointer";
  171. static swig_module_info *SWIG_Php4_GetModule() {
  172. zval *pointer;
  173. swig_module_info *ret = 0;
  174. MAKE_STD_ZVAL(pointer);
  175. TSRMLS_FETCH();
  176. if (zend_get_constant(const_name, sizeof(const_name), pointer TSRMLS_CC)) {
  177. if (pointer->type == IS_LONG) {
  178. ret = (swig_module_info *) pointer->value.lval;
  179. }
  180. }
  181. FREE_ZVAL(pointer);
  182. return ret;
  183. }
  184. static void SWIG_Php4_SetModule(swig_module_info *pointer) {
  185. TSRMLS_FETCH();
  186. REGISTER_MAIN_LONG_CONSTANT(const_name, (long) pointer, 0);
  187. }