Removing some memory leak problems when handling exceptions.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@10713 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
96a52c763c
commit
7e23a5a55e
10 changed files with 336 additions and 39 deletions
|
|
@ -1,3 +1,4 @@
|
|||
# see top-level Makefile.in
|
||||
class
|
||||
simple
|
||||
exception
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ TARGET = example
|
|||
INTERFACE = example.i
|
||||
RUNME = runme.c
|
||||
PROXY = example_proxy.c
|
||||
MEMTOOL = valgrind --leak-check=full
|
||||
|
||||
all::
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
|
|
@ -15,7 +16,14 @@ run:
|
|||
TARGET='$(TARGET)' c_compile
|
||||
env LD_LIBRARY_PATH=. ./runme
|
||||
|
||||
memchk:
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' CXXFLAGS='-g' c_cpp
|
||||
$(MAKE) -f $(TOP)/Makefile RUNME='$(RUNME)' PROXY='$(PROXY)' \
|
||||
TARGET='$(TARGET)' CFLAGS='-g' c_compile
|
||||
env LD_LIBRARY_PATH=. $(MEMTOOL) ./runme
|
||||
|
||||
clean:
|
||||
rm -f *.o *.out *.so *.a *.dll *.exe *_wrap* *_proxy* *~
|
||||
rm -f *.o *.out *.so *.a *.dll *.exe *_wrap* *_proxy* *~ runme
|
||||
|
||||
check: all
|
||||
|
|
|
|||
29
Examples/c/exception/Makefile
Normal file
29
Examples/c/exception/Makefile
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../preinst-swig -debug-module 4 > tree.txt
|
||||
CXXSRCS = example.cxx
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
RUNME = runme.c
|
||||
PROXY = example_proxy.c
|
||||
MEMTOOL = valgrind --leak-check=full
|
||||
|
||||
all::
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' c_cpp
|
||||
|
||||
run:
|
||||
$(MAKE) -f $(TOP)/Makefile RUNME='$(RUNME)' PROXY='$(PROXY)' \
|
||||
TARGET='$(TARGET)' c_compile
|
||||
env LD_LIBRARY_PATH=. ./runme
|
||||
|
||||
memchk:
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' CXXFLAGS='-g' c_cpp
|
||||
$(MAKE) -f $(TOP)/Makefile RUNME='$(RUNME)' PROXY='$(PROXY)' \
|
||||
TARGET='$(TARGET)' CFLAGS='-g' c_compile
|
||||
env LD_LIBRARY_PATH=. $(MEMTOOL) ./runme
|
||||
|
||||
clean:
|
||||
rm -f *.o *.out *.so *.a *.dll *.exe *_wrap* *_proxy* *~ runme
|
||||
|
||||
check: all
|
||||
0
Examples/c/exception/example.cxx
Normal file
0
Examples/c/exception/example.cxx
Normal file
52
Examples/c/exception/example.h
Normal file
52
Examples/c/exception/example.h
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
/* File : example.h */
|
||||
|
||||
#ifndef SWIG
|
||||
struct A {
|
||||
};
|
||||
#endif
|
||||
|
||||
class Exc {
|
||||
public:
|
||||
Exc(int c, const char *m) {
|
||||
code = c;
|
||||
strncpy(msg,m,256);
|
||||
}
|
||||
int code;
|
||||
char msg[256];
|
||||
};
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
|
||||
#endif
|
||||
|
||||
class Test {
|
||||
public:
|
||||
int simple() throw(int&) {
|
||||
throw(37);
|
||||
return 1;
|
||||
}
|
||||
int message() throw(const char *) {
|
||||
throw("I died.");
|
||||
return 1;
|
||||
}
|
||||
int hosed() throw(Exc) {
|
||||
throw(Exc(42,"Hosed"));
|
||||
return 1;
|
||||
}
|
||||
int unknown() throw(A*) {
|
||||
static A a;
|
||||
throw &a;
|
||||
return 1;
|
||||
}
|
||||
int multi(int x) throw(int, const char *, Exc) {
|
||||
if (x == 1) throw(37);
|
||||
if (x == 2) throw("Bleah!");
|
||||
if (x == 3) throw(Exc(42,"No-go-diggy-die"));
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(default: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
|
||||
#endif
|
||||
|
||||
10
Examples/c/exception/example.i
Normal file
10
Examples/c/exception/example.i
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
|
||||
%{
|
||||
#include "example.h"
|
||||
%}
|
||||
|
||||
/* Let's just grab the original header file here */
|
||||
%include "example.h"
|
||||
|
||||
55
Examples/c/exception/runme.c
Normal file
55
Examples/c/exception/runme.c
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#include "example_proxy.h"
|
||||
|
||||
int main() {
|
||||
Test *t = new_Test();
|
||||
|
||||
SWIG_try {
|
||||
Test_unknown(t);
|
||||
}
|
||||
SWIG_catch(SWIG_AnyException) {
|
||||
printf("incomplete type: %s\n", SWIG_exception.msg);
|
||||
}
|
||||
SWIG_endtry;
|
||||
|
||||
SWIG_try {
|
||||
Test_simple(t);
|
||||
}
|
||||
SWIG_catch(SWIG_AnyException) {
|
||||
printf("%s\n", SWIG_exception.msg);
|
||||
}
|
||||
SWIG_endtry;
|
||||
|
||||
SWIG_try {
|
||||
Test_message(t);
|
||||
}
|
||||
SWIG_catch(SWIG_AnyException) {
|
||||
printf("%s\n", SWIG_exception.msg);
|
||||
}
|
||||
SWIG_endtry;
|
||||
|
||||
SWIG_try {
|
||||
Test_hosed(t);
|
||||
}
|
||||
SWIG_catch(Exc) {
|
||||
printf("%d %s\n", Exc_code_get(SWIG_exception.klass), Exc_msg_get(SWIG_exception.klass));
|
||||
}
|
||||
|
||||
int i;
|
||||
for (i = 0; i < 4; ++i) {
|
||||
SWIG_try {
|
||||
Test_multi(t, i);
|
||||
}
|
||||
SWIG_catch(Exc) {
|
||||
printf("%d %s\n", Exc_code_get(SWIG_exception.klass), Exc_msg_get(SWIG_exception.klass));
|
||||
}
|
||||
SWIG_catch(SWIG_AnyException) {
|
||||
printf("%s\n", SWIG_exception.msg);
|
||||
}
|
||||
SWIG_endtry;
|
||||
}
|
||||
|
||||
SWIG_exit(0);
|
||||
}
|
||||
|
||||
|
|
@ -5,6 +5,7 @@ TARGET = example
|
|||
INTERFACE = example.i
|
||||
RUNME = runme.c
|
||||
PROXY = example_proxy.c
|
||||
MEMTOOL = valgrind --leak-check=full
|
||||
|
||||
all::
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
|
|
@ -15,7 +16,14 @@ run:
|
|||
TARGET='$(TARGET)' c_compile
|
||||
env LD_LIBRARY_PATH=. ./runme
|
||||
|
||||
memchk:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' CFLAGS='-g' c
|
||||
$(MAKE) -f $(TOP)/Makefile RUNME='$(RUNME)' PROXY='$(PROXY)' \
|
||||
TARGET='$(TARGET)' CFLAGS='-g' c_compile
|
||||
env LD_LIBRARY_PATH=. $(MEMTOOL) ./runme
|
||||
|
||||
clean:
|
||||
rm -f *.o *.so *.out *.a *.exe *.dll *_wrap* *_proxy* *~
|
||||
rm -f *.o *.so *.out *.a *.exe *.dll *_wrap* *_proxy* *~ runme
|
||||
|
||||
check: all
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue