diff options
author | William S Fulton <wsf@fultondesigns.co.uk> | 2022-10-28 21:53:42 +0100 |
---|---|---|
committer | William S Fulton <wsf@fultondesigns.co.uk> | 2022-11-05 08:40:26 +0000 |
commit | 973590ff915745ade6adf2ae6340db7bdcb94c5a (patch) | |
tree | 558e10da34aec8d2da711899047653079225d499 /Lib/r | |
parent | d6d83f4df4a76e98dfa872679c2466fc59fd9d5a (diff) | |
download | swig-973590ff915745ade6adf2ae6340db7bdcb94c5a.tar.gz |
R rtypecheck typemaps
Further switch to use rtypecheck typemaps instead of hard coded logic.
The full switch to typemaps is deferred until swig-4.2 as it can't be fully
backwards compatible. For now a warning is provided to help the
transition. It provides the full typemap that should be placed into
a user's interface file, for example:
%typemap("rtype") int32_t * "integer"
void testmethod(int32_t * i);
void testmethod();
If there is no rtypecheck typemap for int32_t *, the warning shown is:
example.i:7: Warning 750: Optional rtypecheck code is deprecated. Add the
following typemap to fix as the next version of SWIG will not work without it:
%typemap("rtypecheck") int32_t * %{ (is.integer($arg) || is.numeric($arg)) %}
The warning is shown for any code that previously used "numeric", "integer" or
"character" for the rtype typemap. Copying the rtypecheck typemap as
shown into the user interface file will provide the appropriate fix and
the warning will disappear. This is important to do as swig-4.2 will
not be able to provide this helpful warning.
Diffstat (limited to 'Lib/r')
-rw-r--r-- | Lib/r/rtype.swg | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/Lib/r/rtype.swg b/Lib/r/rtype.swg index a9c067589..c9d68bec8 100644 --- a/Lib/r/rtype.swg +++ b/Lib/r/rtype.swg @@ -3,6 +3,7 @@ for use in class representations. */ +%typemap("rtype") bool, bool * "logical" %typemap("rtype") int, int *, int & "integer" %typemap("rtype") long, long *, long & "integer" %typemap("rtype") float, float*, float & "numeric" @@ -11,7 +12,6 @@ %typemap("rtype") char "character" %typemap("rtype") string, string *, string & "character" %typemap("rtype") std::string, std::string *, std::string & "character" -%typemap("rtype") bool, bool * "logical" %typemap("rtype") enum SWIGTYPE "character" %typemap("rtype") enum SWIGTYPE * "character" %typemap("rtype") enum SWIGTYPE *const& "character" @@ -30,8 +30,7 @@ %typemap("rtypecheck") int *, long * %{ is.integer($arg) || is.numeric($arg) %} - -%typemap("rtypecheck") float, double +%typemap("rtypecheck") float, float &, double, double & %{ is.numeric($arg) && length($arg) == 1 %} %typemap("rtypecheck") float *, double * %{ is.numeric($arg) %} @@ -41,6 +40,41 @@ %typemap("rtypecheck") bool * %{ is.logical($arg) %} +%typemap("rtypecheck") char + %{ is.character($arg) && length($arg) == 1 %} +%typemap("rtypecheck") char *, char ** + %{ is.character($arg) %} + +%typemap("rtypecheck") string, string & + %{ is.character($arg) && length($arg) == 1 %} +%typemap("rtypecheck") string * + %{ is.character($arg) %} + +%typemap("rtypecheck") std::string, std::string & + %{ is.character($arg) && length($arg) == 1 %} +%typemap("rtypecheck") std::string * + %{ is.character($arg) %} + +%typemap("rtypecheck") enum SWIGTYPE, enum SWIGTYPE *const&, enum SWIGTYPE &, const enum SWIGTYPE &, enum SWIGTYPE && + %{ is.character($arg) && length($arg) == 1 %} +%typemap("rtypecheck") enum SWIGTYPE * + %{ is.character($arg) %} + +#if 0 +// Replacement rtypecheck typemaps (for swig-4.2, see r.cxx) +%typemap("rtypecheck") SWIGTYPE * + %{ extends($argtype, '$R_class') || is.null($arg) %} + +%typemap("rtypecheck") SWIGTYPE &, SWIGTYPE && + %{ extends($argtype, '$R_class') && length($arg) == 1 %} + +%typemap("rtypecheck") SWIGTYPE *const& + %{ extends($argtype, '$*R_class') && length($arg) == 1 %} + +%typemap("rtypecheck") SWIGTYPE + %{ extends($argtype, '$&R_class') && length($arg) == 1 %} +#endif + /* Set up type checks to insure overloading precedence. We would like non pointer items to shadow pointer items, so that |