| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 "bin/dartutils.h" | 5 #include "bin/dartutils.h" |
| 6 #include "bin/filter.h" | 6 #include "bin/filter.h" |
| 7 #include "bin/io_buffer.h" | 7 #include "bin/io_buffer.h" |
| 8 | 8 |
| 9 #include "include/dart_api.h" | 9 #include "include/dart_api.h" |
| 10 | 10 |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 Filter* filter = GetFilter(filter_obj); | 147 Filter* filter = GetFilter(filter_obj); |
| 148 Dart_Handle data_obj = Dart_GetNativeArgument(args, 1); | 148 Dart_Handle data_obj = Dart_GetNativeArgument(args, 1); |
| 149 intptr_t start = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 2)); | 149 intptr_t start = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 2)); |
| 150 intptr_t end = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 3)); | 150 intptr_t end = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 3)); |
| 151 intptr_t chunk_length = end - start; | 151 intptr_t chunk_length = end - start; |
| 152 intptr_t length; | 152 intptr_t length; |
| 153 Dart_TypedData_Type type; | 153 Dart_TypedData_Type type; |
| 154 uint8_t* buffer = NULL; | 154 uint8_t* buffer = NULL; |
| 155 Dart_Handle result = Dart_TypedDataAcquireData( | 155 Dart_Handle result = Dart_TypedDataAcquireData( |
| 156 data_obj, &type, reinterpret_cast<void**>(&buffer), &length); | 156 data_obj, &type, reinterpret_cast<void**>(&buffer), &length); |
| 157 |
| 157 if (!Dart_IsError(result)) { | 158 if (!Dart_IsError(result)) { |
| 159 ASSERT(type == Dart_TypedData_kUint8 || type == Dart_TypedData_kInt8); |
| 160 if (type != Dart_TypedData_kUint8 && type != Dart_TypedData_kInt8) { |
| 161 Dart_TypedDataReleaseData(data_obj); |
| 162 Dart_ThrowException(DartUtils::NewInternalError( |
| 163 "Invalid argument passed to Filter_Process")); |
| 164 } |
| 158 uint8_t* zlib_buffer = new uint8_t[chunk_length]; | 165 uint8_t* zlib_buffer = new uint8_t[chunk_length]; |
| 159 if (zlib_buffer == NULL) { | 166 if (zlib_buffer == NULL) { |
| 160 Dart_TypedDataReleaseData(data_obj); | 167 Dart_TypedDataReleaseData(data_obj); |
| 161 Dart_ThrowException(DartUtils::NewInternalError( | 168 Dart_ThrowException(DartUtils::NewInternalError( |
| 162 "Failed to allocate buffer for zlib")); | 169 "Failed to allocate buffer for zlib")); |
| 163 } | 170 } |
| 164 memmove(zlib_buffer, buffer + start, chunk_length); | 171 memmove(zlib_buffer, buffer + start, chunk_length); |
| 165 Dart_TypedDataReleaseData(data_obj); | 172 Dart_TypedDataReleaseData(data_obj); |
| 166 buffer = zlib_buffer; | 173 buffer = zlib_buffer; |
| 167 } else { | 174 } else { |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 } | 406 } |
| 400 | 407 |
| 401 delete[] current_buffer_; | 408 delete[] current_buffer_; |
| 402 current_buffer_ = NULL; | 409 current_buffer_ = NULL; |
| 403 // Either 0 Byte processed or error | 410 // Either 0 Byte processed or error |
| 404 return error ? -1 : 0; | 411 return error ? -1 : 0; |
| 405 } | 412 } |
| 406 | 413 |
| 407 } // namespace bin | 414 } // namespace bin |
| 408 } // namespace dart | 415 } // namespace dart |
| OLD | NEW |