[mapserver-commits] r11619 - in trunk/mapserver: . mapscript/php

svn at osgeo.org svn at osgeo.org
Wed Apr 27 11:23:07 EDT 2011


Author: aboudreault
Date: 2011-04-27 08:23:07 -0700 (Wed, 27 Apr 2011)
New Revision: 11619

Modified:
   trunk/mapserver/HISTORY.TXT
   trunk/mapserver/mapscript/php/class.c
   trunk/mapserver/mapscript/php/layer.c
   trunk/mapserver/mapscript/php/map.c
   trunk/mapserver/mapscript/php/php_mapscript.h
   trunk/mapserver/mapscript/php/php_mapscript_util.h
   trunk/mapserver/mapscript/php/point.c
   trunk/mapserver/mapscript/php/style.c
Log:
Fixed a system specific segmentation fault in PHP/MapScript and improved the php object method calls (#3730)

Modified: trunk/mapserver/HISTORY.TXT
===================================================================
--- trunk/mapserver/HISTORY.TXT	2011-04-27 15:06:17 UTC (rev 11618)
+++ trunk/mapserver/HISTORY.TXT	2011-04-27 15:23:07 UTC (rev 11619)
@@ -15,6 +15,8 @@
 Current Version (SVN trunk): 
 ---------------------------- 
 
+- Fixed segmentation fault in PHP/MapScript and improved the php object method calls (#3730)
+
 - Fix build issue related to unnecessary use of gdal-config --dep-libs (#3316)
 
 Version 6.0.0-beta7 (2011-04-20)

Modified: trunk/mapserver/mapscript/php/class.c
===================================================================
--- trunk/mapserver/mapscript/php/class.c	2011-04-27 15:06:17 UTC (rev 11618)
+++ trunk/mapserver/mapscript/php/class.c	2011-04-27 15:23:07 UTC (rev 11619)
@@ -498,9 +498,7 @@
     zval *zname;
     zval *zobj = getThis();
     php_class_object *php_class;
-    zval retval;
-    zval *args[1];
-    zval function_name;
+    zval *retval;
 
     PHP_MAPSCRIPT_ERROR_HANDLING(TRUE);
     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z",
@@ -513,10 +511,9 @@
     php_class = (php_class_object *) zend_object_store_get_object(zobj TSRMLS_CC);
     CHECK_OBJECT(mapscript_ce_hashtable, php_class->metadata, &php_class->class->metadata);
     
-    args[0] = zname; 
-    MAPSCRIPT_CALL_METHOD(php_class->metadata, "get", retval, 1, args);
+    MAPSCRIPT_CALL_METHOD_1(php_class->metadata, "get", retval, zname);
 
-    RETURN_STRING(Z_STRVAL(retval),1);
+    RETURN_STRING(Z_STRVAL_P(retval),1);
 }
 /* }}} */
 
@@ -527,9 +524,7 @@
     zval *zname, *zvalue;
     zval *zobj = getThis();
     php_class_object *php_class;
-    zval retval;
-    zval *args[2];
-    zval function_name;
+    zval *retval;
 
     PHP_MAPSCRIPT_ERROR_HANDLING(TRUE);
     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz",
@@ -542,11 +537,9 @@
     php_class = (php_class_object *) zend_object_store_get_object(zobj TSRMLS_CC);
     CHECK_OBJECT(mapscript_ce_hashtable, php_class->metadata, &php_class->class->metadata);
     
-    args[0] = zname; 
-    args[1] = zvalue; 
-    MAPSCRIPT_CALL_METHOD(php_class->metadata, "set", retval, 2, args);
+    MAPSCRIPT_CALL_METHOD_2(php_class->metadata, "set", retval, zname, zvalue);
 
-    RETURN_LONG(Z_LVAL(retval));
+    RETURN_LONG(Z_LVAL_P(retval));
 }
 /* }}} */
 
@@ -557,9 +550,7 @@
     zval *zname;
     zval *zobj = getThis();
     php_class_object *php_class;
-    zval retval;
-    zval *args[1];
-    zval function_name;
+    zval *retval;
 
     PHP_MAPSCRIPT_ERROR_HANDLING(TRUE);
     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z",
@@ -572,10 +563,9 @@
     php_class = (php_class_object *) zend_object_store_get_object(zobj TSRMLS_CC);
     CHECK_OBJECT(mapscript_ce_hashtable, php_class->metadata, &php_class->class->metadata);
     
-    args[0] = zname; 
-    MAPSCRIPT_CALL_METHOD(php_class->metadata, "remove", retval, 1, args);
+    MAPSCRIPT_CALL_METHOD_1(php_class->metadata, "remove", retval, zname);
 
-    RETURN_LONG(Z_LVAL(retval));
+    RETURN_LONG(Z_LVAL_P(retval));
 }
 /* }}} */
 

