Skip to content

Commit 24733e6

Browse files
committed
feat(wasm): hacks to make work in a fno-exceptions wasm environment (#1)
* feat(wasm): hacks to make work in a fno-exceptions wasm environment * feat(wasm): properly mark operator as noreturn
1 parent 1c6eabb commit 24733e6

9 files changed

Lines changed: 82 additions & 65 deletions

File tree

erb/v1/cpp03_zone.hpp.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,14 +321,14 @@ T* zone::allocate(<%=(1..i).map{|j|"A#{j} a#{j}"}.join(', ')%>)
321321
m_finalizer_array.push(&zone::object_destruct<T>, x);
322322
} catch (...) {
323323
undo_allocate(sizeof(T));
324-
throw;
324+
RETHROW;
325325
}
326326
try {
327327
return new (x) T(<%=(1..i).map{|j|"a#{j}"}.join(', ')%>);
328328
} catch (...) {
329329
--m_finalizer_array.m_tail;
330330
undo_allocate(sizeof(T));
331-
throw;
331+
RETHROW;
332332
}
333333
}
334334
<%}%>

include/msgpack/assert.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,19 @@
2323

2424
#endif // defined(MSGPACK_NO_BOOST)
2525

26+
#ifdef __wasm__
27+
struct AbortStream {
28+
void operator<< [[noreturn]] (const auto& error) {
29+
info(error.what());
30+
std::abort();
31+
}
32+
};
33+
#define throw AbortStream() <<
34+
#define try if (true)
35+
#define catch(...) if (false)
36+
#define RETHROW
37+
#else
38+
#define RETHROW throw
39+
#endif
40+
2641
#endif // MSGPACK_ASSERT_HPP

include/msgpack/sysdep.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,11 @@
183183
} while (0);
184184

185185
#define _msgpack_store16(to, num) \
186-
do { uint16_t val = _msgpack_be16(num); memcpy(to, &val, 2); } while(0)
186+
do { uint16_t val = (uint16_t)_msgpack_be16(num); memcpy(to, &val, 2); } while(0)
187187
#define _msgpack_store32(to, num) \
188-
do { uint32_t val = _msgpack_be32(num); memcpy(to, &val, 4); } while(0)
188+
do { uint32_t val = (uint32_t)_msgpack_be32(num); memcpy(to, &val, 4); } while(0)
189189
#define _msgpack_store64(to, num) \
190-
do { uint64_t val = _msgpack_be64(num); memcpy(to, &val, 8); } while(0)
190+
do { uint64_t val = (uint64_t)_msgpack_be64(num); memcpy(to, &val, 8); } while(0)
191191

192192
/*
193193
#define _msgpack_load16(cast, from) \

include/msgpack/v1/detail/cpp03_zone.hpp

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -366,14 +366,14 @@ T* zone::allocate()
366366
m_finalizer_array.push(&zone::object_destruct<T>, x);
367367
} catch (...) {
368368
undo_allocate(sizeof(T));
369-
throw;
369+
RETHROW;
370370
}
371371
try {
372372
return new (x) T();
373373
} catch (...) {
374374
--m_finalizer_array.m_tail;
375375
undo_allocate(sizeof(T));
376-
throw;
376+
RETHROW;
377377
}
378378
}
379379

@@ -385,14 +385,14 @@ T* zone::allocate(A1 a1)
385385
m_finalizer_array.push(&zone::object_destruct<T>, x);
386386
} catch (...) {
387387
undo_allocate(sizeof(T));
388-
throw;
388+
RETHROW;
389389
}
390390
try {
391391
return new (x) T(a1);
392392
} catch (...) {
393393
--m_finalizer_array.m_tail;
394394
undo_allocate(sizeof(T));
395-
throw;
395+
RETHROW;
396396
}
397397
}
398398

@@ -404,14 +404,14 @@ T* zone::allocate(A1 a1, A2 a2)
404404
m_finalizer_array.push(&zone::object_destruct<T>, x);
405405
} catch (...) {
406406
undo_allocate(sizeof(T));
407-
throw;
407+
RETHROW;
408408
}
409409
try {
410410
return new (x) T(a1, a2);
411411
} catch (...) {
412412
--m_finalizer_array.m_tail;
413413
undo_allocate(sizeof(T));
414-
throw;
414+
RETHROW;
415415
}
416416
}
417417

@@ -423,14 +423,14 @@ T* zone::allocate(A1 a1, A2 a2, A3 a3)
423423
m_finalizer_array.push(&zone::object_destruct<T>, x);
424424
} catch (...) {
425425
undo_allocate(sizeof(T));
426-
throw;
426+
RETHROW;
427427
}
428428
try {
429429
return new (x) T(a1, a2, a3);
430430
} catch (...) {
431431
--m_finalizer_array.m_tail;
432432
undo_allocate(sizeof(T));
433-
throw;
433+
RETHROW;
434434
}
435435
}
436436

@@ -442,14 +442,14 @@ T* zone::allocate(A1 a1, A2 a2, A3 a3, A4 a4)
442442
m_finalizer_array.push(&zone::object_destruct<T>, x);
443443
} catch (...) {
444444
undo_allocate(sizeof(T));
445-
throw;
445+
RETHROW;
446446
}
447447
try {
448448
return new (x) T(a1, a2, a3, a4);
449449
} catch (...) {
450450
--m_finalizer_array.m_tail;
451451
undo_allocate(sizeof(T));
452-
throw;
452+
RETHROW;
453453
}
454454
}
455455

@@ -461,14 +461,14 @@ T* zone::allocate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5)
461461
m_finalizer_array.push(&zone::object_destruct<T>, x);
462462
} catch (...) {
463463
undo_allocate(sizeof(T));
464-
throw;
464+
RETHROW;
465465
}
466466
try {
467467
return new (x) T(a1, a2, a3, a4, a5);
468468
} catch (...) {
469469
--m_finalizer_array.m_tail;
470470
undo_allocate(sizeof(T));
471-
throw;
471+
RETHROW;
472472
}
473473
}
474474

@@ -480,14 +480,14 @@ T* zone::allocate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6)
480480
m_finalizer_array.push(&zone::object_destruct<T>, x);
481481
} catch (...) {
482482
undo_allocate(sizeof(T));
483-
throw;
483+
RETHROW;
484484
}
485485
try {
486486
return new (x) T(a1, a2, a3, a4, a5, a6);
487487
} catch (...) {
488488
--m_finalizer_array.m_tail;
489489
undo_allocate(sizeof(T));
490-
throw;
490+
RETHROW;
491491
}
492492
}
493493

@@ -499,14 +499,14 @@ T* zone::allocate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7)
499499
m_finalizer_array.push(&zone::object_destruct<T>, x);
500500
} catch (...) {
501501
undo_allocate(sizeof(T));
502-
throw;
502+
RETHROW;
503503
}
504504
try {
505505
return new (x) T(a1, a2, a3, a4, a5, a6, a7);
506506
} catch (...) {
507507
--m_finalizer_array.m_tail;
508508
undo_allocate(sizeof(T));
509-
throw;
509+
RETHROW;
510510
}
511511
}
512512

@@ -518,14 +518,14 @@ T* zone::allocate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8)
518518
m_finalizer_array.push(&zone::object_destruct<T>, x);
519519
} catch (...) {
520520
undo_allocate(sizeof(T));
521-
throw;
521+
RETHROW;
522522
}
523523
try {
524524
return new (x) T(a1, a2, a3, a4, a5, a6, a7, a8);
525525
} catch (...) {
526526
--m_finalizer_array.m_tail;
527527
undo_allocate(sizeof(T));
528-
throw;
528+
RETHROW;
529529
}
530530
}
531531

@@ -537,14 +537,14 @@ T* zone::allocate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9)
537537
m_finalizer_array.push(&zone::object_destruct<T>, x);
538538
} catch (...) {
539539
undo_allocate(sizeof(T));
540-
throw;
540+
RETHROW;
541541
}
542542
try {
543543
return new (x) T(a1, a2, a3, a4, a5, a6, a7, a8, a9);
544544
} catch (...) {
545545
--m_finalizer_array.m_tail;
546546
undo_allocate(sizeof(T));
547-
throw;
547+
RETHROW;
548548
}
549549
}
550550

@@ -556,14 +556,14 @@ T* zone::allocate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9,
556556
m_finalizer_array.push(&zone::object_destruct<T>, x);
557557
} catch (...) {
558558
undo_allocate(sizeof(T));
559-
throw;
559+
RETHROW;
560560
}
561561
try {
562562
return new (x) T(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
563563
} catch (...) {
564564
--m_finalizer_array.m_tail;
565565
undo_allocate(sizeof(T));
566-
throw;
566+
RETHROW;
567567
}
568568
}
569569

@@ -575,14 +575,14 @@ T* zone::allocate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9,
575575
m_finalizer_array.push(&zone::object_destruct<T>, x);
576576
} catch (...) {
577577
undo_allocate(sizeof(T));
578-
throw;
578+
RETHROW;
579579
}
580580
try {
581581
return new (x) T(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11);
582582
} catch (...) {
583583
--m_finalizer_array.m_tail;
584584
undo_allocate(sizeof(T));
585-
throw;
585+
RETHROW;
586586
}
587587
}
588588

@@ -594,14 +594,14 @@ T* zone::allocate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9,
594594
m_finalizer_array.push(&zone::object_destruct<T>, x);
595595
} catch (...) {
596596
undo_allocate(sizeof(T));
597-
throw;
597+
RETHROW;
598598
}
599599
try {
600600
return new (x) T(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12);
601601
} catch (...) {
602602
--m_finalizer_array.m_tail;
603603
undo_allocate(sizeof(T));
604-
throw;
604+
RETHROW;
605605
}
606606
}
607607

@@ -613,14 +613,14 @@ T* zone::allocate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9,
613613
m_finalizer_array.push(&zone::object_destruct<T>, x);
614614
} catch (...) {
615615
undo_allocate(sizeof(T));
616-
throw;
616+
RETHROW;
617617
}
618618
try {
619619
return new (x) T(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13);
620620
} catch (...) {
621621
--m_finalizer_array.m_tail;
622622
undo_allocate(sizeof(T));
623-
throw;
623+
RETHROW;
624624
}
625625
}
626626

@@ -632,14 +632,14 @@ T* zone::allocate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9,
632632
m_finalizer_array.push(&zone::object_destruct<T>, x);
633633
} catch (...) {
634634
undo_allocate(sizeof(T));
635-
throw;
635+
RETHROW;
636636
}
637637
try {
638638
return new (x) T(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14);
639639
} catch (...) {
640640
--m_finalizer_array.m_tail;
641641
undo_allocate(sizeof(T));
642-
throw;
642+
RETHROW;
643643
}
644644
}
645645

@@ -651,14 +651,14 @@ T* zone::allocate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9,
651651
m_finalizer_array.push(&zone::object_destruct<T>, x);
652652
} catch (...) {
653653
undo_allocate(sizeof(T));
654-
throw;
654+
RETHROW;
655655
}
656656
try {
657657
return new (x) T(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15);
658658
} catch (...) {
659659
--m_finalizer_array.m_tail;
660660
undo_allocate(sizeof(T));
661-
throw;
661+
RETHROW;
662662
}
663663
}
664664

include/msgpack/v1/detail/cpp11_zone.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,14 +343,14 @@ T* zone::allocate(Args... args)
343343
m_finalizer_array.push(&zone::object_destruct<T>, x);
344344
} catch (...) {
345345
undo_allocate(sizeof(T));
346-
throw;
346+
RETHROW;
347347
}
348348
try {
349349
return new (x) T(args...);
350350
} catch (...) {
351351
--m_finalizer_array.m_tail;
352352
undo_allocate(sizeof(T));
353-
throw;
353+
RETHROW;
354354
}
355355
}
356356

include/msgpack/v1/object.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,11 +1040,13 @@ inline bool operator==(const msgpack::object& x, const msgpack::object& y)
10401040

10411041
template <typename T>
10421042
inline bool operator==(const msgpack::object& x, const T& y)
1043+
{
10431044
try {
10441045
return x == msgpack::object(y);
10451046
} catch (msgpack::type_error&) {
10461047
return false;
10471048
}
1049+
}
10481050

10491051
inline bool operator!=(const msgpack::object& x, const msgpack::object& y)
10501052
{ return !(x == y); }

0 commit comments

Comments
 (0)