Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#80 %rename global function and class method independently

None
wont-fix
nobody
None
5
2013-12-12
2011-01-31
Paul Colby
No

See feature request 3168551 (https://sourceforge.net/tracker/?func=detail&aid=3168551&group_id=1645&atid=351645) for the motivation behind this feature request.

It would be great if SWIG would allow renaming of a method's global wrapper function, while still preserving the original method name in the PHP class wrapper.

Consider for example:

%module example

%{
class session {
public:
void commit() { };
};
%}

class session {
public:
void commit() { };
};

As mentioned in feature request 3168551 (https://sourceforge.net/tracker/?func=detail&aid=3168551&group_id=1645&atid=351645), the resulting PHP module will attempt to register a global function called "session_commit", which breaks PHP.

So, if we add a simple %rename to fix that:

%rename(_commit_) commit();

Then in php, we will need to call session__commit_(), which is fair enough.

However, if we then include the SWIG-generated example.php class wrapper, we are still forced to use the new _commit_ name like:

<?php
$session = new session();
$session->_commit_();
?>

Since, in this example, we've only renamed the session::commit method to avoid a clash in PHP's global function namespace, it would be nice if I could still do this:

<?php
$session = new session();
$session->commit(); // Wrapper calls the renamed session__commit_ global function.
?>

Of course its relatively easy to modify the resulting example.php by hand (or sed) to use a different method name, but it would be nice if SWIG could provide a feature to do it automatically :)

Discussion

  • Olly Betts
    Olly Betts
    2013-12-12

    • status: open --> wont-fix
    • Group: -->
     
  • Olly Betts
    Olly Betts
    2013-12-12

    I don't think it makes sense to add a feature like this. We should just address #79 directly, e.g. by generating names which won't clash with PHP functions (e.g. prefix with swig_).

    These functions are really an implementation detail if you're generating class wrappers around them. And if you aren't generating class wrappers, then you can rename them as you see fit using %rename.