This is an archive of the discontinued LLVM Phabricator instance.

[lldb] [Host] Refactor Socket::DecodeHostAndPort() to use LLVM API
ClosedPublic

Authored by mgorny on Sep 24 2021, 1:36 AM.

Details

Summary

Refactor Socket::DecodeHostAndPort() to use LLVM API over redundant
LLDB API. In particular, this means llvm::Regex, llvm::Error return
type and llvm::StringRef.getAsInteger().

While at it, change the port type from int32_t to uint16_t. The method
never returns any value outside this range, and using the correct type
allows us to rely on getAsInteger()'s implicit overflow check.

Diff Detail

Event Timeline

mgorny requested review of this revision.Sep 24 2021, 1:36 AM
mgorny created this revision.
mgorny updated this revision to Diff 374762.Sep 24 2021, 2:07 AM
mgorny edited the summary of this revision. (Show Details)

Change the return type to llvm::Error, replacing duplicate bool+Status.

labath accepted this revision.Sep 24 2021, 2:53 AM
labath added inline comments.
lldb/source/Host/common/Socket.cpp
305

Actually, to_integer is already an llvm API (accessed via ADL here :P), and overall I'd prefer to standardize on that, as the most common error with getAsInteger is to get the return value backwards.

(to_integer will also do an implicit StringRef conversion, so you can call it on a std::string without manual casts).

lldb/tools/lldb-server/Acceptor.cpp
101–103

if (!errorToBool(Socket::DecodeHostAndPort(...)))

This revision is now accepted and ready to land.Sep 24 2021, 2:53 AM
mgorny marked 2 inline comments as done.Sep 24 2021, 4:20 AM
mgorny added inline comments.
lldb/source/Host/common/Socket.cpp
305

Well, I personally prefer object-based API but sure, either way is fine.

lldb/tools/lldb-server/Acceptor.cpp
101–103

Note to self: if something takes more than two lines of code, LLVM probably has a helper ;-).

This revision was automatically updated to reflect the committed changes.
mgorny marked 2 inline comments as done.
Herald added a project: Restricted Project. · View Herald TranscriptSep 24 2021, 4:25 AM