Re: [PHP-CVS] com php-src: Allow array_column() to take -1 as a valid value in third param: ext/standard/array.c ext/standard/tests/array/array_column_basic.phpt

2013-04-24 Thread Christopher Jones


[Resend due to lists.php.net rejection]


On 04/22/2013 03:54 PM, Sara Golemon wrote:

Commit:1a03bd5dee97a0f8b9e74b7f8db5231abd8cc7e4
Author:Sara Golemon  Mon, 22 Apr 2013 14:57:05 
-0700
Parents:   f63db963c48775e89e7d5f63235733098c2f653d
Branches:  PHP-5.5 master

Link:   
http://git.php.net/?p=php-src.git;a=commitdiff;h=1a03bd5dee97a0f8b9e74b7f8db5231abd8cc7e4

Log:
Allow array_column() to take -1 as a valid value in third param

Also do some cleanup and simplification to make this code more
readable in the long term.

Changed paths:
   M  ext/standard/array.c
   M  ext/standard/tests/array/array_column_basic.phpt


Hi Sara,

Did this make the NEWS file?

Chris

--
christopher.jo...@oracle.com  http://twitter.com/ghrd
Newly updated, free PHP & Oracle book 
http://www.oracle.com/technetwork/topics/php/underground-php-oracle-manual-098250.html

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



[PHP-CVS] com php-src: Allow array_column() to take -1 as a valid value in third param: ext/standard/array.c ext/standard/tests/array/array_column_basic.phpt

2013-04-22 Thread Sara Golemon
Commit:1a03bd5dee97a0f8b9e74b7f8db5231abd8cc7e4
Author:Sara Golemon  Mon, 22 Apr 2013 14:57:05 
-0700
Parents:   f63db963c48775e89e7d5f63235733098c2f653d
Branches:  PHP-5.5 master

Link:   
http://git.php.net/?p=php-src.git;a=commitdiff;h=1a03bd5dee97a0f8b9e74b7f8db5231abd8cc7e4

Log:
Allow array_column() to take -1 as a valid value in third param

Also do some cleanup and simplification to make this code more
readable in the long term.

Changed paths:
  M  ext/standard/array.c
  M  ext/standard/tests/array/array_column_basic.phpt


Diff:
diff --git a/ext/standard/array.c b/ext/standard/array.c
index 425d53e..6f769da 100644
--- a/ext/standard/array.c
+++ b/ext/standard/array.c
@@ -2524,132 +2524,95 @@ PHP_FUNCTION(array_count_values)
 }
 /* }}} */
 
+/* {{{ array_column_param_helper
+ * Specialized conversion rules for array_column() function
+ */
+static inline
+zend_bool array_column_param_helper(zval **param,
+const char *name TSRMLS_DC) {
+   switch (Z_TYPE_PP(param)) {
+   case IS_NULL:
+   case IS_DOUBLE:
+   convert_to_long_ex(param);
+   /* fallthrough */
+   case IS_LONG:
+   return 1;
+
+   case IS_OBJECT:
+   convert_to_string_ex(param);
+   /* fallthrough */
+   case IS_STRING:
+   return 1;
+
+   default:
+   php_error_docref(NULL TSRMLS_CC, E_WARNING, "The %s key 
should be either a string or an integer", name);
+   return 0;
+   }
+}
+
 /* {{{ proto array array_column(array input, mixed column_key[, mixed 
index_key])
Return the values from a single column in the input array, identified by the
value_key and optionally indexed by the index_key */
 PHP_FUNCTION(array_column)
 {
-   zval *zarray, **zcolumn, **zkey = NULL, **data, **zcolval, **zkeyval;
+   zval **zcolumn, **zkey = NULL, **data;
HashTable *arr_hash;
HashPosition pointer;
-   ulong column_idx = 0, key_idx = 0;
-   char *column = NULL, *key = NULL, *keyval = NULL;
-   int column_len = 0, key_len = 0, keyval_idx = -1;
 
-   if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "aZ|Z", &zarray, 
&zcolumn, &zkey) == FAILURE) {
+   if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "hZ|Z!", 
&arr_hash, &zcolumn, &zkey) == FAILURE) {
return;
}
 
-   switch (Z_TYPE_PP(zcolumn)) {
-   case IS_NULL:
-   column_idx = 0;
-   break;
-   case IS_LONG:
-   column_idx = Z_LVAL_PP(zcolumn);
-   break;
-   case IS_DOUBLE:
-   column_idx = (long)Z_DVAL_PP(zcolumn);
-   break;
-   case IS_STRING:
-   column = Z_STRVAL_PP(zcolumn);
-   column_len = Z_STRLEN_PP(zcolumn);
-   break;
-   case IS_OBJECT:
-   convert_to_string_ex(zcolumn);
-   column = Z_STRVAL_PP(zcolumn);
-   column_len = Z_STRLEN_PP(zcolumn);
-   break;
-   default:
-   php_error_docref(NULL TSRMLS_CC, E_WARNING, "The column 
key should be either a string or an integer");
-   RETURN_FALSE;
-   }
-
-   if (zkey) {
-   switch (Z_TYPE_PP(zkey)) {
-   case IS_NULL:
-   key_idx = 0;
-   break;
-   case IS_LONG:
-   key_idx = Z_LVAL_PP(zkey);
-   break;
-   case IS_DOUBLE:
-   key_idx = (long)Z_DVAL_PP(zkey);
-   break;
-   case IS_STRING:
-   key = Z_STRVAL_PP(zkey);
-   key_len = Z_STRLEN_PP(zkey);
-   break;
-   case IS_OBJECT:
-   convert_to_string_ex(zkey);
-   key = Z_STRVAL_PP(zkey);
-   key_len = Z_STRLEN_PP(zkey);
-   break;
-   default:
-   php_error_docref(NULL TSRMLS_CC, E_WARNING, 
"The index key should be either a string or an integer");
-   RETURN_FALSE;
-   }
+   if (!array_column_param_helper(zcolumn, "column" TSRMLS_CC) ||
+   (zkey && !array_column_param_helper(zkey, "index" TSRMLS_CC))) {
+   RETURN_FALSE;
}
 
-   arr_hash = Z_ARRVAL_P(zarray);
array_init(return_value);
-
for (zend_hash_internal_pointer_reset_ex(arr_hash, &po