-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Tree/Recursive struct support in thrift #84
Conversation
Thanks @djwatson created THRIFT-2421 to track it and will review |
A common complaint is that you can't express trees or other recursive structures in thrift easily - unlike protobufs. This diff loosens up the parser to allow using structs before they are defined (and uses typedef as a forward declaration). This diff is actually enough to make recursive types work for some dyamic languages (I tried php, works out of the box!) Other languages will need forward declarations, or ways to box types, to make this work (i.e. C++ needs both forward decls and a way to express structs as pointers)
For cpp added a cpp.ref annotation. Users will have to make some recursive types use references to avoid a struct containing itself. Also had to explicitly check for null references when reading/writing, so we know to set the reference to null. Merge from fb's branch of facebook/fbthrift@9b36d51 Fb uses C++11 extensively, this merge changes the type to a raw pointer and adds deletes where necessary. This is *very* similar to how protobufs does it.
Hand indent to make code easier to read
Move some funcs to .cpp file to avoid compilation errors using forward declares
This change breaks c++ generation. After this change in compiler/cpp/src/generate/t_cpp_generator.cc
linker complains about missed destructor. |
The destructor is defined in the .cpp file now: // Destructor
Is your _types.cpp linked in? Or other repro? |
There's a log of a failure in Thrift's nightly build. https://builds.apache.org/job/Thrift/1123/console tutorial/shared.thrift and tutorial/tutorial.thrift end up causing problems. The relevant Makefile.am appears to be building in the _types.cpp. I have not looked at the generated source. My current suspicion is that the "final" attribute check is causing problems, but that is currently just a hunch. |
Hi Dave, |
Thanks guys, fix: #98 |
Client: cpp Patch: Dave Watson Github Pull Request: This closes apache#84 ---- commit b6134ce Date: 2014-03-20T18:12:04Z Recursive structs support in parser A common complaint is that you can't express trees or other recursive structures in thrift easily - unlike protobufs. This diff loosens up the parser to allow using structs before they are defined (and uses typedef as a forward declaration). This diff is actually enough to make recursive types work for some dyamic languages (I tried php, works out of the box!) Other languages will need forward declarations, or ways to box types, to make this work (i.e. C++ needs both forward decls and a way to express structs as pointers)
I see a bunch of mutual recursive structure support in the tests, but nothing for an optional single self-referential member, like
Thift does not appear to generate sensible code for this. The example I am working with is from the opentracing jaeger toolset, namely the IDL
This works fine in Java, Go, etc. But in C++ it produces the nonsensical code
in which the class is a by-value member of its self. I think the ideal solution here would be to adopt something like |
Anyone else facing that issue: workaround is to declare a reference:
Note the |
Update KeysScan.md
Patches to implement tree/list/co-recursive structures in thrift, a la protobufs.