kaby76
2017-07-01 13:24:35 UTC
I am using SWIG to wrap the CUDA Driver API in C to C#. I was wondering, is
it possible to define a typemap specific for a function, taking into account
the function name? If so, how?
I can match based on type, or type with the parameter name. E.g.,
%include "typemaps.i"
%module Cuda
%typemap(cstype) char * "string"
%typemap(cstype) char * foo "foo"
typedef int CUresult;
CUresult cuFunc1(char *name, int bar);
CUresult cuFunc2(char * foo);
CUresult cuFunc3(int hi, char * foo);
The first typemap matches cuFunc1. The second typemap refines the pattern
match of "char*" with the addition of the parameter name for additional
context, so it matches cuFunc2 and cuFunc3. But, suppose I'd like to refine
the typemaps further to distinguish between cuFunc2 and cuFunc3. Is this
possible?
I tried adjacent parameter typemaps
(http://www.swig.org/Doc3.0/Typemaps.html#Typemaps_multi_argument_typemaps)
as a further refinement of the pattern, but the documentation is scant, and
they don’t seem to work for me. (It only shows an example with "in"-type
typemaps, not "cstype", "ctype", "imtype", etc.) For example, adding the
additional typemap,
%typemap(cstype) (int hi, char * foo) "sadfasdf"
Produces
public static int cuFunc3(sadfasdf hi, foo) { ////// NOTE MISSING TYPE ON
SECOND PARAMETER, FOO.
int ret = CudaPINVOKE.cuFunc3(hi, foo);
return ret;
}
I cannot get rewrite the second parameter and on.
--
View this message in context: http://swig.10945.n7.nabble.com/Typemaps-with-function-name-tp15195.html
Sent from the swig-user mailing list archive at Nabble.com.
it possible to define a typemap specific for a function, taking into account
the function name? If so, how?
I can match based on type, or type with the parameter name. E.g.,
%include "typemaps.i"
%module Cuda
%typemap(cstype) char * "string"
%typemap(cstype) char * foo "foo"
typedef int CUresult;
CUresult cuFunc1(char *name, int bar);
CUresult cuFunc2(char * foo);
CUresult cuFunc3(int hi, char * foo);
The first typemap matches cuFunc1. The second typemap refines the pattern
match of "char*" with the addition of the parameter name for additional
context, so it matches cuFunc2 and cuFunc3. But, suppose I'd like to refine
the typemaps further to distinguish between cuFunc2 and cuFunc3. Is this
possible?
I tried adjacent parameter typemaps
(http://www.swig.org/Doc3.0/Typemaps.html#Typemaps_multi_argument_typemaps)
as a further refinement of the pattern, but the documentation is scant, and
they don’t seem to work for me. (It only shows an example with "in"-type
typemaps, not "cstype", "ctype", "imtype", etc.) For example, adding the
additional typemap,
%typemap(cstype) (int hi, char * foo) "sadfasdf"
Produces
public static int cuFunc3(sadfasdf hi, foo) { ////// NOTE MISSING TYPE ON
SECOND PARAMETER, FOO.
int ret = CudaPINVOKE.cuFunc3(hi, foo);
return ret;
}
I cannot get rewrite the second parameter and on.
--
View this message in context: http://swig.10945.n7.nabble.com/Typemaps-with-function-name-tp15195.html
Sent from the swig-user mailing list archive at Nabble.com.