Skip to content

Commit e15a9f7

Browse files
committed
Move reserved handle check to C++ too
This allows to completely eliminate statements like `val v;` as compiler can statically prove it doesn't need _emval_free.
1 parent ca47e2f commit e15a9f7

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/embind/emval.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,7 @@ var LibraryEmVal = {
8080

8181
_emval_free__deps: ['$emval_handles'],
8282
_emval_free: (handle) => {
83-
if (handle >= emval_handles.reserved) {
84-
emval_handles.free(handle);
85-
}
83+
emval_handles.free(handle);
8684
},
8785

8886
_emval_run_destructors__deps: ['_emval_free', '$Emval', '$runDestructors'],

system/include/emscripten/val.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ void _emval_register_symbol(const char*);
3838

3939
enum {
4040
_EMVAL_UNDEFINED = 1,
41-
_EMVAL_NULL = 2,
42-
_EMVAL_TRUE = 3,
43-
_EMVAL_FALSE = 4
41+
_EMVAL_NULL,
42+
_EMVAL_TRUE,
43+
_EMVAL_FALSE,
44+
_EMVAL_UNRESERVED_START
4445
};
4546

4647
typedef struct _EM_DESTRUCTORS* EM_DESTRUCTORS;
@@ -322,7 +323,9 @@ struct val_metadata {
322323

323324
// should be only accessible from dec_ref
324325
~val_metadata() {
325-
_emval_free(handle);
326+
if (handle >= EM_VAL(internal::_EMVAL_UNRESERVED_START)) {
327+
internal::_emval_free(handle);
328+
}
326329
}
327330
};
328331

0 commit comments

Comments
 (0)