diff options
| author | Emmanuel Raviart <eraviart@entrouvert.com> | 2005-01-13 13:09:00 +0000 |
|---|---|---|
| committer | Emmanuel Raviart <eraviart@entrouvert.com> | 2005-01-13 13:09:00 +0000 |
| commit | 4411851ee26ed5edf09c30c3cee6aa76650c5a37 (patch) | |
| tree | 0993c3309fb1aaefa440dc3680397adcf0a6eb67 | |
| parent | 69e3012ea735ee512356b49bd3dd66aa319b0674 (diff) | |
| download | lasso-4411851ee26ed5edf09c30c3cee6aa76650c5a37.tar.gz lasso-4411851ee26ed5edf09c30c3cee6aa76650c5a37.tar.xz lasso-4411851ee26ed5edf09c30c3cee6aa76650c5a37.zip | |
PHP Binding: Added support for NULL return value.
| -rwxr-xr-x | php/patch_swig_output.py | 68 | ||||
| -rwxr-xr-x | python/tests/profiles_tests.py | 4 | ||||
| -rw-r--r-- | swig/Lasso.i | 85 |
3 files changed, 113 insertions, 44 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 diff --git a/python/tests/profiles_tests.py b/python/tests/profiles_tests.py index 68d2925e..00615a8e 100755 --- a/python/tests/profiles_tests.py +++ b/python/tests/profiles_tests.py @@ -58,11 +58,15 @@ class BindingTestCase(unittest.TestCase): self.failUnlessEqual(authnRequest.consent, None) authnRequest.consent = lasso.libConsentObtained self.failUnlessEqual(authnRequest.consent, lasso.libConsentObtained) + authnRequest.consent = None + self.failUnlessEqual(authnRequest.consent, None) # Test a renamed string attribute. self.failUnlessEqual(authnRequest.relayState, None) authnRequest.relayState = 'Hello World!' self.failUnlessEqual(authnRequest.relayState, 'Hello World!') + authnRequest.relayState = None + self.failUnlessEqual(authnRequest.relayState, None) # Test an integer attribute. self.failUnlessEqual(authnRequest.majorVersion, 0) diff --git a/swig/Lasso.i b/swig/Lasso.i index bcfba415..dfcd9eee 100644 --- a/swig/Lasso.i +++ b/swig/Lasso.i @@ -138,31 +138,6 @@ Warning = _lasso.Warning ***********************************************************************/ -#define %nonewobject %feature("new","") - -#if defined(SWIGPYTHON) -%typemap(in,parse="z") char *, char [ANY] ""; -#endif - - -#if defined(SWIGPHP4) -%{ -/* ZVAL_STRING segfault when s is null */ -#undef ZVAL_STRING -#define ZVAL_STRING(z, s, duplicate) { \ - char *__s=(s); \ - if (__s) { \ - (z)->value.str.len = strlen(__s); \ - (z)->value.str.val = (duplicate?estrndup(__s, (z)->value.str.len):__s); \ - } else { \ - (z)->value.str.len = 0; \ - (z)->value.str.val = empty_string; \ - } \ - (z)->type = IS_STRING; \ - } -%} -#endif - /* GLib types */ #define gboolean bool @@ -188,7 +163,65 @@ int lasso_init(void); #endif int lasso_shutdown(void); -/* Helper variables and functions */ +/* Swig tuning */ + +#define %nonewobject %feature("new","") + +#if defined(SWIGPYTHON) +%typemap(in,parse="z") char * ""; +#endif + +#if defined(SWIGPHP4) + +%{ +/* ZVAL_STRING segfault when s is null */ +#undef ZVAL_STRING +#define ZVAL_STRING(z, s, duplicate) { \ + char *__s=(s); \ + if (__s) { \ + (z)->value.str.len = strlen(__s); \ + (z)->value.str.val = (duplicate?estrndup(__s, (z)->value.str.len):__s); \ + } else { \ + (z)->value.str.len = 0; \ + (z)->value.str.val = empty_string; \ + } \ + (z)->type = IS_STRING; \ +} +%} + +/* Override default typemap, to accept NULL pointer. Because SWIG_ConvertPtr doesn't accept NULL */ +/* values. */ +%typemap(in) SWIGTYPE * %{ + if (SWIG_ConvertPtr(*$input, (void **) &$1, $1_descriptor) < 0) { + if ((*$input)->type == IS_NULL) + $1 = 0; + else + zend_error(E_ERROR, "Type error in argument %d of $symname. Expected %s", + $argnum-argbase, $1_descriptor->name); + } +%} + +/* Override default typemap, to be able to return NULL pointers. */ +%typemap(out) SWIGTYPE * %{ + if (!$1) { + ZVAL_NULL(return_value); + } else { + SWIG_SetPointerZval(return_value, (void *)$1, $1_descriptor, $owner); + } +%} + +%typemap(out) SWIGTYPE *DYNAMIC %{ + if (!$1) { + ZVAL_NULL(return_value); + } else { + swig_type_info *ty = SWIG_TypeDynamicCast($1_descriptor, (void **) &$1); + SWIG_SetPointerZval(return_value, (void *)$1, ty, $owner); + } +%} + +#endif /* if defined(SWIGPHP4) */ + +/* Dynamic casting handling */ #if defined(SWIGCSHARP) || defined(SWIGJAVA) |
