[Lldb-commits] [PATCH] D111355: [lldb] Add serial:// protocol for connecting to serial port

Pavel Labath via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Wed Oct 20 08:50:03 PDT 2021


labath added inline comments.


================
Comment at: lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp:772-774
+  llvm::Error error = llvm::Error::success();
+  m_io_sp = std::make_shared<SerialPort>(fd, File::eOpenOptionReadWrite,
+                                         serial_options.get(), true, error);
----------------
mgorny wrote:
> labath wrote:
> > mgorny wrote:
> > > labath wrote:
> > > > It would be better to hide this by making the constructor private and have a static factory function returning `Expected<unique_ptr<SerialPort>>`. Bonus points if you can move all the fallible operations into the factory function so that the (now private) constructor does not need the Error argument at all
> > > I know but I couldn't make this work — the compiler just won't find a way to convert the new `SerialPort` instance into `Expected<SerialPort>`. I suspect I would have to add move ctors and assignment operators all the way up the class hierarchy.
> > That's where the `unique_ptr` part comes in. :)
> I presume you mean `shared_ptr` here, or know some dirty trick.
a unique_ptr is convertible to a shared_ptr, but not the other way around, so it's better to return the former


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D111355/new/

https://reviews.llvm.org/D111355



More information about the lldb-commits mailing list