From ed98187e3bd3f2e23e1cce128bace99d36ba5c3a Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Wed, 26 May 2010 00:19:08 +0000 Subject: [PATCH] Tidy up typemaps, combining variants with the same code. Use const_cast to remove const-ness from const char * for stupid PHP API in %throws typemap. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12054 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/php/std_string.i | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/Lib/php/std_string.i b/Lib/php/std_string.i index 6eb8ac22a..de4e15c4e 100644 --- a/Lib/php/std_string.i +++ b/Lib/php/std_string.i @@ -23,8 +23,8 @@ namespace std { class string; - %typemap(typecheck,precedence=SWIG_TYPECHECK_STRING) string %{ - $1 = ( Z_TYPE_PP($input) == IS_STRING ) ? 1 : 0; + %typemap(typecheck,precedence=SWIG_TYPECHECK_STRING) string, const string& %{ + $1 = ( Z_TYPE_PP($input) == IS_STRING ) ? 1 : 0; %} %typemap(in) string %{ @@ -37,15 +37,11 @@ namespace std { $result.assign(Z_STRVAL_PP($input), Z_STRLEN_PP($input)); %} - %typemap(typecheck,precedence=SWIG_TYPECHECK_STRING) const string& %{ - $1 = ( Z_TYPE_PP($input) == IS_STRING ) ? 1 : 0; - %} - %typemap(out) string %{ ZVAL_STRINGL($result, const_cast($1.data()), $1.size(), 1); %} - %typemap(directorin) string %{ + %typemap(directorin) string, const string& %{ ZVAL_STRINGL($input, const_cast($1_name.data()), $1_name.size(), 1); %} @@ -53,16 +49,8 @@ namespace std { ZVAL_STRINGL($result, const_cast($1->data()), $1->size(), 1); %} - %typemap(directorin) const string & %{ - ZVAL_STRINGL($input, const_cast($1_name.data()), $1_name.size(), 1); - %} - - %typemap(throws) string %{ - SWIG_PHP_Error(E_ERROR, (char *)$1.c_str()); - %} - - %typemap(throws) const string& %{ - SWIG_PHP_Error(E_ERROR, (char *)$1.c_str()); + %typemap(throws) string, const string& %{ + SWIG_PHP_Error(E_ERROR, const_cast($1.c_str())); %} /* These next two handle a function which takes a non-const reference to