com gtk/php-gtk: Allow passing PHP NULL for objects which will result in C NULL.: main/php_gtk_util.c

[email protected] (David Soria Parra)
Newsgroups php.gtk.cvs
Message-ID <[email protected]>
Commit:    24275934cdb244438e4308148647ed19dfb2f876
Author:    Andrei Zmievski <[email protected]>         Mon, 24 Apr 2006 02:10:39 +0000
Parents:   58ae6088b51037c9203e67ebe18abd5f2e6f86e9
Branches:  master

Link:       http://git.php.net/?p=gtk/php-gtk.git;a=commitdiff;h=24275934cdb244438e4308148647ed19dfb2f876

Log:
Allow passing PHP NULL for objects which will result in C NULL.

Changed paths:
  M  main/php_gtk_util.c


Diff:
24275934cdb244438e4308148647ed19dfb2f876
diff --git a/main/php_gtk_util.c b/main/php_gtk_util.c
index 14bdaac..d2720cc 100644
--- a/main/php_gtk_util.c
+++ b/main/php_gtk_util.c
@@ -61,6 +61,16 @@ static char *parse_arg_impl(zval **arg, va_list *va, char **spec, char *buf, int
 {
 	char *spec_walk = *spec;
 	char c = *spec_walk++;
+	int return_null = 0;
+
+	while (*spec_walk == '/' || *spec_walk == '!') {
+		if (*spec_walk == '/') {
+			SEPARATE_ZVAL_IF_NOT_REF(arg);
+		} else if (*spec_walk == '!' && Z_TYPE_PP(arg) == IS_NULL) {
+			return_null = 1;
+		}
+		spec_walk++;
+	}
 
 	switch (c) {
 
@@ -299,14 +309,14 @@ static char *parse_arg_impl(zval **arg, va_list *va, char **spec, char *buf, int
 			{
 				zval **p = va_arg(*va, zval **);
 				zend_class_entry *ce = va_arg(*va, zend_class_entry *);
-				if (Z_TYPE_PP(arg) != IS_OBJECT || !instanceof_function(Z_OBJCE_PP(arg), ce TSRMLS_CC))
-					return ce->name;
-				else {
-					if (*spec_walk == '/') {
-						SEPARATE_ZVAL(arg);
-						spec_walk++;
-					}
+				if (Z_TYPE_PP(arg) == IS_OBJECT && (!ce || instanceof_function(Z_OBJCE_PP(arg), ce TSRMLS_CC))) {
 					*p = *arg;
+				} else {
+					if (return_null) {
+						*p = NULL;
+					} else {
+						return ce ? ce->name : "object";
+					}
 				}
 			}
 			break;
@@ -319,10 +329,6 @@ static char *parse_arg_impl(zval **arg, va_list *va, char **spec, char *buf, int
 					sprintf(buf, "%s or null", ce->name);
 					return buf;
 				} else {
-					if (*spec_walk == '/') {
-						SEPARATE_ZVAL(arg);
-						spec_walk++;
-					}
 					*p = *arg;
 				}
 			}
@@ -340,10 +346,6 @@ static char *parse_arg_impl(zval **arg, va_list *va, char **spec, char *buf, int
 ret_zval:
 			{
 				zval **p = va_arg(*va, zval **);
-				if (*spec_walk == '/') {
-					SEPARATE_ZVAL(arg);
-					spec_walk++;
-				}
 				*p = *arg;
 			}
 			break;
@@ -408,6 +410,7 @@ static int parse_va_args(int argc, zval ***args, char *format, va_list *va, int
 			case '#':
 			case '/':
 			case '^':
+			case '!':
 				/* Pass */
 				break;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.