From d770cc18f80257b520c2cf9cdc5ddea707b38680 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Mon, 13 Aug 2018 15:02:35 -0400 Subject: [PATCH] Upgrade Rust Flatbuffers --- build_extra/flatbuffers/BUILD.gn | 3 +++ gclient_config.py | 5 ++-- src/handlers.rs | 42 +++++++++----------------------- src/msg.fbs | 6 ++--- third_party | 2 +- 5 files changed, 22 insertions(+), 36 deletions(-) diff --git a/build_extra/flatbuffers/BUILD.gn b/build_extra/flatbuffers/BUILD.gn index d3ace99c57..aaf82422c5 100644 --- a/build_extra/flatbuffers/BUILD.gn +++ b/build_extra/flatbuffers/BUILD.gn @@ -59,12 +59,15 @@ source_set("compiler_files") { "$fb_src/src/code_generators.cpp", "$fb_src/src/flatc.cpp", "$fb_src/src/idl_gen_cpp.cpp", + "$fb_src/src/idl_gen_dart.cpp", "$fb_src/src/idl_gen_fbs.cpp", "$fb_src/src/idl_gen_general.cpp", "$fb_src/src/idl_gen_go.cpp", "$fb_src/src/idl_gen_grpc.cpp", "$fb_src/src/idl_gen_js.cpp", "$fb_src/src/idl_gen_json_schema.cpp", + "$fb_src/src/idl_gen_lobster.cpp", + "$fb_src/src/idl_gen_lua.cpp", "$fb_src/src/idl_gen_php.cpp", "$fb_src/src/idl_gen_python.cpp", "$fb_src/src/idl_gen_rust.cpp", diff --git a/gclient_config.py b/gclient_config.py index ccb20775e9..214f5ecff4 100644 --- a/gclient_config.py +++ b/gclient_config.py @@ -34,10 +34,11 @@ solutions = [{ 'name': 'cpplint' }, { - # Tracking a bleeding-edge branch that is nearing rust support. + # Tracking a bleeding-edge branch. Upgrade frequently. # https://github.com/google/flatbuffers/pull/3894 + # https://github.com/rw/flatbuffers/tree/2018-08-12--all-tests-passing 'url': - 'https://github.com/rw/flatbuffers.git@2018-02--rust', + 'https://github.com/rw/flatbuffers.git@05e594342043179178da5331407eb1cd43d1cf02', 'name': 'flatbuffers' }] diff --git a/src/handlers.rs b/src/handlers.rs index f0c64e46e5..6f2bc8c8e8 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -2,14 +2,11 @@ use binding; use binding::{deno_buf, deno_set_response, DenoC}; use flatbuffers; -use flatbuffers::ByteStringOffset; -use flatbuffers::LabeledUOffsetT; use from_c; use fs; use futures; use futures::sync::oneshot; use libc::c_char; -use mem; use msg_generated::deno as msg; use std::ffi::CStr; use std::path::Path; @@ -38,7 +35,7 @@ fn reply_error(d: *const DenoC, cmd_id: u32, msg: &String) { // println!("reply_error{}", msg); let args = msg::BaseArgs { cmdId: cmd_id, - error: builder.create_string(msg), + error: Some(builder.create_string(msg)), ..Default::default() }; set_response_base(d, &mut builder, &args) @@ -49,7 +46,7 @@ fn create_msg( args: &msg::BaseArgs, ) -> deno_buf { let base = msg::CreateBase(builder, &args); - builder.finish(base); + msg::FinishBaseBuffer(builder, base); let data = builder.get_active_buf_slice(); deno_buf { // TODO(ry) @@ -112,22 +109,21 @@ pub extern "C" fn handle_code_fetch( // reply_code_fetch let mut builder = flatbuffers::FlatBufferBuilder::new(); let mut msg_args = msg::CodeFetchResArgs { - module_name: builder.create_string(&out.module_name), - filename: builder.create_string(&out.filename), - source_code: builder.create_string(&out.source_code), + module_name: Some(builder.create_string(&out.module_name)), + filename: Some(builder.create_string(&out.filename)), + source_code: Some(builder.create_string(&out.source_code)), ..Default::default() }; match out.maybe_output_code { Some(ref output_code) => { - msg_args.output_code = builder.create_string(output_code); + msg_args.output_code = Some(builder.create_string(output_code)); } _ => (), }; let msg = msg::CreateCodeFetchRes(&mut builder, &msg_args); - builder.finish(msg); let args = msg::BaseArgs { cmdId: cmd_id, - msg: Some(msg.union()), + msg: Some(flatbuffers::Offset::new(msg.value())), msg_type: msg::Any::CodeFetchRes, ..Default::default() }; @@ -219,12 +215,11 @@ fn send_timer_ready(d: *const DenoC, timer_id: u32, done: bool) { ..Default::default() }, ); - builder.finish(msg); send_base( d, &mut builder, &msg::BaseArgs { - msg: Some(msg.union()), + msg: Some(flatbuffers::Offset::new(msg.value())), msg_type: msg::Any::TimerReady, ..Default::default() }, @@ -250,35 +245,22 @@ pub extern "C" fn handle_read_file_sync( } // Build the response message. memcpy data into msg. + // TODO(ry) zero-copy. let mut builder = flatbuffers::FlatBufferBuilder::new(); - let vec = result.unwrap(); - //let data = - // flatbuffers::LabeledUOffsetT::new(builder.push_bytes(vec.as_slice())); - - let data_ = builder.create_byte_vector(vec.as_slice()); - - // TODO(ry) This is a hack that can be removed once builder.create_byte_vector - // works properly. - let data = unsafe { - mem::transmute::, LabeledUOffsetT<&[i8]>>( - data_, - ) - }; - + let data_off = builder.create_byte_vector(vec.as_slice()); let msg = msg::CreateReadFileSyncRes( &mut builder, &msg::ReadFileSyncResArgs { - data, + data: Some(data_off), ..Default::default() }, ); - builder.finish(msg); set_response_base( d, &mut builder, &msg::BaseArgs { - msg: Some(msg.union()), + msg: Some(flatbuffers::Offset::new(msg.value())), msg_type: msg::Any::ReadFileSyncRes, ..Default::default() }, diff --git a/src/msg.fbs b/src/msg.fbs index 46cea1e29b..8126eb3812 100644 --- a/src/msg.fbs +++ b/src/msg.fbs @@ -83,7 +83,7 @@ table FetchRes { id: uint; status: int; header_line: [string]; - body: [byte]; + body: [ubyte]; } table ReadFileSync { @@ -91,12 +91,12 @@ table ReadFileSync { } table ReadFileSyncRes { - data: [byte]; + data: [ubyte]; } table WriteFileSync { filename: string; - data: [byte]; + data: [ubyte]; perm: uint; // perm specified by https://godoc.org/os#FileMode } diff --git a/third_party b/third_party index 221e8d5662..cd53233739 160000 --- a/third_party +++ b/third_party @@ -1 +1 @@ -Subproject commit 221e8d5662be4d7524e31bb7b647623f46ad53ce +Subproject commit cd5323373992f724b5afd2ab5fa074a7357d996a