Merge branch 'master' of github.com:swig/swig
# Conflicts: # CHANGES.current
This commit is contained in:
commit
6814f67cdb
6 changed files with 88 additions and 13 deletions
|
|
@ -7,11 +7,19 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
|
|||
Version 4.0.0 (in progress)
|
||||
===========================
|
||||
|
||||
2018-11-23: adr26
|
||||
2018-11-24: adr26
|
||||
[Python] #1360 Leak of SWIG var link object
|
||||
|
||||
Fix reference counting on _SWIG_globals to allow var link to be freed on module unload.
|
||||
|
||||
2018-11-24: vadz
|
||||
#1358 Fix handling of abstract base classes nested inside templates
|
||||
|
||||
Correct detecting of whether a derived class method overrides a pure virtual
|
||||
base class method when both classes are nested inside a template class: this
|
||||
notably didn't work correctly for methods taking parameters of the base class
|
||||
type.
|
||||
|
||||
2018-11-22: rupertnash
|
||||
[Python] #1282 Make generated module runnable via python -m (PEP 366 conforming)
|
||||
|
||||
|
|
|
|||
10
Examples/test-suite/csharp/nested_in_template_runme.cs
Normal file
10
Examples/test-suite/csharp/nested_in_template_runme.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
using System;
|
||||
using nested_in_templateNamespace;
|
||||
|
||||
public class runme {
|
||||
static void Main() {
|
||||
var cd = new OuterTemplate1.ConcreteDerived(8.8);
|
||||
if (cd.m_value != 8.8)
|
||||
throw new Exception("ConcreteDerived not created correctly");
|
||||
}
|
||||
}
|
||||
34
Examples/test-suite/nested_in_template.i
Normal file
34
Examples/test-suite/nested_in_template.i
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
%module nested_in_template
|
||||
|
||||
#if !defined(SWIGCSHARP) && !defined(SWIGJAVA)
|
||||
%feature("flatnested");
|
||||
#endif
|
||||
|
||||
%inline %{
|
||||
template <int>
|
||||
struct OuterTemplate;
|
||||
|
||||
template <>
|
||||
struct OuterTemplate<1>
|
||||
{
|
||||
struct AbstractBase
|
||||
{
|
||||
virtual bool IsSameAs(const AbstractBase& other) const = 0;
|
||||
virtual ~AbstractBase() {}
|
||||
};
|
||||
|
||||
struct ConcreteDerived : AbstractBase
|
||||
{
|
||||
ConcreteDerived() : m_value(0.) {}
|
||||
explicit ConcreteDerived(double value) : m_value(value) {}
|
||||
|
||||
virtual bool IsSameAs(const AbstractBase& other) const {
|
||||
return m_value == static_cast<const ConcreteDerived&>(other).m_value;
|
||||
}
|
||||
|
||||
double m_value;
|
||||
};
|
||||
};
|
||||
%}
|
||||
|
||||
%template(OuterTemplate1) OuterTemplate<1>;
|
||||
5
Examples/test-suite/python/nested_in_template_runme.py
Normal file
5
Examples/test-suite/python/nested_in_template_runme.py
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
from nested_in_template import *
|
||||
|
||||
cd = ConcreteDerived(8.8)
|
||||
if cd.m_value != 8.8:
|
||||
raise RuntimeError("ConcreteDerived not created correctly")
|
||||
|
|
@ -166,6 +166,11 @@ static Node *copy_node(Node *n) {
|
|||
Setattr(nn, "needs_defaultargs", "1");
|
||||
continue;
|
||||
}
|
||||
/* same for abstracts, which contains pointers to the source node children, and so will need to be patch too */
|
||||
if (strcmp(ckey,"abstracts") == 0) {
|
||||
SetFlag(nn, "needs_abstracts");
|
||||
continue;
|
||||
}
|
||||
/* Looks okay. Just copy the data using Copy */
|
||||
ci = Copy(k.item);
|
||||
Setattr(nn, key, ci);
|
||||
|
|
@ -788,6 +793,22 @@ static List *pure_abstracts(Node *n) {
|
|||
return abstracts;
|
||||
}
|
||||
|
||||
/* Recompute the "abstracts" attribute for the classes in instantiated templates, similarly to update_defaultargs() above. */
|
||||
static void update_abstracts(Node *n) {
|
||||
for (; n; n = nextSibling(n)) {
|
||||
Node* const child = firstChild(n);
|
||||
if (!child)
|
||||
continue;
|
||||
|
||||
update_abstracts(child);
|
||||
|
||||
if (Getattr(n, "needs_abstracts")) {
|
||||
Setattr(n, "abstracts", pure_abstracts(child));
|
||||
Delattr(n, "needs_abstracts");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Make a classname */
|
||||
|
||||
static String *make_class_name(String *name) {
|
||||
|
|
@ -3056,6 +3077,7 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va
|
|||
nn = Getattr(nn,"sym:nextSibling"); /* repeat for overloaded templated functions. If a templated class there will never be a sibling. */
|
||||
}
|
||||
update_defaultargs(linkliststart);
|
||||
update_abstracts(linkliststart);
|
||||
}
|
||||
Swig_symbol_setscope(tscope);
|
||||
Delete(Namespaceprefix);
|
||||
|
|
|
|||
|
|
@ -693,10 +693,6 @@ public:
|
|||
mod_docstring = NULL;
|
||||
}
|
||||
|
||||
Printv(default_import_code, "\nfrom sys import version_info as _swig_python_version_info\n", NULL);
|
||||
Printv(default_import_code, "if _swig_python_version_info < (2, 7, 0):\n", NULL);
|
||||
Printv(default_import_code, tab4, "raise RuntimeError('Python 2.7 or later required')\n", NULL);
|
||||
|
||||
/* Import the C-extension module. This should be a relative import,
|
||||
* since the shadow module may also have been imported by a relative
|
||||
* import, and there is thus no guarantee that the C-extension is on
|
||||
|
|
@ -748,10 +744,6 @@ public:
|
|||
Printf(default_import_code, tab4 "from %s import *\n", module);
|
||||
}
|
||||
|
||||
/* Delete the _swig_python_version_info symbol since we don't use it elsewhere in the
|
||||
* module. */
|
||||
Printv(default_import_code, "del _swig_python_version_info\n\n", NULL);
|
||||
|
||||
/* Need builtins to qualify names like Exception that might also be
|
||||
defined in this module (try both Python 3 and Python 2 names) */
|
||||
Printv(f_shadow, "try:\n", tab4, "import builtins as __builtin__\n", "except ImportError:\n", tab4, "import __builtin__\n", NULL);
|
||||
|
|
@ -910,13 +902,19 @@ public:
|
|||
Printv(f_shadow_py, "\n", f_shadow_begin, "\n", NIL);
|
||||
if (Len(f_shadow_after_begin) > 0)
|
||||
Printv(f_shadow_py, f_shadow_after_begin, "\n", NIL);
|
||||
|
||||
Printv(f_shadow_py, "\nfrom sys import version_info as _swig_python_version_info\n", NULL);
|
||||
Printv(f_shadow_py, "if _swig_python_version_info < (2, 7, 0):\n", NULL);
|
||||
Printv(f_shadow_py, tab4, "raise RuntimeError('Python 2.7 or later required')\n\n", NULL);
|
||||
|
||||
if (moduleimport) {
|
||||
Replaceall(moduleimport, "$module", module);
|
||||
Printv(f_shadow_py, "\n", moduleimport, "\n", NIL);
|
||||
Printv(f_shadow_py, moduleimport, "\n", NIL);
|
||||
} else {
|
||||
Printv(f_shadow_py, default_import_code, NIL);
|
||||
}
|
||||
Printv(f_shadow_py, f_shadow, "\n", NIL);
|
||||
|
||||
Printv(f_shadow_py, "\n", f_shadow, "\n", NIL);
|
||||
Printv(f_shadow_py, f_shadow_stubs, "\n", NIL);
|
||||
Delete(f_shadow_py);
|
||||
}
|
||||
|
|
@ -1123,14 +1121,12 @@ public:
|
|||
Printf(out, "import %s%s%s%s\n", apkg, *Char(apkg) ? "." : "", pfx, mod);
|
||||
Delete(apkg);
|
||||
} else {
|
||||
Printf(out, "from sys import version_info as _swig_python_version_info\n");
|
||||
Printf(out, "if _swig_python_version_info >= (2, 7, 0):\n");
|
||||
if (py3_rlen1)
|
||||
Printf(out, tab4 "from . import %.*s\n", py3_rlen1, rpkg);
|
||||
Printf(out, tab4 "from .%s import %s%s\n", rpkg, pfx, mod);
|
||||
Printf(out, "else:\n");
|
||||
Printf(out, tab4 "import %s%s%s%s\n", rpkg, *Char(rpkg) ? "." : "", pfx, mod);
|
||||
Printf(out, "del _swig_python_version_info\n");
|
||||
Delete(rpkg);
|
||||
}
|
||||
return out;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue