Commit 2760f83
authored
[embind] Manage exceptions' states correctly (#26519)
`libemval.js` has two exception-related functions: `_emval_throw` and
`_emval_from_current_cxa_exception`, but they haven't been correclty
updating various exception-related states. #26276 tried to fix this but
it only updated `exceptionLast`.
This updates other internal states correctly. Some of them only apply to
Emscripten EH, while others apply to both.
1. To make the uncaught exception count updatable for Wasm EH, this adds
`___cxa_in/decrement_uncaught_exception` to
`cxa_exception_js_utils.cpp`, and also adds a common interface
`in/decrementUncaughtExceptionCount` in `libexceptions.js` so that you
can call them regardless of which EH is used. For Wasm EH, the
management of the uncaught exception count is done within libc++abi
functions (`__cxa_throw`, `__cxa_rethrow`, ...), but here in embind we
bypass those functions, so we have to manage them directly.
2. To make refcount work correctly, this adds calls to
`in/decrementExceptionRefcount` to exception-related functions. Also,
this fixes memory leaks by adding the destructor mechanism that
decrements refcount when emvals are destroyed.
`_emval_from_current_cxa_exception` is similar to
`std::current_exception`, which returns `std::exception_ptr`, whose
destructor decrements the refcount so that the exception can be
destroyed:
https://github.com/emscripten-core/emscripten/blob/62e22652509fbe7a00609ce48a653d0d66f27ba5/system/lib/libcxx/src/support/runtime/exception_pointer_cxxabi.ipp#L16
embind didn't have such a mechanism, so exceptions captured by
`_emval_from_current_cxa_exception` leaked memory.
This also fixes #26290.1 parent 840a043 commit 2760f83
6 files changed
Lines changed: 157 additions & 9 deletions
File tree
- src/lib
- system/lib/libcxxabi/src
- test
- embind
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
14 | 17 | | |
15 | 18 | | |
16 | 19 | | |
| |||
80 | 83 | | |
81 | 84 | | |
82 | 85 | | |
83 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
84 | 91 | | |
85 | 92 | | |
86 | 93 | | |
87 | 94 | | |
88 | 95 | | |
| 96 | + | |
89 | 97 | | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
90 | 107 | | |
91 | 108 | | |
92 | 109 | | |
| |||
392 | 409 | | |
393 | 410 | | |
394 | 411 | | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
395 | 423 | | |
396 | | - | |
| 424 | + | |
| 425 | + | |
397 | 426 | | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
398 | 432 | | |
399 | 433 | | |
400 | 434 | | |
401 | 435 | | |
402 | | - | |
403 | | - | |
404 | | - | |
405 | | - | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
406 | 442 | | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
407 | 446 | | |
408 | 447 | | |
409 | 448 | | |
| |||
446 | 485 | | |
447 | 486 | | |
448 | 487 | | |
449 | | - | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
450 | 497 | | |
451 | 498 | | |
452 | 499 | | |
| |||
455 | 502 | | |
456 | 503 | | |
457 | 504 | | |
458 | | - | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
459 | 515 | | |
460 | 516 | | |
461 | 517 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
366 | 366 | | |
367 | 367 | | |
368 | 368 | | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
369 | 375 | | |
370 | 376 | | |
371 | 377 | | |
| |||
384 | 390 | | |
385 | 391 | | |
386 | 392 | | |
387 | | - | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
388 | 407 | | |
389 | 408 | | |
390 | 409 | | |
| |||
394 | 413 | | |
395 | 414 | | |
396 | 415 | | |
| 416 | + | |
397 | 417 | | |
398 | 418 | | |
399 | 419 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
126 | 137 | | |
127 | 138 | | |
128 | 139 | | |
| |||
Lines changed: 47 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
Lines changed: 10 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7782 | 7782 | | |
7783 | 7783 | | |
7784 | 7784 | | |
| 7785 | + | |
| 7786 | + | |
| 7787 | + | |
| 7788 | + | |
7785 | 7789 | | |
7786 | 7790 | | |
7787 | 7791 | | |
| |||
0 commit comments