Skip to content

Commit a024288

Browse files
authored
Avoid separate emval_call_void_method (#20368)
1 parent c0711b2 commit a024288

File tree

3 files changed

+20
-44
lines changed

3 files changed

+20
-44
lines changed

src/embind/emval.js

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
// -- jshint doesn't understand library syntax, so we need to mark the symbols exposed here
1515
/*global getStringOrSymbol, emval_handles, Emval, __emval_unregister, count_emval_handles, emval_symbols, __emval_decref, emval_newers*/
16-
/*global craftEmvalAllocator, emval_addMethodCaller, emval_methodCallers, addToLibrary, emval_allocateDestructors, global, emval_lookupTypes, makeLegalFunctionName*/
16+
/*global craftEmvalAllocator, emval_addMethodCaller, emval_methodCallers, addToLibrary, global, emval_lookupTypes, makeLegalFunctionName*/
1717
/*global emval_get_global*/
1818

1919
var LibraryEmVal = {
@@ -370,13 +370,6 @@ var LibraryEmVal = {
370370
return a;
371371
},
372372

373-
$emval_allocateDestructors__deps: ['$Emval'],
374-
$emval_allocateDestructors: (destructorsRef) => {
375-
var destructors = [];
376-
{{{ makeSetValue('destructorsRef', '0', 'Emval.toHandle(destructors)', '*') }}};
377-
return destructors;
378-
},
379-
380373
// Leave id 0 undefined. It's not a big deal, but might be confusing
381374
// to have null be a valid method caller.
382375
$emval_methodCallers: [undefined],
@@ -414,9 +407,7 @@ var LibraryEmVal = {
414407
types[i].deleteObject(argN[i]);
415408
}
416409
}
417-
if (!retType.isVoid) {
418-
return retType['toWireType'](destructors, rv);
419-
}
410+
return retType['toWireType'](destructors, rv);
420411
};
421412
#else
422413
var params = ["retType"];
@@ -461,20 +452,18 @@ var LibraryEmVal = {
461452
return emval_addMethodCaller(invokerFunction);
462453
},
463454

464-
_emval_call_method__deps: ['$emval_allocateDestructors', '$getStringOrSymbol', '$emval_methodCallers', '$Emval'],
455+
_emval_call_method__deps: ['$getStringOrSymbol', '$emval_methodCallers', '$Emval'],
465456
_emval_call_method: (caller, handle, methodName, destructorsRef, args) => {
466457
caller = emval_methodCallers[caller];
467458
handle = Emval.toValue(handle);
468459
methodName = getStringOrSymbol(methodName);
469-
return caller(handle, methodName, emval_allocateDestructors(destructorsRef), args);
470-
},
471-
472-
_emval_call_void_method__deps: ['$emval_allocateDestructors', '$getStringOrSymbol', '$emval_methodCallers', '$Emval'],
473-
_emval_call_void_method: (caller, handle, methodName, args) => {
474-
caller = emval_methodCallers[caller];
475-
handle = Emval.toValue(handle);
476-
methodName = getStringOrSymbol(methodName);
477-
caller(handle, methodName, null, args);
460+
var destructors = [];
461+
var result = caller(handle, methodName, destructors, args);
462+
// void and any other types w/o destructors don't need to allocate a handle
463+
if (destructors.length) {
464+
{{{ makeSetValue('destructorsRef', '0', 'Emval.toHandle(destructors)', '*') }}};
465+
}
466+
return result;
478467
},
479468

480469
_emval_typeof__deps: ['$Emval'],

src/library_sigs.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,6 @@ sigs = {
339339
_emval_await__sig: 'pp',
340340
_emval_call__sig: 'ppipp',
341341
_emval_call_method__sig: 'dppppp',
342-
_emval_call_void_method__sig: 'vpppp',
343342
_emval_decref__sig: 'vp',
344343
_emval_delete__sig: 'ipp',
345344
_emval_equals__sig: 'ipp',

system/include/emscripten/val.h

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,6 @@ EM_GENERIC_WIRE_TYPE _emval_call_method(
9999
const char* methodName,
100100
EM_DESTRUCTORS* destructors,
101101
EM_VAR_ARGS argv);
102-
void _emval_call_void_method(
103-
EM_METHOD_CALLER caller,
104-
EM_VAL handle,
105-
const char* methodName,
106-
EM_VAR_ARGS argv);
107102
EM_VAL _emval_typeof(EM_VAL value);
108103
bool _emval_instanceof(EM_VAL object, EM_VAL constructor);
109104
bool _emval_is_number(EM_VAL object);
@@ -145,7 +140,9 @@ struct DestructorsRunner {
145140
: destructors(d)
146141
{}
147142
~DestructorsRunner() {
148-
_emval_run_destructors(destructors);
143+
if (destructors) {
144+
_emval_run_destructors(destructors);
145+
}
149146
}
150147

151148
DestructorsRunner(const DestructorsRunner&) = delete;
@@ -170,12 +167,17 @@ struct GenericWireTypeConverter<Pointee*> {
170167
};
171168

172169
template<typename T>
173-
T fromGenericWireType(double g) {
170+
T fromGenericWireType(EM_GENERIC_WIRE_TYPE g) {
174171
typedef typename BindingType<T>::WireType WireType;
175172
WireType wt = GenericWireTypeConverter<WireType>::from(g);
176173
return BindingType<T>::fromWireType(wt);
177174
}
178175

176+
template<>
177+
inline void fromGenericWireType<void>(EM_GENERIC_WIRE_TYPE g) {
178+
(void)g;
179+
}
180+
179181
template<typename... Args>
180182
struct PackSize;
181183

@@ -271,7 +273,7 @@ struct MethodCaller {
271273
auto caller = Signature<ReturnType, Args...>::get_method_caller();
272274

273275
WireTypePack<Args...> argv(std::forward<Args>(args)...);
274-
EM_DESTRUCTORS destructors;
276+
EM_DESTRUCTORS destructors = nullptr;
275277
EM_GENERIC_WIRE_TYPE result = _emval_call_method(
276278
caller,
277279
handle,
@@ -283,20 +285,6 @@ struct MethodCaller {
283285
}
284286
};
285287

286-
template<typename... Args>
287-
struct MethodCaller<void, Args...> {
288-
static void call(EM_VAL handle, const char* methodName, Args&&... args) {
289-
auto caller = Signature<void, Args...>::get_method_caller();
290-
291-
WireTypePack<Args...> argv(std::forward<Args>(args)...);
292-
_emval_call_void_method(
293-
caller,
294-
handle,
295-
methodName,
296-
argv);
297-
}
298-
};
299-
300288
} // end namespace internal
301289

302290
#define EMSCRIPTEN_SYMBOL(name) \

0 commit comments

Comments
 (0)