[PHP-CVS] cvs: php-src(PHP_5_3) /ext/spl spl_fixedarray.c

2009-05-23 Thread Felipe Pena
felipe  Sat May 23 15:14:15 2009 UTC

  Modified files:  (Branch: PHP_5_3)
/php-src/ext/splspl_fixedarray.c 
  Log:
  - MFH: Added missing param checks
  
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl_fixedarray.c?r1=1.1.2.10r2=1.1.2.11diff_format=u
Index: php-src/ext/spl/spl_fixedarray.c
diff -u php-src/ext/spl/spl_fixedarray.c:1.1.2.10 
php-src/ext/spl/spl_fixedarray.c:1.1.2.11
--- php-src/ext/spl/spl_fixedarray.c:1.1.2.10   Wed Dec 31 11:15:43 2008
+++ php-src/ext/spl/spl_fixedarray.cSat May 23 15:14:15 2009
@@ -17,7 +17,7 @@
   +--+
 */
 
-/* $Id: spl_fixedarray.c,v 1.1.2.10 2008/12/31 11:15:43 sebastian Exp $ */
+/* $Id: spl_fixedarray.c,v 1.1.2.11 2009/05/23 15:14:15 felipe Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include config.h
@@ -912,6 +912,10 @@
 SPL_METHOD(SplFixedArray, key)
 {
spl_fixedarray_object *intern = 
(spl_fixedarray_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+   
+   if (zend_parse_parameters_none() == FAILURE) {
+   return;
+   }
 
RETURN_LONG(intern-current);
 }
@@ -922,6 +926,10 @@
 SPL_METHOD(SplFixedArray, next)
 {
spl_fixedarray_object *intern = 
(spl_fixedarray_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+   
+   if (zend_parse_parameters_none() == FAILURE) {
+   return;
+   }
 
intern-current++;
 }
@@ -932,6 +940,10 @@
 SPL_METHOD(SplFixedArray, valid)
 {
spl_fixedarray_object *intern = 
(spl_fixedarray_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+   
+   if (zend_parse_parameters_none() == FAILURE) {
+   return;
+   }
 
RETURN_BOOL(intern-current = 0  intern-array  intern-current  
intern-array-size);
 }
@@ -942,6 +954,10 @@
 SPL_METHOD(SplFixedArray, rewind)
 {
spl_fixedarray_object *intern = 
(spl_fixedarray_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+   
+   if (zend_parse_parameters_none() == FAILURE) {
+   return;
+   }
 
intern-current = 0;
 }
@@ -953,7 +969,10 @@
 {
zval *zindex, **value_pp;
spl_fixedarray_object *intern  = 
(spl_fixedarray_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
-
+   
+   if (zend_parse_parameters_none() == FAILURE) {
+   return;
+   }
 
ALLOC_INIT_ZVAL(zindex);
ZVAL_LONG(zindex, intern-current);



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-CVS] cvs: php-src(PHP_5_3) /ext/spl spl_fixedarray.c

2008-07-20 Thread Etienne Kneuss
colder  Sun Jul 20 17:32:10 2008 UTC

  Modified files:  (Branch: PHP_5_3)
/php-src/ext/splspl_fixedarray.c 
  Log:
  MFH: Iterator methods overwriting optimisations
  http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl_fixedarray.c?r1=1.1.2.5r2=1.1.2.6diff_format=u
Index: php-src/ext/spl/spl_fixedarray.c
diff -u php-src/ext/spl/spl_fixedarray.c:1.1.2.5 
php-src/ext/spl/spl_fixedarray.c:1.1.2.6
--- php-src/ext/spl/spl_fixedarray.c:1.1.2.5Mon Jul 14 08:09:09 2008
+++ php-src/ext/spl/spl_fixedarray.cSun Jul 20 17:32:10 2008
@@ -17,7 +17,7 @@
   +--+
 */
 
-/* $Id: spl_fixedarray.c,v 1.1.2.5 2008/07/14 08:09:09 tony2001 Exp $ */
+/* $Id: spl_fixedarray.c,v 1.1.2.6 2008/07/20 17:32:10 colder Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include config.h
@@ -56,13 +56,9 @@
zend_function *fptr_offset_set;
zend_function *fptr_offset_has;
zend_function *fptr_offset_del;
-   zend_function *fptr_it_next;
-   zend_function *fptr_it_rewind;
-   zend_function *fptr_it_current;
-   zend_function *fptr_it_key;
-   zend_function *fptr_it_valid;
zend_function *fptr_count;
intcurrent;
+   intflags;
zend_class_entry  *ce_get_iterator;
 } spl_fixedarray_object;
 /* }}} */