Modified: trunk/mapserver/mapscript/php/layer.c
===================================================================
--- trunk/mapserver/mapscript/php/layer.c	2011-04-27 15:06:17 UTC (rev 11618)
+++ trunk/mapserver/mapscript/php/layer.c	2011-04-27 15:23:07 UTC (rev 11619)
@@ -1167,9 +1167,7 @@
     zval *zname;
     zval *zobj = getThis();
     php_layer_object *php_layer;
-    zval retval;
-    zval *args[1];
-    zval function_name;
+    zval *retval;
 
     PHP_MAPSCRIPT_ERROR_HANDLING(TRUE);
     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z",
@@ -1182,10 +1180,9 @@
     php_layer = (php_layer_object *) zend_object_store_get_object(zobj TSRMLS_CC);
     CHECK_OBJECT(mapscript_ce_hashtable, php_layer->metadata, &php_layer->layer->metadata);
 
-    args[0] = zname;
-    MAPSCRIPT_CALL_METHOD(php_layer->metadata, "get", retval, 1, args);
+    MAPSCRIPT_CALL_METHOD_1(php_layer->metadata, "get", retval, zname);
 
-    RETURN_STRING(Z_STRVAL(retval),1);
+    RETURN_STRING(Z_STRVAL_P(retval),1);
 }
 /* }}} */
 
@@ -1196,9 +1193,7 @@
     zval *zname, *zvalue;
     zval *zobj = getThis();
     php_layer_object *php_layer;
-    zval retval;
-    zval *args[2];
-    zval function_name;
+    zval *retval;
 
     PHP_MAPSCRIPT_ERROR_HANDLING(TRUE);
     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz",
@@ -1211,11 +1206,9 @@
     php_layer = (php_layer_object *) zend_object_store_get_object(zobj TSRMLS_CC);
     CHECK_OBJECT(mapscript_ce_hashtable, php_layer->metadata, &php_layer->layer->metadata);
     
-    args[0] = zname; 
-    args[1] = zvalue; 
-    MAPSCRIPT_CALL_METHOD(php_layer->metadata, "set", retval, 2, args);
+    MAPSCRIPT_CALL_METHOD_2(php_layer->metadata, "set", retval, zname, zvalue);
 
-    RETURN_LONG(Z_LVAL(retval));
+    RETURN_LONG(Z_LVAL_P(retval));
 }
 /* }}} */
 
@@ -1226,9 +1219,7 @@
     zval *zname;
     zval *zobj = getThis();
     php_layer_object *php_layer;
-    zval retval;
-    zval *args[1];
-    zval function_name;
+    zval *retval;
 
     PHP_MAPSCRIPT_ERROR_HANDLING(TRUE);
     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z",
@@ -1241,10 +1232,9 @@
     php_layer = (php_layer_object *) zend_object_store_get_object(zobj TSRMLS_CC);
     CHECK_OBJECT(mapscript_ce_hashtable, php_layer->metadata, &php_layer->layer->metadata);
     
-    args[0] = zname; 
-    MAPSCRIPT_CALL_METHOD(php_layer->metadata, "remove", retval, 1, args);
+    MAPSCRIPT_CALL_METHOD_1(php_layer->metadata, "remove", retval, zname);
 
-    RETURN_LONG(Z_LVAL(retval));
+    RETURN_LONG(Z_LVAL_P(retval));
 }
 /* }}} */
 

Modified: trunk/mapserver/mapscript/php/map.c
===================================================================
--- trunk/mapserver/mapscript/php/map.c	2011-04-27 15:06:17 UTC (rev 11618)
+++ trunk/mapserver/mapscript/php/map.c	2011-04-27 15:23:07 UTC (rev 11619)
@@ -2191,9 +2191,7 @@
     zval *zname;
     zval *zobj = getThis();
     php_map_object *php_map;
-    zval retval;
-    zval *args[1];
-    zval function_name;
+    zval *retval;
 
     PHP_MAPSCRIPT_ERROR_HANDLING(TRUE);
     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z",
@@ -2206,10 +2204,9 @@
     php_map = (php_map_object *) zend_object_store_get_object(zobj TSRMLS_CC);
     CHECK_OBJECT(mapscript_ce_hashtable, php_map->metadata, &php_map->map->web.metadata);
     
-    args[0] = zname; 
-    MAPSCRIPT_CALL_METHOD(php_map->metadata, "get", retval, 1, args);
+    MAPSCRIPT_CALL_METHOD_1(php_map->metadata, "get", retval, zname); 
 
-    RETURN_STRING(Z_STRVAL(retval),1);
+    RETURN_STRING(Z_STRVAL_P(retval),1);
 }
 /* }}} */
 
@@ -2220,9 +2217,7 @@
     zval *zname, *zvalue;
     zval *zobj = getThis();
     php_map_object *php_map;
-    zval retval;
-    zval *args[2];
-    zval function_name;
+    zval *retval;
 
     PHP_MAPSCRIPT_ERROR_HANDLING(TRUE);
     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz",
@@ -2235,11 +2230,9 @@
     php_map = (php_map_object *) zend_object_store_get_object(zobj TSRMLS_CC);
     CHECK_OBJECT(mapscript_ce_hashtable, php_map->metadata, &php_map->map->web.metadata);
     
-    args[0] = zname; 
-    args[1] = zvalue; 
-    MAPSCRIPT_CALL_METHOD(php_map->metadata, "set", retval, 2, args);
+    MAPSCRIPT_CALL_METHOD_2(php_map->metadata, "set", retval, zname, zvalue);
 
-    RETURN_LONG(Z_LVAL(retval));
+    RETURN_LONG(Z_LVAL_P(retval));
 }
 /* }}} */
 
@@ -2250,9 +2243,7 @@
     zval *zname;
     zval *zobj = getThis();
     php_map_object *php_map;
-    zval retval;
-    zval *args[1];
-    zval function_name;
+    zval *retval;
 
     PHP_MAPSCRIPT_ERROR_HANDLING(TRUE);
     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z",
@@ -2265,10 +2256,9 @@
     php_map = (php_map_object *) zend_object_store_get_object(zobj TSRMLS_CC);
     CHECK_OBJECT(mapscript_ce_hashtable, php_map->metadata, &php_map->map->web.metadata);
     
-    args[0] = zname; 
-    MAPSCRIPT_CALL_METHOD(php_map->metadata, "remove", retval, 1, args);
+    MAPSCRIPT_CALL_METHOD_1(php_map->metadata, "remove", retval, zname); 
 
-    RETURN_LONG(Z_LVAL(retval));
+    RETURN_LONG(Z_LVAL_P(retval));
 }
 /* }}} */
 

Modified: trunk/mapserver/mapscript/php/php_mapscript.h
===================================================================
--- trunk/mapserver/mapscript/php/php_mapscript.h	2011-04-27 15:06:17 UTC (rev 11618)
+++ trunk/mapserver/mapscript/php/php_mapscript.h	2011-04-27 15:23:07 UTC (rev 11619)
@@ -33,6 +33,7 @@
 #define PHP_MAPSCRIPT_H
 
 #include "php.h"
+#include "zend_interfaces.h"
 #include "php_mapscript_util.h"
 
 #ifdef USE_PHP_REGEX

Modified: trunk/mapserver/mapscript/php/php_mapscript_util.h
===================================================================
--- trunk/mapserver/mapscript/php/php_mapscript_util.h	2011-04-27 15:06:17 UTC (rev 11618)
+++ trunk/mapserver/mapscript/php/php_mapscript_util.h	2011-04-27 15:23:07 UTC (rev 11619)
@@ -90,10 +90,12 @@
     parent.val = zobj; \
     parent.child_ptr = ptr;
 
-#define MAPSCRIPT_CALL_METHOD(zobj, function, retval, param_count, args)     \
-    ZVAL_STRING(&function_name, function, 0);                           \
-    call_user_function(EG(function_table), &zobj, &function_name, &retval, param_count, args TSRMLS_CC);
+#define MAPSCRIPT_CALL_METHOD_1(zobj, function_name, retval, arg1) \
+    zend_call_method_with_1_params(&zobj, Z_OBJCE_P(zobj), NULL, function_name, &retval, arg1);
 
+#define MAPSCRIPT_CALL_METHOD_2(zobj, function_name, retval, arg1, arg2) \
+    zend_call_method_with_2_params(&zobj, Z_OBJCE_P(zobj), NULL, function_name, &retval, arg1, arg2);
+
 #define STRING_EQUAL(string1, string2) \
     strcmp(string1, string2) == 0
 

