aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-02-14 15:09:28 -0800
committerAlon Zakai <alonzakai@gmail.com>2012-02-14 15:09:28 -0800
commiteb56795d36b7079b3b6a627c79be10789e028dec (patch)
tree7da88dfdd90fe97783068190a914c6b7801b17c0
parent84e717376a9926782b10e3f3364b014bfee88d88 (diff)
parent423519b3650d1966fd8e436065ea60f937134a4d (diff)
Merge pull request #246 from adetaylor/atexit-fix
Fix for order in which 'atexit' registered functions are called
-rw-r--r--AUTHORS1
-rw-r--r--src/library.js2
-rwxr-xr-xtests/runner.py21
3 files changed, 23 insertions, 1 deletions
diff --git a/AUTHORS b/AUTHORS
index 8a46cef7..c9b0d861 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -13,5 +13,6 @@ under the licensing terms detailed in LICENSE.
* David Yip <yipdw@member.fsf.org>
* Julien Hamaide <julien.hamaide@gmail.com>
* Ehsan Akhgari <ehsan.akhgari@gmail.com> (copyright owned by Mozilla Foundation)
+* Adrian Taylor <adrian@macrobug.com>
diff --git a/src/library.js b/src/library.js
index aee4a416..e0a38817 100644
--- a/src/library.js
+++ b/src/library.js
@@ -3296,7 +3296,7 @@ LibraryManager.library = {
},
atexit: function(func, arg) {
- __ATEXIT__.push({ func: func, arg: arg });
+ __ATEXIT__.unshift({ func: func, arg: arg });
},
__cxa_atexit: 'atexit',
diff --git a/tests/runner.py b/tests/runner.py
index e2bb13d4..ac422e9e 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -2439,6 +2439,27 @@ def process(filename):
self.do_run(src, '*1*', force_c=True)
+ def test_atexit(self):
+ # Confirms they are called in reverse order
+ src = r'''
+ #include <stdio.h>
+ #include <stdlib.h>
+
+ static void cleanA() {
+ printf("A");
+ }
+ static void cleanB() {
+ printf("B");
+ }
+
+ int main() {
+ atexit(cleanA);
+ atexit(cleanB);
+ return 0;
+ }
+ '''
+ self.do_run(src, 'BA')
+
def test_time(self):
# XXX Not sure what the right output is here. Looks like the test started failing with daylight savings changes. Modified it to pass again.
src = open(path_from_root('tests', 'time', 'src.c'), 'r').read()