spl_fixedarray.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 5 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2016 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 3.01 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.php.net/license/3_01.txt |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@php.net so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Author: Antony Dovgal <tony@daylessday.org> |
  16. | Etienne Kneuss <colder@php.net> |
  17. +----------------------------------------------------------------------+
  18. */
  19. /* $Id$ */
  20. #ifdef HAVE_CONFIG_H
  21. #include "config.h"
  22. #endif
  23. #include "php.h"
  24. #include "php_ini.h"
  25. #include "ext/standard/info.h"
  26. #include "zend_exceptions.h"
  27. #include "php_spl.h"
  28. #include "spl_functions.h"
  29. #include "spl_engine.h"
  30. #include "spl_fixedarray.h"
  31. #include "spl_exceptions.h"
  32. #include "spl_iterators.h"
  33. zend_object_handlers spl_handler_SplFixedArray;
  34. PHPAPI zend_class_entry *spl_ce_SplFixedArray;
  35. #ifdef COMPILE_DL_SPL_FIXEDARRAY
  36. ZEND_GET_MODULE(spl_fixedarray)
  37. #endif
  38. typedef struct _spl_fixedarray { /* {{{ */
  39. long size;
  40. zval **elements;
  41. } spl_fixedarray;
  42. /* }}} */
  43. typedef struct _spl_fixedarray_object { /* {{{ */
  44. zend_object std;
  45. spl_fixedarray *array;
  46. zval *retval;
  47. zend_function *fptr_offset_get;
  48. zend_function *fptr_offset_set;
  49. zend_function *fptr_offset_has;
  50. zend_function *fptr_offset_del;
  51. zend_function *fptr_count;
  52. int current;
  53. int flags;
  54. zend_class_entry *ce_get_iterator;
  55. } spl_fixedarray_object;
  56. /* }}} */
  57. typedef struct _spl_fixedarray_it { /* {{{ */
  58. zend_user_iterator intern;
  59. spl_fixedarray_object *object;
  60. } spl_fixedarray_it;
  61. /* }}} */
  62. #define SPL_FIXEDARRAY_OVERLOADED_REWIND 0x0001
  63. #define SPL_FIXEDARRAY_OVERLOADED_VALID 0x0002
  64. #define SPL_FIXEDARRAY_OVERLOADED_KEY 0x0004
  65. #define SPL_FIXEDARRAY_OVERLOADED_CURRENT 0x0008
  66. #define SPL_FIXEDARRAY_OVERLOADED_NEXT 0x0010
  67. static void spl_fixedarray_init(spl_fixedarray *array, long size TSRMLS_DC) /* {{{ */
  68. {
  69. if (size > 0) {
  70. array->size = 0; /* reset size in case ecalloc() fails */
  71. array->elements = ecalloc(size, sizeof(zval *));
  72. array->size = size;
  73. } else {
  74. array->elements = NULL;
  75. array->size = 0;
  76. }
  77. }
  78. /* }}} */
  79. static void spl_fixedarray_resize(spl_fixedarray *array, long size TSRMLS_DC) /* {{{ */
  80. {
  81. if (size == array->size) {
  82. /* nothing to do */
  83. return;
  84. }
  85. /* first initialization */
  86. if (array->size == 0) {
  87. spl_fixedarray_init(array, size TSRMLS_CC);
  88. return;
  89. }
  90. /* clearing the array */
  91. if (size == 0) {
  92. long i;
  93. for (i = 0; i < array->size; i++) {
  94. if (array->elements[i]) {
  95. zval_ptr_dtor(&(array->elements[i]));
  96. }
  97. }
  98. if (array->elements) {
  99. efree(array->elements);
  100. array->elements = NULL;
  101. }
  102. } else if (size > array->size) {
  103. array->elements = safe_erealloc(array->elements, size, sizeof(zval *), 0);
  104. memset(array->elements + array->size, '\0', sizeof(zval *) * (size - array->size));
  105. } else { /* size < array->size */
  106. long i;
  107. for (i = size; i < array->size; i++) {
  108. if (array->elements[i]) {
  109. zval_ptr_dtor(&(array->elements[i]));
  110. }
  111. }
  112. array->elements = erealloc(array->elements, sizeof(zval *) * size);
  113. }
  114. array->size = size;
  115. }
  116. /* }}} */
  117. static void spl_fixedarray_copy(spl_fixedarray *to, spl_fixedarray *from TSRMLS_DC) /* {{{ */
  118. {
  119. int i;
  120. for (i = 0; i < from->size; i++) {
  121. if (from->elements[i]) {
  122. Z_ADDREF_P(from->elements[i]);
  123. to->elements[i] = from->elements[i];
  124. } else {
  125. to->elements[i] = NULL;
  126. }
  127. }
  128. }
  129. /* }}} */
  130. static HashTable* spl_fixedarray_object_get_gc(zval *obj, zval ***table, int *n TSRMLS_DC) /* {{{{ */
  131. {
  132. spl_fixedarray_object *intern = (spl_fixedarray_object*)zend_object_store_get_object(obj TSRMLS_CC);
  133. HashTable *ht = zend_std_get_properties(obj TSRMLS_CC);
  134. if (intern->array) {
  135. *table = intern->array->elements;
  136. *n = intern->array->size;
  137. } else {
  138. *table = NULL;
  139. *n = 0;
  140. }
  141. return ht;
  142. }
  143. /* }}}} */
  144. static HashTable* spl_fixedarray_object_get_properties(zval *obj TSRMLS_DC) /* {{{{ */
  145. {
  146. spl_fixedarray_object *intern = (spl_fixedarray_object*)zend_object_store_get_object(obj TSRMLS_CC);
  147. HashTable *ht = zend_std_get_properties(obj TSRMLS_CC);
  148. int i = 0;
  149. if (intern->array) {
  150. int j = zend_hash_num_elements(ht);
  151. for (i = 0; i < intern->array->size; i++) {
  152. if (intern->array->elements[i]) {
  153. zend_hash_index_update(ht, i, (void *)&intern->array->elements[i], sizeof(zval *), NULL);
  154. Z_ADDREF_P(intern->array->elements[i]);
  155. } else {
  156. zend_hash_index_update(ht, i, (void *)&EG(uninitialized_zval_ptr), sizeof(zval *), NULL);
  157. Z_ADDREF_P(EG(uninitialized_zval_ptr));
  158. }
  159. }
  160. if (j > intern->array->size) {
  161. for (i = intern->array->size; i < j; ++i) {
  162. zend_hash_index_del(ht, i);
  163. }
  164. }
  165. }
  166. return ht;
  167. }
  168. /* }}}} */
  169. static void spl_fixedarray_object_free_storage(void *object TSRMLS_DC) /* {{{ */
  170. {
  171. spl_fixedarray_object *intern = (spl_fixedarray_object *)object;
  172. long i;
  173. if (intern->array) {
  174. for (i = 0; i < intern->array->size; i++) {
  175. if (intern->array->elements[i]) {
  176. zval_ptr_dtor(&(intern->array->elements[i]));
  177. }
  178. }
  179. if (intern->array->size > 0 && intern->array->elements) {
  180. efree(intern->array->elements);
  181. }
  182. efree(intern->array);
  183. }
  184. zend_object_std_dtor(&intern->std TSRMLS_CC);
  185. zval_ptr_dtor(&intern->retval);
  186. efree(object);
  187. }
  188. /* }}} */
  189. zend_object_iterator *spl_fixedarray_get_iterator(zend_class_entry *ce, zval *object, int by_ref TSRMLS_DC);
  190. static zend_object_value spl_fixedarray_object_new_ex(zend_class_entry *class_type, spl_fixedarray_object **obj, zval *orig, int clone_orig TSRMLS_DC) /* {{{ */
  191. {
  192. zend_object_value retval;
  193. spl_fixedarray_object *intern;
  194. zend_class_entry *parent = class_type;
  195. int inherited = 0;
  196. intern = ecalloc(1, sizeof(spl_fixedarray_object));
  197. *obj = intern;
  198. ALLOC_INIT_ZVAL(intern->retval);
  199. zend_object_std_init(&intern->std, class_type TSRMLS_CC);
  200. object_properties_init(&intern->std, class_type);
  201. intern->current = 0;
  202. intern->flags = 0;
  203. if (orig && clone_orig) {
  204. spl_fixedarray_object *other = (spl_fixedarray_object*)zend_object_store_get_object(orig TSRMLS_CC);
  205. intern->ce_get_iterator = other->ce_get_iterator;
  206. if (!other->array) {
  207. /* leave a empty object, will be dtor later by CLONE handler */
  208. zend_throw_exception(spl_ce_RuntimeException, "The instance wasn't initialized properly", 0 TSRMLS_CC);
  209. } else {
  210. intern->array = emalloc(sizeof(spl_fixedarray));
  211. spl_fixedarray_init(intern->array, other->array->size TSRMLS_CC);
  212. spl_fixedarray_copy(intern->array, other->array TSRMLS_CC);
  213. }
  214. }
  215. while (parent) {
  216. if (parent == spl_ce_SplFixedArray) {
  217. retval.handlers = &spl_handler_SplFixedArray;
  218. class_type->get_iterator = spl_fixedarray_get_iterator;
  219. break;
  220. }
  221. parent = parent->parent;
  222. inherited = 1;
  223. }
  224. retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, spl_fixedarray_object_free_storage, NULL TSRMLS_CC);
  225. if (!parent) { /* this must never happen */
  226. php_error_docref(NULL TSRMLS_CC, E_COMPILE_ERROR, "Internal compiler error, Class is not child of SplFixedArray");
  227. }
  228. if (!class_type->iterator_funcs.zf_current) {
  229. zend_hash_find(&class_type->function_table, "rewind", sizeof("rewind"), (void **) &class_type->iterator_funcs.zf_rewind);
  230. zend_hash_find(&class_type->function_table, "valid", sizeof("valid"), (void **) &class_type->iterator_funcs.zf_valid);
  231. zend_hash_find(&class_type->function_table, "key", sizeof("key"), (void **) &class_type->iterator_funcs.zf_key);
  232. zend_hash_find(&class_type->function_table, "current", sizeof("current"), (void **) &class_type->iterator_funcs.zf_current);
  233. zend_hash_find(&class_type->function_table, "next", sizeof("next"), (void **) &class_type->iterator_funcs.zf_next);
  234. }
  235. if (inherited) {
  236. if (class_type->iterator_funcs.zf_rewind->common.scope != parent) {
  237. intern->flags |= SPL_FIXEDARRAY_OVERLOADED_REWIND;
  238. }
  239. if (class_type->iterator_funcs.zf_valid->common.scope != parent) {
  240. intern->flags |= SPL_FIXEDARRAY_OVERLOADED_VALID;
  241. }
  242. if (class_type->iterator_funcs.zf_key->common.scope != parent) {
  243. intern->flags |= SPL_FIXEDARRAY_OVERLOADED_KEY;
  244. }
  245. if (class_type->iterator_funcs.zf_current->common.scope != parent) {
  246. intern->flags |= SPL_FIXEDARRAY_OVERLOADED_CURRENT;
  247. }
  248. if (class_type->iterator_funcs.zf_next->common.scope != parent) {
  249. intern->flags |= SPL_FIXEDARRAY_OVERLOADED_NEXT;
  250. }
  251. zend_hash_find(&class_type->function_table, "offsetget", sizeof("offsetget"), (void **) &intern->fptr_offset_get);
  252. if (intern->fptr_offset_get->common.scope == parent) {
  253. intern->fptr_offset_get = NULL;
  254. }
  255. zend_hash_find(&class_type->function_table, "offsetset", sizeof("offsetset"), (void **) &intern->fptr_offset_set);
  256. if (intern->fptr_offset_set->common.scope == parent) {
  257. intern->fptr_offset_set = NULL;
  258. }
  259. zend_hash_find(&class_type->function_table, "offsetexists", sizeof("offsetexists"), (void **) &intern->fptr_offset_has);
  260. if (intern->fptr_offset_has->common.scope == parent) {
  261. intern->fptr_offset_has = NULL;
  262. }
  263. zend_hash_find(&class_type->function_table, "offsetunset", sizeof("offsetunset"), (void **) &intern->fptr_offset_del);
  264. if (intern->fptr_offset_del->common.scope == parent) {
  265. intern->fptr_offset_del = NULL;
  266. }
  267. zend_hash_find(&class_type->function_table, "count", sizeof("count"), (void **) &intern->fptr_count);
  268. if (intern->fptr_count->common.scope == parent) {
  269. intern->fptr_count = NULL;
  270. }
  271. }
  272. return retval;
  273. }
  274. /* }}} */
  275. static zend_object_value spl_fixedarray_new(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
  276. {
  277. spl_fixedarray_object *tmp;
  278. return spl_fixedarray_object_new_ex(class_type, &tmp, NULL, 0 TSRMLS_CC);
  279. }
  280. /* }}} */
  281. static zend_object_value spl_fixedarray_object_clone(zval *zobject TSRMLS_DC) /* {{{ */
  282. {
  283. zend_object_value new_obj_val;
  284. zend_object *old_object;
  285. zend_object *new_object;
  286. zend_object_handle handle = Z_OBJ_HANDLE_P(zobject);
  287. spl_fixedarray_object *intern;
  288. old_object = zend_objects_get_address(zobject TSRMLS_CC);
  289. new_obj_val = spl_fixedarray_object_new_ex(old_object->ce, &intern, zobject, 1 TSRMLS_CC);
  290. new_object = &intern->std;
  291. zend_objects_clone_members(new_object, new_obj_val, old_object, handle TSRMLS_CC);
  292. return new_obj_val;
  293. }
  294. /* }}} */
  295. static inline zval **spl_fixedarray_object_read_dimension_helper(spl_fixedarray_object *intern, zval *offset TSRMLS_DC) /* {{{ */
  296. {
  297. long index;
  298. /* we have to return NULL on error here to avoid memleak because of
  299. * ZE duplicating uninitialized_zval_ptr */
  300. if (!offset) {
  301. zend_throw_exception(spl_ce_RuntimeException, "Index invalid or out of range", 0 TSRMLS_CC);
  302. return NULL;
  303. }
  304. if (Z_TYPE_P(offset) != IS_LONG) {
  305. index = spl_offset_convert_to_long(offset TSRMLS_CC);
  306. } else {
  307. index = Z_LVAL_P(offset);
  308. }
  309. if (index < 0 || intern->array == NULL || index >= intern->array->size) {
  310. zend_throw_exception(spl_ce_RuntimeException, "Index invalid or out of range", 0 TSRMLS_CC);
  311. return NULL;
  312. } else if(!intern->array->elements[index]) {
  313. return NULL;
  314. } else {
  315. return &intern->array->elements[index];
  316. }
  317. }
  318. /* }}} */
  319. static zval *spl_fixedarray_object_read_dimension(zval *object, zval *offset, int type TSRMLS_DC) /* {{{ */
  320. {
  321. spl_fixedarray_object *intern;
  322. zval **retval;
  323. intern = (spl_fixedarray_object *)zend_object_store_get_object(object TSRMLS_CC);
  324. if (intern->fptr_offset_get) {
  325. zval *rv;
  326. if (!offset) {
  327. ALLOC_INIT_ZVAL(offset);
  328. } else {
  329. SEPARATE_ARG_IF_REF(offset);
  330. }
  331. zend_call_method_with_1_params(&object, intern->std.ce, &intern->fptr_offset_get, "offsetGet", &rv, offset);
  332. zval_ptr_dtor(&offset);
  333. if (rv) {
  334. zval_ptr_dtor(&intern->retval);
  335. MAKE_STD_ZVAL(intern->retval);
  336. ZVAL_ZVAL(intern->retval, rv, 1, 1);
  337. return intern->retval;
  338. }
  339. return EG(uninitialized_zval_ptr);
  340. }
  341. retval = spl_fixedarray_object_read_dimension_helper(intern, offset TSRMLS_CC);
  342. if (retval) {
  343. return *retval;
  344. }
  345. return NULL;
  346. }
  347. /* }}} */
  348. static inline void spl_fixedarray_object_write_dimension_helper(spl_fixedarray_object *intern, zval *offset, zval *value TSRMLS_DC) /* {{{ */
  349. {
  350. long index;
  351. if (!offset) {
  352. /* '$array[] = value' syntax is not supported */
  353. zend_throw_exception(spl_ce_RuntimeException, "Index invalid or out of range", 0 TSRMLS_CC);
  354. return;
  355. }
  356. if (Z_TYPE_P(offset) != IS_LONG) {
  357. index = spl_offset_convert_to_long(offset TSRMLS_CC);
  358. } else {
  359. index = Z_LVAL_P(offset);
  360. }
  361. if (index < 0 || intern->array == NULL || index >= intern->array->size) {
  362. zend_throw_exception(spl_ce_RuntimeException, "Index invalid or out of range", 0 TSRMLS_CC);
  363. return;
  364. } else {
  365. if (intern->array->elements[index]) {
  366. zval_ptr_dtor(&(intern->array->elements[index]));
  367. }
  368. SEPARATE_ARG_IF_REF(value);
  369. intern->array->elements[index] = value;
  370. }
  371. }
  372. /* }}} */
  373. static void spl_fixedarray_object_write_dimension(zval *object, zval *offset, zval *value TSRMLS_DC) /* {{{ */
  374. {
  375. spl_fixedarray_object *intern;
  376. intern = (spl_fixedarray_object *)zend_object_store_get_object(object TSRMLS_CC);
  377. if (intern->fptr_offset_set) {
  378. if (!offset) {
  379. ALLOC_INIT_ZVAL(offset);
  380. } else {
  381. SEPARATE_ARG_IF_REF(offset);
  382. }
  383. SEPARATE_ARG_IF_REF(value);
  384. zend_call_method_with_2_params(&object, intern->std.ce, &intern->fptr_offset_set, "offsetSet", NULL, offset, value);
  385. zval_ptr_dtor(&value);
  386. zval_ptr_dtor(&offset);
  387. return;
  388. }
  389. spl_fixedarray_object_write_dimension_helper(intern, offset, value TSRMLS_CC);
  390. }
  391. /* }}} */
  392. static inline void spl_fixedarray_object_unset_dimension_helper(spl_fixedarray_object *intern, zval *offset TSRMLS_DC) /* {{{ */
  393. {
  394. long index;
  395. if (Z_TYPE_P(offset) != IS_LONG) {
  396. index = spl_offset_convert_to_long(offset TSRMLS_CC);
  397. } else {
  398. index = Z_LVAL_P(offset);
  399. }
  400. if (index < 0 || intern->array == NULL || index >= intern->array->size) {
  401. zend_throw_exception(spl_ce_RuntimeException, "Index invalid or out of range", 0 TSRMLS_CC);
  402. return;
  403. } else {
  404. if (intern->array->elements[index]) {
  405. zval_ptr_dtor(&(intern->array->elements[index]));
  406. }
  407. intern->array->elements[index] = NULL;
  408. }
  409. }
  410. /* }}} */
  411. static void spl_fixedarray_object_unset_dimension(zval *object, zval *offset TSRMLS_DC) /* {{{ */
  412. {
  413. spl_fixedarray_object *intern;
  414. intern = (spl_fixedarray_object *)zend_object_store_get_object(object TSRMLS_CC);
  415. if (intern->fptr_offset_del) {
  416. SEPARATE_ARG_IF_REF(offset);
  417. zend_call_method_with_1_params(&object, intern->std.ce, &intern->fptr_offset_del, "offsetUnset", NULL, offset);
  418. zval_ptr_dtor(&offset);
  419. return;
  420. }
  421. spl_fixedarray_object_unset_dimension_helper(intern, offset TSRMLS_CC);
  422. }
  423. /* }}} */
  424. static inline int spl_fixedarray_object_has_dimension_helper(spl_fixedarray_object *intern, zval *offset, int check_empty TSRMLS_DC) /* {{{ */
  425. {
  426. long index;
  427. int retval;
  428. if (Z_TYPE_P(offset) != IS_LONG) {
  429. index = spl_offset_convert_to_long(offset TSRMLS_CC);
  430. } else {
  431. index = Z_LVAL_P(offset);
  432. }
  433. if (index < 0 || intern->array == NULL || index >= intern->array->size) {
  434. retval = 0;
  435. } else {
  436. if (!intern->array->elements[index]) {
  437. retval = 0;
  438. } else if (check_empty) {
  439. if (zend_is_true(intern->array->elements[index])) {
  440. retval = 1;
  441. } else {
  442. retval = 0;
  443. }
  444. } else { /* != NULL and !check_empty */
  445. retval = 1;
  446. }
  447. }
  448. return retval;
  449. }
  450. /* }}} */
  451. static int spl_fixedarray_object_has_dimension(zval *object, zval *offset, int check_empty TSRMLS_DC) /* {{{ */
  452. {
  453. spl_fixedarray_object *intern;
  454. intern = (spl_fixedarray_object *)zend_object_store_get_object(object TSRMLS_CC);
  455. if (intern->fptr_offset_get) {
  456. zval *rv;
  457. SEPARATE_ARG_IF_REF(offset);
  458. zend_call_method_with_1_params(&object, intern->std.ce, &intern->fptr_offset_has, "offsetExists", &rv, offset);
  459. zval_ptr_dtor(&offset);
  460. if (rv) {
  461. zval_ptr_dtor(&intern->retval);
  462. MAKE_STD_ZVAL(intern->retval);
  463. ZVAL_ZVAL(intern->retval, rv, 1, 1);
  464. return zend_is_true(intern->retval);
  465. }
  466. return 0;
  467. }
  468. return spl_fixedarray_object_has_dimension_helper(intern, offset, check_empty TSRMLS_CC);
  469. }
  470. /* }}} */
  471. static int spl_fixedarray_object_count_elements(zval *object, long *count TSRMLS_DC) /* {{{ */
  472. {
  473. spl_fixedarray_object *intern;
  474. intern = (spl_fixedarray_object *)zend_object_store_get_object(object TSRMLS_CC);
  475. if (intern->fptr_count) {
  476. zval *rv;
  477. zend_call_method_with_0_params(&object, intern->std.ce, &intern->fptr_count, "count", &rv);
  478. if (rv) {
  479. zval_ptr_dtor(&intern->retval);
  480. MAKE_STD_ZVAL(intern->retval);
  481. ZVAL_ZVAL(intern->retval, rv, 1, 1);
  482. convert_to_long(intern->retval);
  483. *count = (long) Z_LVAL_P(intern->retval);
  484. return SUCCESS;
  485. }
  486. } else if (intern->array) {
  487. *count = intern->array->size;
  488. return SUCCESS;
  489. }
  490. *count = 0;
  491. return SUCCESS;
  492. }
  493. /* }}} */
  494. /* {{{ proto void SplFixedArray::__construct([int size])
  495. */
  496. SPL_METHOD(SplFixedArray, __construct)
  497. {
  498. zval *object = getThis();
  499. spl_fixedarray_object *intern;
  500. long size = 0;
  501. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &size) == FAILURE) {
  502. return;
  503. }
  504. if (size < 0) {
  505. zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, "array size cannot be less than zero");
  506. return;
  507. }
  508. intern = (spl_fixedarray_object *)zend_object_store_get_object(object TSRMLS_CC);
  509. if (intern->array) {
  510. /* called __construct() twice, bail out */
  511. return;
  512. }
  513. intern->array = emalloc(sizeof(spl_fixedarray));
  514. spl_fixedarray_init(intern->array, size TSRMLS_CC);
  515. }
  516. /* }}} */
  517. /* {{{ proto void SplFixedArray::__wakeup()
  518. */
  519. SPL_METHOD(SplFixedArray, __wakeup)
  520. {
  521. spl_fixedarray_object *intern = (spl_fixedarray_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
  522. HashPosition ptr;
  523. HashTable *intern_ht = zend_std_get_properties(getThis() TSRMLS_CC);
  524. zval **data;
  525. if (zend_parse_parameters_none() == FAILURE) {
  526. return;
  527. }
  528. if (!intern->array) {
  529. int index = 0;
  530. int size = zend_hash_num_elements(intern_ht);
  531. intern->array = emalloc(sizeof(spl_fixedarray));
  532. spl_fixedarray_init(intern->array, size TSRMLS_CC);
  533. for (zend_hash_internal_pointer_reset_ex(intern_ht, &ptr); zend_hash_get_current_data_ex(intern_ht, (void **) &data, &ptr) == SUCCESS; zend_hash_move_forward_ex(intern_ht, &ptr)) {
  534. Z_ADDREF_PP(data);
  535. intern->array->elements[index++] = *data;
  536. }
  537. /* Remove the unserialised properties, since we now have the elements
  538. * within the spl_fixedarray_object structure. */
  539. zend_hash_clean(intern_ht);
  540. }
  541. }
  542. /* }}} */
  543. /* {{{ proto int SplFixedArray::count(void)
  544. */
  545. SPL_METHOD(SplFixedArray, count)
  546. {
  547. zval *object = getThis();
  548. spl_fixedarray_object *intern;
  549. if (zend_parse_parameters_none() == FAILURE) {
  550. return;
  551. }
  552. intern = (spl_fixedarray_object *)zend_object_store_get_object(object TSRMLS_CC);
  553. if (intern->array) {
  554. RETURN_LONG(intern->array->size);
  555. }
  556. RETURN_LONG(0);
  557. }
  558. /* }}} */
  559. /* {{{ proto object SplFixedArray::toArray()
  560. */
  561. SPL_METHOD(SplFixedArray, toArray)
  562. {
  563. spl_fixedarray_object *intern;
  564. if (zend_parse_parameters_none() == FAILURE) {
  565. return;
  566. }
  567. intern = (spl_fixedarray_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
  568. array_init(return_value);
  569. if (intern->array) {
  570. int i = 0;
  571. for (; i < intern->array->size; i++) {
  572. if (intern->array->elements[i]) {
  573. zend_hash_index_update(Z_ARRVAL_P(return_value), i, (void *)&intern->array->elements[i], sizeof(zval *), NULL);
  574. Z_ADDREF_P(intern->array->elements[i]);
  575. } else {
  576. zend_hash_index_update(Z_ARRVAL_P(return_value), i, (void *)&EG(uninitialized_zval_ptr), sizeof(zval *), NULL);
  577. Z_ADDREF_P(EG(uninitialized_zval_ptr));
  578. }
  579. }
  580. }
  581. }
  582. /* }}} */
  583. /* {{{ proto object SplFixedArray::fromArray(array data[, bool save_indexes])
  584. */
  585. SPL_METHOD(SplFixedArray, fromArray)
  586. {
  587. zval *data;
  588. spl_fixedarray *array;
  589. spl_fixedarray_object *intern;
  590. int num;
  591. zend_bool save_indexes = 1;
  592. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|b", &data, &save_indexes) == FAILURE) {
  593. return;
  594. }
  595. array = ecalloc(1, sizeof(*array));
  596. num = zend_hash_num_elements(Z_ARRVAL_P(data));
  597. if (num > 0 && save_indexes) {
  598. zval **element, *value;
  599. char *str_index;
  600. ulong num_index, max_index = 0;
  601. long tmp;
  602. for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(data));
  603. zend_hash_get_current_data(Z_ARRVAL_P(data), (void **) &element) == SUCCESS;
  604. zend_hash_move_forward(Z_ARRVAL_P(data))
  605. ) {
  606. if (zend_hash_get_current_key(Z_ARRVAL_P(data), &str_index, &num_index, 0) != HASH_KEY_IS_LONG || (long)num_index < 0) {
  607. efree(array);
  608. zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, "array must contain only positive integer keys");
  609. return;
  610. }
  611. if (num_index > max_index) {
  612. max_index = num_index;
  613. }
  614. }
  615. tmp = max_index + 1;
  616. if (tmp <= 0) {
  617. efree(array);
  618. zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, "integer overflow detected");
  619. return;
  620. }
  621. spl_fixedarray_init(array, tmp TSRMLS_CC);
  622. for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(data));
  623. zend_hash_get_current_data(Z_ARRVAL_P(data), (void **) &element) == SUCCESS;
  624. zend_hash_move_forward(Z_ARRVAL_P(data))
  625. ) {
  626. zend_hash_get_current_key(Z_ARRVAL_P(data), &str_index, &num_index, 0);
  627. value = *element;
  628. SEPARATE_ARG_IF_REF(value);
  629. array->elements[num_index] = value;
  630. }
  631. } else if (num > 0 && !save_indexes) {
  632. zval **element, *value;
  633. long i = 0;
  634. spl_fixedarray_init(array, num TSRMLS_CC);
  635. for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(data));
  636. zend_hash_get_current_data(Z_ARRVAL_P(data), (void **) &element) == SUCCESS;
  637. zend_hash_move_forward(Z_ARRVAL_P(data))
  638. ) {
  639. value = *element;
  640. SEPARATE_ARG_IF_REF(value);
  641. array->elements[i] = value;
  642. i++;
  643. }
  644. } else {
  645. spl_fixedarray_init(array, 0 TSRMLS_CC);
  646. }
  647. object_init_ex(return_value, spl_ce_SplFixedArray);
  648. Z_TYPE_P(return_value) = IS_OBJECT;
  649. intern = (spl_fixedarray_object *)zend_object_store_get_object(return_value TSRMLS_CC);
  650. intern->array = array;
  651. }
  652. /* }}} */
  653. /* {{{ proto int SplFixedArray::getSize(void)
  654. */
  655. SPL_METHOD(SplFixedArray, getSize)
  656. {
  657. zval *object = getThis();
  658. spl_fixedarray_object *intern;
  659. if (zend_parse_parameters_none() == FAILURE) {
  660. return;
  661. }
  662. intern = (spl_fixedarray_object *)zend_object_store_get_object(object TSRMLS_CC);
  663. if (intern->array) {
  664. RETURN_LONG(intern->array->size);
  665. }
  666. RETURN_LONG(0);
  667. }
  668. /* }}} */
  669. /* {{{ proto bool SplFixedArray::setSize(int size)
  670. */
  671. SPL_METHOD(SplFixedArray, setSize)
  672. {
  673. zval *object = getThis();
  674. spl_fixedarray_object *intern;
  675. long size;
  676. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &size) == FAILURE) {
  677. return;
  678. }
  679. if (size < 0) {
  680. zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, "array size cannot be less than zero");
  681. return;
  682. }
  683. intern = (spl_fixedarray_object *)zend_object_store_get_object(object TSRMLS_CC);
  684. if (!intern->array) {
  685. intern->array = ecalloc(1, sizeof(spl_fixedarray));
  686. }
  687. spl_fixedarray_resize(intern->array, size TSRMLS_CC);
  688. RETURN_TRUE;
  689. }
  690. /* }}} */
  691. /* {{{ proto bool SplFixedArray::offsetExists(mixed $index) U
  692. Returns whether the requested $index exists. */
  693. SPL_METHOD(SplFixedArray, offsetExists)
  694. {
  695. zval *zindex;
  696. spl_fixedarray_object *intern;
  697. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &zindex) == FAILURE) {
  698. return;
  699. }
  700. intern = (spl_fixedarray_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
  701. RETURN_BOOL(spl_fixedarray_object_has_dimension_helper(intern, zindex, 0 TSRMLS_CC));
  702. } /* }}} */
  703. /* {{{ proto mixed SplFixedArray::offsetGet(mixed $index) U
  704. Returns the value at the specified $index. */
  705. SPL_METHOD(SplFixedArray, offsetGet)
  706. {
  707. zval *zindex, **value_pp;
  708. spl_fixedarray_object *intern;
  709. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &zindex) == FAILURE) {
  710. return;
  711. }
  712. intern = (spl_fixedarray_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
  713. value_pp = spl_fixedarray_object_read_dimension_helper(intern, zindex TSRMLS_CC);
  714. if (value_pp) {
  715. RETURN_ZVAL(*value_pp, 1, 0);
  716. }
  717. RETURN_NULL();
  718. } /* }}} */
  719. /* {{{ proto void SplFixedArray::offsetSet(mixed $index, mixed $newval) U
  720. Sets the value at the specified $index to $newval. */
  721. SPL_METHOD(SplFixedArray, offsetSet)
  722. {
  723. zval *zindex, *value;
  724. spl_fixedarray_object *intern;
  725. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &zindex, &value) == FAILURE) {
  726. return;
  727. }
  728. intern = (spl_fixedarray_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
  729. spl_fixedarray_object_write_dimension_helper(intern, zindex, value TSRMLS_CC);
  730. } /* }}} */
  731. /* {{{ proto void SplFixedArray::offsetUnset(mixed $index) U
  732. Unsets the value at the specified $index. */
  733. SPL_METHOD(SplFixedArray, offsetUnset)
  734. {
  735. zval *zindex;
  736. spl_fixedarray_object *intern;
  737. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &zindex) == FAILURE) {
  738. return;
  739. }
  740. intern = (spl_fixedarray_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
  741. spl_fixedarray_object_unset_dimension_helper(intern, zindex TSRMLS_CC);
  742. } /* }}} */
  743. static void spl_fixedarray_it_dtor(zend_object_iterator *iter TSRMLS_DC) /* {{{ */
  744. {
  745. spl_fixedarray_it *iterator = (spl_fixedarray_it *)iter;
  746. zend_user_it_invalidate_current(iter TSRMLS_CC);
  747. zval_ptr_dtor((zval**)&iterator->intern.it.data);
  748. efree(iterator);
  749. }
  750. /* }}} */
  751. static void spl_fixedarray_it_rewind(zend_object_iterator *iter TSRMLS_DC) /* {{{ */
  752. {
  753. spl_fixedarray_it *iterator = (spl_fixedarray_it *)iter;
  754. spl_fixedarray_object *intern = iterator->object;
  755. if (intern->flags & SPL_FIXEDARRAY_OVERLOADED_REWIND) {
  756. zend_user_it_rewind(iter TSRMLS_CC);
  757. } else {
  758. iterator->object->current = 0;
  759. }
  760. }
  761. /* }}} */
  762. static int spl_fixedarray_it_valid(zend_object_iterator *iter TSRMLS_DC) /* {{{ */
  763. {
  764. spl_fixedarray_it *iterator = (spl_fixedarray_it *)iter;
  765. spl_fixedarray_object *intern = iterator->object;
  766. if (intern->flags & SPL_FIXEDARRAY_OVERLOADED_VALID) {
  767. return zend_user_it_valid(iter TSRMLS_CC);
  768. }
  769. if (iterator->object->current >= 0 && iterator->object->array && iterator->object->current < iterator->object->array->size) {
  770. return SUCCESS;
  771. }
  772. return FAILURE;
  773. }
  774. /* }}} */
  775. static void spl_fixedarray_it_get_current_data(zend_object_iterator *iter, zval ***data TSRMLS_DC) /* {{{ */
  776. {
  777. zval *zindex;
  778. spl_fixedarray_it *iterator = (spl_fixedarray_it *)iter;
  779. spl_fixedarray_object *intern = iterator->object;
  780. if (intern->flags & SPL_FIXEDARRAY_OVERLOADED_CURRENT) {
  781. zend_user_it_get_current_data(iter, data TSRMLS_CC);
  782. } else {
  783. ALLOC_INIT_ZVAL(zindex);
  784. ZVAL_LONG(zindex, iterator->object->current);
  785. *data = spl_fixedarray_object_read_dimension_helper(intern, zindex TSRMLS_CC);
  786. if (*data == NULL) {
  787. *data = &EG(uninitialized_zval_ptr);
  788. }
  789. zval_ptr_dtor(&zindex);
  790. }
  791. }
  792. /* }}} */
  793. static void spl_fixedarray_it_get_current_key(zend_object_iterator *iter, zval *key TSRMLS_DC) /* {{{ */
  794. {
  795. spl_fixedarray_it *iterator = (spl_fixedarray_it *)iter;
  796. spl_fixedarray_object *intern = iterator->object;
  797. if (intern->flags & SPL_FIXEDARRAY_OVERLOADED_KEY) {
  798. zend_user_it_get_current_key(iter, key TSRMLS_CC);
  799. } else {
  800. ZVAL_LONG(key, iterator->object->current);
  801. }
  802. }
  803. /* }}} */
  804. static void spl_fixedarray_it_move_forward(zend_object_iterator *iter TSRMLS_DC) /* {{{ */
  805. {
  806. spl_fixedarray_it *iterator = (spl_fixedarray_it *)iter;
  807. spl_fixedarray_object *intern = iterator->object;
  808. if (intern->flags & SPL_FIXEDARRAY_OVERLOADED_NEXT) {
  809. zend_user_it_move_forward(iter TSRMLS_CC);
  810. } else {
  811. zend_user_it_invalidate_current(iter TSRMLS_CC);
  812. iterator->object->current++;
  813. }
  814. }
  815. /* }}} */
  816. /* {{{ proto int SplFixedArray::key() U
  817. Return current array key */
  818. SPL_METHOD(SplFixedArray, key)
  819. {
  820. spl_fixedarray_object *intern = (spl_fixedarray_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
  821. if (zend_parse_parameters_none() == FAILURE) {
  822. return;
  823. }
  824. RETURN_LONG(intern->current);
  825. }
  826. /* }}} */
  827. /* {{{ proto void SplFixedArray::next() U
  828. Move to next entry */
  829. SPL_METHOD(SplFixedArray, next)
  830. {
  831. spl_fixedarray_object *intern = (spl_fixedarray_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
  832. if (zend_parse_parameters_none() == FAILURE) {
  833. return;
  834. }
  835. intern->current++;
  836. }
  837. /* }}} */
  838. /* {{{ proto bool SplFixedArray::valid() U
  839. Check whether the datastructure contains more entries */
  840. SPL_METHOD(SplFixedArray, valid)
  841. {
  842. spl_fixedarray_object *intern = (spl_fixedarray_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
  843. if (zend_parse_parameters_none() == FAILURE) {
  844. return;
  845. }
  846. RETURN_BOOL(intern->current >= 0 && intern->array && intern->current < intern->array->size);
  847. }
  848. /* }}} */
  849. /* {{{ proto void SplFixedArray::rewind() U
  850. Rewind the datastructure back to the start */
  851. SPL_METHOD(SplFixedArray, rewind)
  852. {
  853. spl_fixedarray_object *intern = (spl_fixedarray_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
  854. if (zend_parse_parameters_none() == FAILURE) {
  855. return;
  856. }
  857. intern->current = 0;
  858. }
  859. /* }}} */
  860. /* {{{ proto mixed|NULL SplFixedArray::current() U
  861. Return current datastructure entry */
  862. SPL_METHOD(SplFixedArray, current)
  863. {
  864. zval *zindex, **value_pp;
  865. spl_fixedarray_object *intern = (spl_fixedarray_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
  866. if (zend_parse_parameters_none() == FAILURE) {
  867. return;
  868. }
  869. ALLOC_INIT_ZVAL(zindex);
  870. ZVAL_LONG(zindex, intern->current);
  871. value_pp = spl_fixedarray_object_read_dimension_helper(intern, zindex TSRMLS_CC);
  872. zval_ptr_dtor(&zindex);
  873. if (value_pp) {
  874. RETURN_ZVAL(*value_pp, 1, 0);
  875. }
  876. RETURN_NULL();
  877. }
  878. /* }}} */
  879. /* iterator handler table */
  880. zend_object_iterator_funcs spl_fixedarray_it_funcs = {
  881. spl_fixedarray_it_dtor,
  882. spl_fixedarray_it_valid,
  883. spl_fixedarray_it_get_current_data,
  884. spl_fixedarray_it_get_current_key,
  885. spl_fixedarray_it_move_forward,
  886. spl_fixedarray_it_rewind
  887. };
  888. zend_object_iterator *spl_fixedarray_get_iterator(zend_class_entry *ce, zval *object, int by_ref TSRMLS_DC) /* {{{ */
  889. {
  890. spl_fixedarray_it *iterator;
  891. spl_fixedarray_object *fixedarray_object = (spl_fixedarray_object*)zend_object_store_get_object(object TSRMLS_CC);
  892. if (by_ref) {
  893. zend_throw_exception(spl_ce_RuntimeException, "An iterator cannot be used with foreach by reference", 0 TSRMLS_CC);
  894. return NULL;
  895. }
  896. Z_ADDREF_P(object);
  897. iterator = emalloc(sizeof(spl_fixedarray_it));
  898. iterator->intern.it.data = (void*)object;
  899. iterator->intern.it.funcs = &spl_fixedarray_it_funcs;
  900. iterator->intern.ce = ce;
  901. iterator->intern.value = NULL;
  902. iterator->object = fixedarray_object;
  903. return (zend_object_iterator*)iterator;
  904. }
  905. /* }}} */
  906. ZEND_BEGIN_ARG_INFO_EX(arginfo_splfixedarray_construct, 0, 0, 0)
  907. ZEND_ARG_INFO(0, size)
  908. ZEND_END_ARG_INFO()
  909. ZEND_BEGIN_ARG_INFO_EX(arginfo_fixedarray_offsetGet, 0, 0, 1)
  910. ZEND_ARG_INFO(0, index)
  911. ZEND_END_ARG_INFO()
  912. ZEND_BEGIN_ARG_INFO_EX(arginfo_fixedarray_offsetSet, 0, 0, 2)
  913. ZEND_ARG_INFO(0, index)
  914. ZEND_ARG_INFO(0, newval)
  915. ZEND_END_ARG_INFO()
  916. ZEND_BEGIN_ARG_INFO(arginfo_fixedarray_setSize, 0)
  917. ZEND_ARG_INFO(0, value)
  918. ZEND_END_ARG_INFO()
  919. ZEND_BEGIN_ARG_INFO_EX(arginfo_fixedarray_fromArray, 0, 0, 1)
  920. ZEND_ARG_INFO(0, data)
  921. ZEND_ARG_INFO(0, save_indexes)
  922. ZEND_END_ARG_INFO()
  923. ZEND_BEGIN_ARG_INFO(arginfo_splfixedarray_void, 0)
  924. ZEND_END_ARG_INFO()
  925. static zend_function_entry spl_funcs_SplFixedArray[] = { /* {{{ */
  926. SPL_ME(SplFixedArray, __construct, arginfo_splfixedarray_construct,ZEND_ACC_PUBLIC)
  927. SPL_ME(SplFixedArray, __wakeup, arginfo_splfixedarray_void, ZEND_ACC_PUBLIC)
  928. SPL_ME(SplFixedArray, count, arginfo_splfixedarray_void, ZEND_ACC_PUBLIC)
  929. SPL_ME(SplFixedArray, toArray, arginfo_splfixedarray_void, ZEND_ACC_PUBLIC)
  930. SPL_ME(SplFixedArray, fromArray, arginfo_fixedarray_fromArray, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
  931. SPL_ME(SplFixedArray, getSize, arginfo_splfixedarray_void, ZEND_ACC_PUBLIC)
  932. SPL_ME(SplFixedArray, setSize, arginfo_fixedarray_setSize, ZEND_ACC_PUBLIC)
  933. SPL_ME(SplFixedArray, offsetExists, arginfo_fixedarray_offsetGet, ZEND_ACC_PUBLIC)
  934. SPL_ME(SplFixedArray, offsetGet, arginfo_fixedarray_offsetGet, ZEND_ACC_PUBLIC)
  935. SPL_ME(SplFixedArray, offsetSet, arginfo_fixedarray_offsetSet, ZEND_ACC_PUBLIC)
  936. SPL_ME(SplFixedArray, offsetUnset, arginfo_fixedarray_offsetGet, ZEND_ACC_PUBLIC)
  937. SPL_ME(SplFixedArray, rewind, arginfo_splfixedarray_void, ZEND_ACC_PUBLIC)
  938. SPL_ME(SplFixedArray, current, arginfo_splfixedarray_void, ZEND_ACC_PUBLIC)
  939. SPL_ME(SplFixedArray, key, arginfo_splfixedarray_void, ZEND_ACC_PUBLIC)
  940. SPL_ME(SplFixedArray, next, arginfo_splfixedarray_void, ZEND_ACC_PUBLIC)
  941. SPL_ME(SplFixedArray, valid, arginfo_splfixedarray_void, ZEND_ACC_PUBLIC)
  942. PHP_FE_END
  943. };
  944. /* }}} */
  945. /* {{{ PHP_MINIT_FUNCTION */
  946. PHP_MINIT_FUNCTION(spl_fixedarray)
  947. {
  948. REGISTER_SPL_STD_CLASS_EX(SplFixedArray, spl_fixedarray_new, spl_funcs_SplFixedArray);
  949. memcpy(&spl_handler_SplFixedArray, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
  950. spl_handler_SplFixedArray.clone_obj = spl_fixedarray_object_clone;
  951. spl_handler_SplFixedArray.read_dimension = spl_fixedarray_object_read_dimension;
  952. spl_handler_SplFixedArray.write_dimension = spl_fixedarray_object_write_dimension;
  953. spl_handler_SplFixedArray.unset_dimension = spl_fixedarray_object_unset_dimension;
  954. spl_handler_SplFixedArray.has_dimension = spl_fixedarray_object_has_dimension;
  955. spl_handler_SplFixedArray.count_elements = spl_fixedarray_object_count_elements;
  956. spl_handler_SplFixedArray.get_properties = spl_fixedarray_object_get_properties;
  957. spl_handler_SplFixedArray.get_gc = spl_fixedarray_object_get_gc;
  958. REGISTER_SPL_IMPLEMENTS(SplFixedArray, Iterator);
  959. REGISTER_SPL_IMPLEMENTS(SplFixedArray, ArrayAccess);
  960. REGISTER_SPL_IMPLEMENTS(SplFixedArray, Countable);
  961. spl_ce_SplFixedArray->get_iterator = spl_fixedarray_get_iterator;
  962. return SUCCESS;
  963. }
  964. /* }}} */
  965. /*
  966. * Local variables:
  967. * tab-width: 4
  968. * c-basic-offset: 4
  969. * End:
  970. * vim600: noet sw=4 ts=4 fdm=marker
  971. * vim<600: noet sw=4 ts=4
  972. */