The kwargs feature no longer turns on compactdefaultargs for languages that don't support kwargs.
Affects all languages except Python and Ruby. Closes #242
This commit is contained in:
parent
b57a675d00
commit
bfde148887
14 changed files with 72 additions and 21 deletions
|
|
@ -5,6 +5,13 @@ See the RELEASENOTES file for a summary of changes in each release.
|
||||||
Version 3.0.3 (in progress)
|
Version 3.0.3 (in progress)
|
||||||
===========================
|
===========================
|
||||||
|
|
||||||
|
2014-10-21: wsfulton
|
||||||
|
Fix issue #242 - Use of the "kwargs" feature no longer automatically turns on the
|
||||||
|
"compactdefaultargs" feature if the target language does not support kwargs.
|
||||||
|
Only Java and Python support kwargs, so this affects all the other languages.
|
||||||
|
|
||||||
|
*** POTENTIAL INCOMPATIBILITY ***
|
||||||
|
|
||||||
2014-10-10: diorcety
|
2014-10-10: diorcety
|
||||||
[Python] Patch #232 Fix property access using directors
|
[Python] Patch #232 Fix property access using directors
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1191,8 +1191,10 @@ values have to be public).
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
This feature is automatically turned on when wrapping <a href="SWIG.html#SWIG_default_args">C code with default arguments</a>
|
The <tt>compactdefaultargs</tt> feature is automatically turned on when wrapping <a href="SWIG.html#SWIG_default_args">C code with default arguments</a>.
|
||||||
and whenever keyword arguments (kwargs) are specified for either C or C++ code.
|
Some target languages will also automatically turn on this feature
|
||||||
|
if the keyword arguments feature (kwargs) is specified for either C or C++ functions, and the target language supports kwargs,
|
||||||
|
the <tt>compactdefaultargs</tt> feature is also automatically turned on.
|
||||||
Keyword arguments are a language feature of some scripting languages, for example Ruby and Python.
|
Keyword arguments are a language feature of some scripting languages, for example Ruby and Python.
|
||||||
SWIG is unable to support kwargs when wrapping overloaded methods, so the default approach cannot be used.
|
SWIG is unable to support kwargs when wrapping overloaded methods, so the default approach cannot be used.
|
||||||
</p>
|
</p>
|
||||||
|
|
|
||||||
|
|
@ -249,6 +249,7 @@ CPP_TEST_CASES += \
|
||||||
insert_directive \
|
insert_directive \
|
||||||
keyword_rename \
|
keyword_rename \
|
||||||
kind \
|
kind \
|
||||||
|
kwargs_feature \
|
||||||
langobj \
|
langobj \
|
||||||
li_attribute \
|
li_attribute \
|
||||||
li_attribute_template \
|
li_attribute_template \
|
||||||
|
|
|
||||||
23
Examples/test-suite/java/kwargs_feature_runme.java
Normal file
23
Examples/test-suite/java/kwargs_feature_runme.java
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
import kwargs_feature.*;
|
||||||
|
|
||||||
|
public class kwargs_feature_runme {
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
System.loadLibrary("kwargs_feature");
|
||||||
|
} catch (UnsatisfiedLinkError e) {
|
||||||
|
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String argv[]) {
|
||||||
|
// Check normal overloading still works (no compactdefaultargs) if the kwargs feature is used,
|
||||||
|
// as the kwargs feature is not supported
|
||||||
|
Foo f = new Foo(99);
|
||||||
|
if (f.foo() != 1)
|
||||||
|
throw new RuntimeException("It went wrong");
|
||||||
|
if (Foo.statfoo(2) != 2)
|
||||||
|
throw new RuntimeException("It went wrong");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
%module kwargs_feature
|
%module kwargs_feature
|
||||||
|
|
||||||
%nocopyctor;
|
%nocopyctor;
|
||||||
%kwargs;
|
%feature("kwargs");
|
||||||
|
|
||||||
%rename(myDel) del;
|
%rename(myDel) del;
|
||||||
%inline
|
%inline
|
||||||
|
|
@ -35,9 +35,7 @@
|
||||||
|
|
||||||
virtual ~Foo() {
|
virtual ~Foo() {
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -64,8 +62,7 @@
|
||||||
|
|
||||||
// Functions
|
// Functions
|
||||||
%inline %{
|
%inline %{
|
||||||
int foo(int a = 1, int b = 0) {return a + b; }
|
int foo_fn(int a = 1, int b = 0) {return a + b; }
|
||||||
|
|
||||||
|
|
||||||
template<typename T> T templatedfunction(T a = 1, T b = 0) { return a + b; }
|
template<typename T> T templatedfunction(T a = 1, T b = 0) { return a + b; }
|
||||||
%}
|
%}
|
||||||
|
|
@ -73,10 +70,8 @@
|
||||||
%template(templatedfunction) templatedfunction<int>;
|
%template(templatedfunction) templatedfunction<int>;
|
||||||
|
|
||||||
|
|
||||||
// Deafult args with references
|
// Default args with references
|
||||||
%inline
|
%inline %{
|
||||||
%{
|
|
||||||
|
|
||||||
typedef int size_type;
|
typedef int size_type;
|
||||||
|
|
||||||
struct Hello
|
struct Hello
|
||||||
|
|
@ -84,13 +79,10 @@
|
||||||
static const size_type hello = 3;
|
static const size_type hello = 3;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int rfoo( const size_type& x = Hello::hello, const Hello& y = Hello() )
|
int rfoo( const size_type& x = Hello::hello, const Hello& y = Hello() )
|
||||||
{
|
{
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
%}
|
%}
|
||||||
%{
|
%{
|
||||||
const int Hello::hello;
|
const int Hello::hello;
|
||||||
|
|
@ -104,9 +96,7 @@
|
||||||
|
|
||||||
int foo_kw(int from = 1, int except = 2) {return from + except; }
|
int foo_kw(int from = 1, int except = 2) {return from + except; }
|
||||||
|
|
||||||
|
|
||||||
int foo_nu(int from = 1, int = 0) {return from; }
|
int foo_nu(int from = 1, int = 0) {return from; }
|
||||||
|
|
||||||
int foo_mm(int min = 1, int max = 2) {return min + max; }
|
int foo_mm(int min = 1, int max = 2) {return min + max; }
|
||||||
|
|
||||||
%}
|
%}
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,6 @@ CPP_TEST_CASES += \
|
||||||
inout \
|
inout \
|
||||||
inplaceadd \
|
inplaceadd \
|
||||||
input \
|
input \
|
||||||
kwargs_feature \
|
|
||||||
li_cstring \
|
li_cstring \
|
||||||
li_cwstring \
|
li_cwstring \
|
||||||
li_factory \
|
li_factory \
|
||||||
|
|
|
||||||
|
|
@ -44,10 +44,10 @@ if BarInt_sbar(b=2) != 3:
|
||||||
if templatedfunction(b=2) != 3:
|
if templatedfunction(b=2) != 3:
|
||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
|
|
||||||
if foo(a=1,b=2) != 3:
|
if foo_fn(a=1,b=2) != 3:
|
||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
|
|
||||||
if foo(b=2) != 3:
|
if foo_fn(b=2) != 3:
|
||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ top_srcdir = @top_srcdir@
|
||||||
top_builddir = @top_builddir@
|
top_builddir = @top_builddir@
|
||||||
|
|
||||||
CPP_TEST_CASES = \
|
CPP_TEST_CASES = \
|
||||||
kwargs_feature \
|
|
||||||
li_cdata \
|
li_cdata \
|
||||||
li_cstring \
|
li_cstring \
|
||||||
li_factory \
|
li_factory \
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,7 @@ static int compact_default_args = 0;
|
||||||
static int template_reduce = 0;
|
static int template_reduce = 0;
|
||||||
static int cparse_externc = 0;
|
static int cparse_externc = 0;
|
||||||
int ignore_nested_classes = 0;
|
int ignore_nested_classes = 0;
|
||||||
|
int kwargs_supported = 0;
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* Assist Functions
|
* Assist Functions
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
@ -1177,7 +1178,7 @@ static void default_arguments(Node *n) {
|
||||||
if (compact_default_args
|
if (compact_default_args
|
||||||
|| is_cfunction(function)
|
|| is_cfunction(function)
|
||||||
|| GetFlag(function,"feature:compactdefaultargs")
|
|| GetFlag(function,"feature:compactdefaultargs")
|
||||||
|| GetFlag(function,"feature:kwargs")) {
|
|| (GetFlag(function,"feature:kwargs") && kwargs_supported)) {
|
||||||
ParmList *p = Getattr(function,"parms");
|
ParmList *p = Getattr(function,"parms");
|
||||||
if (p)
|
if (p)
|
||||||
Setattr(p,"compactdefargs", "1"); /* mark parameters for special handling */
|
Setattr(p,"compactdefargs", "1"); /* mark parameters for special handling */
|
||||||
|
|
|
||||||
|
|
@ -3525,6 +3525,14 @@ Language::NestedClassSupport Language::nestedClassesSupport() const {
|
||||||
return NCS_Unknown;
|
return NCS_Unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* Language::kwargsSupport()
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
bool Language::kwargsSupport() const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* Language::is_wrapping_class()
|
* Language::is_wrapping_class()
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,7 @@ int SwigRuntime = 0; // 0 = no option, 1 = -runtime, 2 = -noruntime
|
||||||
extern "C" {
|
extern "C" {
|
||||||
extern String *ModuleName;
|
extern String *ModuleName;
|
||||||
extern int ignore_nested_classes;
|
extern int ignore_nested_classes;
|
||||||
|
extern int kwargs_supported;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* usage string split into multiple parts otherwise string is too big for some compilers */
|
/* usage string split into multiple parts otherwise string is too big for some compilers */
|
||||||
|
|
@ -904,6 +905,8 @@ int SWIG_main(int argc, char *argv[], Language *l) {
|
||||||
// Inform the parser if the nested classes should be ignored unless explicitly told otherwise via feature:flatnested
|
// Inform the parser if the nested classes should be ignored unless explicitly told otherwise via feature:flatnested
|
||||||
ignore_nested_classes = l->nestedClassesSupport() == Language::NCS_Unknown ? 1 : 0;
|
ignore_nested_classes = l->nestedClassesSupport() == Language::NCS_Unknown ? 1 : 0;
|
||||||
|
|
||||||
|
kwargs_supported = l->kwargsSupport() ? 1 : 0;
|
||||||
|
|
||||||
// Create Library search directories
|
// Create Library search directories
|
||||||
|
|
||||||
// Check for SWIG_LIB environment variable
|
// Check for SWIG_LIB environment variable
|
||||||
|
|
|
||||||
|
|
@ -4785,6 +4785,13 @@ public:
|
||||||
return NewString("swigpyrun.h");
|
return NewString("swigpyrun.h");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------
|
||||||
|
* kwargsSupport()
|
||||||
|
*--------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
bool kwargsSupport() const {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/* ---------------------------------------------------------------
|
/* ---------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -3426,6 +3426,14 @@ public:
|
||||||
String *defaultExternalRuntimeFilename() {
|
String *defaultExternalRuntimeFilename() {
|
||||||
return NewString("swigrubyrun.h");
|
return NewString("swigrubyrun.h");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------
|
||||||
|
* kwargsSupport()
|
||||||
|
*--------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
bool kwargsSupport() const {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}; /* class RUBY */
|
}; /* class RUBY */
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -315,6 +315,9 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual NestedClassSupport nestedClassesSupport() const;
|
virtual NestedClassSupport nestedClassesSupport() const;
|
||||||
|
|
||||||
|
/* Returns true if the target language supports key word arguments (kwargs) */
|
||||||
|
virtual bool kwargsSupport() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/* Identifies if a protected members that are generated when the allprotected option is used.
|
/* Identifies if a protected members that are generated when the allprotected option is used.
|
||||||
This does not include protected virtual methods as they are turned on with the dirprot option. */
|
This does not include protected virtual methods as they are turned on with the dirprot option. */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue