PageRenderTime 53ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/runtime/ext_zend_compat/ezc_test/ezc_test.cpp

https://gitlab.com/Blueprint-Marketing/hhvm
C++ | 820 lines | 584 code | 113 blank | 123 comment | 83 complexity | e7abaaa3d8218103c2924853640a6744 MD5 | raw file
  1. #ifdef HAVE_CONFIG_H
  2. #include "config.h"
  3. #endif
  4. #include "php.h"
  5. #include "php_ini.h"
  6. #include "ext/standard/info.h" // @nolint
  7. #include "php_ezc_test.h"
  8. #include "zend_exceptions.h"
  9. #include <stdexcept>
  10. static int le_ezc_test_hash;
  11. #define le_ezc_test_hash_name "EZC test hashtable"
  12. static void ezc_hash_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC);
  13. static void ezc_hash_element_dtor(void * data);
  14. static zend_object_value EzcTestCloneable_create_object(zend_class_entry *ce TSRMLS_DC);
  15. static void EzcTestCloneable_free_storage(void *object TSRMLS_DC);
  16. static void EzcTestCloneable_clone_obj(void *object, void **object_clone TSRMLS_DC);
  17. static zend_object_value EzcTestUncloneable1_create_object(zend_class_entry *ce TSRMLS_DC);
  18. static zend_object_value EzcTestUncloneable2_create_object(zend_class_entry *ce TSRMLS_DC);
  19. zend_object_handlers EzcTestCloneable_handlers;
  20. zend_object_handlers EzcTestUncloneable1_handlers;
  21. zend_object_handlers EzcTestUncloneable2_handlers;
  22. zend_class_entry * EzcTestCloneable_ce;
  23. zend_class_entry * EzcTestUncloneable1_ce;
  24. zend_class_entry * EzcTestUncloneable2_ce;
  25. /* {{{ EzcTestCloneable methods
  26. */
  27. const zend_function_entry ezc_empty_methods[] = {
  28. ZEND_FE_END
  29. };
  30. /* }}} */
  31. ZEND_DECLARE_MODULE_GLOBALS(ezc_test)
  32. /* {{{ PHP_INI
  33. */
  34. PHP_INI_BEGIN()
  35. STD_PHP_INI_ENTRY("ezc_test.integer", "42", PHP_INI_ALL, OnUpdateLong, ini_integer, zend_ezc_test_globals, ezc_test_globals)
  36. STD_PHP_INI_ENTRY("ezc_test.string", "foobar", PHP_INI_ALL, OnUpdateString, ini_string, zend_ezc_test_globals, ezc_test_globals)
  37. PHP_INI_END()
  38. /* }}} */
  39. /* {{{ PHP_MINIT_FUNCTION
  40. */
  41. PHP_MINIT_FUNCTION(ezc_test)
  42. {
  43. REGISTER_INI_ENTRIES();
  44. le_ezc_test_hash = zend_register_list_destructors_ex(
  45. ezc_hash_dtor, NULL, le_ezc_test_hash_name, module_number);
  46. zend_class_entry ce;
  47. INIT_CLASS_ENTRY(ce, "EzcTestCloneable", ezc_empty_methods);
  48. EzcTestCloneable_ce = zend_register_internal_class(&ce TSRMLS_CC);
  49. EzcTestCloneable_ce->create_object = EzcTestCloneable_create_object;
  50. memcpy(&EzcTestCloneable_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
  51. EzcTestCloneable_handlers.clone_obj = zend_objects_store_clone_obj;
  52. INIT_CLASS_ENTRY(ce, "EzcTestUncloneable1", ezc_empty_methods);
  53. EzcTestUncloneable1_ce = zend_register_internal_class(&ce TSRMLS_CC);
  54. EzcTestUncloneable1_ce->create_object = EzcTestUncloneable1_create_object;
  55. memcpy(&EzcTestUncloneable1_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
  56. EzcTestUncloneable1_handlers.clone_obj = NULL;
  57. INIT_CLASS_ENTRY(ce, "EzcTestUncloneable2", ezc_empty_methods);
  58. EzcTestUncloneable2_ce = zend_register_internal_class(&ce TSRMLS_CC);
  59. EzcTestUncloneable2_ce->create_object = EzcTestUncloneable2_create_object;
  60. memcpy(&EzcTestUncloneable2_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
  61. EzcTestUncloneable2_handlers.clone_obj = zend_objects_store_clone_obj;
  62. return SUCCESS;
  63. }
  64. /* }}} */
  65. /* {{{ PHP_MSHUTDOWN_FUNCTION
  66. */
  67. PHP_MSHUTDOWN_FUNCTION(ezc_test)
  68. {
  69. UNREGISTER_INI_ENTRIES();
  70. return SUCCESS;
  71. }
  72. /* }}} */
  73. /* {{{ PHP_RINIT_FUNCTION
  74. */
  75. PHP_RINIT_FUNCTION(ezc_test)
  76. {
  77. return SUCCESS;
  78. }
  79. /* }}} */
  80. /* {{{ PHP_RSHUTDOWN_FUNCTION
  81. */
  82. PHP_RSHUTDOWN_FUNCTION(ezc_test)
  83. {
  84. if (EZC_TEST_G(user_global)) {
  85. zval_ptr_dtor(&EZC_TEST_G(user_global));
  86. EZC_TEST_G(user_global) = NULL;
  87. }
  88. return SUCCESS;
  89. }
  90. /* }}} */
  91. /* {{{ PHP_MINFO_FUNCTION
  92. */
  93. PHP_MINFO_FUNCTION(ezc_test)
  94. {
  95. php_info_print_table_start();
  96. php_info_print_table_header(2, "ezc_test support", "enabled");
  97. php_info_print_table_end();
  98. DISPLAY_INI_ENTRIES();
  99. }
  100. /* }}} */
  101. /* {{{ PHP_GINIT_FUNCTION */
  102. PHP_GINIT_FUNCTION(ezc_test)
  103. {
  104. memset(ezc_test_globals, 0, sizeof(*ezc_test_globals));
  105. ezc_test_globals->init = 1;
  106. }
  107. /* }}} */
  108. /* {{{ PHP_GSHUTDOWN_FUNCTION */
  109. PHP_GSHUTDOWN_FUNCTION(ezc_test)
  110. {
  111. if (ezc_test_globals->init != 1) {
  112. php_error_docref(NULL TSRMLS_CC, E_ERROR, "Globals not initialised correctly");
  113. }
  114. ezc_test_globals->init = 0;
  115. }
  116. /* }}} */
  117. /* {{{ ezc_test_post_deactivate */
  118. static int ezc_test_post_deactivate()
  119. {
  120. return SUCCESS;
  121. }
  122. /* }}} */
  123. /* {{{ proto mixed ezc_fetch_global()
  124. * Get the value of the global */
  125. PHP_FUNCTION(ezc_fetch_global)
  126. {
  127. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) {
  128. RETURN_FALSE;
  129. }
  130. if (EZC_TEST_G(user_global) == NULL) {
  131. RETURN_NULL();
  132. }
  133. RETURN_ZVAL(EZC_TEST_G(user_global), 1, 0);
  134. }
  135. /* }}} */
  136. /* {{{ proto void ezc_set_global(mixed value)
  137. * Set the value of the global */
  138. PHP_FUNCTION(ezc_set_global)
  139. {
  140. zval * arg;
  141. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &arg) == FAILURE) {
  142. RETURN_FALSE;
  143. }
  144. if (EZC_TEST_G(user_global)) {
  145. zval_ptr_dtor(&EZC_TEST_G(user_global));
  146. EZC_TEST_G(user_global) = NULL;
  147. }
  148. MAKE_STD_ZVAL(EZC_TEST_G(user_global));
  149. ZVAL_ZVAL(EZC_TEST_G(user_global), arg, 1, 0);
  150. }
  151. /* }}} */
  152. /* {{{ proto mixed ezc_call(mixed function_name [, mixed parameter] [, mixed ...])
  153. * Call a function, like call_user_func() */
  154. PHP_FUNCTION(ezc_call)
  155. {
  156. zval *retval_ptr = NULL;
  157. zend_fcall_info fci;
  158. zend_fcall_info_cache fci_cache;
  159. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "f*",
  160. &fci, &fci_cache, &fci.params, &fci.param_count) == FAILURE) {
  161. return;
  162. }
  163. fci.retval_ptr_ptr = &retval_ptr;
  164. if (zend_call_function(&fci, &fci_cache TSRMLS_CC) == SUCCESS
  165. && fci.retval_ptr_ptr && *fci.retval_ptr_ptr) {
  166. COPY_PZVAL_TO_ZVAL(*return_value, *fci.retval_ptr_ptr);
  167. }
  168. if (fci.params) {
  169. efree(fci.params);
  170. }
  171. }
  172. /* }}} */
  173. /* {{{ proto mixed ezc_try_call(mixed function_name [, mixed parameter] [, mixed ...])
  174. * Call a function. If it throws an exception, catch it and return the exception
  175. * object. Otherwise, return the return value. */
  176. PHP_FUNCTION(ezc_try_call)
  177. {
  178. zval *retval_ptr = NULL;
  179. zend_fcall_info fci;
  180. zend_fcall_info_cache fci_cache;
  181. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "f*",
  182. &fci, &fci_cache, &fci.params, &fci.param_count) == FAILURE) {
  183. return;
  184. }
  185. fci.retval_ptr_ptr = &retval_ptr;
  186. if (zend_call_function(&fci, &fci_cache TSRMLS_CC) == SUCCESS
  187. && fci.retval_ptr_ptr && *fci.retval_ptr_ptr) {
  188. if (EG(exception)) {
  189. /* Unlikely for a function to return a value despite throwing an
  190. * exception, but if it did, I suppose we would have to clean up
  191. * here */
  192. zval_ptr_dtor(fci.retval_ptr_ptr);
  193. } else {
  194. COPY_PZVAL_TO_ZVAL(*return_value, *fci.retval_ptr_ptr);
  195. }
  196. }
  197. if (fci.params) {
  198. efree(fci.params);
  199. }
  200. if (EG(exception)) {
  201. RETVAL_ZVAL(EG(exception), 1, 0);
  202. zend_clear_exception(TSRMLS_C);
  203. }
  204. }
  205. /* }}} */
  206. /* {{{ proto mixed ezc_throw(string exception_class)
  207. * Throw an exception with the class of the given name */
  208. PHP_FUNCTION(ezc_throw)
  209. {
  210. char *class_name = NULL;
  211. int class_name_length;
  212. zend_class_entry *ce;
  213. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
  214. &class_name, &class_name_length) == FAILURE) {
  215. RETURN_FALSE;
  216. }
  217. ce = zend_fetch_class_by_name(
  218. class_name, class_name_length, NULL, ZEND_FETCH_CLASS_SILENT TSRMLS_CC);
  219. if (!ce) {
  220. php_error_docref(NULL TSRMLS_CC, E_WARNING, "no such class \"%s\"",
  221. class_name);
  222. RETURN_FALSE;
  223. }
  224. zend_throw_exception(ce, "ezc_throw", 0 TSRMLS_CC);
  225. }
  226. /* }}} */
  227. /* {{{ proto void ezc_throw_cpp_std()
  228. * Throw a C++ std::exception */
  229. PHP_FUNCTION(ezc_throw_std)
  230. {
  231. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) {
  232. RETURN_FALSE;
  233. }
  234. throw std::runtime_error("ezc_throw_std");
  235. }
  236. /* }}} */
  237. /* {{{ proto void ezc_throw_cpp_nonstd()
  238. * Throw a non-standard C++ exception */
  239. PHP_FUNCTION(ezc_throw_nonstd)
  240. {
  241. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) {
  242. RETURN_FALSE;
  243. }
  244. throw "ezc_throw_nonstd";
  245. }
  246. /* }}} */
  247. /* {{{ proto string ezc_realpath(string path)
  248. * Return the resolved path
  249. */
  250. PHP_FUNCTION(ezc_realpath)
  251. {
  252. char *filename;
  253. int filename_len;
  254. char resolved_path_buff[MAXPATHLEN];
  255. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) {
  256. return;
  257. }
  258. if (VCWD_REALPATH(filename, resolved_path_buff)) {
  259. if (php_check_open_basedir(resolved_path_buff TSRMLS_CC)) {
  260. RETURN_FALSE;
  261. }
  262. #ifdef ZTS
  263. if (VCWD_ACCESS(resolved_path_buff, F_OK)) {
  264. RETURN_FALSE;
  265. }
  266. #endif
  267. RETURN_STRING(resolved_path_buff, 1);
  268. } else {
  269. RETURN_FALSE;
  270. }
  271. }
  272. /* }}} */
  273. /* {{{ proto mixed ezc_min(mixed arg1 [, mixed arg2 [, mixed ...]])
  274. Varadic argument test, equivalent to min() */
  275. PHP_FUNCTION(ezc_min)
  276. {
  277. int argc;
  278. zval ***args = nullptr;
  279. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "+",
  280. &args, &argc) == FAILURE) {
  281. return;
  282. }
  283. zval **min;
  284. zval * result;
  285. ALLOC_ZVAL(result);
  286. int i;
  287. min = args[0];
  288. for (i = 1; i < argc; i++) {
  289. is_smaller_function(result, *args[i], *min TSRMLS_CC);
  290. if (Z_LVAL_P(result) == 1) {
  291. min = args[i];
  292. }
  293. }
  294. FREE_ZVAL(result);
  295. RETVAL_ZVAL(*min, 1, 0);
  296. if (args) {
  297. efree(args);
  298. }
  299. }
  300. /* }}} */
  301. /** {{{ proto resource ezc_hash_create()
  302. * Create a hash which maps string keys to string values. When a value is
  303. * deleted from the hash, it is written to the current output buffer.
  304. */
  305. PHP_FUNCTION(ezc_hash_create)
  306. {
  307. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) {
  308. return;
  309. }
  310. HashTable * hash;
  311. ALLOC_HASHTABLE(hash);
  312. zend_hash_init(hash, 0, NULL, ezc_hash_element_dtor, 0);
  313. ZEND_REGISTER_RESOURCE(return_value, hash, le_ezc_test_hash);
  314. }
  315. /* }}} */
  316. /** {{{ proto void ezc_hash_set(resource table, string key, string value)
  317. * Set a hash item
  318. */
  319. PHP_FUNCTION(ezc_hash_set)
  320. {
  321. zval * zht;
  322. HashTable * hash;
  323. char * key;
  324. int key_len;
  325. char * value;
  326. int value_len;
  327. char * initial_value;
  328. char * dest;
  329. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
  330. "rss", &zht, &key, &key_len, &value, &value_len) == FAILURE) {
  331. return;
  332. }
  333. ZEND_FETCH_RESOURCE(hash, HashTable*, &zht, -1, le_ezc_test_hash_name, le_ezc_test_hash);
  334. initial_value = (char*)ecalloc(1, value_len + 1);
  335. zend_symtable_update(hash, key, key_len + 1, initial_value, value_len + 1, (void**)&dest);
  336. memcpy(dest, value, value_len);
  337. dest[value_len] = '\0';
  338. efree(initial_value);
  339. }
  340. /* }}} */
  341. /** {{{ proto mixed ezc_hash_get(resource table, string key)
  342. * Get a hash item
  343. */
  344. PHP_FUNCTION(ezc_hash_get)
  345. {
  346. zval * zht;
  347. HashTable * hash;
  348. char * key;
  349. int key_len;
  350. char * value;
  351. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
  352. "rs", &zht, &key, &key_len) == FAILURE) {
  353. return;
  354. }
  355. ZEND_FETCH_RESOURCE(hash, HashTable*, &zht, -1, le_ezc_test_hash_name, le_ezc_test_hash);
  356. if (zend_symtable_find(hash, key, key_len + 1, (void**)&value) == SUCCESS) {
  357. RETURN_STRING(value, 1);
  358. } else {
  359. RETURN_FALSE;
  360. }
  361. }
  362. /* }}} */
  363. /** {{{ proto ezc_hash_append(resource table, string value)
  364. * Append a value to the hash, with the next-highest available numeric
  365. * key.
  366. */
  367. PHP_FUNCTION(ezc_hash_append)
  368. {
  369. zval * zht;
  370. HashTable * hash;
  371. char * value;
  372. int value_len;
  373. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
  374. "rs", &zht, &value, &value_len) == FAILURE) {
  375. return;
  376. }
  377. ZEND_FETCH_RESOURCE(hash, HashTable*, &zht, -1, le_ezc_test_hash_name, le_ezc_test_hash);
  378. zend_hash_next_index_insert(hash, value, value_len + 1, NULL);
  379. }
  380. /* }}} */
  381. static void ezc_hash_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) /* {{{ */
  382. {
  383. HashTable * hash = (HashTable*)rsrc->ptr;
  384. zend_hash_destroy(hash);
  385. FREE_HASHTABLE(ht);
  386. }
  387. /* }}} */
  388. static void ezc_hash_element_dtor(void * data) /* {{{ */
  389. {
  390. TSRMLS_FETCH();
  391. char * value = (char*)data;
  392. php_write(value, strlen(value) TSRMLS_CC);
  393. }
  394. /* }}} */
  395. /* {{{ proto void ezc_array_val_set(array a, mixed key, mixed value)
  396. * Set an element of an array passed by value, by modifying the data pointer
  397. * returned by zend_hash_find(). This should theoretically have no effect
  398. * on the caller.
  399. */
  400. PHP_FUNCTION(ezc_array_val_set)
  401. {
  402. zval *array, *key, *value;
  403. zval ** data;
  404. int found;
  405. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
  406. "azz", &array, &key, &value) == FAILURE)
  407. {
  408. return;
  409. }
  410. if (Z_TYPE_P(key) == IS_LONG) {
  411. found = zend_hash_index_find(
  412. Z_ARRVAL_P(array), Z_LVAL_P(key), (void**)&data);
  413. } else if (Z_TYPE_P(key) == IS_STRING) {
  414. found = zend_hash_find(
  415. Z_ARRVAL_P(array), Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, (void**)&data);
  416. } else {
  417. php_error_docref(NULL TSRMLS_CC, E_WARNING, "array key must be either integer or string");
  418. return;
  419. }
  420. if (found == FAILURE) {
  421. php_error_docref(NULL TSRMLS_CC, E_WARNING, "array key must exist");
  422. return;
  423. }
  424. zval_ptr_dtor(data);
  425. Z_ADDREF_P(value);
  426. *data = value;
  427. }
  428. /* }}} */
  429. /* {{{ proto void ezc_array_set(array a, mixed key, mixed value)
  430. * Set an element of an array passed by reference, by modifying the data
  431. * pointer returned by zend_hash_find().
  432. */
  433. PHP_FUNCTION(ezc_array_set)
  434. {
  435. zval *array, *key, *value;
  436. zval **data;
  437. int found;
  438. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
  439. "azz", &array, &key, &value) == FAILURE)
  440. {
  441. return;
  442. }
  443. if (Z_TYPE_P(key) == IS_LONG) {
  444. found = zend_hash_index_find(
  445. Z_ARRVAL_P(array), Z_LVAL_P(key), (void**)&data);
  446. } else if (Z_TYPE_P(key) == IS_STRING) {
  447. found = zend_hash_find(
  448. Z_ARRVAL_P(array), Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, (void**)&data);
  449. } else {
  450. php_error_docref(NULL TSRMLS_CC, E_WARNING, "array key must be either integer or string");
  451. return;
  452. }
  453. if (found == FAILURE) {
  454. php_error_docref(NULL TSRMLS_CC, E_WARNING, "array key must exist");
  455. return;
  456. }
  457. zval_ptr_dtor(data);
  458. Z_ADDREF_P(value);
  459. *data = value;
  460. }
  461. /* }}} */
  462. /* {{{ proto mixed ezc_get_error_reporting()
  463. * Use the zend construct EG(error_reporting) in rval context.
  464. */
  465. PHP_FUNCTION(ezc_get_error_reporting)
  466. {
  467. int old_error_reporting = EG(error_reporting);
  468. RETVAL_LONG(old_error_reporting);
  469. }
  470. /* }}} */
  471. /* {{{ proto mixed ezc_set_error_reporting(integer $val)
  472. * Use the zend construct EG(error_reporting) in rval and then lval context.
  473. */
  474. PHP_FUNCTION(ezc_set_error_reporting)
  475. {
  476. long old_error_reporting = EG(error_reporting);
  477. long new_error_reporting = 0;
  478. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &new_error_reporting) == FAILURE) {
  479. RETURN_FALSE;
  480. }
  481. EG(error_reporting) = new_error_reporting;
  482. RETVAL_LONG(old_error_reporting);
  483. }
  484. /* }}} */
  485. /* {{{ EzcTestCloneable_create_object */
  486. static zend_object_value EzcTestCloneable_create_object(zend_class_entry *ce TSRMLS_DC)
  487. {
  488. php_ezctest_obj * obj = (php_ezctest_obj*)emalloc(sizeof(php_ezctest_obj));
  489. zend_object_value retval;
  490. memset(obj, 0, sizeof(php_ezctest_obj));
  491. zend_object_std_init(&obj->std, ce TSRMLS_CC);
  492. object_properties_init(&obj->std, ce);
  493. obj->clone_count = 0;
  494. retval.handle = zend_objects_store_put(
  495. obj,
  496. (zend_objects_store_dtor_t) NULL,
  497. EzcTestCloneable_free_storage,
  498. EzcTestCloneable_clone_obj
  499. TSRMLS_CC);
  500. retval.handlers = &EzcTestCloneable_handlers;
  501. return retval;
  502. }
  503. /* }}} */
  504. /* {{{ EzcTestCloneable_free_storage */
  505. static void EzcTestCloneable_free_storage(void *object TSRMLS_DC)
  506. {
  507. php_ezctest_obj * eobj = (php_ezctest_obj*)object;
  508. php_printf("EzcTestCloneable free_storage (clone %d)\n", eobj->clone_count);
  509. zend_object_std_dtor(&eobj->std TSRMLS_CC);
  510. efree(object);
  511. }
  512. /* }}} */
  513. /* {{{ EzcTestCloneable_clone_obj */
  514. static void EzcTestCloneable_clone_obj(void *object, void **object_clone TSRMLS_DC)
  515. {
  516. php_ezctest_obj * srcobj = (php_ezctest_obj*)object;
  517. php_ezctest_obj * clone = (php_ezctest_obj*)emalloc(sizeof(php_ezctest_obj));
  518. memset(clone, 0, sizeof(php_ezctest_obj));
  519. zend_object_std_init(&clone->std, srcobj->std.ce TSRMLS_CC);
  520. object_properties_init(&clone->std, srcobj->std.ce);
  521. clone->clone_count = srcobj->clone_count + 1;
  522. *object_clone = (void*)clone;
  523. }
  524. /* }}} */
  525. /* {{{ EzcTestUncloneable1_create_object */
  526. static zend_object_value EzcTestUncloneable1_create_object(zend_class_entry *ce TSRMLS_DC)
  527. {
  528. zend_object * obj;
  529. zend_object_value retval = zend_objects_new(&obj, ce TSRMLS_CC);
  530. retval.handlers = &EzcTestUncloneable1_handlers;
  531. return retval;
  532. }
  533. /* }}} */
  534. /* {{{ EzcTestUncloneable2_create_object */
  535. static zend_object_value EzcTestUncloneable2_create_object(zend_class_entry *ce TSRMLS_DC)
  536. {
  537. zend_object * obj = (zend_object*)emalloc(sizeof(zend_object));
  538. zend_object_value retval;
  539. memset(obj, 0, sizeof(zend_object));
  540. zend_object_std_init(obj, ce TSRMLS_CC);
  541. object_properties_init(obj, ce);
  542. retval.handle = zend_objects_store_put(
  543. obj,
  544. (zend_objects_store_dtor_t) zend_objects_destroy_object,
  545. (zend_objects_free_object_storage_t) zend_objects_free_object_storage,
  546. NULL // clone
  547. TSRMLS_CC);
  548. retval.handlers = &EzcTestUncloneable2_handlers;
  549. return retval;
  550. }
  551. /* }}} */
  552. /* {{{ proto object ezc_create_cloneable_in_array()
  553. * Create an array with a TestCloneable object in it. Test of
  554. * object_init_ex(). */
  555. PHP_FUNCTION(ezc_create_cloneable_in_array)
  556. {
  557. zval * element;
  558. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) {
  559. return;
  560. }
  561. array_init_size(return_value, 1);
  562. ALLOC_INIT_ZVAL(element);
  563. object_init_ex(element, EzcTestCloneable_ce);
  564. zend_hash_next_index_insert(Z_ARRVAL_P(return_value),
  565. (void*)&element, sizeof(zval*), NULL);
  566. }
  567. /* }}} */
  568. /* {{{ proto mixed ezc_atof_toa()
  569. * Convert a string to a double and back to a string again */
  570. PHP_FUNCTION(ezc_atof_toa)
  571. {
  572. char *value;
  573. int valuelen;
  574. double d;
  575. const char *end_value;
  576. const int ndigits = 10;
  577. int decpt = -1;
  578. int sign = -1;
  579. char *result;
  580. char *resulte;
  581. char *composed_result;
  582. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
  583. &value, &valuelen) == FAILURE) {
  584. RETURN_FALSE;
  585. }
  586. d = zend_strtod(value, &end_value);
  587. (void)end_value;
  588. result = zend_dtoa(d, 0, ndigits, &decpt, &sign, &resulte);
  589. asprintf(&composed_result, "%d %d %s", decpt, sign, result);
  590. zend_freedtoa(result);
  591. RETVAL_STRING(composed_result, 1);
  592. }
  593. /* }}} */
  594. /* {{{ arginfo */
  595. ZEND_BEGIN_ARG_INFO(arginfo_ezc_fetch_global, 0)
  596. ZEND_END_ARG_INFO()
  597. ZEND_BEGIN_ARG_INFO(arginfo_ezc_set_global, 0)
  598. ZEND_ARG_INFO(0, value)
  599. ZEND_END_ARG_INFO()
  600. ZEND_BEGIN_ARG_INFO(arginfo_ezc_call, 0)
  601. ZEND_ARG_INFO(0, function_name)
  602. ZEND_ARG_INFO(0, parameter)
  603. ZEND_ARG_INFO(0, ...)
  604. ZEND_END_ARG_INFO()
  605. ZEND_BEGIN_ARG_INFO(arginfo_ezc_try_call, 0)
  606. ZEND_ARG_INFO(0, function_name)
  607. ZEND_ARG_INFO(0, parameter)
  608. ZEND_ARG_INFO(0, ...)
  609. ZEND_END_ARG_INFO()
  610. ZEND_BEGIN_ARG_INFO(arginfo_ezc_throw, 0)
  611. ZEND_ARG_INFO(0, class_name)
  612. ZEND_END_ARG_INFO()
  613. ZEND_BEGIN_ARG_INFO(arginfo_ezc_throw_std, 0)
  614. ZEND_END_ARG_INFO()
  615. ZEND_BEGIN_ARG_INFO(arginfo_ezc_throw_nonstd, 0)
  616. ZEND_END_ARG_INFO()
  617. ZEND_BEGIN_ARG_INFO(arginfo_ezc_realpath, 0)
  618. ZEND_ARG_INFO(0, path)
  619. ZEND_END_ARG_INFO()
  620. ZEND_BEGIN_ARG_INFO_EX(arginfo_ezc_min, 0, 0, 1)
  621. ZEND_ARG_INFO(0, arg1)
  622. ZEND_ARG_INFO(0, arg2)
  623. ZEND_ARG_INFO(0, ...)
  624. ZEND_END_ARG_INFO()
  625. ZEND_BEGIN_ARG_INFO(arginfo_ezc_hash_create, 0)
  626. ZEND_END_ARG_INFO()
  627. ZEND_BEGIN_ARG_INFO(arginfo_ezc_hash_set, 0)
  628. ZEND_ARG_INFO(0, table)
  629. ZEND_ARG_INFO(0, key)
  630. ZEND_ARG_INFO(0, value)
  631. ZEND_END_ARG_INFO()
  632. ZEND_BEGIN_ARG_INFO(arginfo_ezc_hash_get, 0)
  633. ZEND_ARG_INFO(0, table)
  634. ZEND_ARG_INFO(0, key)
  635. ZEND_END_ARG_INFO()
  636. ZEND_BEGIN_ARG_INFO(arginfo_ezc_hash_append, 0)
  637. ZEND_ARG_INFO(0, table)
  638. ZEND_ARG_INFO(0, value)
  639. ZEND_END_ARG_INFO()
  640. ZEND_BEGIN_ARG_INFO(arginfo_ezc_array_val_set, 0)
  641. ZEND_ARG_INFO(0, a)
  642. ZEND_ARG_INFO(0, key)
  643. ZEND_ARG_INFO(0, value)
  644. ZEND_END_ARG_INFO()
  645. ZEND_BEGIN_ARG_INFO(arginfo_ezc_create_cloneable_in_array, 0)
  646. ZEND_END_ARG_INFO()
  647. ZEND_BEGIN_ARG_INFO(arginfo_ezc_array_set, 0)
  648. ZEND_ARG_INFO(1, a)
  649. ZEND_ARG_INFO(0, key)
  650. ZEND_ARG_INFO(0, value)
  651. ZEND_END_ARG_INFO()
  652. ZEND_BEGIN_ARG_INFO(arginfo_ezc_get_error_reporting, 0)
  653. ZEND_END_ARG_INFO()
  654. ZEND_BEGIN_ARG_INFO(arginfo_ezc_set_error_reporting, 0)
  655. ZEND_ARG_INFO(0, value)
  656. ZEND_END_ARG_INFO()
  657. ZEND_BEGIN_ARG_INFO(arginfo_ezc_atof_toa, 0)
  658. ZEND_ARG_INFO(0, value)
  659. ZEND_END_ARG_INFO()
  660. /* }}} */
  661. /* {{{ ezc_test_functions[]
  662. */
  663. const zend_function_entry ezc_test_functions[] = {
  664. PHP_FE(ezc_fetch_global, arginfo_ezc_fetch_global)
  665. PHP_FE(ezc_set_global, arginfo_ezc_set_global)
  666. PHP_FE(ezc_call, arginfo_ezc_call)
  667. PHP_FE(ezc_try_call, arginfo_ezc_try_call)
  668. PHP_FE(ezc_throw, arginfo_ezc_throw)
  669. PHP_FE(ezc_throw_std, arginfo_ezc_throw_std)
  670. PHP_FE(ezc_throw_nonstd, arginfo_ezc_throw_nonstd)
  671. PHP_FE(ezc_realpath, arginfo_ezc_realpath)
  672. PHP_FE(ezc_min, arginfo_ezc_min)
  673. PHP_FE(ezc_hash_create, arginfo_ezc_hash_create)
  674. PHP_FE(ezc_hash_set, arginfo_ezc_hash_set)
  675. PHP_FE(ezc_hash_get, arginfo_ezc_hash_get)
  676. PHP_FE(ezc_hash_append, arginfo_ezc_hash_append)
  677. PHP_FE(ezc_array_val_set, arginfo_ezc_array_val_set)
  678. PHP_FE(ezc_create_cloneable_in_array, arginfo_ezc_create_cloneable_in_array)
  679. PHP_FE(ezc_array_set, arginfo_ezc_array_set)
  680. PHP_FE(ezc_get_error_reporting, arginfo_ezc_get_error_reporting)
  681. PHP_FE(ezc_set_error_reporting, arginfo_ezc_set_error_reporting)
  682. PHP_FE(ezc_atof_toa, arginfo_ezc_atof_toa)
  683. PHP_FE_END
  684. };
  685. /* }}} */
  686. /* {{{ ezc_test_module_entry
  687. */
  688. zend_module_entry ezc_test_module_entry = {
  689. STANDARD_MODULE_HEADER,
  690. "ezc_test",
  691. ezc_test_functions,
  692. PHP_MINIT(ezc_test),
  693. PHP_MSHUTDOWN(ezc_test),
  694. PHP_RINIT(ezc_test),
  695. PHP_RSHUTDOWN(ezc_test),
  696. PHP_MINFO(ezc_test),
  697. PHP_EZC_TEST_VERSION,
  698. PHP_MODULE_GLOBALS(ezc_test),
  699. PHP_GINIT(ezc_test),
  700. PHP_GSHUTDOWN(ezc_test),
  701. ezc_test_post_deactivate,
  702. STANDARD_MODULE_PROPERTIES_EX
  703. };
  704. /* }}} */
  705. #ifdef COMPILE_DL_EZC_TEST
  706. ZEND_GET_MODULE(ezc_test)
  707. #endif