diff --git a/AK/Assertions.h b/AK/Assertions.h index f78ccd921b2..ca074781f18 100644 --- a/AK/Assertions.h +++ b/AK/Assertions.h @@ -1,13 +1,16 @@ #pragma once +#ifdef SERENITY_KERNEL +#include "kassert.h" +#else #include - #define ASSERT(x) assert(x) #define ASSERT_NOT_REACHED() assert(false) +#endif namespace AK { -inline void notImplemented() { assert(false); } +inline void notImplemented() { ASSERT(false); } } diff --git a/AK/MappedFile.cpp b/AK/MappedFile.cpp index 0afec761855..6a8ad3515b4 100644 --- a/AK/MappedFile.cpp +++ b/AK/MappedFile.cpp @@ -22,7 +22,7 @@ MappedFile::MappedFile(String&& fileName) perror(""); } - printf("MappedFile{%s} := { m_fd=%d, m_fileLength=%u, m_map=%p }\n", m_fileName.characters(), m_fd, m_fileLength, m_map); + printf("MappedFile{%s} := { m_fd=%d, m_fileLength=%zu, m_map=%p }\n", m_fileName.characters(), m_fd, m_fileLength, m_map); } MappedFile::~MappedFile() diff --git a/AK/Retainable.h b/AK/Retainable.h index 1d22428e901..cf4308520c3 100644 --- a/AK/Retainable.h +++ b/AK/Retainable.h @@ -15,7 +15,7 @@ public: void release() { - assert(m_retainCount); + ASSERT(m_retainCount); if (!--m_retainCount) delete static_cast(this); } diff --git a/AK/SimpleMalloc.cpp b/AK/SimpleMalloc.cpp index ef8c8483af1..e92d7295d0a 100644 --- a/AK/SimpleMalloc.cpp +++ b/AK/SimpleMalloc.cpp @@ -222,6 +222,8 @@ byte* allocateZeroed(dword size) byte* reallocate(byte* ptr, dword size) { // FIXME; + (void) ptr; + (void) size; ASSERT_NOT_REACHED(); return nullptr; } diff --git a/AK/StdLib.h b/AK/StdLib.h index c4448ed4235..a5046e530f7 100644 --- a/AK/StdLib.h +++ b/AK/StdLib.h @@ -1,5 +1,12 @@ #pragma once +#ifdef SERENITY_KERNEL +#include +#else +#include +#include +#endif + namespace AK { template @@ -34,10 +41,10 @@ template struct identity { typedef T type; }; -template -T&& forward(typename identity::type&& param) +template +constexpr T&& forward(typename identity::type& param) { - return static_cast::type&&>(param); + return static_cast(param); } template diff --git a/AK/Types.h b/AK/Types.h index f970c128481..38cd7cb9256 100644 --- a/AK/Types.h +++ b/AK/Types.h @@ -1,10 +1,18 @@ #pragma once #ifdef SERENITY_KERNEL +typedef unsigned char byte; +typedef unsigned short word; +typedef unsigned int dword; +typedef unsigned long long int qword; + +typedef signed char signed_byte; +typedef signed short signed_word; +typedef signed int signed_dword; +typedef signed long long int signed_qword; #else #include #include -#endif typedef uint8_t byte; typedef uint16_t word; @@ -15,6 +23,7 @@ typedef int8_t signed_byte; typedef int16_t signed_word; typedef int32_t signed_dword; typedef int64_t signed_qword; +#endif constexpr unsigned KB = 1024; constexpr unsigned MB = KB * KB; diff --git a/AK/Vector.h b/AK/Vector.h index 3bf78213675..971e45f192e 100644 --- a/AK/Vector.h +++ b/AK/Vector.h @@ -13,24 +13,24 @@ template class VectorImpl { public: ~VectorImpl() { } - static OwnPtr create(unsigned capacity) + static OwnPtr create(size_t capacity) { size_t size = sizeof(VectorImpl) + sizeof(T) * capacity; void* slot = kmalloc(size); return OwnPtr(new (slot) VectorImpl(capacity)); } - unsigned size() const { return m_size; } - unsigned capacity() const { return m_capacity; } + size_t size() const { return m_size; } + size_t capacity() const { return m_capacity; } - T& at(unsigned i) { return *slot(i); } - const T& at(unsigned i) const { return *slot(i); } + T& at(size_t i) { return *slot(i); } + const T& at(size_t i) const { return *slot(i); } - void remove(unsigned index) + void remove(size_t index) { ASSERT(index < m_size); at(index).~T(); - for (unsigned i = index + 1; i < m_size; ++i) { + for (size_t i = index + 1; i < m_size; ++i) { new (slot(i - 1)) T(move(at(i))); at(i).~T(); } @@ -41,16 +41,16 @@ public: private: friend class Vector; - VectorImpl(unsigned capacity) : m_capacity(capacity) { } + VectorImpl(size_t capacity) : m_capacity(capacity) { } T* tail() { return reinterpret_cast(this + 1); } - T* slot(unsigned i) { return &tail()[i]; } + T* slot(size_t i) { return &tail()[i]; } const T* tail() const { return reinterpret_cast(this + 1); } - const T* slot(unsigned i) const { return &tail()[i]; } + const T* slot(size_t i) const { return &tail()[i]; } - unsigned m_size { 0 }; - unsigned m_capacity; + size_t m_size { 0 }; + size_t m_capacity; }; template @@ -73,21 +73,21 @@ public: void clear() { - for (unsigned i = 0; i < size(); ++i) { + for (size_t i = 0; i < size(); ++i) { at(i).~T(); } m_impl = nullptr; } bool isEmpty() const { return size() == 0; } - unsigned size() const { return m_impl ? m_impl->size() : 0; } - unsigned capacity() const { return m_impl ? m_impl->capacity() : 0; } + size_t size() const { return m_impl ? m_impl->size() : 0; } + size_t capacity() const { return m_impl ? m_impl->capacity() : 0; } - const T& at(unsigned i) const { return m_impl->at(i); } - T& at(unsigned i) { return m_impl->at(i); } + const T& at(size_t i) const { return m_impl->at(i); } + T& at(size_t i) { return m_impl->at(i); } - const T& operator[](unsigned i) const { return at(i); } - T& operator[](unsigned i) { return at(i); } + const T& operator[](size_t i) const { return at(i); } + T& operator[](size_t i) { return at(i); } const T& first() const { return at(0); } T& first() { return at(0); } @@ -104,7 +104,7 @@ public: return value; } - void remove(unsigned index) + void remove(size_t index) { m_impl->remove(index); } @@ -123,7 +123,7 @@ public: ++m_impl->m_size; } - void ensureCapacity(unsigned neededCapacity) + void ensureCapacity(size_t neededCapacity) { if (capacity() >= neededCapacity) return; @@ -131,7 +131,7 @@ public: auto newImpl = VectorImpl::create(newCapacity); if (m_impl) { newImpl->m_size = m_impl->m_size; - for (unsigned i = 0; i < size(); ++i) { + for (size_t i = 0; i < size(); ++i) { new (newImpl->slot(i)) T(move(m_impl->at(i))); m_impl->at(i).~T(); } @@ -146,9 +146,9 @@ public: T& operator*() { return m_vector[m_index]; } private: friend class Vector; - Iterator(Vector& vector, unsigned index) : m_vector(vector), m_index(index) { } + Iterator(Vector& vector, size_t index) : m_vector(vector), m_index(index) { } Vector& m_vector; - unsigned m_index { 0 }; + size_t m_index { 0 }; }; Iterator begin() { return Iterator(*this, 0); } @@ -161,18 +161,18 @@ public: const T& operator*() const { return m_vector[m_index]; } private: friend class Vector; - ConstIterator(const Vector& vector, const unsigned index) : m_vector(vector), m_index(index) { } + ConstIterator(const Vector& vector, const size_t index) : m_vector(vector), m_index(index) { } const Vector& m_vector; - unsigned m_index { 0 }; + size_t m_index { 0 }; }; ConstIterator begin() const { return ConstIterator(*this, 0); } ConstIterator end() const { return ConstIterator(*this, size()); } private: - static unsigned paddedCapacity(unsigned capacity) + static size_t paddedCapacity(size_t capacity) { - return max(4u, capacity + (capacity / 4) + 4); + return max(size_t(4), capacity + (capacity / 4) + 4); } OwnPtr> m_impl; diff --git a/AK/kmalloc.cpp b/AK/kmalloc.cpp index deeacc7a673..5540bfa0911 100644 --- a/AK/kmalloc.cpp +++ b/AK/kmalloc.cpp @@ -9,12 +9,12 @@ extern "C" { -void* kcalloc(dword nmemb, dword size) +void* kcalloc(size_t nmemb, size_t size) { return calloc(nmemb, size); } -void* kmalloc(dword size) +void* kmalloc(size_t size) { return malloc(size); } @@ -24,7 +24,7 @@ void kfree(void* ptr) free(ptr); } -void* krealloc(void* ptr, dword size) +void* krealloc(void* ptr, size_t size) { return realloc(ptr, size); } @@ -35,14 +35,14 @@ void* krealloc(void* ptr, dword size) extern "C" { -void* kcalloc(dword nmemb, dword size) +void* kcalloc(size_t nmemb, size_t size) { if (!nmemb || !size) return nullptr; return SimpleMalloc::allocateZeroed(nmemb * size); } -void* kmalloc(dword size) +void* kmalloc(size_t size) { if (!size) return nullptr; @@ -56,7 +56,7 @@ void kfree(void* ptr) SimpleMalloc::free((byte*)ptr); } -void* krealloc(void* ptr, dword size) +void* krealloc(void* ptr, size_t size) { if (!ptr) return ptr; diff --git a/AK/kmalloc.h b/AK/kmalloc.h index 89b455bb70e..2c30774456b 100644 --- a/AK/kmalloc.h +++ b/AK/kmalloc.h @@ -4,10 +4,10 @@ extern "C" { -void* kcalloc(dword nmemb, dword size); -void* kmalloc(dword size); +void* kcalloc(size_t nmemb, size_t size); +void* kmalloc(size_t size); void kfree(void* ptr); -void* krealloc(void* ptr, dword size); +void* krealloc(void* ptr, size_t size); } diff --git a/AK/test.cpp b/AK/test.cpp index 92838cbc290..0cb2b89de7f 100644 --- a/AK/test.cpp +++ b/AK/test.cpp @@ -136,7 +136,7 @@ int main(int, char**) } auto charbuf = Buffer::createUninitialized(1024); - printf("charbuf.size() = %u\n", charbuf->size()); + printf("charbuf.size() = %zu\n", charbuf->size()); { Vector problem; @@ -146,7 +146,7 @@ int main(int, char**) { auto printInts = [] (const Vector& v) { - printf("Vector {\n size: %u\n capacity: %u\n elements: ", v.size(), v.capacity()); + printf("Vector {\n size: %zu\n capacity: %zu\n elements: ", v.size(), v.capacity()); for (auto i : v) printf("%d ", i); printf("\n}\n");