Merge master and C++11 strongly typed enum support
Merging from master: * 'master' of github.com:/swig/swig: Add more docs about _global_ prefix in typemap temporary variables Add clarification on _global_ prefix. fix for nested template defined out of class (issue #265) using an unknown constant emits a notice, not a warning Fix typo Consistently put whitespace outside of <tt>...</tt> and not inside wording tweak Go: Document memory management of C++ classes allocated in Go. Fixes #266. revert unrelated file Fix #224 Fixes for clang -fsanitize=undefined-trap -fsanitize-undefined-trap-on-error delete unmeaningful macro Go: fix overload functions with polymorphic issue del tmp files GoLang:fix overload functions with polymorphic issue
This commit is contained in:
commit
b9b9b3cd21
18 changed files with 157 additions and 42 deletions
|
|
@ -854,6 +854,7 @@
|
||||||
<li><a href="Go.html#Go_enumerations">Go Enumerations</a>
|
<li><a href="Go.html#Go_enumerations">Go Enumerations</a>
|
||||||
<li><a href="Go.html#Go_classes">Go Classes</a>
|
<li><a href="Go.html#Go_classes">Go Classes</a>
|
||||||
<ul>
|
<ul>
|
||||||
|
<li><a href="Go.html#Go_class_memory">Go Class Memory Management</a>
|
||||||
<li><a href="Go.html#Go_class_inheritance">Go Class Inheritance</a>
|
<li><a href="Go.html#Go_class_inheritance">Go Class Inheritance</a>
|
||||||
</ul>
|
</ul>
|
||||||
<li><a href="Go.html#Go_templates">Go Templates</a>
|
<li><a href="Go.html#Go_templates">Go Templates</a>
|
||||||
|
|
|
||||||
|
|
@ -547,7 +547,7 @@ Below shows the expansions for the 1st of the overloaded <tt>something</tt> wrap
|
||||||
The <tt>exception.i</tt> library file provides support for creating
|
The <tt>exception.i</tt> library file provides support for creating
|
||||||
language independent exceptions in your interfaces. To use it, simply
|
language independent exceptions in your interfaces. To use it, simply
|
||||||
put an "<tt>%include exception.i</tt>" in your interface file. This
|
put an "<tt>%include exception.i</tt>" in your interface file. This
|
||||||
creates a function<tt> SWIG_exception()</tt> that can be used to raise
|
provides a function <tt>SWIG_exception()</tt> that can be used to raise
|
||||||
common scripting language exceptions in a portable manner. For example :</p>
|
common scripting language exceptions in a portable manner. For example :</p>
|
||||||
|
|
||||||
<div class="code"><pre>
|
<div class="code"><pre>
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@
|
||||||
<li><a href="#Go_enumerations">Go Enumerations</a>
|
<li><a href="#Go_enumerations">Go Enumerations</a>
|
||||||
<li><a href="#Go_classes">Go Classes</a>
|
<li><a href="#Go_classes">Go Classes</a>
|
||||||
<ul>
|
<ul>
|
||||||
|
<li><a href="#Go_class_memory">Go Class Memory Management</a>
|
||||||
<li><a href="#Go_class_inheritance">Go Class Inheritance</a>
|
<li><a href="#Go_class_inheritance">Go Class Inheritance</a>
|
||||||
</ul>
|
</ul>
|
||||||
<li><a href="#Go_templates">Go Templates</a>
|
<li><a href="#Go_templates">Go Templates</a>
|
||||||
|
|
@ -375,7 +376,40 @@ returns a go interface. If the returned pointer can be null, you can check
|
||||||
for this by calling the Swigcptr() method.
|
for this by calling the Swigcptr() method.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<H4><a name="Go_class_inheritance"></a>23.3.5.1 Go Class Inheritance</H4>
|
<H4><a name="Go_class_memory"></a>23.3.5.1 Go Class Memory Management</H4>
|
||||||
|
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Calling <tt>NewClassName</tt> for some C++ class <tt>ClassName</tt>
|
||||||
|
will allocate memory using the C++ memory allocator. This memory will
|
||||||
|
not be automatically freed by Go's garbage collector. When you are
|
||||||
|
done with the C++ object you must free it using <tt>DeleteClassName</tt>.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
A common technique is to store the C++ object into a Go object, and
|
||||||
|
use the Go function <tt>runtime.SetFinalizer</tt> to free the C++
|
||||||
|
object when the Go object is freed. For example, if the SWIG package
|
||||||
|
is imported as "wrap":
|
||||||
|
</p>
|
||||||
|
<div class="code">
|
||||||
|
<pre>
|
||||||
|
type GoClassName struct {
|
||||||
|
w wrap.ClassName
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewGoClassName() *GoClassName {
|
||||||
|
r := &GoClassName{wrap.NewClassName()}
|
||||||
|
runtime.SetFinalizer(r,
|
||||||
|
func(r *GoClassName) {
|
||||||
|
wrap.DeleteClassName(r.w)
|
||||||
|
})
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<H4><a name="Go_class_inheritance"></a>23.3.5.2 Go Class Inheritance</H4>
|
||||||
|
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
|
|
||||||
|
|
@ -136,14 +136,14 @@ least work for Linux though):
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div class="code"><pre>
|
<div class="code"><pre>
|
||||||
gcc `php-config --includes` -fpic -c example_wrap.c
|
gcc `php-config --includes` -fpic -c example_wrap.c example.c
|
||||||
gcc -shared example_wrap.o -o example.so
|
gcc -shared example_wrap.o example.o -o example.so
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<H3><a name="Php_nn1_3"></a>34.1.2 Using PHP Extensions</H3>
|
<H3><a name="Php_nn1_3"></a>34.1.2 Using PHP Extensions</H3>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
To test the extension from a PHP script, you first need to load tell PHP to
|
To test the extension from a PHP script, you first need to tell PHP to
|
||||||
load it. To do this, add a line like this to the <tt>[PHP]</tt> section of
|
load it. To do this, add a line like this to the <tt>[PHP]</tt> section of
|
||||||
<tt>php.ini</tt>:
|
<tt>php.ini</tt>:
|
||||||
</p>
|
</p>
|
||||||
|
|
@ -235,9 +235,9 @@ echo "E = " . E . "\n";
|
||||||
<p>
|
<p>
|
||||||
There's one peculiarity of how constants work in PHP which it is useful
|
There's one peculiarity of how constants work in PHP which it is useful
|
||||||
to note (this is not specific to SWIG though) - if you try to use an undeclared
|
to note (this is not specific to SWIG though) - if you try to use an undeclared
|
||||||
constant, PHP will issue a warning and then expand the constant to a string
|
constant, PHP will emit a notice and then expand the constant to a string
|
||||||
version of the constant's name. The warning will often be missed though as
|
version of the constant's name. Unfortunately it is easy to miss the notice
|
||||||
if you're using PHP in a webserver, it will probably end up in error.log or
|
if you're using PHP in a webserver, as it will probably end up in error.log or
|
||||||
similar.
|
similar.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1380,8 +1380,8 @@ values they point at, while the non-const iterators can both read and
|
||||||
modify the values.</p>
|
modify the values.</p>
|
||||||
|
|
||||||
<p>The Ruby STL wrappings support both type of iterators by using
|
<p>The Ruby STL wrappings support both type of iterators by using
|
||||||
a proxy class in-between. This proxy class is <tt>swig::Iterator or
|
a proxy class in-between. This proxy class is <tt>swig::Iterator</tt> or
|
||||||
swig::ConstIterator. </tt> Derived from them are template
|
<tt>swig::ConstIterator</tt>. Derived from them are template
|
||||||
classes that need to be initialized with the actual iterator for the
|
classes that need to be initialized with the actual iterator for the
|
||||||
container you are wrapping and often times with the beginning and
|
container you are wrapping and often times with the beginning and
|
||||||
ending points of the iteration range.</p>
|
ending points of the iteration range.</p>
|
||||||
|
|
|
||||||
|
|
@ -2050,6 +2050,22 @@ wrap_foo() {
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<p>There is an exception: if the variable name starts with the <tt>_global_</tt> prefix,
|
||||||
|
the argument number is not appended. Such variables can be used throughout the generated
|
||||||
|
wrapper function. For example, the above typemap could be rewritten to use <tt>_global_temp</tt>
|
||||||
|
instead of <tt>temp</tt> and the generated code would then contain a single <tt>_global_temp</tt> variable
|
||||||
|
instead of <tt>temp1</tt>, <tt>temp2</tt> and <tt>temp3</tt>:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div class="code">
|
||||||
|
<pre>
|
||||||
|
%typemap(in) std::string * <b>(std::string _global_temp)</b> {
|
||||||
|
... as above ...
|
||||||
|
}
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Some typemaps do not recognize local variables (or they may simply not
|
Some typemaps do not recognize local variables (or they may simply not
|
||||||
apply). At this time, only typemaps that apply to argument conversion support this (input typemaps such as the "in" typemap).
|
apply). At this time, only typemaps that apply to argument conversion support this (input typemaps such as the "in" typemap).
|
||||||
|
|
|
||||||
|
|
@ -311,6 +311,7 @@ CPP_TEST_CASES += \
|
||||||
overload_extend \
|
overload_extend \
|
||||||
overload_method \
|
overload_method \
|
||||||
overload_numeric \
|
overload_numeric \
|
||||||
|
overload_polymorphic \
|
||||||
overload_rename \
|
overload_rename \
|
||||||
overload_return_type \
|
overload_return_type \
|
||||||
overload_simple \
|
overload_simple \
|
||||||
|
|
|
||||||
11
Examples/test-suite/go/overload_polymorphic_runme.go
Normal file
11
Examples/test-suite/go/overload_polymorphic_runme.go
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import "./overload_polymorphic"
|
||||||
|
|
||||||
|
func main(){
|
||||||
|
t := overload_polymorphic.NewDerived()
|
||||||
|
|
||||||
|
if overload_polymorphic.Test(t) != 0 {
|
||||||
|
panic("failed")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -31,10 +31,34 @@ namespace ns {
|
||||||
struct Nested1;
|
struct Nested1;
|
||||||
public:
|
public:
|
||||||
struct Nested2;
|
struct Nested2;
|
||||||
|
template <class T> class Abstract;
|
||||||
|
class Real;
|
||||||
};
|
};
|
||||||
struct Outer1::Nested2 {
|
struct Outer1::Nested2 {
|
||||||
int data;
|
int data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class Class {
|
||||||
|
public:
|
||||||
|
template <class T> class Abstract;
|
||||||
|
class Real;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T> class Class::Abstract {
|
||||||
|
public:
|
||||||
|
virtual void Method() = 0;
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
%}
|
||||||
|
#ifndef __clang__
|
||||||
|
%template(abstract_int) Class::Abstract <int>;
|
||||||
|
#endif
|
||||||
|
%inline %{
|
||||||
|
#ifndef __clang__
|
||||||
|
class Class::Real : public Abstract <int> {
|
||||||
|
public:
|
||||||
|
virtual void Method() {}
|
||||||
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
%}
|
%}
|
||||||
|
|
|
||||||
22
Examples/test-suite/overload_polymorphic.i
Normal file
22
Examples/test-suite/overload_polymorphic.i
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
%module overload_polymorphic
|
||||||
|
|
||||||
|
%inline %{
|
||||||
|
|
||||||
|
class Base {
|
||||||
|
public:
|
||||||
|
Base(){}
|
||||||
|
virtual ~Base(){}
|
||||||
|
};
|
||||||
|
|
||||||
|
class Derived : public Base {
|
||||||
|
public:
|
||||||
|
Derived(){}
|
||||||
|
virtual ~Derived(){}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int test(Base* base){ return 0;}
|
||||||
|
int test(int hello){ return 1; }
|
||||||
|
|
||||||
|
%}
|
||||||
|
|
@ -2504,6 +2504,7 @@ types_directive : TYPES LPAREN parms RPAREN stringbracesemi {
|
||||||
template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN valparms GREATERTHAN SEMI {
|
template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN valparms GREATERTHAN SEMI {
|
||||||
Parm *p, *tp;
|
Parm *p, *tp;
|
||||||
Node *n;
|
Node *n;
|
||||||
|
Node *outer_class = currentOuterClass;
|
||||||
Symtab *tscope = 0;
|
Symtab *tscope = 0;
|
||||||
int specialized = 0;
|
int specialized = 0;
|
||||||
int variadic = 0;
|
int variadic = 0;
|
||||||
|
|
@ -2516,6 +2517,9 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va
|
||||||
if (!inclass) {
|
if (!inclass) {
|
||||||
$5 = resolve_create_node_scope($5);
|
$5 = resolve_create_node_scope($5);
|
||||||
}
|
}
|
||||||
|
if (nscope_inner && Strcmp(nodeType(nscope_inner), "class") == 0) {
|
||||||
|
outer_class = nscope_inner;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
We use the new namespace entry 'nscope' only to
|
We use the new namespace entry 'nscope' only to
|
||||||
|
|
@ -2648,7 +2652,7 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va
|
||||||
Setattr(templnode,"sym:typename","1");
|
Setattr(templnode,"sym:typename","1");
|
||||||
}
|
}
|
||||||
/* for now, nested %template is allowed only in the same scope as the template declaration */
|
/* for now, nested %template is allowed only in the same scope as the template declaration */
|
||||||
if ($3 && !(nnisclass && ((currentOuterClass && (currentOuterClass != Getattr(nn, "nested:outer")))
|
if ($3 && !(nnisclass && ((outer_class && (outer_class != Getattr(nn, "nested:outer")))
|
||||||
||(extendmode && current_class && (current_class != Getattr(nn, "nested:outer")))))) {
|
||(extendmode && current_class && (current_class != Getattr(nn, "nested:outer")))))) {
|
||||||
/*
|
/*
|
||||||
Comment this out for 1.3.28. We need to
|
Comment this out for 1.3.28. We need to
|
||||||
|
|
@ -2677,9 +2681,9 @@ template_directive: SWIGTEMPLATE LPAREN idstringopt RPAREN idcolonnt LESSTHAN va
|
||||||
Setfile(templnode,cparse_file);
|
Setfile(templnode,cparse_file);
|
||||||
Setline(templnode,cparse_line);
|
Setline(templnode,cparse_line);
|
||||||
Delete(temparms);
|
Delete(temparms);
|
||||||
if (currentOuterClass) {
|
if (outer_class && nnisclass) {
|
||||||
SetFlag(templnode, "nested");
|
SetFlag(templnode, "nested");
|
||||||
Setattr(templnode, "nested:outer", currentOuterClass);
|
Setattr(templnode, "nested:outer", outer_class);
|
||||||
}
|
}
|
||||||
add_symbols_copy(templnode);
|
add_symbols_copy(templnode);
|
||||||
|
|
||||||
|
|
@ -4017,7 +4021,9 @@ cpp_template_decl : TEMPLATE LESSTHAN template_parms GREATERTHAN {
|
||||||
Swig_symbol_setscope(cscope);
|
Swig_symbol_setscope(cscope);
|
||||||
Delete(Namespaceprefix);
|
Delete(Namespaceprefix);
|
||||||
Namespaceprefix = Swig_symbol_qualifiedscopename(0);
|
Namespaceprefix = Swig_symbol_qualifiedscopename(0);
|
||||||
if (error) $$ = 0;
|
if (error || (nscope_inner && Strcmp(nodeType(nscope_inner), "class") == 0)) {
|
||||||
|
$$ = 0;
|
||||||
|
}
|
||||||
if (currentOuterClass)
|
if (currentOuterClass)
|
||||||
template_parameters = Getattr(currentOuterClass, "template_parameters");
|
template_parameters = Getattr(currentOuterClass, "template_parameters");
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -181,10 +181,10 @@ static int String_hash(DOH *so) {
|
||||||
return s->hashkey;
|
return s->hashkey;
|
||||||
} else {
|
} else {
|
||||||
register char *c = s->str;
|
register char *c = s->str;
|
||||||
register int len = s->len > 50 ? 50 : s->len;
|
register unsigned int len = s->len > 50 ? 50 : s->len;
|
||||||
register int h = 0;
|
register unsigned int h = 0;
|
||||||
register int mlen = len >> 2;
|
register unsigned int mlen = len >> 2;
|
||||||
register int i = mlen;
|
register unsigned int i = mlen;
|
||||||
for (; i; --i) {
|
for (; i; --i) {
|
||||||
h = (h << 5) + *(c++);
|
h = (h << 5) + *(c++);
|
||||||
h = (h << 5) + *(c++);
|
h = (h << 5) + *(c++);
|
||||||
|
|
@ -195,7 +195,7 @@ static int String_hash(DOH *so) {
|
||||||
h = (h << 5) + *(c++);
|
h = (h << 5) + *(c++);
|
||||||
}
|
}
|
||||||
h &= 0x7fffffff;
|
h &= 0x7fffffff;
|
||||||
s->hashkey = h;
|
s->hashkey = (int)h;
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4427,7 +4427,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
fn = i + 1;
|
fn = i + 1;
|
||||||
Printf(f_go_wrappers, "\t\tif _, ok := a[%d].(%s); !ok {\n", j, tm);
|
Printf(f_go_wrappers, "\t\tif _, ok := a[%d].(%s); !ok {\n", j, goType(pj, Getattr(pj, "type")));
|
||||||
Printf(f_go_wrappers, "\t\t\tgoto check_%d\n", fn);
|
Printf(f_go_wrappers, "\t\t\tgoto check_%d\n", fn);
|
||||||
Printv(f_go_wrappers, "\t\t}\n", NULL);
|
Printv(f_go_wrappers, "\t\t}\n", NULL);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue