Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(414)

Side by Side Diff: utils/archive/messaging.c

Issue 10824210: Fix the archive code so that it compiles in a stricter mode. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Small fixes Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « utils/archive/messaging.h ('k') | utils/archive/options.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <errno.h> 5 #include <errno.h>
6 #include <stdarg.h> 6 #include <stdarg.h>
7 7
8 #include "messaging.h" 8 #include "messaging.h"
9 9
10 void postResult(Dart_Port p, bool success, int err, Dart_CObject* response) { 10 void postResult(Dart_Port p, bool success, int err, Dart_CObject* response) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 49
50 DART_NULL(null_response); 50 DART_NULL(null_response);
51 postResult(p, true, 0, &null_response); 51 postResult(p, true, 0, &null_response);
52 } 52 }
53 53
54 bool checkError(Dart_Port p, struct archive* a, int result) { 54 bool checkError(Dart_Port p, struct archive* a, int result) {
55 if (result == ARCHIVE_OK) return false; 55 if (result == ARCHIVE_OK) return false;
56 // TODO(nweiz): What should we do about non-fatal warnings? 56 // TODO(nweiz): What should we do about non-fatal warnings?
57 if (result == ARCHIVE_WARN) return false; 57 if (result == ARCHIVE_WARN) return false;
58 postError(p, a); 58 postError(p, a);
59 return true;
59 } 60 }
60 61
61 bool checkPointerError(Dart_Port p, void* pointer, char* name) { 62 bool checkPointerError(Dart_Port p, void* pointer, char* name) {
62 if (pointer != NULL) return false; 63 if (pointer != NULL) return false;
63 char buffer[100]; 64 char buffer[100];
64 snprintf(buffer, 100, "Failed to allocate memory for %s.", name); 65 snprintf(buffer, 100, "Failed to allocate memory for %s.", name);
65 DART_STRING(error_string, buffer); 66 DART_STRING(error_string, buffer);
66 postResult(p, false, ENOMEM, &error_string); 67 postResult(p, false, ENOMEM, &error_string);
67 return true; 68 return true;
68 } 69 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 if (arg->type == kInt32) return arg; 114 if (arg->type == kInt32) return arg;
114 postInvalidArgument(p, "Invalid argument %d: expected integer, was type %d.", 115 postInvalidArgument(p, "Invalid argument %d: expected integer, was type %d.",
115 i+1, arg->type); 116 i+1, arg->type);
116 return NULL; 117 return NULL;
117 } 118 }
118 119
119 int64_t getInteger(Dart_CObject* object) { 120 int64_t getInteger(Dart_CObject* object) {
120 assert(object->type == kInt64 || object->type == kInt32); 121 assert(object->type == kInt64 || object->type == kInt32);
121 if (object->type == kInt64) return object->value.as_int64; 122 if (object->type == kInt64) return object->value.as_int64;
122 if (object->type == kInt32) return (int64_t) object->value.as_int32; 123 if (object->type == kInt32) return (int64_t) object->value.as_int32;
124 return 0; // Should never reach this point.
123 } 125 }
124 126
125 Dart_CObject* getNullableStringArgument(Dart_Port p, Dart_CObject* request, 127 Dart_CObject* getNullableStringArgument(Dart_Port p, Dart_CObject* request,
126 int i) { 128 int i) {
127 Dart_CObject* arg = getArgument(p, request, i); 129 Dart_CObject* arg = getArgument(p, request, i);
128 if (arg == NULL) return NULL; 130 if (arg == NULL) return NULL;
129 if (arg->type == kNull) return arg; 131 if (arg->type == kNull) return arg;
130 if (arg->type == kString) return arg; 132 if (arg->type == kString) return arg;
131 postInvalidArgument(p, "Invalid argument %d: expected string or null, was " \ 133 postInvalidArgument(p, "Invalid argument %d: expected string or null, was " \
132 "type %d.", i+1, arg->type); 134 "type %d.", i+1, arg->type);
133 return NULL; 135 return NULL;
134 } 136 }
135 137
136 char* getNullableString(Dart_CObject* object) { 138 char* getNullableString(Dart_CObject* object) {
137 assert(object->type == kNull || object->type == kString); 139 assert(object->type == kNull || object->type == kString);
138 if (object->type == kString) return object->value.as_string; 140 if (object->type == kString) return object->value.as_string;
139 return NULL; 141 return NULL;
140 } 142 }
143
144 bool getOptionArguments(Dart_Port p, Dart_CObject* request, char** module,
145 char** name, char** value) {
146 *module = *name = *value = NULL;
147
148 Dart_CObject* wrappedModule = getNullableStringArgument(p, request, 0);
149 if (wrappedModule == NULL) return false;
150 *module = getNullableString(wrappedModule);
151
152 Dart_CObject* wrappedName = getTypedArgument(p, request, 0, kString);
153 if (wrappedName == NULL) return false;
154 *name = wrappedName->value.as_string;
155
156 Dart_CObject* wrappedValue = getNullableStringArgument(p, request, 0);
157 if (wrappedValue == NULL) return false;
158 *value = getNullableString(wrappedValue);
159
160 return true;
161 }
162
OLDNEW
« no previous file with comments | « utils/archive/messaging.h ('k') | utils/archive/options.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698