mirror of https://github.com/swig/swig
Fix seg fault using %template
Fix seg fault when instantiating templates with parameters that are function parameters containing templates, such as: %template(MyC) C<int(std::vector<int>)>; Closes #983
This commit is contained in:
parent
2fc0edc4fd
commit
b18b75369c
|
@ -7,6 +7,12 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
|
||||||
Version 4.2.0 (in progress)
|
Version 4.2.0 (in progress)
|
||||||
===========================
|
===========================
|
||||||
|
|
||||||
|
2023-01-03: wsfulton
|
||||||
|
#983 Fix seg fault when instantiating templates with parameters that are function
|
||||||
|
parameters containing templates, such as:
|
||||||
|
|
||||||
|
%template(MyC) C<int(std::vector<int>)>;
|
||||||
|
|
||||||
2023-01-03: wsfulton
|
2023-01-03: wsfulton
|
||||||
Complete support for C++11 variadic function templates. Support was previously limited
|
Complete support for C++11 variadic function templates. Support was previously limited
|
||||||
to just one template parameter. Now zero or more template parameters are supported
|
to just one template parameter. Now zero or more template parameters are supported
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
import template_function_parm.*;
|
||||||
|
|
||||||
|
public class template_function_parm_runme {
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
System.loadLibrary("template_function_parm");
|
||||||
|
} 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[]) {
|
||||||
|
VectorInt vi = new VectorInt();
|
||||||
|
vi.add(10);
|
||||||
|
vi.add(20);
|
||||||
|
vi.add(30);
|
||||||
|
|
||||||
|
MyC myc = new MyC();
|
||||||
|
int sum = myc.take_function(template_function_parmConstants.accumulate_integers, vi);
|
||||||
|
if (sum != 60)
|
||||||
|
throw new RuntimeException("Expected sum of 60, got " + sum);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
%module template_function_parm
|
||||||
|
|
||||||
|
%include <std_vector.i>
|
||||||
|
|
||||||
|
%{
|
||||||
|
#include <numeric>
|
||||||
|
static int accumulate_integers(std::vector<int> vi) {
|
||||||
|
int sum = std::accumulate(vi.begin(), vi.end(), 0);
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
||||||
|
%inline %{
|
||||||
|
template<typename A>
|
||||||
|
struct C {
|
||||||
|
int take_function(int fp(std::vector<int>), std::vector<int> v) {
|
||||||
|
return fp(v);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
%}
|
||||||
|
|
||||||
|
%constant int accumulate_integers(std::vector<int>);
|
||||||
|
|
||||||
|
%template(VectorInt) std::vector<int>;
|
||||||
|
|
||||||
|
// seg fault #983
|
||||||
|
%template(MyC) C<int(std::vector<int>)>;
|
||||||
|
|
|
@ -1746,7 +1746,7 @@ SwigType *Swig_symbol_typedef_reduce(const SwigType *ty, Symtab *tab) {
|
||||||
|
|
||||||
n = Swig_symbol_clookup(base, tab);
|
n = Swig_symbol_clookup(base, tab);
|
||||||
if (!n) {
|
if (!n) {
|
||||||
if (SwigType_istemplate(ty)) {
|
if (SwigType_istemplate(base)) {
|
||||||
SwigType *qt = Swig_symbol_template_reduce(base, tab);
|
SwigType *qt = Swig_symbol_template_reduce(base, tab);
|
||||||
Append(prefix, qt);
|
Append(prefix, qt);
|
||||||
Delete(qt);
|
Delete(qt);
|
||||||
|
|
Loading…
Reference in New Issue