| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 if (Dart_IsError(result)) { | 75 if (Dart_IsError(result)) { |
| 76 delete filter; | 76 delete filter; |
| 77 Dart_PropagateError(result); | 77 Dart_PropagateError(result); |
| 78 } | 78 } |
| 79 } | 79 } |
| 80 | 80 |
| 81 void FUNCTION_NAME(Filter_Process)(Dart_NativeArguments args) { | 81 void FUNCTION_NAME(Filter_Process)(Dart_NativeArguments args) { |
| 82 Dart_Handle filter_obj = Dart_GetNativeArgument(args, 0); | 82 Dart_Handle filter_obj = Dart_GetNativeArgument(args, 0); |
| 83 Filter* filter = GetFilter(filter_obj); | 83 Filter* filter = GetFilter(filter_obj); |
| 84 Dart_Handle data_obj = Dart_GetNativeArgument(args, 1); | 84 Dart_Handle data_obj = Dart_GetNativeArgument(args, 1); |
| 85 intptr_t start = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); |
| 86 intptr_t end = DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); |
| 87 intptr_t chunk_length = end - start; |
| 85 intptr_t length; | 88 intptr_t length; |
| 86 Dart_TypedData_Type type; | 89 Dart_TypedData_Type type; |
| 87 uint8_t* buffer = NULL; | 90 uint8_t* buffer = NULL; |
| 88 Dart_Handle result = Dart_TypedDataAcquireData( | 91 Dart_Handle result = Dart_TypedDataAcquireData( |
| 89 data_obj, &type, reinterpret_cast<void**>(&buffer), &length); | 92 data_obj, &type, reinterpret_cast<void**>(&buffer), &length); |
| 90 if (!Dart_IsError(result)) { | 93 if (!Dart_IsError(result)) { |
| 91 uint8_t* zlib_buffer = new uint8_t[length]; | 94 uint8_t* zlib_buffer = new uint8_t[chunk_length]; |
| 92 if (zlib_buffer == NULL) { | 95 if (zlib_buffer == NULL) { |
| 93 Dart_TypedDataReleaseData(data_obj); | 96 Dart_TypedDataReleaseData(data_obj); |
| 94 Dart_ThrowException(DartUtils::NewInternalError( | 97 Dart_ThrowException(DartUtils::NewInternalError( |
| 95 "Failed to allocate buffer for zlib")); | 98 "Failed to allocate buffer for zlib")); |
| 96 } | 99 } |
| 97 memmove(zlib_buffer, buffer, length); | 100 memmove(zlib_buffer, buffer + start, chunk_length); |
| 98 Dart_TypedDataReleaseData(data_obj); | 101 Dart_TypedDataReleaseData(data_obj); |
| 99 buffer = zlib_buffer; | 102 buffer = zlib_buffer; |
| 100 } else { | 103 } else { |
| 101 if (Dart_IsError(Dart_ListLength(data_obj, &length))) { | 104 if (Dart_IsError(Dart_ListLength(data_obj, &length))) { |
| 102 Dart_ThrowException(DartUtils::NewInternalError( | 105 Dart_ThrowException(DartUtils::NewInternalError( |
| 103 "Failed to get list length")); | 106 "Failed to get list length")); |
| 104 } | 107 } |
| 105 buffer = new uint8_t[length]; | 108 buffer = new uint8_t[chunk_length]; |
| 106 if (Dart_IsError(Dart_ListGetAsBytes(data_obj, 0, buffer, length))) { | 109 if (Dart_IsError(Dart_ListGetAsBytes( |
| 110 data_obj, start, buffer, chunk_length))) { |
| 107 delete[] buffer; | 111 delete[] buffer; |
| 108 Dart_ThrowException(DartUtils::NewInternalError( | 112 Dart_ThrowException(DartUtils::NewInternalError( |
| 109 "Failed to get list bytes")); | 113 "Failed to get list bytes")); |
| 110 } | 114 } |
| 111 } | 115 } |
| 112 // Process will take ownership of buffer, if successful. | 116 // Process will take ownership of buffer, if successful. |
| 113 if (!filter->Process(buffer, length)) { | 117 if (!filter->Process(buffer, chunk_length)) { |
| 114 delete[] buffer; | 118 delete[] buffer; |
| 115 EndFilter(filter_obj, filter); | 119 EndFilter(filter_obj, filter); |
| 116 Dart_ThrowException(DartUtils::NewInternalError( | 120 Dart_ThrowException(DartUtils::NewInternalError( |
| 117 "Call to Process while still processing data")); | 121 "Call to Process while still processing data")); |
| 118 } | 122 } |
| 119 } | 123 } |
| 120 | 124 |
| 121 | 125 |
| 122 void FUNCTION_NAME(Filter_Processed)(Dart_NativeArguments args) { | 126 void FUNCTION_NAME(Filter_Processed)(Dart_NativeArguments args) { |
| 123 Dart_Handle filter_obj = Dart_GetNativeArgument(args, 0); | 127 Dart_Handle filter_obj = Dart_GetNativeArgument(args, 0); |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 case Z_STREAM_ERROR: | 304 case Z_STREAM_ERROR: |
| 301 // An error occoured. | 305 // An error occoured. |
| 302 delete[] current_buffer_; | 306 delete[] current_buffer_; |
| 303 current_buffer_ = NULL; | 307 current_buffer_ = NULL; |
| 304 return -1; | 308 return -1; |
| 305 } | 309 } |
| 306 } | 310 } |
| 307 | 311 |
| 308 } // namespace bin | 312 } // namespace bin |
| 309 } // namespace dart | 313 } // namespace dart |
| OLD | NEW |