From 59fb70c9dbde86edf4d7406a645db0dbb66e0c07 Mon Sep 17 00:00:00 2001 From: Sathyanarayanan Gunasekaran Date: Tue, 17 Jun 2014 00:04:45 -0700 Subject: don't open files with empty path --- src/library_fs.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/library_fs.js b/src/library_fs.js index d825892c..a75dab97 100644 --- a/src/library_fs.js +++ b/src/library_fs.js @@ -932,6 +932,9 @@ mergeInto(LibraryManager.library, { }); }, open: function(path, flags, mode, fd_start, fd_end) { + if (path === "") { + throw new FS.ErrnoError(ERRNO_CODES.ENOENT); + } flags = typeof flags === 'string' ? FS.modeStringToFlags(flags) : flags; mode = typeof mode === 'undefined' ? 438 /* 0666 */ : mode; if ((flags & {{{ cDefine('O_CREAT') }}})) { -- cgit v1.2.3-18-g5258 From 65f3054a90a1275f831a595c84e6fbfb070e7aab Mon Sep 17 00:00:00 2001 From: Sathyanarayanan Gunasekaran Date: Tue, 17 Jun 2014 00:09:34 -0700 Subject: Add test case for empty path Test case credits to wilkie from - https://github.com/kripken/emscripten/issues/2235 --- tests/fs/test_emptyPath.c | 14 ++++++++++++++ tests/fs/test_emptyPath.out | 2 ++ tests/test_core.py | 6 ++++++ 3 files changed, 22 insertions(+) create mode 100644 tests/fs/test_emptyPath.c create mode 100644 tests/fs/test_emptyPath.out diff --git a/tests/fs/test_emptyPath.c b/tests/fs/test_emptyPath.c new file mode 100644 index 00000000..27d56ea1 --- /dev/null +++ b/tests/fs/test_emptyPath.c @@ -0,0 +1,14 @@ +#include + +int main() { + FILE* f1 = fopen("s", "r"); + if (f1 == NULL) { + printf("file 's' not found!\n"); + } + + FILE* f2 = fopen("", "r"); + if (f2 == NULL) { + printf("file '' not found!\n"); + } + return 0; +} diff --git a/tests/fs/test_emptyPath.out b/tests/fs/test_emptyPath.out new file mode 100644 index 00000000..78352877 --- /dev/null +++ b/tests/fs/test_emptyPath.out @@ -0,0 +1,2 @@ +file 's' not found! +file '' not found! diff --git a/tests/test_core.py b/tests/test_core.py index 08e3594e..137e5e4a 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -4348,6 +4348,12 @@ def process(filename): out = path_from_root('tests', 'fs', 'test_writeFile.out') self.do_run_from_file(src, out) + def test_fs_emptyPath(self): + if self.emcc_args is None: return self.skip('requires emcc') + src = path_from_root('tests', 'fs', 'test_emptyPath.c') + out = path_from_root('tests', 'fs', 'test_emptyPath.out') + self.do_run_from_file(src, out) + def test_fs_append(self): if self.emcc_args is None: return self.skip('requires emcc') src = open(path_from_root('tests', 'fs', 'test_append.c'), 'r').read() -- cgit v1.2.3-18-g5258 From d54f3a7b86e2b266cc86341b6e06096dc7f04d5e Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 17 Jun 2014 13:48:39 -0700 Subject: support argv[0] containing the script node is running; fixes #2431 --- src/postamble.js | 2 +- src/shell.js | 1 + tests/test_other.py | 12 ++++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/postamble.js b/src/postamble.js index b90049bc..94b88d4e 100644 --- a/src/postamble.js +++ b/src/postamble.js @@ -56,7 +56,7 @@ Module['callMain'] = Module.callMain = function callMain(args) { argv.push(0); } } - var argv = [allocate(intArrayFromString("/bin/this.program"), 'i8', ALLOC_NORMAL) ]; + var argv = [allocate(intArrayFromString(Module['thisProgram'] || '/bin/this.program'), 'i8', ALLOC_NORMAL) ]; pad(); for (var i = 0; i < argc-1; i = i + 1) { argv.push(allocate(intArrayFromString(args[i]), 'i8', ALLOC_NORMAL)); diff --git a/src/shell.js b/src/shell.js index 279a3461..85b13337 100644 --- a/src/shell.js +++ b/src/shell.js @@ -70,6 +70,7 @@ if (ENVIRONMENT_IS_NODE) { globalEval(read(f)); }; + Module['thisProgram'] = process['argv'][1]; Module['arguments'] = process['argv'].slice(2); module['exports'] = Module; diff --git a/tests/test_other.py b/tests/test_other.py index 14c3f00b..5e631b41 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -2892,3 +2892,15 @@ int main(int argc, char **argv) { Popen([PYTHON, EMCC, 'src.cpp']).communicate() self.assertContained('read: 0\nfile size is 104\n', run_js('a.out.js')) + def test_argv0_node(self): + open('code.cpp', 'w').write(r''' +#include +int main(int argc, char **argv) { + printf("I am %s.\n", argv[0]); + return 0; +} +''') + + Popen([PYTHON, EMCC, 'code.cpp']).communicate() + self.assertContained('I am ' + self.get_dir() + '/a.out.js', run_js('a.out.js', engine=NODE_JS)) + -- cgit v1.2.3-18-g5258 From 22d2a0fcd2729d9c0c8d53e59471432ddf206b6a Mon Sep 17 00:00:00 2001 From: Nikolay Vorobyov Date: Wed, 18 Jun 2014 16:44:03 +0300 Subject: Added embind support for std::unique_ptr --- AUTHORS | 1 + system/include/emscripten/bind.h | 4 ++-- system/include/emscripten/wire.h | 5 ++++- tests/embind/embind.test.js | 12 ++++++++++++ tests/embind/embind_test.cpp | 35 +++++++++++++++++++++++++++++++++++ 5 files changed, 54 insertions(+), 3 deletions(-) diff --git a/AUTHORS b/AUTHORS index 5930c012..44b8e0ea 100644 --- a/AUTHORS +++ b/AUTHORS @@ -145,3 +145,4 @@ a license to everyone to use it as detailed in LICENSE.) * Ningxin Hu (copyright owned by Intel) * Nicolas Guillemot * Sathyanarayanan Gunasekaran (copyright owned by Mozilla Foundation) +* Nikolay Vorobyov diff --git a/system/include/emscripten/bind.h b/system/include/emscripten/bind.h index 7bc28ff6..67e7c6a3 100644 --- a/system/include/emscripten/bind.h +++ b/system/include/emscripten/bind.h @@ -422,8 +422,8 @@ namespace emscripten { namespace internal { template - ClassType* operator_new(Args... args) { - return new ClassType(args...); + ClassType* operator_new(Args&&... args) { + return new ClassType(std::forward(args)...); } template diff --git a/system/include/emscripten/wire.h b/system/include/emscripten/wire.h index c20e2f55..1a9432d6 100644 --- a/system/include/emscripten/wire.h +++ b/system/include/emscripten/wire.h @@ -293,7 +293,6 @@ namespace emscripten { } }; - // Is this necessary? template struct GenericBindingType> { typedef typename BindingType::WireType WireType; @@ -301,6 +300,10 @@ namespace emscripten { static WireType toWireType(std::unique_ptr p) { return BindingType::toWireType(*p); } + + static std::unique_ptr fromWireType(WireType wt) { + return std::unique_ptr(new T(std::move(BindingType::fromWireType(wt)))); + } }; template diff --git a/tests/embind/embind.test.js b/tests/embind/embind.test.js index 432202ff..f1de1a12 100644 --- a/tests/embind/embind.test.js +++ b/tests/embind/embind.test.js @@ -604,6 +604,18 @@ module({ c.delete(); }); + test("can pass unique_ptr", function() { + var p = cm.embind_test_return_unique_ptr(42); + var m = cm.embind_test_accept_unique_ptr(p); + assert.equal(42, m); + }); + + test("can pass unique_ptr to constructor", function() { + var c = new cm.embind_test_construct_class_with_unique_ptr(42); + assert.equal(42, c.getValue()); + c.delete(); + }); + test("can get member classes then call its member functions", function() { var p = new cm.ParentClass(); var c = p.getBigClass(); diff --git a/tests/embind/embind_test.cpp b/tests/embind/embind_test.cpp index 30267994..511f179b 100644 --- a/tests/embind/embind_test.cpp +++ b/tests/embind/embind_test.cpp @@ -856,6 +856,32 @@ void emval_test_call_function(val v, int i, float f, TupleVector tv, StructVecto v(i, f, tv, sv); } +class UniquePtrToConstructor { +public: + UniquePtrToConstructor(std::unique_ptr p) + : value(*p) + {} + + int getValue() const { + return value; + } + +private: + int value; +}; + +std::unique_ptr embind_test_return_unique_ptr(int v) { + return std::unique_ptr(new int(v)); +} + +UniquePtrToConstructor* embind_test_construct_class_with_unique_ptr(int v) { + return new UniquePtrToConstructor(embind_test_return_unique_ptr(v)); +} + +int embind_test_accept_unique_ptr(std::unique_ptr p) { + return *p.get(); +} + std::unique_ptr emval_test_return_unique_ptr() { return std::unique_ptr(new ValHolder(val::object())); } @@ -1818,6 +1844,15 @@ EMSCRIPTEN_BINDINGS(tests) { function("embind_test_accept_small_class_instance", &embind_test_accept_small_class_instance); function("embind_test_accept_big_class_instance", &embind_test_accept_big_class_instance); + class_("UniquePtrToConstructor") + .constructor>() + .function("getValue", &UniquePtrToConstructor::getValue) + ; + + function("embind_test_construct_class_with_unique_ptr", embind_test_construct_class_with_unique_ptr, allow_raw_pointer()); + function("embind_test_return_unique_ptr", embind_test_return_unique_ptr); + function("embind_test_accept_unique_ptr", embind_test_accept_unique_ptr); + function("embind_test_return_raw_base_ptr", embind_test_return_raw_base_ptr, allow_raw_pointer()); function("embind_test_return_raw_derived_ptr_as_base", embind_test_return_raw_derived_ptr_as_base, allow_raw_pointer()); function("embind_test_return_raw_sibling_derived_ptr_as_base", embind_test_return_raw_sibling_derived_ptr_as_base, allow_raw_pointer()); -- cgit v1.2.3-18-g5258 From 93f1c7704be12993a0557e6fa99a2b484bbc2a24 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 18 Jun 2014 17:07:19 -0700 Subject: fix test_i64_varargs --- tests/core/test_i64_varargs.in | 1 + tests/core/test_i64_varargs.out | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/core/test_i64_varargs.in b/tests/core/test_i64_varargs.in index 7d2e4267..a0cbec64 100644 --- a/tests/core/test_i64_varargs.in +++ b/tests/core/test_i64_varargs.in @@ -16,6 +16,7 @@ int64_t ccv_cache_generate_signature(char *msg, int len, int64_t sig_start, } int main(int argc, char **argv) { + argv[0] = "..."; for (int i = 0; i < argc; i++) { int64_t x; if (i % 123123 == 0) diff --git a/tests/core/test_i64_varargs.out b/tests/core/test_i64_varargs.out index 8c7b7843..01832abc 100644 --- a/tests/core/test_i64_varargs.out +++ b/tests/core/test_i64_varargs.out @@ -1,6 +1,6 @@ -in/this.program +. nada -1536 +1504 a nada 5760 -- cgit v1.2.3-18-g5258 From 2132725af047e02248679f8ac5f2b625a01a1e72 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 18 Jun 2014 17:12:05 -0700 Subject: try to fix test_argv0_node for windows --- tests/test_other.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_other.py b/tests/test_other.py index 5e631b41..f8b9d027 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -2902,5 +2902,5 @@ int main(int argc, char **argv) { ''') Popen([PYTHON, EMCC, 'code.cpp']).communicate() - self.assertContained('I am ' + self.get_dir() + '/a.out.js', run_js('a.out.js', engine=NODE_JS)) + self.assertContained('I am ' + self.get_dir().replace('\\', '/') + '/a.out.js', run_js('a.out.js', engine=NODE_JS)) -- cgit v1.2.3-18-g5258 From ab04917cb39891520be2130d9142ced2100f627b Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Fri, 20 Jun 2014 21:55:20 +0700 Subject: [embind tests] Give AbstractClassWithConstructor a virtual destructor. This is required for the IMVU build as it errors on this. --- tests/embind/embind_test.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/embind/embind_test.cpp b/tests/embind/embind_test.cpp index 511f179b..7ac321a8 100644 --- a/tests/embind/embind_test.cpp +++ b/tests/embind/embind_test.cpp @@ -1201,6 +1201,8 @@ struct AbstractClassWithConstructor { : s(s) {} + virtual ~AbstractClassWithConstructor() {}; + virtual std::string abstractMethod() = 0; std::string concreteMethod() { return s; -- cgit v1.2.3-18-g5258 From f1d1fa4432c93627a461b3c538198888e10990e2 Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Fri, 20 Jun 2014 23:00:58 +0700 Subject: [browser library] Fix error in strict mode. --- src/library_browser.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/library_browser.js b/src/library_browser.js index 57ca5a24..1740eaed 100644 --- a/src/library_browser.js +++ b/src/library_browser.js @@ -196,6 +196,12 @@ mergeInto(LibraryManager.library, { // Canvas event setup var canvas = Module['canvas']; + function pointerLockChange() { + Browser.pointerLock = document['pointerLockElement'] === canvas || + document['mozPointerLockElement'] === canvas || + document['webkitPointerLockElement'] === canvas || + document['msPointerLockElement'] === canvas; + } if (canvas) { // forced aspect ratio can be enabled by defining 'forcedAspectRatio' on Module // Module['forcedAspectRatio'] = 4 / 3; @@ -212,12 +218,6 @@ mergeInto(LibraryManager.library, { function(){}; // no-op if function does not exist canvas.exitPointerLock = canvas.exitPointerLock.bind(document); - function pointerLockChange() { - Browser.pointerLock = document['pointerLockElement'] === canvas || - document['mozPointerLockElement'] === canvas || - document['webkitPointerLockElement'] === canvas || - document['msPointerLockElement'] === canvas; - } document.addEventListener('pointerlockchange', pointerLockChange, false); document.addEventListener('mozpointerlockchange', pointerLockChange, false); -- cgit v1.2.3-18-g5258 From 3eb16db0edc678ca6183b3d0254b925aee575469 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 23 Jun 2014 14:50:45 -0700 Subject: proper fix for other.test_argv0_node --- tests/test_other.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_other.py b/tests/test_other.py index f8b9d027..4fb90b1a 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -2902,5 +2902,5 @@ int main(int argc, char **argv) { ''') Popen([PYTHON, EMCC, 'code.cpp']).communicate() - self.assertContained('I am ' + self.get_dir().replace('\\', '/') + '/a.out.js', run_js('a.out.js', engine=NODE_JS)) + self.assertContained('I am ' + self.get_dir().replace('\\', '/') + '/a.out.js', run_js('a.out.js', engine=NODE_JS).replace('\\', '/')) -- cgit v1.2.3-18-g5258