Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:24272 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 96162 invoked by uid 1010); 5 Jul 2006 09:25:18 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 96147 invoked from network); 5 Jul 2006 09:25:18 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Jul 2006 09:25:18 -0000 X-PHP-List-Original-Sender: php_lists@realplain.com X-Host-Fingerprint: 209.142.136.132 msa2-mx.centurytel.net Linux 2.4/2.6 Received: from ([209.142.136.132:41013] helo=msa2-mx.centurytel.net) by pb1.pair.com (ecelerity 2.1.1.3 r(11751M)) with ESMTP id 8B/97-16663-C758BA44 for ; Wed, 05 Jul 2006 05:25:18 -0400 Received: from pc1 (72-161-63-107.dyn.centurytel.net [72.161.63.107]) by msa2-mx.centurytel.net (8.13.6/8.13.6) with SMTP id k659PDax029166; Wed, 5 Jul 2006 04:25:13 -0500 Message-ID: <008701c6a014$ec07ebd0$0201a8c0@pc1> To: , "Marcus Boerger" References: <009a01c69848$06f22e80$0201a8c0@pc1> <009f01c69cf9$6b493f30$0201a8c0@pc1> <1772356126.20060701125346@marcus-boerger.de> Date: Wed, 5 Jul 2006 04:25:14 -0500 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0084_01C69FEB.02D9B1B0" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1807 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1807 Subject: Re: [PHP-DEV] [PATCH] array_fill: Allow an array to specify keys From: php_lists@realplain.com ("Matt W") ------=_NextPart_000_0084_01C69FEB.02D9B1B0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Hi Marcus, Thanks for the info. I'm sending along the patch for 5.2 now, since I didn't know whether to wait until the MAIN patch was agreed to (that's what I got from your message), or if you wanted both first. :-) I didn't realize tests were needed for every function, change, etc. (being new at this, sorry). And I don't see any tests for the current array_fill()... Anyway, if I need to make a test, how thorough should it be? Should all error messages be checked also, or not, since the message text may change in the future? Are tests needed before the patches will get committed? (Assuming they're agreed to, of course.) ;-) Again, don't know how long that takes either... Thanks, Matt ----- Original Message ----- From: "Marcus Boerger" > Hello Matt, > > patch looks fine now, once we agree to this set you'd have to provide > a patch for 5.2 as well. Another thing we need is tests to ensure all > is working as expected. > > best regards > marcus ------=_NextPart_000_0084_01C69FEB.02D9B1B0 Content-Type: text/plain; name="array_fill_patch_5_2.txt" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="array_fill_patch_5_2.txt" Index: ext/standard/array.c=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= RCS file: /repository/php-src/ext/standard/array.c,v=0A= retrieving revision 1.308.2.21.2.2=0A= diff -u -r1.308.2.21.2.2 array.c=0A= --- ext/standard/array.c 26 Jun 2006 18:48:56 -0000 1.308.2.21.2.2=0A= +++ ext/standard/array.c 5 Jul 2006 08:42:00 -0000=0A= @@ -1536,45 +1536,81 @@=0A= Create an array containing num elements starting with index = start_key each initialized to val */=0A= PHP_FUNCTION(array_fill)=0A= {=0A= - zval **start_key, **num, **val, *newval;=0A= + zval **key_data, **num, **val, **entry;=0A= long i;=0A= + HashPosition pos;=0A= =0A= - if (ZEND_NUM_ARGS() !=3D 3 || zend_get_parameters_ex(3, &start_key, = &num, &val) =3D=3D FAILURE) {=0A= + if ((ZEND_NUM_ARGS() !=3D 3 || zend_get_parameters_ex(3, &key_data, = &num, &val) =3D=3D FAILURE) &&=0A= + (ZEND_NUM_ARGS() !=3D 2 || zend_get_parameters_ex(2, &key_data, &val) = =3D=3D FAILURE)) {=0A= WRONG_PARAM_COUNT;=0A= }=0A= =0A= - switch (Z_TYPE_PP(start_key)) {=0A= - case IS_STRING:=0A= - case IS_LONG:=0A= - case IS_DOUBLE:=0A= - /* allocate an array for return */=0A= - array_init(return_value);=0A= - =0A= - if (PZVAL_IS_REF(*val)) {=0A= - SEPARATE_ZVAL(val);=0A= - }=0A= - convert_to_long_ex(start_key);=0A= - zval_add_ref(val);=0A= - zend_hash_index_update(Z_ARRVAL_P(return_value), = Z_LVAL_PP(start_key), val, sizeof(val), NULL);=0A= - break;=0A= - default:=0A= - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Wrong data type for = start key");=0A= + if (ZEND_NUM_ARGS() =3D=3D 2) {=0A= + if (Z_TYPE_PP(key_data) !=3D IS_ARRAY) {=0A= + php_error_docref(NULL TSRMLS_CC, E_WARNING, "First parameter must be = an array when passing 2 parameters");=0A= RETURN_FALSE;=0A= - break;=0A= - } =0A= + }=0A= + } else {=0A= + switch (Z_TYPE_PP(key_data)) {=0A= + case IS_LONG:=0A= + case IS_STRING:=0A= + case IS_DOUBLE:=0A= + convert_to_long_ex(num);=0A= +=0A= + i =3D Z_LVAL_PP(num) - 1;=0A= + if (i < 0) {=0A= + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Number of elements = must be positive");=0A= + RETURN_FALSE;=0A= + }=0A= =0A= - convert_to_long_ex(num);=0A= - i =3D Z_LVAL_PP(num) - 1; =0A= - if (i < 0) {=0A= - zend_hash_destroy(Z_ARRVAL_P(return_value));=0A= - efree(Z_ARRVAL_P(return_value));=0A= - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Number of elements must = be positive");=0A= - RETURN_FALSE;=0A= + convert_to_long_ex(key_data);=0A= + break;=0A= + default:=0A= + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Wrong data type for = start key");=0A= + RETURN_FALSE;=0A= + break;=0A= + }=0A= }=0A= - newval =3D *val;=0A= - while (i--) {=0A= - zval_add_ref(&newval);=0A= - zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &newval, = sizeof(zval *), NULL);=0A= +=0A= + /* Initialize return array */=0A= + array_init(return_value);=0A= +=0A= + if (PZVAL_IS_REF(*val)) {=0A= + SEPARATE_ZVAL(val);=0A= + }=0A= +=0A= +=0A= + if (Z_TYPE_PP(key_data) =3D=3D IS_LONG) {=0A= + zval_add_ref(val);=0A= + zend_hash_index_update(Z_ARRVAL_P(return_value), Z_LVAL_PP(key_data), = val, sizeof(zval *), NULL);=0A= +=0A= + while (i--) {=0A= + zval_add_ref(val);=0A= + zend_hash_next_index_insert(Z_ARRVAL_P(return_value), val, = sizeof(zval *), NULL);=0A= + }=0A= + } else {=0A= + zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(key_data), &pos);=0A= +=0A= + while (zend_hash_get_current_data_ex(Z_ARRVAL_PP(key_data), (void = **)&entry, &pos) =3D=3D SUCCESS) {=0A= + zval_add_ref(val);=0A= +=0A= + if (Z_TYPE_PP(entry) =3D=3D IS_STRING) {=0A= + zend_symtable_update(Z_ARRVAL_P(return_value), Z_STRVAL_PP(entry), = Z_STRLEN_PP(entry) + 1, val, sizeof(zval *), NULL);=0A= + } else if (Z_TYPE_PP(entry) =3D=3D IS_LONG) {=0A= + zend_hash_index_update(Z_ARRVAL_P(return_value), Z_LVAL_PP(entry), = val, sizeof(zval *), NULL);=0A= + } else {=0A= + zval tmpkey;=0A= +=0A= + tmpkey =3D **entry;=0A= + zval_copy_ctor(&tmpkey);=0A= + convert_to_string(&tmpkey);=0A= +=0A= + zend_symtable_update(Z_ARRVAL_P(return_value), Z_STRVAL(tmpkey), = Z_STRLEN(tmpkey) + 1, val, sizeof(zval *), NULL);=0A= +=0A= + zval_dtor(&tmpkey);=0A= + }=0A= + zend_hash_move_forward_ex(Z_ARRVAL_PP(key_data), &pos);=0A= + }=0A= }=0A= }=0A= /* }}} */=0A= ------=_NextPart_000_0084_01C69FEB.02D9B1B0--