cvs: ZendEngine2 / zend_API.c
| From: | Marcus Boerger | Date: | Tue, 01 Nov 2005 16:53:38 +0000 |
| Subject: | cvs: ZendEngine2 / zend_API.c | ||
| Groups: | php.zend-engine.cvs | ||
| Request: | Send a blank email to php-zend-engine-cvs+get-4313@lists.php.net to get a copy of this message | ||
helly Tue Nov 1 11:53:38 2005 EDT
Modified files:
/ZendEngine2 zend_API.c
Log:
- Allow parameter parsing implementation raise an error early where more
information is available. And add ability to prevent double errors by
returning "".
- Implement parameter parsing C which checks for a class name, if the value
on input is not NULL then the pointer must be the zend_class_entry of the
required base class.
# Do the KISS approach, looking at the code it isn't that easy does it?
http://cvs.php.net/diff.php/ZendEngine2/zend_API.c?r1=1.324&r2=1.325&ty=u
Index: ZendEngine2/zend_API.c
diff -u ZendEngine2/zend_API.c:1.324 ZendEngine2/zend_API.c:1.325
--- ZendEngine2/zend_API.c:1.324 Fri Oct 28 09:48:15 2005
+++ ZendEngine2/zend_API.c Tue Nov 1 11:53:29 2005
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zend_API.c,v 1.324 2005/10/28 13:48:15 dmitry Exp $ */
+/* $Id: zend_API.c,v 1.325 2005/11/01 16:53:29 helly Exp $ */
#include "zend.h"
#include "zend_execute.h"
@@ -291,7 +291,7 @@
*pl = Z_USTRLEN_PP(arg); \
*type = IS_UNICODE;
-static char *zend_parse_arg_impl(zval **arg, va_list *va, char **spec, char T_arg_type TSRMLS_DC)
+static char *zend_parse_arg_impl(int arg_num, zval **arg, va_list *va, char **spec, char T_arg_type
TSRMLS_DC)
{
char *spec_walk = *spec;
char c = *spec_walk++;
@@ -577,7 +577,7 @@
char *class_name = get_active_class_name(&space TSRMLS_CC);
zend_error(E_WARNING, "%v%s%v() does not allow mixing binary and Unicode
parameters",
class_name, space, get_active_function_name(TSRMLS_C));
- return "native or binary string";
+ return "";
} else {
convert_to_binary_ex(arg);
RETURN_AS_BINARY(arg, p, pl, type);
@@ -754,6 +754,45 @@
}
break;
+ case 'C':
+ {
+ zend_class_entry **lookup, **pce = va_arg(*va, zend_class_entry **);
+ zend_class_entry *ce_base = *pce;
+
+ if (UG(unicode)) {
+ convert_to_unicode_ex(arg);
+ } else {
+ convert_to_string_ex(arg);
+ }
+ if (zend_u_lookup_class(Z_TYPE_PP(arg), Z_STRVAL_PP(arg), Z_STRLEN_PP(arg), &lookup
TSRMLS_CC) == FAILURE) {
+ *pce = NULL;
+ } else {
+ *pce = *lookup;
+ }
+ if (ce_base) {
+ if ((!*pce || !instanceof_function(*pce, ce_base TSRMLS_CC)) && !return_null) {
+ char *space;
+ char *class_name = get_active_class_name(&space TSRMLS_CC);
+ zend_error(E_WARNING, "%v%s%v() expects parameter %d to be a class name derived from %v,
'%v' given",
+ class_name, space, get_active_function_name(TSRMLS_C),
+ arg_num, ce_base->name, Z_STRVAL_PP(arg));
+ *pce = NULL;
+ return "";
+ }
+ }
+ if (!*pce && !return_null) {
+ char *space;
+ char *class_name = get_active_class_name(&space TSRMLS_CC);
+ zend_error(E_WARNING, "%v%s%v() expects parameter %d to be a valid class name,
'%v' given",
+ class_name, space, get_active_function_name(TSRMLS_C),
+ arg_num, Z_STRVAL_PP(arg));
+ return "";
+ }
+ break;
+
+ }
+ break;
+
case 'z':
{
zval **p = va_arg(*va, zval **);
@@ -787,9 +826,9 @@
{
char *expected_type = NULL;
- expected_type = zend_parse_arg_impl(arg, va, spec, T_arg_type TSRMLS_CC);
+ expected_type = zend_parse_arg_impl(arg_num, arg, va, spec, T_arg_type TSRMLS_CC);
if (expected_type) {
- if (!quiet) {
+ if (!quiet && *expected_type) {
char *space;
char *class_name = get_active_class_name(&space TSRMLS_CC);
@@ -828,7 +867,7 @@
case 'o': case 'O':
case 'z': case 'Z':
case 't': case 'y':
- case 'u':
+ case 'u': case 'C':
max_num_args++;
break;