diff options
author | Robert <me@rwinslow.com> | 2016-07-22 15:12:35 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-22 15:12:35 -0700 |
commit | a56c6e51950353bc96327275f940e043bea7843d (patch) | |
tree | cd7ad5d44999fbce0f4fb8b6e9a2cafcf3467402 /src/idl_gen_python.cpp | |
parent | 5efa22447e5496549159cf2e55ccff0436a7b8aa (diff) | |
parent | 483223870852aac6819a4147605447b552bb3b33 (diff) | |
download | flatbuffers-a56c6e51950353bc96327275f940e043bea7843d.tar.gz flatbuffers-a56c6e51950353bc96327275f940e043bea7843d.tar.bz2 flatbuffers-a56c6e51950353bc96327275f940e043bea7843d.zip |
Merge pull request #363 from danring/fix-341
Emit GetRootAs methods for all types in Go and Python
Diffstat (limited to 'src/idl_gen_python.cpp')
-rw-r--r-- | src/idl_gen_python.cpp | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/src/idl_gen_python.cpp b/src/idl_gen_python.cpp index 7e8dc0eb..52944bfc 100644 --- a/src/idl_gen_python.cpp +++ b/src/idl_gen_python.cpp @@ -94,7 +94,7 @@ static void NewRootTypeFromBuffer(const StructDef &struct_def, code += Indent + Indent + "x = " + struct_def.name + "()\n"; code += Indent + Indent + "x.Init(buf, n + offset)\n"; code += Indent + Indent + "return x\n"; - code += "\n\n"; + code += "\n"; } // Initialize an existing object with other data, to avoid an allocation. @@ -478,13 +478,12 @@ static void GenTableBuilders(const StructDef &struct_def, // Generate struct or table methods. static void GenStruct(const StructDef &struct_def, - std::string *code_ptr, - StructDef *root_struct_def) { + std::string *code_ptr) { if (struct_def.generated) return; GenComment(struct_def.doc_comment, code_ptr, nullptr, "# "); BeginClass(struct_def, code_ptr); - if (&struct_def == root_struct_def) { + if (!struct_def.fixed) { // Generate a special accessor for the table that has been declared as // the root type. NewRootTypeFromBuffer(struct_def, code_ptr); @@ -621,7 +620,7 @@ class PythonGenerator : public BaseGenerator { it != parser_.structs_.vec.end(); ++it) { auto &struct_def = **it; std::string declcode; - GenStruct(struct_def, &declcode, parser_.root_struct_def_); + GenStruct(struct_def, &declcode); if (!SaveType(struct_def, declcode, true)) return false; } return true; |