Fix regression introduced in r12784 where SWIG accepts a non standard constructor and destructor name in %extend, where the typedef name is used as the constructor/destructor name.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12801 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
2fd6b5367d
commit
a141af9574
4 changed files with 178 additions and 16 deletions
|
|
@ -195,6 +195,7 @@ CPP_TEST_CASES += \
|
|||
evil_diamond_prop \
|
||||
exception_order \
|
||||
extend \
|
||||
extend_constructor_destructor \
|
||||
extend_default \
|
||||
extend_placement \
|
||||
extend_template \
|
||||
|
|
|
|||
105
Examples/test-suite/extend_constructor_destructor.i
Normal file
105
Examples/test-suite/extend_constructor_destructor.i
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
%module extend_constructor_destructor
|
||||
|
||||
%inline %{
|
||||
int global = 0;
|
||||
|
||||
namespace Space {
|
||||
typedef struct tagAStruct {
|
||||
int ivar;
|
||||
} AStruct;
|
||||
|
||||
struct BStruct {
|
||||
int ivar;
|
||||
};
|
||||
|
||||
typedef struct tagCStruct {
|
||||
int ivar;
|
||||
} CStruct;
|
||||
|
||||
// Unnamed struct
|
||||
typedef struct {
|
||||
int ivar;
|
||||
} DStruct;
|
||||
}
|
||||
|
||||
typedef struct tagEStruct {
|
||||
int ivar;
|
||||
} EStruct;
|
||||
|
||||
%}
|
||||
|
||||
%extend Junk {
|
||||
void thingy() {}
|
||||
}
|
||||
%inline %{
|
||||
struct Junk {};
|
||||
%}
|
||||
namespace Space {
|
||||
|
||||
%extend tagAStruct {
|
||||
tagAStruct(int ivar0) {
|
||||
Space::AStruct *s = new Space::AStruct();
|
||||
s->ivar = ivar0;
|
||||
global = ivar0;
|
||||
return s;
|
||||
}
|
||||
~tagAStruct() {
|
||||
global = -$self->ivar;
|
||||
delete $self;
|
||||
}
|
||||
}
|
||||
|
||||
%extend BStruct {
|
||||
BStruct(int ivar0) {
|
||||
Space::BStruct *s = new Space::BStruct();
|
||||
s->ivar = ivar0;
|
||||
global = ivar0;
|
||||
return s;
|
||||
}
|
||||
~BStruct() {
|
||||
global = -$self->ivar;
|
||||
delete $self;
|
||||
}
|
||||
}
|
||||
|
||||
%extend CStruct {
|
||||
CStruct(int ivar0) {
|
||||
Space::CStruct *s = new Space::CStruct();
|
||||
s->ivar = ivar0;
|
||||
global = ivar0;
|
||||
return s;
|
||||
}
|
||||
~CStruct() {
|
||||
global = -$self->ivar;
|
||||
delete $self;
|
||||
}
|
||||
}
|
||||
|
||||
%extend DStruct {
|
||||
DStruct(int ivar0) {
|
||||
Space::DStruct *s = new Space::DStruct();
|
||||
s->ivar = ivar0;
|
||||
global = ivar0;
|
||||
return s;
|
||||
}
|
||||
~DStruct() {
|
||||
global = -$self->ivar;
|
||||
delete $self;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
%extend EStruct {
|
||||
EStruct(int ivar0) {
|
||||
EStruct *s = new EStruct();
|
||||
s->ivar = ivar0;
|
||||
global = ivar0;
|
||||
return s;
|
||||
}
|
||||
~EStruct() {
|
||||
global = -$self->ivar;
|
||||
delete $self;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
import extend_constructor_destructor.*;
|
||||
|
||||
public class extend_constructor_destructor_runme {
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("extend_constructor_destructor");
|
||||
} 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[]) {
|
||||
AStruct a = new AStruct(10);
|
||||
checkGlobal(10);
|
||||
BStruct b = new BStruct(20);
|
||||
checkGlobal(20);
|
||||
CStruct c = new CStruct(30);
|
||||
checkGlobal(30);
|
||||
DStruct d = new DStruct(40);
|
||||
checkGlobal(40);
|
||||
|
||||
a.delete();
|
||||
checkGlobal(-10);
|
||||
b.delete();
|
||||
checkGlobal(-20);
|
||||
c.delete();
|
||||
checkGlobal(-30);
|
||||
d.delete();
|
||||
checkGlobal(-40);
|
||||
}
|
||||
|
||||
public static void checkGlobal(int val) {
|
||||
int global = extend_constructor_destructor.getGlobal();
|
||||
if (global != val)
|
||||
throw new RuntimeException("global value incorrect. Expected: " + val + " got: " + global);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue