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

Side by Side Diff: third_party/protobuf/ruby/ext/google/protobuf_c/message.c

Issue 2495533002: third_party/protobuf: Update to HEAD (83d681ee2c) (Closed)
Patch Set: Make chrome settings proto generated file a component Created 4 years 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
OLDNEW
1 // Protocol Buffers - Google's data interchange format 1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2014 Google Inc. All rights reserved. 2 // Copyright 2014 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/ 3 // https://developers.google.com/protocol-buffers/
4 // 4 //
5 // Redistribution and use in source and binary forms, with or without 5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are 6 // modification, are permitted provided that the following conditions are
7 // met: 7 // met:
8 // 8 //
9 // * Redistributions of source code must retain the above copyright 9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer. 10 // notice, this list of conditions and the following disclaimer.
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 rb_raise(rb_eArgError, "No value provided to setter."); 171 rb_raise(rb_eArgError, "No value provided to setter.");
172 } 172 }
173 layout_set(self->descriptor->layout, Message_data(self), f, argv[1]); 173 layout_set(self->descriptor->layout, Message_data(self), f, argv[1]);
174 return Qnil; 174 return Qnil;
175 } else { 175 } else {
176 return layout_get(self->descriptor->layout, Message_data(self), f); 176 return layout_get(self->descriptor->layout, Message_data(self), f);
177 } 177 }
178 } 178 }
179 } 179 }
180 180
181 VALUE Message_respond_to_missing(int argc, VALUE* argv, VALUE _self) {
182 MessageHeader* self;
183 VALUE method_name, method_str;
184 char* name;
185 size_t name_len;
186 bool setter;
187 const upb_oneofdef* o;
188 const upb_fielddef* f;
189
190 TypedData_Get_Struct(_self, MessageHeader, &Message_type, self);
191 if (argc < 1) {
192 rb_raise(rb_eArgError, "Expected method name as first argument.");
193 }
194 method_name = argv[0];
195 if (!SYMBOL_P(method_name)) {
196 rb_raise(rb_eArgError, "Expected symbol as method name.");
197 }
198 method_str = rb_id2str(SYM2ID(method_name));
199 name = RSTRING_PTR(method_str);
200 name_len = RSTRING_LEN(method_str);
201 setter = false;
202
203 // Setters have names that end in '='.
204 if (name[name_len - 1] == '=') {
205 setter = true;
206 name_len--;
207 }
208
209 // See if this name corresponds to either a oneof or field in this message.
210 if (!upb_msgdef_lookupname(self->descriptor->msgdef, name, name_len, &f,
211 &o)) {
212 return rb_call_super(argc, argv);
213 }
214 if (o != NULL) {
215 return setter ? Qfalse : Qtrue;
216 }
217 return Qtrue;
218 }
219
181 int Message_initialize_kwarg(VALUE key, VALUE val, VALUE _self) { 220 int Message_initialize_kwarg(VALUE key, VALUE val, VALUE _self) {
182 MessageHeader* self; 221 MessageHeader* self;
183 VALUE method_str; 222 VALUE method_str;
184 char* name; 223 char* name;
185 const upb_fielddef* f; 224 const upb_fielddef* f;
186 TypedData_Get_Struct(_self, MessageHeader, &Message_type, self); 225 TypedData_Get_Struct(_self, MessageHeader, &Message_type, self);
187 226
188 if (!SYMBOL_P(key)) { 227 if (!SYMBOL_P(key)) {
189 rb_raise(rb_eArgError, 228 rb_raise(rb_eArgError,
190 "Expected symbols as hash keys in initialization map."); 229 "Expected symbols as hash keys in initialization map.");
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 * Message.==(other) => boolean 337 * Message.==(other) => boolean
299 * 338 *
300 * Performs a deep comparison of this message with another. Messages are equal 339 * Performs a deep comparison of this message with another. Messages are equal
301 * if they have the same type and if each field is equal according to the :== 340 * if they have the same type and if each field is equal according to the :==
302 * method's semantics (a more efficient comparison may actually be done if the 341 * method's semantics (a more efficient comparison may actually be done if the
303 * field is of a primitive type). 342 * field is of a primitive type).
304 */ 343 */
305 VALUE Message_eq(VALUE _self, VALUE _other) { 344 VALUE Message_eq(VALUE _self, VALUE _other) {
306 MessageHeader* self; 345 MessageHeader* self;
307 MessageHeader* other; 346 MessageHeader* other;
347 if (TYPE(_self) != TYPE(_other)) {
348 return Qfalse;
349 }
308 TypedData_Get_Struct(_self, MessageHeader, &Message_type, self); 350 TypedData_Get_Struct(_self, MessageHeader, &Message_type, self);
309 TypedData_Get_Struct(_other, MessageHeader, &Message_type, other); 351 TypedData_Get_Struct(_other, MessageHeader, &Message_type, other);
310 352
311 if (self->descriptor != other->descriptor) { 353 if (self->descriptor != other->descriptor) {
312 return Qfalse; 354 return Qfalse;
313 } 355 }
314 356
315 return layout_eq(self->descriptor->layout, 357 return layout_eq(self->descriptor->layout,
316 Message_data(self), 358 Message_data(self),
317 Message_data(other)); 359 Message_data(other));
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 rb_ivar_set(klass, descriptor_instancevar_interned, 494 rb_ivar_set(klass, descriptor_instancevar_interned,
453 get_def_obj(desc->msgdef)); 495 get_def_obj(desc->msgdef));
454 rb_define_alloc_func(klass, Message_alloc); 496 rb_define_alloc_func(klass, Message_alloc);
455 rb_require("google/protobuf/message_exts"); 497 rb_require("google/protobuf/message_exts");
456 rb_include_module(klass, rb_eval_string("Google::Protobuf::MessageExts")); 498 rb_include_module(klass, rb_eval_string("Google::Protobuf::MessageExts"));
457 rb_extend_object( 499 rb_extend_object(
458 klass, rb_eval_string("Google::Protobuf::MessageExts::ClassMethods")); 500 klass, rb_eval_string("Google::Protobuf::MessageExts::ClassMethods"));
459 501
460 rb_define_method(klass, "method_missing", 502 rb_define_method(klass, "method_missing",
461 Message_method_missing, -1); 503 Message_method_missing, -1);
504 rb_define_method(klass, "respond_to_missing?",
505 Message_respond_to_missing, -1);
462 rb_define_method(klass, "initialize", Message_initialize, -1); 506 rb_define_method(klass, "initialize", Message_initialize, -1);
463 rb_define_method(klass, "dup", Message_dup, 0); 507 rb_define_method(klass, "dup", Message_dup, 0);
464 // Also define #clone so that we don't inherit Object#clone. 508 // Also define #clone so that we don't inherit Object#clone.
465 rb_define_method(klass, "clone", Message_dup, 0); 509 rb_define_method(klass, "clone", Message_dup, 0);
466 rb_define_method(klass, "==", Message_eq, 1); 510 rb_define_method(klass, "==", Message_eq, 1);
467 rb_define_method(klass, "hash", Message_hash, 0); 511 rb_define_method(klass, "hash", Message_hash, 0);
468 rb_define_method(klass, "to_h", Message_to_h, 0); 512 rb_define_method(klass, "to_h", Message_to_h, 0);
469 rb_define_method(klass, "to_hash", Message_to_h, 0); 513 rb_define_method(klass, "to_hash", Message_to_h, 0);
470 rb_define_method(klass, "inspect", Message_inspect, 0); 514 rb_define_method(klass, "inspect", Message_inspect, 0);
471 rb_define_method(klass, "[]", Message_index, 1); 515 rb_define_method(klass, "[]", Message_index, 1);
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 VALUE Google_Protobuf_deep_copy(VALUE self, VALUE obj) { 613 VALUE Google_Protobuf_deep_copy(VALUE self, VALUE obj) {
570 VALUE klass = CLASS_OF(obj); 614 VALUE klass = CLASS_OF(obj);
571 if (klass == cRepeatedField) { 615 if (klass == cRepeatedField) {
572 return RepeatedField_deep_copy(obj); 616 return RepeatedField_deep_copy(obj);
573 } else if (klass == cMap) { 617 } else if (klass == cMap) {
574 return Map_deep_copy(obj); 618 return Map_deep_copy(obj);
575 } else { 619 } else {
576 return Message_deep_copy(obj); 620 return Message_deep_copy(obj);
577 } 621 }
578 } 622 }
OLDNEW
« no previous file with comments | « third_party/protobuf/ruby/ext/google/protobuf_c/map.c ('k') | third_party/protobuf/ruby/ext/google/protobuf_c/protobuf.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698