Modified: trunk/mapserver/mapscript/php/point.c
===================================================================
--- trunk/mapserver/mapscript/php/point.c	2011-04-27 15:06:17 UTC (rev 11618)
+++ trunk/mapserver/mapscript/php/point.c	2011-04-27 15:23:07 UTC (rev 11619)
@@ -175,15 +175,12 @@
    Set new point. Returns MS_FAILURE on error. */
 PHP_METHOD(pointObj, setXY)
 {
-    zval *x, *y, *m = NULL;
+    double x, y, m;
     zval *zobj = getThis();
-    zval retval;
-    zval *args[2];
-    zval property_name, function_name;
     php_point_object *php_point;
 
     PHP_MAPSCRIPT_ERROR_HANDLING(TRUE);
-    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz|z",
+    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "dd|d",
                               &x, &y, &m) == FAILURE) {
         PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
         return;
@@ -192,23 +189,13 @@
     
     php_point = (php_point_object *) zend_object_store_get_object(zobj TSRMLS_CC);
     
-    ZVAL_STRING(&property_name, "x", 0);      
-    args[0] = &property_name; 
-    args[1] = x; 
-    MAPSCRIPT_CALL_METHOD(zobj, "__set", retval, 2, args);
-            
-    ZVAL_STRING(&property_name, "y", 0);      
-    args[0] = &property_name; 
-    args[1] = y; 
-    MAPSCRIPT_CALL_METHOD(zobj, "__set", retval, 2, args);
+    php_point->point->x = x;
+    php_point->point->y = y;
 
 #ifdef USE_POINT_Z_M
-    if (m)
+    if (ZEND_NUM_ARGS() == 3)
     {
-        ZVAL_STRING(&property_name, "m", 0);      
-        args[0] = &property_name; 
-        args[1] = m; 
-        MAPSCRIPT_CALL_METHOD(zobj, "__set", retval, 2, args);
+            php_point->point->m = m;
     }
 #endif
 
@@ -221,15 +208,12 @@
    Set new point. Returns MS_FAILURE on error. */
 PHP_METHOD(pointObj, setXYZ)
 {
-    zval *x, *y, *z, *m = NULL;
+    double x, y, z, m;
     zval *zobj = getThis();
-    zval retval;
-    zval *args[2];
-    zval property_name, function_name;
     php_point_object *php_point;
 
     PHP_MAPSCRIPT_ERROR_HANDLING(TRUE);
-    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzz|z",
+    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ddd|d",
                               &x, &y, &z, &m) == FAILURE) {
         PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
         return;
@@ -238,28 +222,15 @@
     
     php_point = (php_point_object *) zend_object_store_get_object(zobj TSRMLS_CC);
     
-    ZVAL_STRING(&property_name, "x", 0);      
-    args[0] = &property_name; 
-    args[1] = x; 
-    MAPSCRIPT_CALL_METHOD(zobj, "__set", retval, 2, args);
-            
-    ZVAL_STRING(&property_name, "y", 0);      
-    args[0] = &property_name; 
-    args[1] = y; 
-    MAPSCRIPT_CALL_METHOD(zobj, "__set", retval, 2, args);
+    php_point->point->x = x;
+    php_point->point->y = y;
 
 #ifdef USE_POINT_Z_M
-    ZVAL_STRING(&property_name, "z", 0);      
-    args[0] = &property_name; 
-    args[1] = z; 
-    MAPSCRIPT_CALL_METHOD(zobj, "__set", retval, 2, args);
+    php_point->point->z = z;
 
-    if (m)
+    if (ZEND_NUM_ARGS() == 4)
     {
-        ZVAL_STRING(&property_name, "m", 0);      
-        args[0] = &property_name; 
-        args[1] = m; 
-        MAPSCRIPT_CALL_METHOD(zobj, "__set", retval, 2, args);
+        php_point->point->m = m;
     }
 #endif
 

Modified: trunk/mapserver/mapscript/php/style.c
===================================================================
--- trunk/mapserver/mapscript/php/style.c	2011-04-27 15:06:17 UTC (rev 11618)
+++ trunk/mapserver/mapscript/php/style.c	2011-04-27 15:23:07 UTC (rev 11619)
@@ -249,9 +249,8 @@
     char *snippet;
     long snippet_len;
     int status = MS_FAILURE;
-    zval retval;
-    zval *args[2];
-    zval function_name;
+    zval *retval;
+    zval property_name, value;
     php_style_object *php_style;
 
     PHP_MAPSCRIPT_ERROR_HANDLING(TRUE);
@@ -270,21 +269,17 @@
         return;
     }
     
-    ZVAL_LONG(&retval, status);
-
     /* verify the symbol if needed */
     if (php_style->style->symbolname) 
     {
-        MAKE_STD_ZVAL(args[0]);
-        MAKE_STD_ZVAL(args[1]);
-        ZVAL_STRING(args[0], "symbolname", 1);
-        ZVAL_STRING(args[1], php_style->style->symbolname, 1);
-        MAPSCRIPT_CALL_METHOD(zobj, "__set", retval, 2, args);
-        zval_ptr_dtor(&args[0]);
-        zval_ptr_dtor(&args[1]);
+        INIT_ZVAL(property_name);
+        INIT_ZVAL(value);
+        ZVAL_STRING(&property_name, "symbolname", 1);
+        ZVAL_STRING(&value, php_style->style->symbolname, 1);
+        MAPSCRIPT_CALL_METHOD_2(zobj, "__set", retval, &property_name, &value);
     }
 
-    RETURN_LONG(Z_LVAL(retval));
+    RETURN_LONG(status);
 }
 /* }}} */
 



More information about the mapserver-commits mailing list