| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 5e5be99 commit 33984d6
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -660,27 +660,24 @@ void WASI::FdPread(const FunctionCallbackInfo<Value>& args) { | |||
| 660 | 660 | iovs_ptr, | |
| 661 | 661 | iovs_len * UVWASI_SERDES_SIZE_iovec_t); | |
| 662 | 662 | CHECK_BOUNDS_OR_RETURN(args, mem_size, nread_ptr, UVWASI_SERDES_SIZE_size_t); | |
| 663 | - uvwasi_iovec_t* iovs = UncheckedCalloc<uvwasi_iovec_t>(iovs_len); | ||
| 663 | + std::vector<uvwasi_iovec_t> iovs(iovs_len); | ||
| 664 | 664 | uvwasi_errno_t err; | |
| 665 | 665 | ||
| 666 | - if (iovs == nullptr) { | ||
| 667 | - args.GetReturnValue().Set(UVWASI_ENOMEM); | ||
| 668 | - return; | ||
| 669 | - } | ||
| 670 | - | ||
| 671 | - err = uvwasi_serdes_readv_iovec_t(memory, mem_size, iovs_ptr, iovs, iovs_len); | ||
| 666 | + err = uvwasi_serdes_readv_iovec_t(memory, | ||
| 667 | + mem_size, | ||
| 668 | + iovs_ptr, | ||
| 669 | + iovs.data(), | ||
| 670 | + iovs_len); | ||
| 672 | 671 | if (err != UVWASI_ESUCCESS) { | |
| 673 | - free(iovs); | ||
| 674 | 672 | args.GetReturnValue().Set(err); | |
| 675 | 673 | return; | |
| 676 | 674 | } | |
| 677 | 675 | ||
| 678 | 676 | uvwasi_size_t nread; | |
| 679 | - err = uvwasi_fd_pread(&wasi->uvw_, fd, iovs, iovs_len, offset, &nread); | ||
| 677 | + err = uvwasi_fd_pread(&wasi->uvw_, fd, iovs.data(), iovs_len, offset, &nread); | ||
| 680 | 678 | if (err == UVWASI_ESUCCESS) | |
| 681 | 679 | uvwasi_serdes_write_size_t(memory, nread_ptr, nread); | |
| 682 | 680 | ||
| 683 | - free(iovs); | ||
| 684 | 681 | args.GetReturnValue().Set(err); | |
| 685 | 682 | } | |
| 686 | 683 | ||
@@ -763,31 +760,29 @@ void WASI::FdPwrite(const FunctionCallbackInfo<Value>& args) { | |||
| 763 | 760 | mem_size, | |
| 764 | 761 | nwritten_ptr, | |
| 765 | 762 | UVWASI_SERDES_SIZE_size_t); | |
| 766 | - uvwasi_ciovec_t* iovs = UncheckedCalloc<uvwasi_ciovec_t>(iovs_len); | ||
| 763 | + std::vector<uvwasi_ciovec_t> iovs(iovs_len); | ||
| 767 | 764 | uvwasi_errno_t err; | |
| 768 | 765 | ||
| 769 | - if (iovs == nullptr) { | ||
| 770 | - args.GetReturnValue().Set(UVWASI_ENOMEM); | ||
| 771 | - return; | ||
| 772 | - } | ||
| 773 | - | ||
| 774 | 766 | err = uvwasi_serdes_readv_ciovec_t(memory, | |
| 775 | 767 | mem_size, | |
| 776 | 768 | iovs_ptr, | |
| 777 | - iovs, | ||
| 769 | + iovs.data(), | ||
| 778 | 770 | iovs_len); | |
| 779 | 771 | if (err != UVWASI_ESUCCESS) { | |
| 780 | - free(iovs); | ||
| 781 | 772 | args.GetReturnValue().Set(err); | |
| 782 | 773 | return; | |
| 783 | 774 | } | |
| 784 | 775 | ||
| 785 | 776 | uvwasi_size_t nwritten; | |
| 786 | - err = uvwasi_fd_pwrite(&wasi->uvw_, fd, iovs, iovs_len, offset, &nwritten); | ||
| 777 | + err = uvwasi_fd_pwrite(&wasi->uvw_, | ||
| 778 | + fd, | ||
| 779 | + iovs.data(), | ||
| 780 | + iovs_len, | ||
| 781 | + offset, | ||
| 782 | + &nwritten); | ||
| 787 | 783 | if (err == UVWASI_ESUCCESS) | |
| 788 | 784 | uvwasi_serdes_write_size_t(memory, nwritten_ptr, nwritten); | |
| 789 | 785 | ||
| 790 | - free(iovs); | ||
| 791 | 786 | args.GetReturnValue().Set(err); | |
| 792 | 787 | } | |
| 793 | 788 | ||
@@ -813,27 +808,24 @@ void WASI::FdRead(const FunctionCallbackInfo<Value>& args) { | |||
| 813 | 808 | iovs_ptr, | |
| 814 | 809 | iovs_len * UVWASI_SERDES_SIZE_iovec_t); | |
| 815 | 810 | CHECK_BOUNDS_OR_RETURN(args, mem_size, nread_ptr, UVWASI_SERDES_SIZE_size_t); | |
| 816 | - uvwasi_iovec_t* iovs = UncheckedCalloc<uvwasi_iovec_t>(iovs_len); | ||
| 811 | + std::vector<uvwasi_iovec_t> iovs(iovs_len); | ||
| 817 | 812 | uvwasi_errno_t err; | |
| 818 | 813 | ||
| 819 | - if (iovs == nullptr) { | ||
| 820 | - args.GetReturnValue().Set(UVWASI_ENOMEM); | ||
| 821 | - return; | ||
| 822 | - } | ||
| 823 | - | ||
| 824 | - err = uvwasi_serdes_readv_iovec_t(memory, mem_size, iovs_ptr, iovs, iovs_len); | ||
| 814 | + err = uvwasi_serdes_readv_iovec_t(memory, | ||
| 815 | + mem_size, | ||
| 816 | + iovs_ptr, | ||
| 817 | + iovs.data(), | ||
| 818 | + iovs_len); | ||
| 825 | 819 | if (err != UVWASI_ESUCCESS) { | |
| 826 | - free(iovs); | ||
| 827 | 820 | args.GetReturnValue().Set(err); | |
| 828 | 821 | return; | |
| 829 | 822 | } | |
| 830 | 823 | ||
| 831 | 824 | uvwasi_size_t nread; | |
| 832 | - err = uvwasi_fd_read(&wasi->uvw_, fd, iovs, iovs_len, &nread); | ||
| 825 | + err = uvwasi_fd_read(&wasi->uvw_, fd, iovs.data(), iovs_len, &nread); | ||
| 833 | 826 | if (err == UVWASI_ESUCCESS) | |
| 834 | 827 | uvwasi_serdes_write_size_t(memory, nread_ptr, nread); | |
| 835 | 828 | ||
| 836 | - free(iovs); | ||
| 837 | 829 | args.GetReturnValue().Set(err); | |
| 838 | 830 | } | |
| 839 | 831 | ||
@@ -995,31 +987,24 @@ void WASI::FdWrite(const FunctionCallbackInfo<Value>& args) { | |||
| 995 | 987 | mem_size, | |
| 996 | 988 | nwritten_ptr, | |
| 997 | 989 | UVWASI_SERDES_SIZE_size_t); | |
| 998 | - uvwasi_ciovec_t* iovs = UncheckedCalloc<uvwasi_ciovec_t>(iovs_len); | ||
| 990 | + std::vector<uvwasi_ciovec_t> iovs(iovs_len); | ||
| 999 | 991 | uvwasi_errno_t err; | |
| 1000 | 992 | ||
| 1001 | - if (iovs == nullptr) { | ||
| 1002 | - args.GetReturnValue().Set(UVWASI_ENOMEM); | ||
| 1003 | - return; | ||
| 1004 | - } | ||
| 1005 | - | ||
| 1006 | 993 | err = uvwasi_serdes_readv_ciovec_t(memory, | |
| 1007 | 994 | mem_size, | |
| 1008 | 995 | iovs_ptr, | |
| 1009 | - iovs, | ||
| 996 | + iovs.data(), | ||
| 1010 | 997 | iovs_len); | |
| 1011 | 998 | if (err != UVWASI_ESUCCESS) { | |
| 1012 | - free(iovs); | ||
| 1013 | 999 | args.GetReturnValue().Set(err); | |
| 1014 | 1000 | return; | |
| 1015 | 1001 | } | |
| 1016 | 1002 | ||
| 1017 | 1003 | uvwasi_size_t nwritten; | |
| 1018 | - err = uvwasi_fd_write(&wasi->uvw_, fd, iovs, iovs_len, &nwritten); | ||
| 1004 | + err = uvwasi_fd_write(&wasi->uvw_, fd, iovs.data(), iovs_len, &nwritten); | ||
| 1019 | 1005 | if (err == UVWASI_ESUCCESS) | |
| 1020 | 1006 | uvwasi_serdes_write_size_t(memory, nwritten_ptr, nwritten); | |
| 1021 | 1007 | ||
| 1022 | - free(iovs); | ||
| 1023 | 1008 | args.GetReturnValue().Set(err); | |
| 1024 | 1009 | } | |
| 1025 | 1010 | ||
@@ -1434,21 +1419,8 @@ void WASI::PollOneoff(const FunctionCallbackInfo<Value>& args) { | |||
| 1434 | 1419 | mem_size, | |
| 1435 | 1420 | nevents_ptr, | |
| 1436 | 1421 | UVWASI_SERDES_SIZE_size_t); | |
| 1437 | - uvwasi_subscription_t* in = | ||
| 1438 | - UncheckedCalloc<uvwasi_subscription_t>(nsubscriptions); | ||
| 1439 | - | ||
| 1440 | - if (in == nullptr) { | ||
| 1441 | - args.GetReturnValue().Set(UVWASI_ENOMEM); | ||
| 1442 | - return; | ||
| 1443 | - } | ||
| 1444 | - | ||
| 1445 | - uvwasi_event_t* out = UncheckedCalloc<uvwasi_event_t>(nsubscriptions); | ||
| 1446 | - | ||
| 1447 | - if (out == nullptr) { | ||
| 1448 | - free(in); | ||
| 1449 | - args.GetReturnValue().Set(UVWASI_ENOMEM); | ||
| 1450 | - return; | ||
| 1451 | - } | ||
| 1422 | + std::vector<uvwasi_subscription_t> in(nsubscriptions); | ||
| 1423 | + std::vector<uvwasi_event_t> out(nsubscriptions); | ||
| 1452 | 1424 | ||
| 1453 | 1425 | for (uint32_t i = 0; i < nsubscriptions; ++i) { | |
| 1454 | 1426 | uvwasi_serdes_read_subscription_t(memory, in_ptr, &in[i]); | |
@@ -1457,8 +1429,8 @@ void WASI::PollOneoff(const FunctionCallbackInfo<Value>& args) { | |||
| 1457 | 1429 | ||
| 1458 | 1430 | uvwasi_size_t nevents; | |
| 1459 | 1431 | uvwasi_errno_t err = uvwasi_poll_oneoff(&wasi->uvw_, | |
| 1460 | - in, | ||
| 1461 | - out, | ||
| 1432 | + in.data(), | ||
| 1433 | + out.data(), | ||
| 1462 | 1434 | nsubscriptions, | |
| 1463 | 1435 | &nevents); | |
| 1464 | 1436 | if (err == UVWASI_ESUCCESS) { | |
@@ -1470,8 +1442,6 @@ void WASI::PollOneoff(const FunctionCallbackInfo<Value>& args) { | |||
| 1470 | 1442 | } | |
| 1471 | 1443 | } | |
| 1472 | 1444 | ||
| 1473 | - free(in); | ||
| 1474 | - free(out); | ||
| 1475 | 1445 | args.GetReturnValue().Set(err); | |
| 1476 | 1446 | } | |
| 1477 | 1447 | ||
@@ -1562,20 +1532,13 @@ void WASI::SockRecv(const FunctionCallbackInfo<Value>& args) { | |||
| 1562 | 1532 | ri_data_len * UVWASI_SERDES_SIZE_iovec_t); | |
| 1563 | 1533 | CHECK_BOUNDS_OR_RETURN(args, mem_size, ro_datalen_ptr, 4); | |
| 1564 | 1534 | CHECK_BOUNDS_OR_RETURN(args, mem_size, ro_flags_ptr, 4); | |
| 1565 | - uvwasi_iovec_t* ri_data = UncheckedCalloc<uvwasi_iovec_t>(ri_data_len); | ||
| 1566 | - | ||
| 1567 | - if (ri_data == nullptr) { | ||
| 1568 | - args.GetReturnValue().Set(UVWASI_ENOMEM); | ||
| 1569 | - return; | ||
| 1570 | - } | ||
| 1571 | - | ||
| 1535 | + std::vector<uvwasi_iovec_t> ri_data(ri_data_len); | ||
| 1572 | 1536 | uvwasi_errno_t err = uvwasi_serdes_readv_iovec_t(memory, | |
| 1573 | 1537 | mem_size, | |
| 1574 | 1538 | ri_data_ptr, | |
| 1575 | - ri_data, | ||
| 1539 | + ri_data.data(), | ||
| 1576 | 1540 | ri_data_len); | |
| 1577 | 1541 | if (err != UVWASI_ESUCCESS) { | |
| 1578 | - free(ri_data); | ||
| 1579 | 1542 | args.GetReturnValue().Set(err); | |
| 1580 | 1543 | return; | |
| 1581 | 1544 | } | |
@@ -1584,7 +1547,7 @@ void WASI::SockRecv(const FunctionCallbackInfo<Value>& args) { | |||
| 1584 | 1547 | uvwasi_roflags_t ro_flags; | |
| 1585 | 1548 | err = uvwasi_sock_recv(&wasi->uvw_, | |
| 1586 | 1549 | sock, | |
| 1587 | - ri_data, | ||
| 1550 | + ri_data.data(), | ||
| 1588 | 1551 | ri_data_len, | |
| 1589 | 1552 | ri_flags, | |
| 1590 | 1553 | &ro_datalen, | |
@@ -1594,7 +1557,6 @@ void WASI::SockRecv(const FunctionCallbackInfo<Value>& args) { | |||
| 1594 | 1557 | uvwasi_serdes_write_roflags_t(memory, ro_flags_ptr, ro_flags); | |
| 1595 | 1558 | } | |
| 1596 | 1559 | ||
| 1597 | - free(ri_data); | ||
| 1598 | 1560 | args.GetReturnValue().Set(err); | |
| 1599 | 1561 | } | |
| 1600 | 1562 | ||
@@ -1631,35 +1593,27 @@ void WASI::SockSend(const FunctionCallbackInfo<Value>& args) { | |||
| 1631 | 1593 | mem_size, | |
| 1632 | 1594 | so_datalen_ptr, | |
| 1633 | 1595 | UVWASI_SERDES_SIZE_size_t); | |
| 1634 | - uvwasi_ciovec_t* si_data = UncheckedCalloc<uvwasi_ciovec_t>(si_data_len); | ||
| 1635 | - | ||
| 1636 | - if (si_data == nullptr) { | ||
| 1637 | - args.GetReturnValue().Set(UVWASI_ENOMEM); | ||
| 1638 | - return; | ||
| 1639 | - } | ||
| 1640 | - | ||
| 1596 | + std::vector<uvwasi_ciovec_t> si_data(si_data_len); | ||
| 1641 | 1597 | uvwasi_errno_t err = uvwasi_serdes_readv_ciovec_t(memory, | |
| 1642 | 1598 | mem_size, | |
| 1643 | 1599 | si_data_ptr, | |
| 1644 | - si_data, | ||
| 1600 | + si_data.data(), | ||
| 1645 | 1601 | si_data_len); | |
| 1646 | 1602 | if (err != UVWASI_ESUCCESS) { | |
| 1647 | - free(si_data); | ||
| 1648 | 1603 | args.GetReturnValue().Set(err); | |
| 1649 | 1604 | return; | |
| 1650 | 1605 | } | |
| 1651 | 1606 | ||
| 1652 | 1607 | uvwasi_size_t so_datalen; | |
| 1653 | 1608 | err = uvwasi_sock_send(&wasi->uvw_, | |
| 1654 | 1609 | sock, | |
| 1655 | - si_data, | ||
| 1610 | + si_data.data(), | ||
| 1656 | 1611 | si_data_len, | |
| 1657 | 1612 | si_flags, | |
| 1658 | 1613 | &so_datalen); | |
| 1659 | 1614 | if (err == UVWASI_ESUCCESS) | |
| 1660 | 1615 | uvwasi_serdes_write_size_t(memory, so_datalen_ptr, so_datalen); | |
| 1661 | 1616 | ||
| 1662 | - free(si_data); | ||
| 1663 | 1617 | args.GetReturnValue().Set(err); | |
| 1664 | 1618 | } | |
| 1665 | 1619 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments