Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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/dfe.h" | 5 #include "bin/dfe.h" |
| 6 #include "bin/dartutils.h" | 6 #include "bin/dartutils.h" |
| 7 #include "bin/error_exit.h" | 7 #include "bin/error_exit.h" |
| 8 #include "bin/file.h" | 8 #include "bin/file.h" |
| 9 | 9 |
| 10 #include "vm/kernel.h" | 10 #include "vm/kernel.h" |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 *kernel_ir_size = -1; | 139 *kernel_ir_size = -1; |
| 140 void* script_file = DartUtils::OpenFile(script_uri, false); | 140 void* script_file = DartUtils::OpenFile(script_uri, false); |
| 141 if (script_file != NULL) { | 141 if (script_file != NULL) { |
| 142 const uint8_t* buffer = NULL; | 142 const uint8_t* buffer = NULL; |
| 143 DartUtils::ReadFile(&buffer, kernel_ir_size, script_file); | 143 DartUtils::ReadFile(&buffer, kernel_ir_size, script_file); |
| 144 DartUtils::CloseFile(script_file); | 144 DartUtils::CloseFile(script_file); |
| 145 if (*kernel_ir_size > 0 && buffer != NULL) { | 145 if (*kernel_ir_size > 0 && buffer != NULL) { |
| 146 // We need a temporary variable because SniffForMagicNumber modifies the | 146 // We need a temporary variable because SniffForMagicNumber modifies the |
| 147 // buffer pointer to skip snapshot magic number. | 147 // buffer pointer to skip snapshot magic number. |
| 148 const uint8_t* temp = buffer; | 148 const uint8_t* temp = buffer; |
| 149 if (DartUtils::SniffForMagicNumber(&temp, kernel_ir_size) != | 149 if (DartUtils::SniffForMagicNumber(temp, *kernel_ir_size) != |
|
siva
2017/08/04 17:11:29
Now that SniffMagicNumber does not modify the buff
rmacnak
2017/08/07 18:18:57
Done.
| |
| 150 DartUtils::kKernelMagicNumber) { | 150 DartUtils::kKernelMagicNumber) { |
| 151 free(const_cast<uint8_t*>(buffer)); | 151 free(const_cast<uint8_t*>(buffer)); |
| 152 *kernel_ir = NULL; | 152 *kernel_ir = NULL; |
| 153 *kernel_ir_size = -1; | 153 *kernel_ir_size = -1; |
| 154 return false; | 154 return false; |
| 155 } else { | 155 } else { |
| 156 // Do not free buffer if this is a kernel file - kernel_file will be | 156 // Do not free buffer if this is a kernel file - kernel_file will be |
| 157 // backed by the same memory as the buffer and caller will own it. | 157 // backed by the same memory as the buffer and caller will own it. |
| 158 // Caller is responsible for freeing the buffer when this function | 158 // Caller is responsible for freeing the buffer when this function |
| 159 // returns true. | 159 // returns true. |
| 160 *kernel_ir = buffer; | 160 *kernel_ir = buffer; |
| 161 return true; | 161 return true; |
| 162 } | 162 } |
| 163 } | 163 } |
| 164 } | 164 } |
| 165 return false; | 165 return false; |
| 166 } | 166 } |
| 167 | 167 |
| 168 } // namespace bin | 168 } // namespace bin |
| 169 } // namespace dart | 169 } // namespace dart |
| OLD | NEW |