Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(511)

Side by Side Diff: runtime/vm/dart_api_impl.cc

Issue 9384027: Add multi-byte ByteArray access methods to the Dart API. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: minor changes to formatting and comments Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/include/dart_api.h ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "include/dart_api.h" 5 #include "include/dart_api.h"
6 6
7 #include "vm/bigint_operations.h" 7 #include "vm/bigint_operations.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/compiler.h" 9 #include "vm/compiler.h"
10 #include "vm/dart.h" 10 #include "vm/dart.h"
(...skipping 1703 matching lines...) Expand 10 before | Expand all | Expand 10 after
1714 } 1714 }
1715 if (peer == NULL) { 1715 if (peer == NULL) {
1716 return Api::NewError("%s expects argument 'peer' to be non-null.", 1716 return Api::NewError("%s expects argument 'peer' to be non-null.",
1717 CURRENT_FUNC); 1717 CURRENT_FUNC);
1718 } 1718 }
1719 *peer = array.GetPeer(); 1719 *peer = array.GetPeer();
1720 return Api::Success(); 1720 return Api::Success();
1721 } 1721 }
1722 1722
1723 1723
1724 template<typename T>
1725 Dart_Handle ByteArrayGetAt(T* value, Dart_Handle array, intptr_t offset) {
1726 const ByteArray& array_obj = Api::UnwrapByteArrayHandle(array);
1727 if (array_obj.IsNull()) {
1728 RETURN_TYPE_ERROR(array, ByteArray);
1729 }
1730 intptr_t length = sizeof(T);
1731 if (!Utils::RangeCheck(offset, length, array_obj.Length())) {
1732 return Api::NewError("Invalid index passed in to get byte array element");
1733 }
1734 uint8_t* dst = reinterpret_cast<uint8_t*>(value);
1735 ByteArray::Copy(dst, array_obj, offset, length);
1736 return Api::Success();
1737 }
1738
1739
1740 template<typename T>
1741 Dart_Handle ByteArraySetAt(Dart_Handle array, intptr_t offset, T value) {
1742 const ByteArray& array_obj = Api::UnwrapByteArrayHandle(array);
1743 if (array_obj.IsNull()) {
1744 RETURN_TYPE_ERROR(array, ByteArray);
1745 }
1746 intptr_t length = sizeof(T);
1747 if (!Utils::RangeCheck(offset, length, array_obj.Length())) {
1748 return Api::NewError("Invalid index passed in to get byte array element");
1749 }
1750 const uint8_t* src = reinterpret_cast<uint8_t*>(&value);
1751 ByteArray::Copy(array_obj, offset, src, length);
1752 return Api::Success();
1753 }
1754
1755
1756 DART_EXPORT Dart_Handle Dart_ByteArrayGetInt8At(Dart_Handle array,
1757 intptr_t offset,
1758 int8_t* value) {
1759 return ByteArrayGetAt(value, array, offset);
1760 }
1761
1762
1763 DART_EXPORT Dart_Handle Dart_ByteArraySetInt8At(Dart_Handle array,
1764 intptr_t offset,
1765 int8_t value) {
1766 return ByteArraySetAt(array, offset, value);
1767 }
1768
1769
1770 DART_EXPORT Dart_Handle Dart_ByteArrayGetUint8At(Dart_Handle array,
1771 intptr_t offset,
1772 uint8_t* value) {
1773 return ByteArrayGetAt(value, array, offset);
1774 }
1775
1776
1777 DART_EXPORT Dart_Handle Dart_ByteArraySetUint8At(Dart_Handle array,
1778 intptr_t offset,
1779 uint8_t value) {
1780 return ByteArraySetAt(array, offset, value);
1781 }
1782
1783
1784 DART_EXPORT Dart_Handle Dart_ByteArrayGetInt16At(Dart_Handle array,
1785 intptr_t offset,
1786 int16_t* value) {
1787 return ByteArrayGetAt(value, array, offset);
1788 }
1789
1790
1791 DART_EXPORT Dart_Handle Dart_ByteArraySetInt16At(Dart_Handle array,
1792 intptr_t offset,
1793 int16_t value) {
1794 return ByteArraySetAt(array, offset, value);
1795 }
1796
1797
1798 DART_EXPORT Dart_Handle Dart_ByteArrayGetUint16At(Dart_Handle array,
1799 intptr_t offset,
1800 uint16_t* value) {
1801 return ByteArrayGetAt(value, array, offset);
1802 }
1803
1804
1805 DART_EXPORT Dart_Handle Dart_ByteArraySetUint16At(Dart_Handle array,
1806 intptr_t offset,
1807 uint16_t value) {
1808 return ByteArraySetAt(array, offset, value);
1809 }
1810
1811
1812 DART_EXPORT Dart_Handle Dart_ByteArrayGetInt32At(Dart_Handle array,
1813 intptr_t offset,
1814 int32_t* value) {
1815 return ByteArrayGetAt(value, array, offset);
1816 }
1817
1818
1819 DART_EXPORT Dart_Handle Dart_ByteArraySetInt32At(Dart_Handle array,
1820 intptr_t offset,
1821 int32_t value) {
1822 return ByteArraySetAt(array, offset, value);
1823 }
1824
1825
1826 DART_EXPORT Dart_Handle Dart_ByteArrayGetUint32At(Dart_Handle array,
1827 intptr_t offset,
1828 uint32_t* value) {
1829 return ByteArrayGetAt(value, array, offset);
1830 }
1831
1832
1833 DART_EXPORT Dart_Handle Dart_ByteArraySetUint32At(Dart_Handle array,
1834 intptr_t offset,
1835 uint32_t value) {
1836 return ByteArraySetAt(array, offset, value);
1837 }
1838
1839
1840 DART_EXPORT Dart_Handle Dart_ByteArrayGetInt64At(Dart_Handle array,
1841 intptr_t offset,
1842 int64_t* value) {
1843 return ByteArrayGetAt(value, array, offset);
1844 }
1845
1846
1847 DART_EXPORT Dart_Handle Dart_ByteArraySetInt64At(Dart_Handle array,
1848 intptr_t offset,
1849 int64_t value) {
1850 return ByteArraySetAt(array, offset, value);
1851 }
1852
1853
1854 DART_EXPORT Dart_Handle Dart_ByteArrayGetUint64At(Dart_Handle array,
1855 intptr_t offset,
1856 uint64_t* value) {
1857 return ByteArrayGetAt(value, array, offset);
1858 }
1859
1860
1861 DART_EXPORT Dart_Handle Dart_ByteArraySetUint64At(Dart_Handle array,
1862 intptr_t offset,
1863 uint64_t value) {
1864 return ByteArraySetAt(array, offset, value);
1865 }
1866
1867
1868 DART_EXPORT Dart_Handle Dart_ByteArrayGetFloat32At(Dart_Handle array,
1869 intptr_t offset,
1870 float* value) {
1871 return ByteArrayGetAt(value, array, offset);
1872 }
1873
1874
1875 DART_EXPORT Dart_Handle Dart_ByteArraySetFloat32At(Dart_Handle array,
1876 intptr_t offset,
1877 float value) {
1878 return ByteArraySetAt(array, offset, value);
1879 }
1880
1881
1882 DART_EXPORT Dart_Handle Dart_ByteArrayGetFloat64At(Dart_Handle array,
1883 intptr_t offset,
1884 double* value) {
1885 return ByteArrayGetAt(value, array, offset);
1886 }
1887
1888
1889 DART_EXPORT Dart_Handle Dart_ByteArraySetFloat64At(Dart_Handle array,
1890 intptr_t offset,
1891 double value) {
1892 return ByteArraySetAt(array, offset, value);
1893 }
1894
1895
1724 // --- Closures --- 1896 // --- Closures ---
1725 1897
1726 1898
1727 DART_EXPORT bool Dart_IsClosure(Dart_Handle object) { 1899 DART_EXPORT bool Dart_IsClosure(Dart_Handle object) {
1728 DARTSCOPE(Isolate::Current()); 1900 DARTSCOPE(Isolate::Current());
1729 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); 1901 const Object& obj = Object::Handle(Api::UnwrapHandle(object));
1730 return obj.IsClosure(); 1902 return obj.IsClosure();
1731 } 1903 }
1732 1904
1733 1905
(...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after
2503 *buffer = NULL; 2675 *buffer = NULL;
2504 } 2676 }
2505 delete debug_region; 2677 delete debug_region;
2506 } else { 2678 } else {
2507 *buffer = NULL; 2679 *buffer = NULL;
2508 *buffer_size = 0; 2680 *buffer_size = 0;
2509 } 2681 }
2510 } 2682 }
2511 2683
2512 } // namespace dart 2684 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/include/dart_api.h ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698