Menu

#1174 using swig to generate the python code with INPUT parameter

None
closed-invalid
nobody
python (260)
5
2022-03-20
2011-06-21
trum ken
No

I have a small with INPUT keyword in interface file . and then using the swig to generate the code C to python . And call python function to call C function .

But I has a issue :

xxxxx ....argument 1 of type 'char'

---------------------------

I don't know the reason .. Please help

Discussion

  • trum ken

    trum ken - 2011-06-21

    attachment sample

     
  • Olly Betts

    Olly Betts - 2022-03-20
    • status: open --> closed-invalid
    • Group: -->
     
  • Olly Betts

    Olly Betts - 2022-03-20

    I think you're just getting what you asked for (which isn't what you wanted):

    int insert(char *INPUT);

    This tells SWIG that insert takes a single char as input, and it's passed as a pointer to that single char.

    I assume what you're wanting is to tell SWIG the functions take a string and doesn't modified it - i.e. to effectively pretend the parameter is const char* not char *.

    Doing exactly that works, though gives a compiler warning:

    %module prov
    %{
    #include "prov.h"
    %}
    int insert(const char *);
    

    The better approach is to tell SWIG to apply the typemaps for const char* here:

    %module prov
    %{
    #include "prov.h"
    %}
    %apply const char * {char * s};
    %include "prov.h"
    

    Usage error rather than a bug, so closing.

     

Log in to post a comment.