OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 #ifndef VM_OS_H_ | 5 #ifndef VM_OS_H_ |
6 #define VM_OS_H_ | 6 #define VM_OS_H_ |
7 | 7 |
8 #include "vm/globals.h" | 8 #include "vm/globals.h" |
9 | 9 |
| 10 // SNPRINT is a macro wrapping OS::SNPrint which makes two calls. The first call |
| 11 // is with NULL for the buffer. This call returns the number of bytes that would |
| 12 // have been written had the buffer not been NULL. The macro allocates that many |
| 13 // bytes plus room for the null terminator, and makes a second call to |
| 14 // OS::SNPrint, passing the allocated buffer. |
| 15 // |
| 16 // The reason for wrapping OS::SNPrint in a macro is so that the format string |
| 17 // literal can be passed directly to both calls without doing a copy-paste. |
| 18 // The format string literal must be passed directly to both calls to make sure |
| 19 // that we get compiler errors when the format string does not match the passed |
| 20 // arguments. |
| 21 #if defined(_MSC_VER_) |
| 22 #define SNPRINT(buffer, allocator, format, ...) \ |
| 23 { \ |
| 24 intptr_t len = OS::SNPrint(NULL, 0, (format), __VA_ARGS__); \ |
| 25 (buffer) = reinterpret_cast<char*>((allocator)(len + 1)); \ |
| 26 ASSERT(buffer != NULL); \ |
| 27 OS::SNPrint((buffer), len + 1, (format), __VA_ARGS__); \ |
| 28 } \ |
| 29 |
| 30 #else |
| 31 #define SNPRINT(buffer, allocator, format, ...) \ |
| 32 { \ |
| 33 intptr_t len = OS::SNPrint(NULL, 0, (format), ##__VA_ARGS__); \ |
| 34 (buffer) = reinterpret_cast<char*>((allocator)(len + 1)); \ |
| 35 ASSERT(buffer != NULL); \ |
| 36 OS::SNPrint((buffer), len + 1, (format), ##__VA_ARGS__); \ |
| 37 } \ |
| 38 |
| 39 #endif |
| 40 |
10 // Forward declarations. | 41 // Forward declarations. |
11 struct tm; | 42 struct tm; |
12 | 43 |
13 namespace dart { | 44 namespace dart { |
14 | 45 |
15 // Forward declarations. | 46 // Forward declarations. |
16 class Isolate; | 47 class Isolate; |
17 | 48 |
18 // Interface to the underlying OS platform. | 49 // Interface to the underlying OS platform. |
19 class OS { | 50 class OS { |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 static void Shutdown(); | 169 static void Shutdown(); |
139 | 170 |
140 static void Abort(); | 171 static void Abort(); |
141 | 172 |
142 static void Exit(int code); | 173 static void Exit(int code); |
143 }; | 174 }; |
144 | 175 |
145 } // namespace dart | 176 } // namespace dart |
146 | 177 |
147 #endif // VM_OS_H_ | 178 #endif // VM_OS_H_ |
OLD | NEW |