diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-01-07 18:01:09 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-01-07 18:01:09 -0800 |
commit | 5c02f40d3422617d0be4f0542b8b5281cae7883b (patch) | |
tree | 0a486e9da09016e3c47981d88844f3ccbc65acab /tests/new.cpp | |
parent | 16230c8cf1e947e03714da3fd3307a9eff41405a (diff) |
automatic malloc need detection for new
Diffstat (limited to 'tests/new.cpp')
-rw-r--r-- | tests/new.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/new.cpp b/tests/new.cpp new file mode 100644 index 00000000..3e09fbc1 --- /dev/null +++ b/tests/new.cpp @@ -0,0 +1,38 @@ +// Emscripten tests + +#include <stdio.h> +#include <stdlib.h> +#include <assert.h> + +struct Structy { char data[100]; int x; }; + +int main() { + int NUM = 100; + char* allocations[NUM]; + for (int i = 0; i < NUM/2; i++) { + allocations[i] = (char*){{{ NEW }}}; + assert(allocations[i]); + if (i > 10 && i%4 == 1 && allocations[i-10]) { + {{{ DELETE }}}(allocations[i-10]); + allocations[i-10] = NULL; + } + } + for (int i = NUM/2; i < NUM; i++) { + allocations[i] = (char*){{{ NEW }}}; + assert(allocations[i]); + if (i > 10 && i%4 != 1 && allocations[i-10]) { + {{{ DELETE }}}(allocations[i-10]); + allocations[i-10] = NULL; + } + } + char* first = allocations[0]; + for (int i = 0; i < NUM; i++) { + if (allocations[i]) { + {{{ DELETE }}}(allocations[i]); + } + } + char *last = (char*){{{ NEW }}}; /* should be identical, as we free'd it all */ + char *newer = (char*){{{ NEW }}}; /* should be different */ + printf("*%d,%d*\n", first == last, first == newer); +} + |