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

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

Issue 10832116: Attach the native entry struct to the ArchiveEntry object. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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
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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 } 59 }
60 60
61 bool checkPointerError(Dart_Port p, void* pointer, char* name) {
62 if (pointer != NULL) return false;
63 char buffer[100];
64 snprintf(buffer, 100, "Failed to allocate memory for %s.", name);
65 DART_STRING(error_string, buffer);
66 postResult(p, false, ENOMEM, &error_string);
67 return true;
68 }
69
61 bool checkType(Dart_Port p, Dart_CObject* object, enum Type type) { 70 bool checkType(Dart_Port p, Dart_CObject* object, enum Type type) {
62 if (object->type == type) return false; 71 if (object->type == type) return false;
63 postInvalidArgument(p, "Invalid argument: expected type %d, was type %d.", 72 postInvalidArgument(p, "Invalid argument: expected type %d, was type %d.",
64 type, object->type); 73 type, object->type);
65 return true; 74 return true;
66 } 75 }
67 76
68 void checkResult(Dart_Port p, struct archive* a, int result) { 77 void checkResult(Dart_Port p, struct archive* a, int result) {
69 if (checkError(p, a, result)) return; 78 if (checkError(p, a, result)) return;
70 postSuccess(p, NULL); 79 postSuccess(p, NULL);
71 } 80 }
72 81
82 void checkPointerResult(Dart_Port p, void* pointer, char* name) {
83 if (checkPointerError(p, pointer, name)) return;
84 DART_INT64(result, (intptr_t) pointer);
85 postSuccess(p, &result);
86 }
87
73 Dart_CObject* getArgument(Dart_Port p, Dart_CObject* request, int i) { 88 Dart_CObject* getArgument(Dart_Port p, Dart_CObject* request, int i) {
74 if (checkType(p, request, kArray)) return NULL; 89 if (checkType(p, request, kArray)) return NULL;
75 90
76 i += 2; // Skip over the message name and archive id. 91 i += 2; // Skip over the message name and archive id.
77 if (request->value.as_array.length > i) { 92 if (request->value.as_array.length > i) {
78 return request->value.as_array.values[i]; 93 return request->value.as_array.values[i];
79 } 94 }
80 95
81 postInvalidArgument(p, "Invalid argument: expected at least %d arguments, " \ 96 postInvalidArgument(p, "Invalid argument: expected at least %d arguments, " \
82 "were %d.", i - 2, request->value.as_array.length - 2); 97 "were %d.", i - 2, request->value.as_array.length - 2);
(...skipping 16 matching lines...) Expand all
99 postInvalidArgument(p, "Invalid argument %d: expected integer, was type %d.", 114 postInvalidArgument(p, "Invalid argument %d: expected integer, was type %d.",
100 i+1, arg->type); 115 i+1, arg->type);
101 return NULL; 116 return NULL;
102 } 117 }
103 118
104 int64_t getInteger(Dart_CObject* object) { 119 int64_t getInteger(Dart_CObject* object) {
105 assert(object->type == kInt64 || object->type == kInt32); 120 assert(object->type == kInt64 || object->type == kInt32);
106 if (object->type == kInt64) return object->value.as_int64; 121 if (object->type == kInt64) return object->value.as_int64;
107 if (object->type == kInt32) return (int64_t) object->value.as_int32; 122 if (object->type == kInt32) return (int64_t) object->value.as_int32;
108 } 123 }
124
125 Dart_CObject* getNullableStringArgument(Dart_Port p, Dart_CObject* request,
126 int i) {
127 Dart_CObject* arg = getArgument(p, request, i);
128 if (arg == NULL) return NULL;
129 if (arg->type == kNull) return arg;
130 if (arg->type == kString) return arg;
131 postInvalidArgument(p, "Invalid argument %d: expected string or null, was " \
132 "type %d.", i+1, arg->type);
133 return NULL;
134 }
135
136 char* getNullableString(Dart_CObject* object) {
137 assert(object->type == kNull || object->type == kString);
138 if (object->type == kString) return object->value.as_string;
139 return NULL;
140 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698