Made comment more informative.

Added convert_to_{double|long}_ex in the in typemaps.
Corrected the REFERENCE typemaps so they now work.


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@7394 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Kevin Ruland 2005-08-25 18:33:26 +00:00
commit 88736745e4

View file

@ -14,16 +14,26 @@
// //
// Define macros to define the following typemaps: // Define macros to define the following typemaps:
// //
// INPUT arguments by Pointer // TYPE *INPUT. Argument is passed in as native variable by value.
// OUTPUT arguments by Pointer // TYPE *OUTPUT. Argument is returned as an array from the function call.
// INPUT arguments by Php reference // TYPE *INOUT. Argument is passed in by value, and out as part of returned list
// OUTPUT arguments by Php reference // TYPE *REFERENCE. Argument is passed in as native variable with value
// semantics. Variable value is changed with result.
// Use like this:
// int foo(int *REFERENCE);
//
// $a = 0;
// $rc = foo($a);
//
// Even though $a looks like it's passed by value,
// it's value can be changed by foo().
// //
%define double_typemap(TYPE) %define double_typemap(TYPE)
%typemap(in) TYPE *INPUT(TYPE temp) %typemap(in) TYPE *INPUT(TYPE temp)
{ {
temp = (TYPE) Z_DVAL_PP($input); convert_to_double_ex($input);
$1 = &temp; temp = (TYPE) Z_DVAL_PP($input);
$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)
@ -39,18 +49,13 @@
} }
%typemap(in) TYPE *REFERENCE (TYPE dvalue) %typemap(in) TYPE *REFERENCE (TYPE dvalue)
{ {
if(!ParameterPassedByReference(ht, argvi)) convert_to_double_ex($input);
{
SWIG_PHP_Error(E_WARNING, "Parameter wasn't passed by reference");
RETURN_NULL();
}
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)(*$arg); $1->value.dval = (double)(lvalue$argnum);
$1->type = IS_DOUBLE; $1->type = IS_DOUBLE;
} }
%enddef %enddef
@ -58,8 +63,9 @@
%define int_typemap(TYPE) %define int_typemap(TYPE)
%typemap(in) TYPE *INPUT(TYPE temp) %typemap(in) TYPE *INPUT(TYPE temp)
{ {
temp = (TYPE) Z_LVAL_PP($input); convert_to_long_ex($input);
$1 = &temp; temp = (TYPE) Z_LVAL_PP($input);
$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)
@ -75,19 +81,14 @@
} }
%typemap(in) TYPE *REFERENCE (TYPE lvalue) %typemap(in) TYPE *REFERENCE (TYPE lvalue)
{ {
if(!ParameterPassedByReference(ht, argvi)) convert_to_long_ex($input);
{
SWIG_PHP_Error(E_WARNING, "Parameter wasn't passed by reference");
RETURN_NULL();
}
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)(*$input); (*$arg)->value.lval = (long)(lvalue$argnum);
(*$arg)->type = IS_LONG; (*$arg)->type = IS_LONG;
} }
%enddef %enddef