diff options
author | Frederic Peters <fpeters@entrouvert.com> | 2006-12-28 15:42:17 +0000 |
---|---|---|
committer | Frederic Peters <fpeters@entrouvert.com> | 2006-12-28 15:42:17 +0000 |
commit | c86d99e9e09ce219c869e01ec7430cbd6e779a80 (patch) | |
tree | 59bee60771ee1b4c0534cb6eb259967a4eb0cfce /php | |
parent | 342bfd307345befb2d9258e60ab0bf972e629211 (diff) | |
download | lasso-c86d99e9e09ce219c869e01ec7430cbd6e779a80.tar.gz lasso-c86d99e9e09ce219c869e01ec7430cbd6e779a80.tar.xz lasso-c86d99e9e09ce219c869e01ec7430cbd6e779a80.zip |
more fixes for optional arg support in PHP
Diffstat (limited to 'php')
-rwxr-xr-x | php/patch_swig_output.py | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/php/patch_swig_output.py b/php/patch_swig_output.py index 1463b82e..8c8b6c3b 100755 --- a/php/patch_swig_output.py +++ b/php/patch_swig_output.py @@ -194,18 +194,38 @@ wrap = wrap.replace('if(zend_get_parameters_array_ex(arg_count-argbase,args)!=SU 'if(zend_get_parameters_array_ex(arg_count,args)!=SUCCESS)') -pattern = re.compile( - 'This function uses a this_ptr\*/\n arg_count.*\n if\(arg_count<(\d) \|\| arg_count>(\d)') +function_pattern = re.compile('ZEND_NAMED_FUNCTION(.*?)\n}', re.DOTALL) +argcount_less_pattern = re.compile('if\(arg_count<(\d) \|\| arg_count>(\d)') +argcount_more_pattern = re.compile('if\(arg_count > (\d)\)') -def rep(match): + +def rep2(match): arg1 = int(match.group(1)) - 1 arg2 = int(match.group(2)) - 1 - return """This function uses a this_ptr*/ - arg_count = ZEND_NUM_ARGS(); - if(arg_count<%s || arg_count>%s""" % (arg1, arg2) + return 'if(arg_count<%s || arg_count>%s' % (arg1, arg2) -wrap = pattern.sub(rep, wrap) +def rep3(match): + arg1 = int(match.group(1)) - 1 + return 'if(arg_count > %s)' % arg1 +def rep(match): + m = match.group(0) + if not 'This function uses a this_ptr' in m: + return m + if not 'arg_count<' in m: + return m + lines = match.group(0).splitlines() + s = [] + for l in lines: + if l.startswith('if(arg_count<'): + l = argcount_less_pattern.sub(rep2, l) + elif l.startswith(' if(arg_count >'): + l = argcount_more_pattern.sub(rep3, l) + s.append(l) + + return ''.join(s) + +wrap = function_pattern.sub(rep, wrap) wrap = re.sub(r'zend_register_internal_class_ex(.*)NULL,NULL\)', r'zend_register_internal_class_ex\1NULL,NULL TSRMLS_CC)', wrap) |