diff options
author | Chad Austin <caustin@gmail.com> | 2014-03-23 15:48:44 -0700 |
---|---|---|
committer | Chad Austin <chad@chadaustin.me> | 2014-03-28 23:56:41 -0700 |
commit | bcb2da768ab5b559b1603b28e3f7b1a3e1b0b6fc (patch) | |
tree | a43712a76c2a0918ec9afa1d4dae93416a8b0130 | |
parent | f9ef5a0002a3b2980d14f874514eeffa4f48dbbd (diff) |
Fix passing memory_views in varargs
-rw-r--r-- | src/embind/embind.js | 11 | ||||
-rw-r--r-- | src/embind/emval.js | 3 | ||||
-rw-r--r-- | tests/embind/embind.test.js | 6 | ||||
-rw-r--r-- | tests/embind/embind_test.cpp | 5 |
4 files changed, 22 insertions, 3 deletions
diff --git a/src/embind/embind.js b/src/embind/embind.js index f8707986..4ef8646f 100644 --- a/src/embind/embind.js +++ b/src/embind/embind.js @@ -292,6 +292,7 @@ function __embind_register_bool(rawType, name, size, trueValue, falseValue) { 'toWireType': function(destructors, o) { return o ? trueValue : falseValue; }, + 'varArgAdvance': 8, 'readValueFromPointer': function(pointer) { // TODO: if heap is fixed (like in asm.js) this could be executed outside var heap; @@ -406,6 +407,7 @@ function __embind_register_integer(primitiveType, name, size, minRange, maxRange } return value | 0; }, + 'varArgAdvance': 8, 'readValueFromPointer': integerReadValueFromPointer(shift, minRange !== 0), writeValueToPointer: integerWriteValueToPointer(shift, minRange !== 0), destructorFunction: null, // This type does not need a destructor @@ -428,6 +430,7 @@ function __embind_register_float(rawType, name, size) { } return value; }, + 'varArgAdvance': 8, 'readValueFromPointer': function(pointer) { var heap = (shift === 2) ? HEAPF32 : HEAPF64; return this['fromWireType'](heap[pointer >> shift]); @@ -501,6 +504,7 @@ function __embind_register_std_string(rawType, name) { } return ptr; }, + 'varArgAdvance': 8, 'readValueFromPointer': simpleReadValueFromPointer, writeValueToPointer: simpleWriteValueToPointer, destructorFunction: function(ptr) { _free(ptr); }, @@ -543,6 +547,7 @@ function __embind_register_std_wstring(rawType, charSize, name) { } return ptr; }, + 'varArgAdvance': 8, 'readValueFromPointer': simpleReadValueFromPointer, writeValueToPointer: simpleWriteValueToPointer, destructorFunction: function(ptr) { _free(ptr); }, @@ -561,6 +566,7 @@ function __embind_register_emval(rawType, name) { 'toWireType': function(destructors, value) { return __emval_register(value); }, + 'varArgAdvance': 8, 'readValueFromPointer': simpleReadValueFromPointer, writeValueToPointer: simpleWriteValueToPointer, destructorFunction: null, // This type does not need a destructor @@ -589,6 +595,7 @@ function __embind_register_memory_view(rawType, name) { var TA = typeMapping[type]; return new TA(HEAP8.buffer, data, size); }, + 'varArgAdvance': 16, 'readValueFromPointer': function(ptr) { return this['fromWireType'](ptr); }, @@ -834,6 +841,7 @@ function __embind_finalize_value_array(rawTupleType) { } return ptr; }, + 'varArgAdvance': 8, 'readValueFromPointer': simpleReadValueFromPointer, writeValueToPointer: simpleWriteValueToPointer, destructorFunction: rawDestructor, @@ -937,6 +945,7 @@ function __embind_finalize_value_object(structType) { } return ptr; }, + 'varArgAdvance': 8, 'readValueFromPointer': simpleReadValueFromPointer, writeValueToPointer: simpleWriteValueToPointer, destructorFunction: rawDestructor, @@ -1123,6 +1132,7 @@ RegisteredPointer.prototype.destructor = function(ptr) { } }; +RegisteredPointer.prototype['varArgAdvance'] = 8; RegisteredPointer.prototype['readValueFromPointer'] = simpleReadValueFromPointer; RegisteredPointer.prototype.writeValueToPointer = simpleWriteValueToPointer; @@ -1771,6 +1781,7 @@ function __embind_register_enum( 'toWireType': function(destructors, c) { return c.value; }, + 'varArgAdvance': 8, 'readValueFromPointer': integerReadValueFromPointer(shift, isSigned), writeValueToPointer: integerWriteValueToPointer(shift, isSigned), destructorFunction: null, diff --git a/src/embind/emval.js b/src/embind/emval.js index f6f0f343..535b5d57 100644 --- a/src/embind/emval.js +++ b/src/embind/emval.js @@ -139,7 +139,8 @@ function craftEmvalAllocator(argCount) { for(var i = 0; i < argCount; ++i) { functionBody += "var argType"+i+" = requireRegisteredType(HEAP32[(argTypes >> 2) + "+i+"], \"parameter "+i+"\");\n" + - "var arg"+i+" = argType"+i+".readValueFromPointer(args + " + i * 8 + ");\n"; + "var arg"+i+" = argType"+i+".readValueFromPointer(args);\n" + + "args += argType"+i+".varArgAdvance;\n"; } functionBody += "var obj = new constructor("+argsList+");\n" + diff --git a/tests/embind/embind.test.js b/tests/embind/embind.test.js index 2e74c133..4ac8fe52 100644 --- a/tests/embind/embind.test.js +++ b/tests/embind/embind.test.js @@ -1986,12 +1986,16 @@ module({ }); test("memory view", function() { - function factory(view) { + function factory(before, view, after) { + this.before = before; this.view = view; + this.after = after; } var instance = cm.construct_with_memory_view(factory); + assert.equal("before", instance.before); assert.equal(10, instance.view.byteLength); + assert.equal("after", instance.after); }); }); }); diff --git a/tests/embind/embind_test.cpp b/tests/embind/embind_test.cpp index 2746e114..0b3f67e9 100644 --- a/tests/embind/embind_test.cpp +++ b/tests/embind/embind_test.cpp @@ -2345,7 +2345,10 @@ val construct_with_6(val factory) { val construct_with_memory_view(val factory) { static const char data[11] = "0123456789"; - return factory.new_(memory_view(10, data)); + return factory.new_( + std::string("before"), + memory_view(10, data), + std::string("after")); } EMSCRIPTEN_BINDINGS(val_new_) { |