How can I make Swig correctly wrap a char* buffer that is modified in C as a Java Something-or-other?

后端 未结 3 2003
春和景丽
春和景丽 2020-12-30 10:11

I am trying to wrap some legacy code for use in Java and I was quite happy to see that Swig was able to handle the header file and it generate a great wrapper that almost wo

3条回答
  •  庸人自扰
    2020-12-30 10:52

    Perhaps this part of the SWIG documentation is helpful:

    A common problem in some C programs is handling parameters passed as simple pointers or references. For example:

    void add(int x, int y, int *result) {
        *result = x + y;
    }
    

    [...]

    The typemaps.i library file will help in these situations. For example:

    %module example
    %include "typemaps.i"
    
    void add(int, int, int *OUTPUT);
    

    There's also a section on wrapping arrays.

    I'm sorry this isn't a ready-made, complete answer. SWIG is mind-bending at times.

提交回复
热议问题