twid
twid

Reputation: 6686

SWIG rename functions

I am using following code in an interface file to rename the global function free

%ignore free;
%rename(my_free) free;

But resultant header file I don't see any of free is renamed to my_free. Am I doing anything wrong here? The above lines are placed at top of the interface file means first and second line respectively. I saw this here.

Upvotes: 0

Views: 1930

Answers (1)

The example you showed seems to work exactly as you'd expect. For example given:

%module test

%ignore free;
%rename(my_free) free;

// Function declaration:
void free();
// Or use %include if you prefer

Running:

swig -Wall -java test.i

Generates test.java as:

public class test {
  public static void my_free() {
    testJNI.my_free();
  }
}

So it has been renamed as expected.

Actually the %ignore is entirely redundant here though, the %rename alone would be sufficient to achieve this result. The order is important though - the %rename supersedes the %ignore and both must be before the declaration of free is seen.

The official documentation is at swig.org, I'd tend to prefer that over other sites. (If you're using SWIG 2.0 there's a lot of extra features for renaming too and you can use %rename to ignore functions: %rename("$ignore") free;)

Upvotes: 1

Related Questions