Skip to content

Commit

Permalink
Avoid separate emval_call_void_method (#20368)
Browse files Browse the repository at this point in the history
  • Loading branch information
RReverser authored Oct 3, 2023
1 parent c0711b2 commit a024288
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 44 deletions.
31 changes: 10 additions & 21 deletions src/embind/emval.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

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

var LibraryEmVal = {
Expand Down Expand Up @@ -370,13 +370,6 @@ var LibraryEmVal = {
return a;
},

$emval_allocateDestructors__deps: ['$Emval'],
$emval_allocateDestructors: (destructorsRef) => {
var destructors = [];
{{{ makeSetValue('destructorsRef', '0', 'Emval.toHandle(destructors)', '*') }}};
return destructors;
},

// Leave id 0 undefined. It's not a big deal, but might be confusing
// to have null be a valid method caller.
$emval_methodCallers: [undefined],
Expand Down Expand Up @@ -414,9 +407,7 @@ var LibraryEmVal = {
types[i].deleteObject(argN[i]);
}
}
if (!retType.isVoid) {
return retType['toWireType'](destructors, rv);
}
return retType['toWireType'](destructors, rv);
};
#else
var params = ["retType"];
Expand Down Expand Up @@ -461,20 +452,18 @@ var LibraryEmVal = {
return emval_addMethodCaller(invokerFunction);
},

_emval_call_method__deps: ['$emval_allocateDestructors', '$getStringOrSymbol', '$emval_methodCallers', '$Emval'],
_emval_call_method__deps: ['$getStringOrSymbol', '$emval_methodCallers', '$Emval'],
_emval_call_method: (caller, handle, methodName, destructorsRef, args) => {
caller = emval_methodCallers[caller];
handle = Emval.toValue(handle);
methodName = getStringOrSymbol(methodName);
return caller(handle, methodName, emval_allocateDestructors(destructorsRef), args);
},

_emval_call_void_method__deps: ['$emval_allocateDestructors', '$getStringOrSymbol', '$emval_methodCallers', '$Emval'],
_emval_call_void_method: (caller, handle, methodName, args) => {
caller = emval_methodCallers[caller];
handle = Emval.toValue(handle);
methodName = getStringOrSymbol(methodName);
caller(handle, methodName, null, args);
var destructors = [];
var result = caller(handle, methodName, destructors, args);
// void and any other types w/o destructors don't need to allocate a handle
if (destructors.length) {
{{{ makeSetValue('destructorsRef', '0', 'Emval.toHandle(destructors)', '*') }}};
}
return result;
},

_emval_typeof__deps: ['$Emval'],
Expand Down
1 change: 0 additions & 1 deletion src/library_sigs.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,6 @@ sigs = {
_emval_await__sig: 'pp',
_emval_call__sig: 'ppipp',
_emval_call_method__sig: 'dppppp',
_emval_call_void_method__sig: 'vpppp',
_emval_decref__sig: 'vp',
_emval_delete__sig: 'ipp',
_emval_equals__sig: 'ipp',
Expand Down
32 changes: 10 additions & 22 deletions system/include/emscripten/val.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,6 @@ EM_GENERIC_WIRE_TYPE _emval_call_method(
const char* methodName,
EM_DESTRUCTORS* destructors,
EM_VAR_ARGS argv);
void _emval_call_void_method(
EM_METHOD_CALLER caller,
EM_VAL handle,
const char* methodName,
EM_VAR_ARGS argv);
EM_VAL _emval_typeof(EM_VAL value);
bool _emval_instanceof(EM_VAL object, EM_VAL constructor);
bool _emval_is_number(EM_VAL object);
Expand Down Expand Up @@ -145,7 +140,9 @@ struct DestructorsRunner {
: destructors(d)
{}
~DestructorsRunner() {
_emval_run_destructors(destructors);
if (destructors) {
_emval_run_destructors(destructors);
}
}

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

template<typename T>
T fromGenericWireType(double g) {
T fromGenericWireType(EM_GENERIC_WIRE_TYPE g) {
typedef typename BindingType<T>::WireType WireType;
WireType wt = GenericWireTypeConverter<WireType>::from(g);
return BindingType<T>::fromWireType(wt);
}

template<>
inline void fromGenericWireType<void>(EM_GENERIC_WIRE_TYPE g) {
(void)g;
}

template<typename... Args>
struct PackSize;

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

WireTypePack<Args...> argv(std::forward<Args>(args)...);
EM_DESTRUCTORS destructors;
EM_DESTRUCTORS destructors = nullptr;
EM_GENERIC_WIRE_TYPE result = _emval_call_method(
caller,
handle,
Expand All @@ -283,20 +285,6 @@ struct MethodCaller {
}
};

template<typename... Args>
struct MethodCaller<void, Args...> {
static void call(EM_VAL handle, const char* methodName, Args&&... args) {
auto caller = Signature<void, Args...>::get_method_caller();

WireTypePack<Args...> argv(std::forward<Args>(args)...);
_emval_call_void_method(
caller,
handle,
methodName,
argv);
}
};

} // end namespace internal

#define EMSCRIPTEN_SYMBOL(name) \
Expand Down

0 comments on commit a024288

Please sign in to comment.