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

Unified Diff: mojo/public/c/bindings/lib/type_descriptor.c

Issue 2200843002: C bindings: Implement _DeepCopy() & some unittests. (Closed) Base URL: git@github.com:domokit/mojo.git@cgen_validate
Patch Set: fix tab indent, update sha1 Created 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/public/c/bindings/lib/type_descriptor.h ('k') | mojo/public/c/bindings/lib/union.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/c/bindings/lib/type_descriptor.c
diff --git a/mojo/public/c/bindings/lib/type_descriptor.c b/mojo/public/c/bindings/lib/type_descriptor.c
index 083738d8f9fca4cfa48c0f33797764cb13a8e2e7..34d577aa3dc4c308c7a19eae2bc73325fe7574b4 100644
--- a/mojo/public/c/bindings/lib/type_descriptor.c
+++ b/mojo/public/c/bindings/lib/type_descriptor.c
@@ -401,3 +401,60 @@ MojomValidationResult MojomType_DispatchValidate(
}
return MOJOM_VALIDATION_ERROR_NONE;
}
+
+bool MojomType_DispatchDeepCopy(struct MojomBuffer* buffer,
+ enum MojomTypeDescriptorType in_elem_type,
+ const void* in_type_desc,
+ const void* in_data,
+ void* out_data) {
+ assert(in_data);
+
+ const struct MojomUnionLayout* in_union_data =
+ (const struct MojomUnionLayout*)in_data;
+ struct MojomUnionLayout* out_union_data = (struct MojomUnionLayout*)out_data;
+ const union MojomPointer* in_pointer = in_data;
+ switch (in_elem_type) {
+ case MOJOM_TYPE_DESCRIPTOR_TYPE_MAP_PTR:
+ case MOJOM_TYPE_DESCRIPTOR_TYPE_STRUCT_PTR:
+ if (in_pointer->ptr == NULL) {
+ ((union MojomPointer*)out_data)->ptr = NULL;
+ break;
+ }
+ return MojomStruct_DeepCopy(
+ buffer, (const struct MojomTypeDescriptorStruct*)in_type_desc,
+ ((union MojomPointer*)in_data)->ptr,
+ out_data);
+ case MOJOM_TYPE_DESCRIPTOR_TYPE_ARRAY_PTR:
+ if (in_pointer->ptr == NULL) {
+ ((union MojomPointer*)out_data)->ptr = NULL;
+ break;
+ }
+ return MojomArray_DeepCopy(
+ buffer, (const struct MojomTypeDescriptorArray*)in_type_desc,
+ ((union MojomPointer*)in_data)->ptr,
+ out_data);
+ case MOJOM_TYPE_DESCRIPTOR_TYPE_UNION_PTR:
+ in_union_data = ((const union MojomPointer*)in_data)->ptr;
+ if (in_union_data == NULL) {
+ ((union MojomPointer*)out_data)->ptr = NULL;
+ break;
+ }
+ out_union_data =
+ MojomBuffer_Allocate(buffer, sizeof(struct MojomUnionLayout));
+ if (out_union_data == NULL)
+ return false;
+ ((union MojomPointer*)out_data)->ptr = out_union_data;
+ // Fall through.
+ case MOJOM_TYPE_DESCRIPTOR_TYPE_UNION:
+ return MojomUnion_DeepCopy(buffer,
+ (const struct MojomTypeDescriptorUnion*)in_type_desc,
+ in_union_data,
+ out_union_data);
+ case MOJOM_TYPE_DESCRIPTOR_TYPE_HANDLE:
+ case MOJOM_TYPE_DESCRIPTOR_TYPE_INTERFACE:
+ case MOJOM_TYPE_DESCRIPTOR_TYPE_POD:
+ break;
+ }
+
+ return true;
+}
« no previous file with comments | « mojo/public/c/bindings/lib/type_descriptor.h ('k') | mojo/public/c/bindings/lib/union.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698