1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 07:07:34 +00:00

AK: Rename the common integer typedefs to make it obvious what they are.

These types can be picked up by including <AK/Types.h>:

* u8, u16, u32, u64 (unsigned)
* i8, i16, i32, i64 (signed)
This commit is contained in:
Andreas Kling 2019-07-03 21:17:35 +02:00
parent c4c4bbc5ba
commit 27f699ef0c
208 changed files with 1603 additions and 1621 deletions

View file

@ -20,8 +20,8 @@ public:
{
}
word id() const { return m_id; }
void set_id(word w) { m_id = w; }
u16 id() const { return m_id; }
void set_id(u16 w) { m_id = w; }
bool recursion_desired() const { return m_recursion_desired; }
void set_recursion_desired(bool b) { m_recursion_desired = b; }
@ -32,16 +32,16 @@ public:
bool is_authoritative_answer() const { return m_authoritative_answer; }
void set_authoritative_answer(bool b) { m_authoritative_answer = b; }
byte opcode() const { return m_opcode; }
void set_opcode(byte b) { m_opcode = b; }
u8 opcode() const { return m_opcode; }
void set_opcode(u8 b) { m_opcode = b; }
bool is_query() const { return !m_query_or_response; }
bool is_response() const { return m_query_or_response; }
void set_is_query() { m_query_or_response = false; }
void set_is_response() { m_query_or_response = true; }
byte response_code() const { return m_response_code; }
void set_response_code(byte b) { m_response_code = b; }
u8 response_code() const { return m_response_code; }
void set_response_code(u8 b) { m_response_code = b; }
bool checking_disabled() const { return m_checking_disabled; }
void set_checking_disabled(bool b) { m_checking_disabled = b; }
@ -52,39 +52,39 @@ public:
bool is_recursion_available() const { return m_recursion_available; }
void set_recursion_available(bool b) { m_recursion_available = b; }
word question_count() const { return m_question_count; }
void set_question_count(word w) { m_question_count = w; }
u16 question_count() const { return m_question_count; }
void set_question_count(u16 w) { m_question_count = w; }
word answer_count() const { return m_answer_count; }
void set_answer_count(word w) { m_answer_count = w; }
u16 answer_count() const { return m_answer_count; }
void set_answer_count(u16 w) { m_answer_count = w; }
word authority_count() const { return m_authority_count; }
void set_authority_count(word w) { m_authority_count = w; }
u16 authority_count() const { return m_authority_count; }
void set_authority_count(u16 w) { m_authority_count = w; }
word additional_count() const { return m_additional_count; }
void set_additional_count(word w) { m_additional_count = w; }
u16 additional_count() const { return m_additional_count; }
void set_additional_count(u16 w) { m_additional_count = w; }
void* payload() { return this + 1; }
const void* payload() const { return this + 1; }
private:
NetworkOrdered<word> m_id;
NetworkOrdered<u16> m_id;
bool m_recursion_desired : 1;
bool m_truncated : 1;
bool m_authoritative_answer : 1;
byte m_opcode : 4;
u8 m_opcode : 4;
bool m_query_or_response : 1;
byte m_response_code : 4;
u8 m_response_code : 4;
bool m_checking_disabled : 1;
bool m_authenticated_data : 1;
bool m_zero : 1;
bool m_recursion_available : 1;
NetworkOrdered<word> m_question_count;
NetworkOrdered<word> m_answer_count;
NetworkOrdered<word> m_authority_count;
NetworkOrdered<word> m_additional_count;
NetworkOrdered<u16> m_question_count;
NetworkOrdered<u16> m_answer_count;
NetworkOrdered<u16> m_authority_count;
NetworkOrdered<u16> m_additional_count;
};
static_assert(sizeof(DNSPacket) == 12);

View file

@ -8,21 +8,21 @@ class [[gnu::packed]] DNSRecord
public:
DNSRecord() {}
word name() const { return m_name; }
word type() const { return m_type; }
word record_class() const { return m_class; }
dword ttl() const { return m_ttl; }
word data_length() const { return m_data_length; }
u16 name() const { return m_name; }
u16 type() const { return m_type; }
u16 record_class() const { return m_class; }
u32 ttl() const { return m_ttl; }
u16 data_length() const { return m_data_length; }
void* data() { return this + 1; }
const void* data() const { return this + 1; }
private:
NetworkOrdered<word> m_name;
NetworkOrdered<word> m_type;
NetworkOrdered<word> m_class;
NetworkOrdered<dword> m_ttl;
NetworkOrdered<word> m_data_length;
NetworkOrdered<u16> m_name;
NetworkOrdered<u16> m_type;
NetworkOrdered<u16> m_class;
NetworkOrdered<u32> m_ttl;
NetworkOrdered<u16> m_data_length;
};
static_assert(sizeof(DNSRecord) == 12);

View file

@ -29,7 +29,7 @@
static HashMap<String, String> dns_custom_hostnames;
static Vector<String> lookup(const String& hostname, bool& did_timeout, const String& DNS_IP, unsigned short record_type);
static String parse_dns_name(const byte*, int& offset, int max_offset);
static String parse_dns_name(const u8*, int& offset, int max_offset);
static void load_etc_hosts()
{
@ -46,20 +46,20 @@ static void load_etc_hosts()
auto sections = fields[0].split('.');
IPv4Address addr {
(byte)atoi(sections[0].characters()),
(byte)atoi(sections[1].characters()),
(byte)atoi(sections[2].characters()),
(byte)atoi(sections[3].characters()),
(u8)atoi(sections[0].characters()),
(u8)atoi(sections[1].characters()),
(u8)atoi(sections[2].characters()),
(u8)atoi(sections[3].characters()),
};
auto name = fields[1];
dns_custom_hostnames.set(name, addr.to_string());
IPv4Address reverse_addr {
(byte)atoi(sections[3].characters()),
(byte)atoi(sections[2].characters()),
(byte)atoi(sections[1].characters()),
(byte)atoi(sections[0].characters()),
(u8)atoi(sections[3].characters()),
(u8)atoi(sections[2].characters()),
(u8)atoi(sections[1].characters()),
(u8)atoi(sections[0].characters()),
};
StringBuilder builder;
builder.append(reverse_addr.to_string());
@ -198,9 +198,9 @@ int main(int argc, char** argv)
return 0;
}
static word get_next_id()
static u16 get_next_id()
{
static word s_next_id = 0;
static u16 s_next_id = 0;
return ++s_next_id;
}
@ -221,7 +221,7 @@ Vector<String> lookup(const String& hostname, bool& did_timeout, const String& D
stream << ByteBuffer::wrap(&request_header, sizeof(request_header));
auto parts = hostname.split('.');
for (auto& part : parts) {
stream << (byte)part.length();
stream << (u8)part.length();
stream << part;
}
stream << '\0';
@ -262,7 +262,7 @@ Vector<String> lookup(const String& hostname, bool& did_timeout, const String& D
struct sockaddr_in src_addr;
socklen_t src_addr_len = sizeof(src_addr);
byte response_buffer[4096];
u8 response_buffer[4096];
ssize_t nrecv = recvfrom(fd, response_buffer, sizeof(response_buffer) - 1, 0, (struct sockaddr*)&src_addr, &src_addr_len);
if (nrecv < 0) {
if (errno == EAGAIN) {
@ -303,13 +303,13 @@ Vector<String> lookup(const String& hostname, bool& did_timeout, const String& D
}
int offset = 0;
auto question = parse_dns_name((const byte*)response_header.payload(), offset, nrecv);
auto question = parse_dns_name((const u8*)response_header.payload(), offset, nrecv);
offset += 4;
Vector<String> addresses;
for (word i = 0; i < response_header.answer_count(); ++i) {
auto& record = *(const DNSRecord*)(&((const byte*)response_header.payload())[offset]);
for (u16 i = 0; i < response_header.answer_count(); ++i) {
auto& record = *(const DNSRecord*)(&((const u8*)response_header.payload())[offset]);
dbgprintf("LookupServer: Answer #%u: (question: %s), type=%u, ttl=%u, length=%u, data=",
i,
question.characters(),
@ -320,11 +320,11 @@ Vector<String> lookup(const String& hostname, bool& did_timeout, const String& D
offset += sizeof(DNSRecord) + record.data_length();
if (record.type() == T_PTR) {
int dummy = 0;
auto name = parse_dns_name((const byte*)record.data(), dummy, record.data_length());
auto name = parse_dns_name((const u8*)record.data(), dummy, record.data_length());
dbgprintf("%s\n", name.characters());
addresses.append(name);
} else if (record.type() == T_A) {
auto ipv4_address = IPv4Address((const byte*)record.data());
auto ipv4_address = IPv4Address((const u8*)record.data());
dbgprintf("%s\n", ipv4_address.to_string().characters());
addresses.append(ipv4_address.to_string());
} else {
@ -337,11 +337,11 @@ Vector<String> lookup(const String& hostname, bool& did_timeout, const String& D
return addresses;
}
static String parse_dns_name(const byte* data, int& offset, int max_offset)
static String parse_dns_name(const u8* data, int& offset, int max_offset)
{
Vector<char, 128> buf;
while (offset < max_offset) {
byte ch = data[offset];
u8 ch = data[offset];
if (ch == '\0') {
++offset;
break;

View file

@ -159,13 +159,13 @@ struct WSAPI_ServerMessage {
WSAPI_Point position;
WSAPI_MouseButton button;
unsigned buttons;
byte modifiers;
u8 modifiers;
int wheel_delta;
} mouse;
struct {
char character;
byte key;
byte modifiers;
u8 key;
u8 modifiers;
bool ctrl : 1;
bool alt : 1;
bool shift : 1;

View file

@ -44,8 +44,8 @@ void WSCPUMonitor::get_cpu_usage(unsigned& busy, unsigned& idle)
auto json = JsonValue::from_string({ file_contents.data(), file_contents.size() });
json.as_array().for_each([&](auto& value) {
const JsonObject& process_object = value.as_object();
pid_t pid = process_object.get("pid").to_dword();
unsigned nsched = process_object.get("times_scheduled").to_dword();
pid_t pid = process_object.get("pid").to_u32();
unsigned nsched = process_object.get("times_scheduled").to_u32();
if (pid == 0)
idle += nsched;
else

View file

@ -86,7 +86,7 @@ void WSClientConnection::post_message(const WSAPI_ServerMessage& message, const
iov[0].iov_len = sizeof(message);
if (!extra_data.is_empty()) {
iov[1].iov_base = const_cast<byte*>(extra_data.data());
iov[1].iov_base = const_cast<u8*>(extra_data.data());
iov[1].iov_len = extra_data.size();
++iov_count;
}

View file

@ -16,11 +16,11 @@ WSClipboard::~WSClipboard()
{
}
const byte* WSClipboard::data() const
const u8* WSClipboard::data() const
{
if (!m_shared_buffer)
return nullptr;
return (const byte*)m_shared_buffer->data();
return (const u8*)m_shared_buffer->data();
}
int WSClipboard::size() const

View file

@ -13,7 +13,7 @@ public:
return m_shared_buffer;
}
const byte* data() const;
const u8* data() const;
int size() const;
void clear();

View file

@ -186,9 +186,9 @@ void WSCompositor::flush(const Rect& a_rect)
size_t pitch = m_back_bitmap->pitch();
for (int y = 0; y < rect.height(); ++y) {
fast_dword_copy(back_ptr, front_ptr, rect.width());
front_ptr = (const RGBA32*)((const byte*)front_ptr + pitch);
back_ptr = (RGBA32*)((byte*)back_ptr + pitch);
fast_u32_copy(back_ptr, front_ptr, rect.width());
front_ptr = (const RGBA32*)((const u8*)front_ptr + pitch);
back_ptr = (RGBA32*)((u8*)back_ptr + pitch);
}
}

View file

@ -726,7 +726,7 @@ private:
Vector<Rect, 32> m_rects;
};
enum class MouseButton : byte {
enum class MouseButton : u8 {
None = 0,
Left = 1,
Right = 2,
@ -735,7 +735,7 @@ enum class MouseButton : byte {
class WSKeyEvent final : public WSEvent {
public:
WSKeyEvent(Type type, int key, char character, byte modifiers)
WSKeyEvent(Type type, int key, char character, u8 modifiers)
: WSEvent(type)
, m_key(key)
, m_character(character)
@ -748,7 +748,7 @@ public:
bool alt() const { return m_modifiers & Mod_Alt; }
bool shift() const { return m_modifiers & Mod_Shift; }
bool logo() const { return m_modifiers & Mod_Logo; }
byte modifiers() const { return m_modifiers; }
u8 modifiers() const { return m_modifiers; }
char character() const { return m_character; }
private:
@ -756,7 +756,7 @@ private:
friend class WSScreen;
int m_key { 0 };
char m_character { 0 };
byte m_modifiers { 0 };
u8 m_modifiers { 0 };
};
class WSMouseEvent final : public WSEvent {

View file

@ -92,7 +92,7 @@ void WSEventLoop::drain_keyboard()
auto& screen = WSScreen::the();
for (;;) {
KeyEvent event;
ssize_t nread = read(m_keyboard_fd, (byte*)&event, sizeof(KeyEvent));
ssize_t nread = read(m_keyboard_fd, (u8*)&event, sizeof(KeyEvent));
if (nread == 0)
break;
ASSERT(nread == sizeof(KeyEvent));

View file

@ -44,5 +44,5 @@ private:
inline RGBA32* WSScreen::scanline(int y)
{
size_t pitch = sizeof(RGBA32) * width();
return reinterpret_cast<RGBA32*>(((byte*)m_framebuffer) + (y * pitch));
return reinterpret_cast<RGBA32*>(((u8*)m_framebuffer) + (y * pitch));
}

View file

@ -51,7 +51,7 @@ WSWindowManager::WSWindowManager()
{ "/bin/ProcessManager", "Open ProcessManager..." }
};
byte system_menu_name[] = { 0xf8, 0 };
u8 system_menu_name[] = { 0xf8, 0 };
m_system_menu = make<WSMenu>(nullptr, -1, String((const char*)system_menu_name));
int appIndex = 1;

View file

@ -232,7 +232,7 @@ private:
Point m_resize_origin;
ResizeDirection m_resize_direction { ResizeDirection::None };
byte m_keyboard_modifiers { 0 };
u8 m_keyboard_modifiers { 0 };
OwnPtr<WSMenu> m_system_menu;
Color m_menu_selection_color;