@@ -73,6 +69,12 @@
 } spl_fixedarray_it;
 /* }}} */
 
+#define SPL_FIXEDARRAY_OVERLOADED_REWIND  0x0001
+#define SPL_FIXEDARRAY_OVERLOADED_VALID   0x0002
+#define SPL_FIXEDARRAY_OVERLOADED_KEY 0x0004
+#define SPL_FIXEDARRAY_OVERLOADED_CURRENT 0x0008
+#define SPL_FIXEDARRAY_OVERLOADED_NEXT0x0010
+
 static void spl_fixedarray_init(spl_fixedarray *array, long size TSRMLS_DC) /* 
{{{ */
 {
if (size  0) {
@@ -209,6 +211,7 @@
zend_hash_copy(intern-std.properties, class_type-default_properties, 
(copy_ctor_func_t) zval_add_ref, (void *) tmp, sizeof(zval *));
 
intern-current = 0;
+   intern-flags = 0;
 
if (orig  clone_orig) {
spl_fixedarray_object *other = 
(spl_fixedarray_object*)zend_object_store_get_object(orig TSRMLS_CC);
@@ -222,6 +225,7 @@
while (parent) {
if (parent == spl_ce_SplFixedArray) {
retval.handlers = spl_handler_SplFixedArray;
+   class_type-get_iterator = spl_fixedarray_get_iterator;
break;
}
 
@@ -234,7 +238,30 @@
if (!parent) { /* this must never happen */
php_error_docref(NULL TSRMLS_CC, E_COMPILE_ERROR, Internal 
compiler error, Class is not child of SplFixedArray);
}
+   if (!class_type-iterator_funcs.zf_current) {
+   zend_hash_find(class_type-function_table, rewind,  
sizeof(rewind),  (void **) class_type-iterator_funcs.zf_rewind);
+   zend_hash_find(class_type-function_table, valid,   
sizeof(valid),   (void **) class_type-iterator_funcs.zf_valid);
+   zend_hash_find(class_type-function_table, key, 
sizeof(key), (void **) class_type-iterator_funcs.zf_key);
+   zend_hash_find(class_type-function_table, current, 
sizeof(current), (void **) class_type-iterator_funcs.zf_current);
+   zend_hash_find(class_type-function_table, next,
sizeof(next),(void **) class_type-iterator_funcs.zf_next);
+   }
if (inherited) {
+   if (class_type-iterator_funcs.zf_rewind-common.scope  != 
parent) { 
+   intern-flags |= SPL_FIXEDARRAY_OVERLOADED_REWIND;
+   }
+   if (class_type-iterator_funcs.zf_valid-common.scope   != 
parent) { 
+   intern-flags |= SPL_FIXEDARRAY_OVERLOADED_VALID;
+   }
+   if (class_type-iterator_funcs.zf_key-common.scope != 
parent) { 
+   intern-flags |= SPL_FIXEDARRAY_OVERLOADED_KEY;
+   }
+   if (class_type-iterator_funcs.zf_current-common.scope != 
parent) { 
+   intern-flags |= SPL_FIXEDARRAY_OVERLOADED_CURRENT;
+   }
+   if (class_type-iterator_funcs.zf_next-common.scope!= 
parent) { 
+   intern-flags |= SPL_FIXEDARRAY_OVERLOADED_NEXT;
+   }
+
zend_hash_find(class_type-function_table, offsetget,
sizeof(offsetget),(void **) intern-fptr_offset_get);
if (intern-fptr_offset_get-common.scope == parent) {
intern-fptr_offset_get = NULL;
@@ -251,26 +278,6 @@
if (intern-fptr_offset_del-common.scope == parent) {
intern-fptr_offset_del = NULL;
}
-   zend_hash_find(class_type-function_table, next, 
sizeof(next), (void **) intern-fptr_it_next);
-   if (intern-fptr_it_next-common.scope == parent) {
-   

[PHP-CVS] cvs: php-src(PHP_5_3) /ext/spl spl_fixedarray.c

2008-07-14 Thread Antony Dovgal
tony2001Mon Jul 14 08:09:09 2008 UTC

  Modified files:  (Branch: PHP_5_3)
/php-src/ext/splspl_fixedarray.c 
  Log:
  MFH: minor speedup - convert offset to long only when needed
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl_fixedarray.c?r1=1.1.2.4r2=1.1.2.5diff_format=u
Index: php-src/ext/spl/spl_fixedarray.c
diff -u php-src/ext/spl/spl_fixedarray.c:1.1.2.4 
php-src/ext/spl/spl_fixedarray.c:1.1.2.5
--- php-src/ext/spl/spl_fixedarray.c:1.1.2.4Sun Jul 13 15:59:52 2008
+++ php-src/ext/spl/spl_fixedarray.cMon Jul 14 08:09:09 2008
@@ -17,7 +17,7 @@
   +--+
 */
 
-/* $Id: spl_fixedarray.c,v 1.1.2.4 2008/07/13 15:59:52 colder Exp $ */
+/* $Id: spl_fixedarray.c,v 1.1.2.5 2008/07/14 08:09:09 tony2001 Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include config.h
@@ -317,7 +317,11 @@
return NULL;
}
 
-   index = spl_offset_convert_to_long(offset TSRMLS_CC);
+   if (Z_TYPE_P(offset) != IS_LONG) {
+   index = spl_offset_convert_to_long(offset TSRMLS_CC);
+   } else {
+   index = Z_LVAL_P(offset);
+   }

if (index  0 || intern-array == NULL || index = intern-array-size) 
{
zend_throw_exception(spl_ce_RuntimeException, Index invalid or 
out of range, 0 TSRMLS_CC);
@@ -369,7 +373,11 @@
return;
}
 
-   index = spl_offset_convert_to_long(offset TSRMLS_CC);
+   if (Z_TYPE_P(offset) != IS_LONG) {
+   index = spl_offset_convert_to_long(offset TSRMLS_CC);
+   } else {
+   index = Z_LVAL_P(offset);
+   }
 
if (index  0 || intern-array == NULL || index = intern-array-size) 
{
zend_throw_exception(spl_ce_RuntimeException, Index invalid or 
out of range, 0 TSRMLS_CC);
@@ -407,7 +415,11 @@
 {
long index;

-   index = spl_offset_convert_to_long(offset TSRMLS_CC);
+   if (Z_TYPE_P(offset) != IS_LONG) {
+   index = spl_offset_convert_to_long(offset TSRMLS_CC);
+   } else {
+   index = Z_LVAL_P(offset);
+   }

if (index  0 || intern-array == NULL || index = intern-array-size) 
{
zend_throw_exception(spl_ce_RuntimeException, Index invalid or 
out of range, 0 TSRMLS_CC);
@@ -444,7 +456,11 @@
long index;
int retval;

-   index = spl_offset_convert_to_long(offset TSRMLS_CC);
+   if (Z_TYPE_P(offset) != IS_LONG) {
+   index = spl_offset_convert_to_long(offset TSRMLS_CC);
+   } else {
+   index = Z_LVAL_P(offset);
+   }

if (index  0 || intern-array == NULL || index = intern-array-size) 
{
retval = 0;



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-CVS] cvs: php-src(PHP_5_3) /ext/spl spl_fixedarray.c /ext/spl/tests fixedarray_016.phpt fixedarray_017.phpt fixedarray_018.phpt fixedarray_019.phpt fixedarray_020.phpt

2008-07-13 Thread Etienne Kneuss
colder  Sun Jul 13 15:59:52 2008 UTC

  Added files: (Branch: PHP_5_3)
/php-src/ext/spl/tests  fixedarray_020.phpt 

  Modified files:  
/php-src/ext/splspl_fixedarray.c 
/php-src/ext/spl/tests  fixedarray_016.phpt fixedarray_017.phpt 
fixedarray_018.phpt fixedarray_019.phpt 
  Log:
  MFH: Implement toArray,fromArray and get_properties (Thanks Tony for the 
patches)
  http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl_fixedarray.c?r1=1.1.2.3r2=1.1.2.4diff_format=u
Index: php-src/ext/spl/spl_fixedarray.c
diff -u php-src/ext/spl/spl_fixedarray.c:1.1.2.3 
php-src/ext/spl/spl_fixedarray.c:1.1.2.4
--- php-src/ext/spl/spl_fixedarray.c:1.1.2.3Sun Jul  6 23:45:55 2008
+++ php-src/ext/spl/spl_fixedarray.cSun Jul 13 15:59:52 2008
@@ -17,7 +17,7 @@
   +--+
 */
 
-/* $Id: spl_fixedarray.c,v 1.1.2.3 2008/07/06 23:45:55 colder Exp $ */
+/* $Id: spl_fixedarray.c,v 1.1.2.4 2008/07/13 15:59:52 colder Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include config.h
@@ -145,46 +145,24 @@
 }
 /* }}} */
 
-static HashTable* spl_fixedarray_object_get_debug_info(zval *obj, int *is_temp 
TSRMLS_DC) /*  */
+static HashTable* spl_fixedarray_object_get_properties(zval *obj TSRMLS_DC) /* 
 */
 {
spl_fixedarray_object *intern  = 
(spl_fixedarray_object*)zend_object_store_get_object(obj TSRMLS_CC);
-   HashTable *rv;
-   zval *tmp, zrv, *fixedarray_array;
-   char *pnstr;
-   int  pnlen;
-   int  i = 0;;
-
-   *is_temp = 1;
-
-   ALLOC_HASHTABLE(rv);
-   ZEND_INIT_SYMTABLE_EX(rv, 
zend_hash_num_elements(intern-std.properties) + 1, 0);
-
-   INIT_PZVAL(zrv);
-   Z_ARRVAL(zrv) = rv;
-
-   zend_hash_copy(rv, intern-std.properties, (copy_ctor_func_t) 
zval_add_ref, (void *) tmp, sizeof(zval *));
-
-   ALLOC_INIT_ZVAL(fixedarray_array);
-   array_init(fixedarray_array);
-
+   int  i = 0;
 
if (intern-array) {
for (i = 0; i  intern-array-size; i++) {
if (intern-array-elements[i]) {
-   add_index_zval(fixedarray_array, i, (zval 
*)intern-array-elements[i]);
+   zend_hash_index_update(intern-std.properties, 
i, (void *)intern-array-elements[i], sizeof(zval *), NULL);
Z_ADDREF_P(intern-array-elements[i]);
} else {
-   add_index_zval(fixedarray_array, i, (zval 
*)EG(uninitialized_zval_ptr));
+   zend_hash_index_update(intern-std.properties, 
i, (void *)EG(uninitialized_zval_ptr), sizeof(zval *), NULL);
Z_ADDREF_P(EG(uninitialized_zval_ptr));
}
}
}
 
-   pnstr = spl_gen_private_prop_name(spl_ce_SplFixedArray, array, 
sizeof(array)-1, pnlen TSRMLS_CC);
-   add_assoc_zval_ex(zrv, pnstr, pnlen+1, fixedarray_array);
-   efree(pnstr);
-
-   return rv;
+   return intern-std.properties;
 }
 /*  */
 
@@ -586,6 +564,119 @@
 }
 /* }}} */
 
+/* {{{ proto object SplFixedArray::toArray()
+*/
+SPL_METHOD(SplFixedArray, toArray)
+{
+   spl_fixedarray_object *intern;
+   zval *ret, *tmp;
+   HashTable *ret_ht, *obj_ht;
+
+   if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, )) {
+   return;
+   }
+
+   intern = (spl_fixedarray_object 
*)zend_object_store_get_object(getThis() TSRMLS_CC);
+
+   ALLOC_HASHTABLE(ret_ht);
+   zend_hash_init(ret_ht, 0, NULL, ZVAL_PTR_DTOR, 0);
+   ALLOC_INIT_ZVAL(ret);
+   Z_TYPE_P(ret) = IS_ARRAY;
+   obj_ht = spl_fixedarray_object_get_properties(getThis() TSRMLS_CC);
+   zend_hash_copy(ret_ht, obj_ht, (copy_ctor_func_t) zval_add_ref, (void 
*) tmp, sizeof(zval *));
+   Z_ARRVAL_P(ret) = ret_ht;
+
+   RETURN_ZVAL(ret, 1, 1);
+}
+/* }}} */
+
+/* {{{ proto object SplFixedArray::fromArray(array data[, bool save_indexes])
+*/
+SPL_METHOD(SplFixedArray, fromArray)
+{
+   zval *data;
+   spl_fixedarray *array;
+   spl_fixedarray_object *intern;
+   int num;
+   zend_bool save_indexes = 1;
+
+   if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, a|b, 
data, save_indexes)) {
+   return;
+   }
+
+   array = ecalloc(1, sizeof(*array));
+   num = zend_hash_num_elements(Z_ARRVAL_P(data));
+   
+   if (num  0  save_indexes) {
+   zval **element, *value;
+   char *str_index;
+   ulong num_index, max_index = 0;
+   long tmp;
+
+   for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(data));
+   zend_hash_get_current_data(Z_ARRVAL_P(data), (void **) 
element) == SUCCESS;
+   zend_hash_move_forward(Z_ARRVAL_P(data))
+   ) {
+   if