Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:19902 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 11904 invoked by uid 1010); 4 Nov 2005 08:04:39 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 11871 invoked from network); 4 Nov 2005 08:04:39 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Nov 2005 08:04:39 -0000 X-Host-Fingerprint: 198.237.84.92 unknown Linux 2.4/2.6 Received: from ([198.237.84.92:1401] helo=bobsilva.com) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id D9/89-19819-6161B634 for ; Fri, 04 Nov 2005 03:04:38 -0500 Received: from [198.237.84.93] (HELO jake) by bobsilva.com (CommuniGate Pro SMTP 4.1.8) with ESMTP id 676860 for internals@lists.php.net; Thu, 03 Nov 2005 20:45:18 -0800 To: Date: Fri, 4 Nov 2005 00:06:27 -0800 Message-ID: <000101c5e116$a7f3ccb0$5d54edc6@jake> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0002_01C5E0D3.99D2D6A0" X-Mailer: Microsoft Office Outlook 11 Thread-Index: AcXhFqfj2DVLmKeqQbucjrYAqHc6Eg== X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670 Subject: [PATCH] - Standardize argument parsing of objects From: me@bobsilva.com ("Bob Silva") ------=_NextPart_000_0002_01C5E0D3.99D2D6A0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Please take under consideration this patch to fully utilize cast_object handlers in the new parameter parsing API. The old parameter API forced the called function to validate and convert its arguments using the convert_to_* functions. The convert_to_* functions make use of cast_object handlers if they exist on objects which makes passing objects (which implement cast_object) to these functions possible. However, with the new parameter parsing API (zend_parse_parameters, et.al.), it only makes use of the cast_object handler if the expected type is a string. This unnecessarily weakens the capability of the cast_object handler. It makes sense that if an object implements a handler for a string cast, then it should be able to be used anywhere a string can. The patch is also attached as a .txt file in case the email really hoses it. --- zend_API.c 2005-11-03 20:26:02.000000000 -0800 +++ zend_API.c 2005-11-03 20:26:02.000000000 -0800 @@ -312,8 +312,17 @@ *p = Z_LVAL_PP(arg); break; + case IS_OBJECT: { + if (Z_OBJ_HANDLER_PP(arg, cast_object)) { + SEPARATE_ZVAL_IF_NOT_REF(arg); + if (Z_OBJ_HANDLER_PP(arg, cast_object)(*arg, *arg, IS_LONG, 0 TSRMLS_CC) == SUCCESS) { + *p = Z_LVAL_PP(arg); + break; + } + } + } + case IS_ARRAY: - case IS_OBJECT: case IS_RESOURCE: default: return "long"; @@ -346,8 +355,17 @@ *p = Z_DVAL_PP(arg); break; + case IS_OBJECT: { + if (Z_OBJ_HANDLER_PP(arg, cast_object)) { + SEPARATE_ZVAL_IF_NOT_REF(arg); + if (Z_OBJ_HANDLER_PP(arg, cast_object)(*arg, *arg, IS_DOUBLE, 0 TSRMLS_CC) == SUCCESS) { + *p = Z_DVAL_PP(arg); + break; + } + } + } + case IS_ARRAY: - case IS_OBJECT: case IS_RESOURCE: default: return "double"; @@ -408,8 +426,17 @@ *p = Z_BVAL_PP(arg); break; + case IS_OBJECT: { + if (Z_OBJ_HANDLER_PP(arg, cast_object)) { + SEPARATE_ZVAL_IF_NOT_REF(arg); + if (Z_OBJ_HANDLER_PP(arg, cast_object)(*arg, *arg, IS_BOOL, 0 TSRMLS_CC) == SUCCESS) { + *p = Z_BVAL_PP(arg); + break; + } + } + } + case IS_ARRAY: - case IS_OBJECT: case IS_RESOURCE: default: return "boolean"; @@ -434,6 +461,15 @@ case 'a': { zval **p = va_arg(*va, zval **); + if (Z_TYPE_PP(arg) == IS_OBJECT) { + if (Z_OBJ_HANDLER_PP(arg, cast_object)) { + SEPARATE_ZVAL_IF_NOT_REF(arg); + if (Z_OBJ_HANDLER_PP(arg, cast_object)(*arg, *arg, IS_ARRAY, 0 TSRMLS_CC) == SUCCESS) { + *p = *arg; + break; + } + } + } if (Z_TYPE_PP(arg) != IS_ARRAY) { if (Z_TYPE_PP(arg) == IS_NULL && return_null) { *p = NULL; ------=_NextPart_000_0002_01C5E0D3.99D2D6A0 Content-Type: text/plain; name="patch.txt" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="patch.txt" --- zend_API.c 2005-11-03 20:26:02.000000000 -0800=0A= +++ zend_API.c 2005-11-03 20:26:02.000000000 -0800=0A= @@ -312,8 +312,17 @@=0A= *p =3D Z_LVAL_PP(arg);=0A= break;=0A= =0A= + case IS_OBJECT: {=0A= + if = (Z_OBJ_HANDLER_PP(arg, cast_object)) {=0A= + = SEPARATE_ZVAL_IF_NOT_REF(arg);=0A= + if = (Z_OBJ_HANDLER_PP(arg, cast_object)(*arg, *arg, IS_LONG, 0 TSRMLS_CC) = =3D=3D SUCCESS) {=0A= + *p =3D = Z_LVAL_PP(arg);=0A= + break;=0A= + }=0A= + }=0A= + }=0A= +=0A= case IS_ARRAY:=0A= - case IS_OBJECT:=0A= case IS_RESOURCE:=0A= default:=0A= return "long";=0A= @@ -346,8 +355,17 @@=0A= *p =3D Z_DVAL_PP(arg);=0A= break;=0A= =0A= + case IS_OBJECT: {=0A= + if = (Z_OBJ_HANDLER_PP(arg, cast_object)) {=0A= + = SEPARATE_ZVAL_IF_NOT_REF(arg);=0A= + if = (Z_OBJ_HANDLER_PP(arg, cast_object)(*arg, *arg, IS_DOUBLE, 0 TSRMLS_CC) = =3D=3D SUCCESS) {=0A= + *p =3D = Z_DVAL_PP(arg);=0A= + break;=0A= + }=0A= + }=0A= + }=0A= +=0A= case IS_ARRAY:=0A= - case IS_OBJECT:=0A= case IS_RESOURCE:=0A= default:=0A= return "double";=0A= @@ -408,8 +426,17 @@=0A= *p =3D Z_BVAL_PP(arg);=0A= break;=0A= =0A= + case IS_OBJECT: {=0A= + if = (Z_OBJ_HANDLER_PP(arg, cast_object)) {=0A= + = SEPARATE_ZVAL_IF_NOT_REF(arg);=0A= + if = (Z_OBJ_HANDLER_PP(arg, cast_object)(*arg, *arg, IS_BOOL, 0 TSRMLS_CC) = =3D=3D SUCCESS) {=0A= + *p =3D = Z_BVAL_PP(arg);=0A= + break;=0A= + }=0A= + }=0A= + }=0A= +=0A= case IS_ARRAY:=0A= - case IS_OBJECT:=0A= case IS_RESOURCE:=0A= default:=0A= return "boolean";=0A= @@ -434,6 +461,15 @@=0A= case 'a':=0A= {=0A= zval **p =3D va_arg(*va, zval **);=0A= + if (Z_TYPE_PP(arg) =3D=3D IS_OBJECT) {=0A= + if (Z_OBJ_HANDLER_PP(arg, = cast_object)) {=0A= + = SEPARATE_ZVAL_IF_NOT_REF(arg);=0A= + if = (Z_OBJ_HANDLER_PP(arg, cast_object)(*arg, *arg, IS_ARRAY, 0 TSRMLS_CC) = =3D=3D SUCCESS) {=0A= + *p =3D *arg;=0A= + break;=0A= + }=0A= + }=0A= + }=0A= if (Z_TYPE_PP(arg) !=3D IS_ARRAY) {=0A= if (Z_TYPE_PP(arg) =3D=3D = IS_NULL && return_null) {=0A= *p =3D NULL;=0A= ------=_NextPart_000_0002_01C5E0D3.99D2D6A0--