OLD | NEW |
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 "bin/file.h" | 5 #include "bin/file.h" |
6 #include "bin/platform.h" | 6 #include "bin/platform.h" |
7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 | 8 |
9 | 9 |
10 void FUNCTION_NAME(Platform_NumberOfProcessors)(Dart_NativeArguments args) { | 10 void FUNCTION_NAME(Platform_NumberOfProcessors)(Dart_NativeArguments args) { |
11 Dart_EnterScope(); | 11 Dart_EnterScope(); |
12 Dart_SetReturnValue(args, Dart_NewInteger(Platform::NumberOfProcessors())); | 12 Dart_SetReturnValue(args, Dart_NewInteger(Platform::NumberOfProcessors())); |
13 Dart_ExitScope(); | 13 Dart_ExitScope(); |
14 } | 14 } |
15 | 15 |
16 | 16 |
17 void FUNCTION_NAME(Platform_OperatingSystem)(Dart_NativeArguments args) { | 17 void FUNCTION_NAME(Platform_OperatingSystem)(Dart_NativeArguments args) { |
18 Dart_EnterScope(); | 18 Dart_EnterScope(); |
19 Dart_SetReturnValue(args, | 19 Dart_SetReturnValue(args, DartUtils::NewString(Platform::OperatingSystem())); |
20 Dart_NewStringFromCString(Platform::OperatingSystem())); | |
21 Dart_ExitScope(); | 20 Dart_ExitScope(); |
22 } | 21 } |
23 | 22 |
24 | 23 |
25 void FUNCTION_NAME(Platform_PathSeparator)(Dart_NativeArguments args) { | 24 void FUNCTION_NAME(Platform_PathSeparator)(Dart_NativeArguments args) { |
26 Dart_EnterScope(); | 25 Dart_EnterScope(); |
27 Dart_SetReturnValue(args, Dart_NewStringFromCString(File::PathSeparator())); | 26 Dart_SetReturnValue(args, DartUtils::NewString(File::PathSeparator())); |
28 Dart_ExitScope(); | 27 Dart_ExitScope(); |
29 } | 28 } |
30 | 29 |
31 | 30 |
32 void FUNCTION_NAME(Platform_LocalHostname)(Dart_NativeArguments args) { | 31 void FUNCTION_NAME(Platform_LocalHostname)(Dart_NativeArguments args) { |
33 Dart_EnterScope(); | 32 Dart_EnterScope(); |
34 const intptr_t HOSTNAME_LENGTH = 256; | 33 const intptr_t HOSTNAME_LENGTH = 256; |
35 char hostname[HOSTNAME_LENGTH]; | 34 char hostname[HOSTNAME_LENGTH]; |
36 if (Platform::LocalHostname(hostname, HOSTNAME_LENGTH)) { | 35 if (Platform::LocalHostname(hostname, HOSTNAME_LENGTH)) { |
37 Dart_SetReturnValue(args, Dart_NewStringFromCString(hostname)); | 36 Dart_SetReturnValue(args, DartUtils::NewString(hostname)); |
38 } else { | 37 } else { |
39 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); | 38 Dart_SetReturnValue(args, DartUtils::NewDartOSError()); |
40 } | 39 } |
41 Dart_ExitScope(); | 40 Dart_ExitScope(); |
42 } | 41 } |
43 | 42 |
44 | 43 |
45 void FUNCTION_NAME(Platform_Environment)(Dart_NativeArguments args) { | 44 void FUNCTION_NAME(Platform_Environment)(Dart_NativeArguments args) { |
46 Dart_EnterScope(); | 45 Dart_EnterScope(); |
47 intptr_t count = 0; | 46 intptr_t count = 0; |
48 char** env = Platform::Environment(&count); | 47 char** env = Platform::Environment(&count); |
49 if (env == NULL) { | 48 if (env == NULL) { |
50 OSError error(-1, | 49 OSError error(-1, |
51 "Failed to retrieve environment variables.", | 50 "Failed to retrieve environment variables.", |
52 OSError::kUnknown); | 51 OSError::kUnknown); |
53 Dart_SetReturnValue(args, DartUtils::NewDartOSError(&error)); | 52 Dart_SetReturnValue(args, DartUtils::NewDartOSError(&error)); |
54 } else { | 53 } else { |
55 Dart_Handle result = Dart_NewList(count); | 54 Dart_Handle result = Dart_NewList(count); |
56 if (Dart_IsError(result)) { | 55 if (Dart_IsError(result)) { |
| 56 Platform::FreeEnvironment(env, count); |
57 Dart_PropagateError(result); | 57 Dart_PropagateError(result); |
58 } | 58 } |
59 for (intptr_t i = 0; i < count; i++) { | 59 for (intptr_t i = 0; i < count; i++) { |
60 Dart_Handle str = Dart_NewStringFromCString(env[i]); | 60 Dart_Handle str = DartUtils::NewString(env[i]); |
61 if (Dart_IsError(str)) { | 61 if (Dart_IsError(str)) { |
| 62 Platform::FreeEnvironment(env, count); |
62 Dart_PropagateError(str); | 63 Dart_PropagateError(str); |
63 } | 64 } |
64 Dart_Handle error = Dart_ListSetAt(result, i, str); | 65 Dart_Handle error = Dart_ListSetAt(result, i, str); |
65 if (Dart_IsError(error)) { | 66 if (Dart_IsError(error)) { |
| 67 Platform::FreeEnvironment(env, count); |
66 Dart_PropagateError(error); | 68 Dart_PropagateError(error); |
67 } | 69 } |
68 } | 70 } |
69 delete[] env; | 71 Platform::FreeEnvironment(env, count); |
70 Dart_SetReturnValue(args, result); | 72 Dart_SetReturnValue(args, result); |
71 } | 73 } |
72 Dart_ExitScope(); | 74 Dart_ExitScope(); |
73 } | 75 } |
OLD | NEW |