Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buggy %rename behavior with templates and builtins #845

Closed
sethrj opened this issue Dec 4, 2016 · 1 comment
Closed

Buggy %rename behavior with templates and builtins #845

sethrj opened this issue Dec 4, 2016 · 1 comment

Comments

@sethrj
Copy link
Contributor

sethrj commented Dec 4, 2016

[This example uses Python but applies to other languages with built-in keywords.]

There are a couple (probably related) issues here.

  • A warning is issued for only templated classes when a built-in type is used, even though it has an %ignore directive
  • A warning is issued for only templated classes when a built-in type is used, even though it's renamed with a %rename directive
  • If a built-in type is renamed, the %rename is ignored unless it's applied to a specific template-instantiated class.

Consider the following example with a templated and non-templated class, both with the same keywordy function names:

%module test

// Templated
%ignore Foo::def;
%rename(printme) Foo::print;
%rename(lambduh) Foo<double>::lambda;
%rename(do_whatever) Foo::do_something;

// Non-templated
%ignore Bar::def;
%rename(printme) Bar::print;
%rename(lambduh) Bar::lambda;
%rename(do_whatever) Bar::do_something;

%inline %{
template<class T>
class Foo
{
  public:
    void def();
    void print();
    void lambda();
    void do_something();
};

class Bar
{
  public:
    void def();
    void print();
    void lambda();
    void do_something();
};

%}

%template(FooDouble) Foo<double>;

This produces warnings only for the templated class:

$ swig -c++ -python foo.i
foo.i:22: Warning 314: 'lambda' is a python keyword, renaming to '_lambda'
foo.i:20: Warning 314: 'def' is a python keyword, renaming to '_def'
foo.i:21: Warning 314: 'print' is a python keyword, renaming to '_print'

and even weirder, it ignores the %rename directive only for the templated class with the non-instantiated %rename, producing the following wrapper code:

class Bar(_object):
    def printme(self): ...
    def lambduh(self): ...
    def do_whatever(self): ...
    def __init__(self): ...

class FooDouble(_object):
    def _print(self): ...
    def lambduh(self): ...
    def do_whatever(self): ...
    def __init__(self): ...

Expected behavior is to have no warnings, and to have the _print in FooDouble actually renamed to printme.

@wsfulton
Copy link
Member

This is related to a fix I happen to put in a recently, see 7268f58. Now FooDouble does have a correctly renamed printme method. The only remaining warning is:

example.i:22: Warning 314: 'lambda' is a python keyword, renaming to '_lambda'

The fix was for %ignore, but does not seem to cover the %namewarn case. If you run with swig -E you can see the macros in pythonkw.swg boil down to using %namewarn:

 %namewarn("314"":""'" "lambda" "' is a python keyword, renaming to '_" "lambda" "'",rename="_%s")  "lambda";

and in parser.y, Swig_name_namewarn_add is called instead of Swig_name_rename_add, so there is a bit more to do in naming.c.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants