Skip to content

Commit

Permalink
AK+IPCCompiler: Get rid of BufferStream overloads for size_t
Browse files Browse the repository at this point in the history
Since BufferStream is about creating specific binary stream formats,
let's not have a flaky type like size_t in there. Instead, clients of
BufferStream can cast their size_t to the binary size they want to use.

Account for this in IPCCompiler by making String lengths always 32-bit.
  • Loading branch information
awesomekling committed Feb 5, 2020
1 parent be0034d commit 0cff25a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 40 deletions.
37 changes: 0 additions & 37 deletions AK/BufferStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,43 +297,6 @@ class BufferStream {
return *this;
}

BufferStream& operator<<(size_t value)
{
if constexpr(sizeof(size_t) == 4)
return *this << (u32)value;
else if constexpr(sizeof(size_t) == 8)
return *this << (u64)value;
ASSERT_NOT_REACHED();
}
BufferStream& operator>>(size_t& value)
{
if constexpr(sizeof(size_t) == 4)
return *this >> (u32&)value;
else if constexpr(sizeof(size_t) == 8)
return *this >> (u64&)value;
ASSERT_NOT_REACHED();
}

#ifndef __i386__
BufferStream& operator<<(ssize_t value)
{
if constexpr(sizeof(ssize_t) == 4)
return *this << (i32)value;
else if constexpr(sizeof(ssize_t) == 8)
return *this << (i64)value;
ASSERT_NOT_REACHED();
}
BufferStream& operator>>(ssize_t& value)
{
if constexpr(sizeof(ssize_t) == 4)
return *this >> (i32&)value;
else if constexpr(sizeof(ssize_t) == 8)
return *this >> (i64&)value;
ASSERT_NOT_REACHED();
}
#endif


BufferStream& operator<<(const char* value)
{
return *this << StringView(value);
Expand Down
6 changes: 3 additions & 3 deletions DevTools/IPCCompiler/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,11 @@ int main(int argc, char** argv)
dbg() << " " << parameter.type << " " << parameter.name << " = " << initial_value << ";";

if (parameter.type == "String") {
dbg() << " size_t " << parameter.name << "_length = 0;";
dbg() << " u32 " << parameter.name << "_length = 0;";
dbg() << " stream >> " << parameter.name << "_length;";
dbg() << " if (" << parameter.name << "_length == 0) {";
dbg() << " " << parameter.name << " = String::empty();";
dbg() << " } else if ((ssize_t)" << parameter.name << "_length == -1) {";
dbg() << " } else if ((i32)" << parameter.name << "_length == -1) {";
dbg() << " " << parameter.name << " = String();";
dbg() << " } else {";
dbg() << " char* " << parameter.name << "_buffer = nullptr;";
Expand Down Expand Up @@ -395,7 +395,7 @@ int main(int argc, char** argv)
for (auto& parameter : parameters) {
if (parameter.type == "String") {
dbg() << " if (m_" << parameter.name << ".is_null()) {";
dbg() << " stream << (ssize_t)-1;";
dbg() << " stream << (i32)-1;";
dbg() << " } else {";
dbg() << " stream << m_" << parameter.name << ".length();";
dbg() << " stream << m_" << parameter.name << ";";
Expand Down

0 comments on commit 0cff25a

Please sign in to comment.