Skip to content

Commit

Permalink
Fixed unbound calling of destructor in exception handler; updated test.
Browse files Browse the repository at this point in the history
  • Loading branch information
max99x committed Sep 15, 2011
1 parent a39cbaf commit 76c1581
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 30 deletions.
16 changes: 9 additions & 7 deletions src/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -4044,18 +4044,20 @@ LibraryManager.library = {
}
// Clear state flag.
__THREW__ = false;
// Free ptr if it isn't null.
if ({{{ makeGetValue('_llvm_eh_exception.buf', '0', 'void*') }}}) {
___cxa_free_exception({{{ makeGetValue('_llvm_eh_exception.buf', '0', 'void*') }}});
{{{ makeSetValue('_llvm_eh_exception.buf', '0', '0', 'void*') }}}
}
// Clear type.
{{{ makeSetValue('_llvm_eh_exception.buf', '4', '0', 'void*') }}}
// Call destructor if one is registered then clear it.
if ({{{ makeGetValue('_llvm_eh_exception.buf', '8', 'void*') }}}) {
FUNCTION_TABLE[{{{ makeGetValue('_llvm_eh_exception.buf', '8', 'void*') }}}]();
var ptr = {{{ makeGetValue('_llvm_eh_exception.buf', '0', 'void*') }}};
var destructor = {{{ makeGetValue('_llvm_eh_exception.buf', '8', 'void*') }}};
if (destructor) {
FUNCTION_TABLE[destructor](ptr);
{{{ makeSetValue('_llvm_eh_exception.buf', '8', '0', 'i32') }}}
}
// Free ptr if it isn't null.
if (ptr) {
___cxa_free_exception(ptr);
{{{ makeSetValue('_llvm_eh_exception.buf', '0', '0', 'void*') }}}
}
},
__cxa_get_exception_ptr__deps: ['llvm_eh_exception'],
__cxa_get_exception_ptr: function(ptr) {
Expand Down
22 changes: 9 additions & 13 deletions tests/exceptions/output.txt
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
*CREATING A FOO
*CREATING A BAR
*CREATING A QUUX
*CREATING A QUUX
*CREATING A CHILD
start


throwing ExFooInstance
*COPYING A FOO
*COPYING A FOO
outer catch foo: 11
*DESTROYING A FOO
*DESTROYING A FOO
*DESTROYING A FOO (11)
*DESTROYING A FOO (11)


throwing ExBarInstance
*COPYING A BAR
*COPYING A BAR
inner re-throw: 22
*DESTROYING A BAR
*DESTROYING A BAR (22)
outer catch bar-ref: 22
*DESTROYING A BAR
*DESTROYING A BAR (22)


throwing ExQuuxInstance
*COPYING A QUUX
*COPYING A QUUX
inner catch quux: 33
*DESTROYING A QUUX
*DESTROYING A QUUX
*DESTROYING A QUUX (33)
*DESTROYING A QUUX (33)



Expand All @@ -47,8 +45,6 @@ outer catch-all


end
*DESTROYING A CHILD
*DESTROYING A QUUX
*DESTROYING A QUUX
*DESTROYING A BAR
*DESTROYING A FOO
*DESTROYING A QUUX (33)
*DESTROYING A BAR (22)
*DESTROYING A FOO (11)
20 changes: 10 additions & 10 deletions tests/exceptions/typed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,29 @@ class ExFoo {
int x;
ExFoo(int x) { this->x = x; printf("*CREATING A FOO\n"); }
ExFoo(const ExFoo& other) { x=other.x; printf("*COPYING A FOO\n"); }
~ExFoo() { printf("*DESTROYING A FOO\n"); }
~ExFoo() { printf("*DESTROYING A FOO (%d)\n", x); }
} ExFooInstance(11);
class ExBar {
public:
int x;
ExBar(int x) { this->x = x; printf("*CREATING A BAR\n"); }
ExBar(const ExBar& other) { x=other.x; printf("*COPYING A BAR\n"); }
~ExBar() { printf("*DESTROYING A BAR\n"); }
~ExBar() { printf("*DESTROYING A BAR (%d)\n", x); }
} ExBarInstance(22);
class ExQuux {
public:
int x;
ExQuux(int x) { this->x = x; printf("*CREATING A QUUX\n"); }
ExQuux(const ExQuux& other) { x=other.x; printf("*COPYING A QUUX\n"); }
~ExQuux() { printf("*DESTROYING A QUUX\n"); }
~ExQuux() { printf("*DESTROYING A QUUX (%d)\n", x); }
} ExQuuxInstance(33);
class ExChild : public ExQuux {
public:
int x;
ExChild(int x) : ExQuux(x) { this->x = x; printf("*CREATING A CHILD\n"); }
ExChild(const ExChild& other) : ExQuux(x) { x=other.x; printf("*COPYING CHILD\n"); }
~ExChild() { printf("*DESTROYING A CHILD\n"); }
} ExChildInstance(44);
// NOTE: Throwing pointers and polymorphic matching not supported.
// class ExChild : public ExQuux {
// public:
// ExChild(int x) : ExQuux(x) { printf("*CREATING A CHILD\n"); }
// ExChild(const ExChild& other) : ExQuux(x) { x=other.x; printf("*COPYING CHILD\n"); }
// ~ExChild() { printf("*DESTROYING A CHILD (%d)\n", x); }
// } ExChildInstance(44);

void magic(int which) {
try {
Expand Down

0 comments on commit 76c1581

Please sign in to comment.