Adjust brackets on typemaps to eliminate superfluous {} blocks in generated
C/C++ wrapper code. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9980 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
41af8afda1
commit
2982a37ad5
4 changed files with 50 additions and 59 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
%define %pass_by_ref( TYPE, CONVERT_IN, CONVERT_OUT )
|
%define %pass_by_ref( TYPE, CONVERT_IN, CONVERT_OUT )
|
||||||
%typemap(in) TYPE *REF ($*1_ltype tmp),
|
%typemap(in) TYPE *REF ($*1_ltype tmp),
|
||||||
TYPE &REF ($*1_ltype tmp)
|
TYPE &REF ($*1_ltype tmp)
|
||||||
{
|
%{
|
||||||
/* First Check for SWIG wrapped type */
|
/* First Check for SWIG wrapped type */
|
||||||
if ( ZVAL_IS_NULL( *$input ) ) {
|
if ( ZVAL_IS_NULL( *$input ) ) {
|
||||||
$1 = 0;
|
$1 = 0;
|
||||||
|
|
@ -12,11 +12,10 @@
|
||||||
} else {
|
} else {
|
||||||
SWIG_PHP_Error( E_ERROR, SWIG_PHP_Arg_Error_Msg($argnum, Expected a reference) );
|
SWIG_PHP_Error( E_ERROR, SWIG_PHP_Arg_Error_Msg($argnum, Expected a reference) );
|
||||||
}
|
}
|
||||||
}
|
%}
|
||||||
%typemap(argout) TYPE *REF,
|
%typemap(argout) TYPE *REF,
|
||||||
TYPE &REF {
|
TYPE &REF
|
||||||
CONVERT_OUT(*$input, tmp$argnum );
|
"CONVERT_OUT(*$input, tmp$argnum );";
|
||||||
}
|
|
||||||
%enddef
|
%enddef
|
||||||
|
|
||||||
%pass_by_ref( size_t, CONVERT_INT_IN, ZVAL_LONG );
|
%pass_by_ref( size_t, CONVERT_INT_IN, ZVAL_LONG );
|
||||||
|
|
|
||||||
|
|
@ -26,26 +26,26 @@ namespace std {
|
||||||
|
|
||||||
class string;
|
class string;
|
||||||
|
|
||||||
%typemap(typecheck,precedence=SWIG_TYPECHECK_STRING) string {
|
%typemap(typecheck,precedence=SWIG_TYPECHECK_STRING) string %{
|
||||||
$1 = ( Z_TYPE_PP($input) == IS_STRING ) ? 1 : 0;
|
$1 = ( Z_TYPE_PP($input) == IS_STRING ) ? 1 : 0;
|
||||||
}
|
%}
|
||||||
|
|
||||||
%typemap(in) string {
|
%typemap(in) string %{
|
||||||
convert_to_string_ex($input);
|
convert_to_string_ex($input);
|
||||||
$1.assign(Z_STRVAL_PP($input), Z_STRLEN_PP($input));
|
$1.assign(Z_STRVAL_PP($input), Z_STRLEN_PP($input));
|
||||||
}
|
%}
|
||||||
|
|
||||||
%typemap(typecheck,precedence=SWIG_TYPECHECK_STRING) const string& {
|
%typemap(typecheck,precedence=SWIG_TYPECHECK_STRING) const string& %{
|
||||||
$1 = ( Z_TYPE_PP($input) == IS_STRING ) ? 1 : 0;
|
$1 = ( Z_TYPE_PP($input) == IS_STRING ) ? 1 : 0;
|
||||||
}
|
%}
|
||||||
|
|
||||||
%typemap(out) string {
|
%typemap(out) string %{
|
||||||
ZVAL_STRINGL($result, const_cast<char*>($1.data()), $1.size(), 1);
|
ZVAL_STRINGL($result, const_cast<char*>($1.data()), $1.size(), 1);
|
||||||
}
|
%}
|
||||||
|
|
||||||
%typemap(out) const string & {
|
%typemap(out) const string & %{
|
||||||
ZVAL_STRINGL($result, const_cast<char*>($1->data()), $1->size(), 1);
|
ZVAL_STRINGL($result, const_cast<char*>($1->data()), $1->size(), 1);
|
||||||
}
|
%}
|
||||||
|
|
||||||
%typemap(throws) string %{
|
%typemap(throws) string %{
|
||||||
SWIG_PHP_Error(E_ERROR, (char *)$1.c_str());
|
SWIG_PHP_Error(E_ERROR, (char *)$1.c_str());
|
||||||
|
|
@ -57,15 +57,17 @@ namespace std {
|
||||||
|
|
||||||
/* These next two handle a function which takes a non-const reference to
|
/* These next two handle a function which takes a non-const reference to
|
||||||
* a std::string and modifies the string. */
|
* a std::string and modifies the string. */
|
||||||
%typemap(in) string & (std::string temp) {
|
%typemap(in) string & (std::string temp) %{
|
||||||
convert_to_string_ex($input);
|
convert_to_string_ex($input);
|
||||||
temp.assign(Z_STRVAL_PP($input), Z_STRLEN_PP($input));
|
temp.assign(Z_STRVAL_PP($input), Z_STRLEN_PP($input));
|
||||||
$1 = &temp;
|
$1 = &temp;
|
||||||
}
|
%}
|
||||||
|
|
||||||
%typemap(argout) string & {
|
%typemap(argout) string & %{
|
||||||
ZVAL_STRINGL(*($input), const_cast<char*>($1->data()), $1->size(), 1);
|
ZVAL_STRINGL(*($input), const_cast<char*>($1->data()), $1->size(), 1);
|
||||||
}
|
%}
|
||||||
|
|
||||||
%typemap(argout) const string & { }
|
/* SWIG will apply the non-const typemap above to const string& without
|
||||||
|
* this more specific typemap. */
|
||||||
|
%typemap(argout) const string & "";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,16 +29,13 @@
|
||||||
|
|
||||||
%define double_typemap(TYPE)
|
%define double_typemap(TYPE)
|
||||||
%typemap(in) TYPE *INPUT(TYPE temp)
|
%typemap(in) TYPE *INPUT(TYPE temp)
|
||||||
{
|
%{
|
||||||
convert_to_double_ex($input);
|
convert_to_double_ex($input);
|
||||||
temp = (TYPE) Z_DVAL_PP($input);
|
temp = (TYPE) Z_DVAL_PP($input);
|
||||||
$1 = &temp;
|
$1 = &temp;
|
||||||
}
|
%}
|
||||||
%typemap(argout) TYPE *INPUT "";
|
%typemap(argout) TYPE *INPUT "";
|
||||||
%typemap(in,numinputs=0) TYPE *OUTPUT(TYPE temp)
|
%typemap(in,numinputs=0) TYPE *OUTPUT(TYPE temp) "$1 = &temp;";
|
||||||
{
|
|
||||||
$1 = &temp;
|
|
||||||
}
|
|
||||||
%typemap(argout,fragment="t_output_helper") TYPE *OUTPUT
|
%typemap(argout,fragment="t_output_helper") TYPE *OUTPUT
|
||||||
{
|
{
|
||||||
zval *o;
|
zval *o;
|
||||||
|
|
@ -47,30 +44,27 @@
|
||||||
t_output_helper( &$result, o );
|
t_output_helper( &$result, o );
|
||||||
}
|
}
|
||||||
%typemap(in) TYPE *REFERENCE (TYPE dvalue)
|
%typemap(in) TYPE *REFERENCE (TYPE dvalue)
|
||||||
{
|
%{
|
||||||
convert_to_double_ex($input);
|
convert_to_double_ex($input);
|
||||||
dvalue = (TYPE) (*$input)->value.dval;
|
dvalue = (TYPE) (*$input)->value.dval;
|
||||||
$1 = &dvalue;
|
$1 = &dvalue;
|
||||||
}
|
%}
|
||||||
%typemap(argout) TYPE *REFERENCE
|
%typemap(argout) TYPE *REFERENCE
|
||||||
{
|
%{
|
||||||
$1->value.dval = (double)(lvalue$argnum);
|
$1->value.dval = (double)(lvalue$argnum);
|
||||||
$1->type = IS_DOUBLE;
|
$1->type = IS_DOUBLE;
|
||||||
}
|
%}
|
||||||
%enddef
|
%enddef
|
||||||
|
|
||||||
%define int_typemap(TYPE)
|
%define int_typemap(TYPE)
|
||||||
%typemap(in) TYPE *INPUT(TYPE temp)
|
%typemap(in) TYPE *INPUT(TYPE temp)
|
||||||
{
|
%{
|
||||||
convert_to_long_ex($input);
|
convert_to_long_ex($input);
|
||||||
temp = (TYPE) Z_LVAL_PP($input);
|
temp = (TYPE) Z_LVAL_PP($input);
|
||||||
$1 = &temp;
|
$1 = &temp;
|
||||||
}
|
%}
|
||||||
%typemap(argout) TYPE *INPUT "";
|
%typemap(argout) TYPE *INPUT "";
|
||||||
%typemap(in,numinputs=0) TYPE *OUTPUT(TYPE temp)
|
%typemap(in,numinputs=0) TYPE *OUTPUT(TYPE temp) "$1 = &temp;";
|
||||||
{
|
|
||||||
$1 = &temp;
|
|
||||||
}
|
|
||||||
%typemap(argout,fragment="t_output_helper") TYPE *OUTPUT
|
%typemap(argout,fragment="t_output_helper") TYPE *OUTPUT
|
||||||
{
|
{
|
||||||
zval *o;
|
zval *o;
|
||||||
|
|
@ -79,17 +73,16 @@
|
||||||
t_output_helper( &$result, o );
|
t_output_helper( &$result, o );
|
||||||
}
|
}
|
||||||
%typemap(in) TYPE *REFERENCE (TYPE lvalue)
|
%typemap(in) TYPE *REFERENCE (TYPE lvalue)
|
||||||
{
|
%{
|
||||||
convert_to_long_ex($input);
|
convert_to_long_ex($input);
|
||||||
lvalue = (TYPE) (*$input)->value.lval;
|
lvalue = (TYPE) (*$input)->value.lval;
|
||||||
$1 = &lvalue;
|
$1 = &lvalue;
|
||||||
}
|
%}
|
||||||
%typemap(argout) TYPE *REFERENCE
|
%typemap(argout) TYPE *REFERENCE
|
||||||
{
|
%{
|
||||||
|
|
||||||
(*$arg)->value.lval = (long)(lvalue$argnum);
|
(*$arg)->value.lval = (long)(lvalue$argnum);
|
||||||
(*$arg)->type = IS_LONG;
|
(*$arg)->type = IS_LONG;
|
||||||
}
|
%}
|
||||||
%enddef
|
%enddef
|
||||||
|
|
||||||
double_typemap(float);
|
double_typemap(float);
|
||||||
|
|
@ -125,16 +118,13 @@ int_typemap(unsigned char);
|
||||||
%typemap(argout) unsigned char *INOUT = unsigned char *OUTPUT;
|
%typemap(argout) unsigned char *INOUT = unsigned char *OUTPUT;
|
||||||
|
|
||||||
%typemap(in) char INPUT[ANY] ( char temp[$1_dim0] )
|
%typemap(in) char INPUT[ANY] ( char temp[$1_dim0] )
|
||||||
{
|
%{
|
||||||
convert_to_string_ex($input);
|
convert_to_string_ex($input);
|
||||||
char *val = Z_LVAL_PP($input);
|
strncpy(temp,Z_LVAL_PP($input),$1_dim0);
|
||||||
strncpy(temp,val,$1_dim0);
|
|
||||||
$1 = temp;
|
$1 = temp;
|
||||||
}
|
%}
|
||||||
%typemap(in,numinputs=0) char OUTPUT[ANY] ( char temp[$1_dim0] )
|
%typemap(in,numinputs=0) char OUTPUT[ANY] ( char temp[$1_dim0] )
|
||||||
{
|
"$1 = temp;";
|
||||||
$1 = temp;
|
|
||||||
}
|
|
||||||
%typemap(argout) char OUTPUT[ANY]
|
%typemap(argout) char OUTPUT[ANY]
|
||||||
{
|
{
|
||||||
zval *o;
|
zval *o;
|
||||||
|
|
@ -145,7 +135,7 @@ int_typemap(unsigned char);
|
||||||
|
|
||||||
%typemap(in,numinputs=0) void **OUTPUT (int force),
|
%typemap(in,numinputs=0) void **OUTPUT (int force),
|
||||||
void *&OUTPUT (int force)
|
void *&OUTPUT (int force)
|
||||||
{
|
%{
|
||||||
/* If they pass NULL by reference, make it into a void*
|
/* If they pass NULL by reference, make it into a void*
|
||||||
This bit should go in arginit if arginit support init-ing scripting args */
|
This bit should go in arginit if arginit support init-ing scripting args */
|
||||||
if(SWIG_ConvertPtr(*$input, (void **) &$1, $1_descriptor, 0) < 0) {
|
if(SWIG_ConvertPtr(*$input, (void **) &$1, $1_descriptor, 0) < 0) {
|
||||||
|
|
@ -166,16 +156,16 @@ int_typemap(unsigned char);
|
||||||
/* have to passback arg$arg too */
|
/* have to passback arg$arg too */
|
||||||
force=1;
|
force=1;
|
||||||
}
|
}
|
||||||
}
|
%}
|
||||||
|
|
||||||
%typemap(argout) void **OUTPUT,
|
%typemap(argout) void **OUTPUT,
|
||||||
void *&OUTPUT
|
void *&OUTPUT
|
||||||
{
|
%{
|
||||||
if (force$argnum) { /* pass back arg$argnum through params ($arg) if we can */
|
if (force$argnum) { /* pass back arg$argnum through params ($arg) if we can */
|
||||||
if(! PZVAL_IS_REF(*$arg)) {
|
if (!PZVAL_IS_REF(*$arg)) {
|
||||||
SWIG_PHP_Error(E_WARNING, "Parameter $argnum of $symname wasn't passed by reference");
|
SWIG_PHP_Error(E_WARNING, "Parameter $argnum of $symname wasn't passed by reference");
|
||||||
} else {
|
} else {
|
||||||
SWIG_SetPointerZval(*$arg, (void *) ptr$argnum, $*1_descriptor, 1);
|
SWIG_SetPointerZval(*$arg, (void *) ptr$argnum, $*1_descriptor, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
%}
|
||||||
|
|
|
||||||
|
|
@ -30,9 +30,9 @@
|
||||||
|
|
||||||
%define %pass_by_val( TYPE, CONVERT_IN )
|
%define %pass_by_val( TYPE, CONVERT_IN )
|
||||||
%typemap(in) TYPE
|
%typemap(in) TYPE
|
||||||
{
|
%{
|
||||||
CONVERT_IN($1,$1_ltype,$input);
|
CONVERT_IN($1,$1_ltype,$input);
|
||||||
}
|
%}
|
||||||
%enddef
|
%enddef
|
||||||
|
|
||||||
%fragment("t_output_helper","header") %{
|
%fragment("t_output_helper","header") %{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue