summaryrefslogtreecommitdiffstats
path: root/php
diff options
context:
space:
mode:
authorEmmanuel Raviart <eraviart@entrouvert.com>2005-01-13 13:09:00 +0000
committerEmmanuel Raviart <eraviart@entrouvert.com>2005-01-13 13:09:00 +0000
commit4411851ee26ed5edf09c30c3cee6aa76650c5a37 (patch)
tree0993c3309fb1aaefa440dc3680397adcf0a6eb67 /php
parent69e3012ea735ee512356b49bd3dd66aa319b0674 (diff)
downloadlasso-4411851ee26ed5edf09c30c3cee6aa76650c5a37.tar.gz
lasso-4411851ee26ed5edf09c30c3cee6aa76650c5a37.tar.xz
lasso-4411851ee26ed5edf09c30c3cee6aa76650c5a37.zip
PHP Binding: Added support for NULL return value.
Diffstat (limited to 'php')
-rwxr-xr-xphp/patch_swig_output.py68
1 files changed, 50 insertions, 18 deletions
diff --git a/php/patch_swig_output.py b/php/patch_swig_output.py
index 7a8fec2f..6e886aa2 100755
--- a/php/patch_swig_output.py
+++ b/php/patch_swig_output.py
@@ -2,14 +2,21 @@
"""Correct Swig output for PHP binding.
-The PHP binding of Swig version 1.3.22 doest handle dynamic cast of function results well: After
-the C object is dynamically casted, it creates a statically caster PHP object.
+The PHP binding of Swig version 1.3.22 has several bugs:
-This program corrects this, by replacing:
- {
+(1) It wraps NULL pointers into non NULL PHP objects.
+
+(2) It doesn't handle dynamic cast of function results well: After the C object is dynamically
+ casted, it creates a statically casted PHP object.
+
+This program corrects (1) and (2), by replacing things like:
+ if (!result) {
+ ZVAL_NULL(return_value);
+ } else {
swig_type_info *ty = SWIG_TypeDynamicCast(SWIGTYPE_p_LassoXXX, (void **) &result);
SWIG_SetPointerZval(return_value, (void *)result, ty, 1);
}
+
/* Wrap this return value */
if (this_ptr) {
/* NATIVE Constructor, use this_ptr */
@@ -29,7 +36,9 @@ This program corrects this, by replacing:
*return_value=*obj;
}
with:
- {
+ if (!result) {
+ ZVAL_NULL(return_value);
+ } else {
swig_type_info *ty = SWIG_TypeDynamicCast(SWIGTYPE_p_LassoXXX, (void **) &result);
SWIG_SetPointerZval(return_value, (void *)result, ty, 1);
/* Wrap this return value */
@@ -46,15 +55,18 @@ with:
MAKE_STD_ZVAL(_cPtr);
*_cPtr = *return_value;
INIT_ZVAL(*return_value);
- object_init_ex(obj,ptr_ce_swig_LassoXXX);
+ object_init_ex(obj,get_node_info_with_swig(ty)->php);
add_property_zval(obj,"_cPtr",_cPtr);
*return_value=*obj;
}}
and
- {
+ if (!result) {
+ ZVAL_NULL(return_value);
+ } else {
swig_type_info *ty = SWIG_TypeDynamicCast(SWIGTYPE_p_LassoXXX, (void **) &result);
SWIG_SetPointerZval(return_value, (void *)result, ty, 0);
}
+
/* Wrap this return value */
{
/* ALTERNATIVE Constructor, make an object wrapper */
@@ -63,12 +75,14 @@ and
MAKE_STD_ZVAL(_cPtr);
*_cPtr = *return_value;
INIT_ZVAL(*return_value);
- object_init_ex(obj,ptr_ce_swig_LassoSamlpResponseAbstract);
+ object_init_ex(obj,ptr_ce_swig_LassoXXX);
add_property_zval(obj,"_cPtr",_cPtr);
*return_value=*obj;
}
with:
- {
+ if (!result) {
+ ZVAL_NULL(return_value);
+ } else {
swig_type_info *ty = SWIG_TypeDynamicCast(SWIGTYPE_p_LassoXXX, (void **) &result);
SWIG_SetPointerZval(return_value, (void *)result, ty, 0);
/* Wrap this return value */
@@ -79,7 +93,7 @@ with:
MAKE_STD_ZVAL(_cPtr);
*_cPtr = *return_value;
INIT_ZVAL(*return_value);
- object_init_ex(obj,ptr_ce_swig_LassoSamlpResponseAbstract);
+ object_init_ex(obj,get_node_info_with_swig(ty)->php);
add_property_zval(obj,"_cPtr",_cPtr);
*return_value=*obj;
}}
@@ -89,28 +103,46 @@ import sys
wrap = sys.stdin.read()
-i = wrap.find(' {\n swig_type_info *ty = SWIG_TypeDynamicCast(')
-while i >= 0:
- end = """
+# (1)
+begin = """
+ }
+
+ /* Wrap this return value */
+"""
+end = """
*return_value=*obj;
}
"""
+i = wrap.find(begin)
+while i >= 0:
j = wrap.find(end, i) + len(end)
segment = wrap[i:j]
- segment = segment.replace("""
- }
- /* Wrap this return value */
-""", """
+ segment = segment.replace(begin, """
/* Wrap this return value */
""")
segment = segment.replace(end, """
*return_value=*obj;
}}
""")
+ wrap = '%s%s%s' % (wrap[:i], segment, wrap[j:])
+ i = wrap.find(begin, i + len(segment))
+
+# (2)
+begin = """
+ {
+ swig_type_info *ty = SWIG_TypeDynamicCast("""
+end = """
+ *return_value=*obj;
+ }}
+"""
+i = wrap.find(begin)
+while i >= 0:
+ j = wrap.find(end, i) + len(end)
+ segment = wrap[i:j]
x = segment.find('object_init_ex(obj,') + len('object_init_ex(obj,')
y = segment.find(')', x)
segment = '%s%s%s' % (segment[:x], 'get_node_info_with_swig(ty)->php', segment[y:])
wrap = '%s%s%s' % (wrap[:i], segment, wrap[j:])
- i = wrap.find(' {\n swig_type_info *ty = SWIG_TypeDynamicCast(', i + len(segment))
+ i = wrap.find(begin, i + len(segment))
print wrap