-
Notifications
You must be signed in to change notification settings - Fork 364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deep copying of constructed types including sequences #2123
Comments
Good question ... I'd say there is no good reason we don't generate deep copy functions for C. There is a reasonable simple way to do it if you don't mind an extra copy: that's through the serializer. It is more of a hack than a good solution of course, but it goes like: cyclonedds/src/core/ddsc/tests/psmx.c Lines 1418 to 1433 in d8cef89
Caching the result of |
There is one nasty detail: booleans. This serializes to IDL, which says a boolean is represented as a byte that is either 0 or 1, and so that's what It used to pass them through unchanged, I fixed that fairly recently 😳 So maybe the trick won't work for you after all ... |
issue2123-add-deepcopyfunc-wip-20241102.diff.txt I started adding the _copy functions, here is my snapshot. |
Hi @okellogg! That's wonderful I think it is fine to do it "old school": serialising and deserialising is necessarily slower then a dedicated copy routine, adding yet another operation to So, in principle, I think the approach you are taking is sensible. I noticed a few things in the diff that you might want to do differently: firstly, there's an Secondly — but this, I think is something that's simply a result of sharing an early-stage version, because it is so obvious — sequences can't in general be While I think it'd be nice to use struct/union assignment and then patch any strings, sequence buffers, optionals and externals, I think it might be harder to do that than it would be to do a field-by-field copy, simply because patching up pointers in nested types would bring its own complications. Finally, I checked and for externals, the deep copy function is supposed to make a copy, so "external" and "optional" can be treated the same. Sequence buffers can be owned by the middleware or not and this is indicated in the Those are just some things that came to mind ... hopefully one or two of those turn out to be useful 🙂 |
- Create branch issue-2123-add-deepcopy-func from master @ d8cef89 - Work in progress, build currently fails on compiling CdrStreamOptimize.c generated for src/core/ddsc/tests/ CdrStreamOptimize.idl. src/idl/include/idl/tree.h src/idl/src/tree.c - Add function idl_is_scalar_type. src/core/ddsc/include/dds/ddsc/dds_public_alloc.h - Add defines for __alloc functions of primitive types. src/tools/idlc/src/libidlc/libidlc__generator.c - In function print_includes add generation of #include <string.h> for strcat() / strcpy() required by libidlc__types.c emit_struct() added generation of _copy function. src/tools/idlc/src/libidlc/libidlc__types.c - In various emit() functions remove superfluous ending semicolon in generated __alloc() macros. - In function emit_implicit_sequence add generation of _copy function. - In function emit_struct start adding generation of _copy function. Generation for @optional and @external members is work in progress and struct supertypes have not yet been considered. Also, have not started adding _copy generation in emit_union().
Many thanks for your comments. |
I notice that idlc generates
__alloc()
and_free()
functions for constructed types but does not generate a function for deep copying.Deep copy functions would make life easier when programming in C but are particularly interesting when making language bindings e.g. to C++ or Ada, where the assignment operator is required to have deep copy semantics.
For example,
How is this handled in CycloneDDS?
The text was updated successfully, but these errors were encountered: