Skip to content

Commit

Permalink
Everywhere: Remove all KERNEL #defines
Browse files Browse the repository at this point in the history
  • Loading branch information
tcl3 authored and awesomekling committed Jun 18, 2024
1 parent de99dd2 commit 5ca2f4d
Show file tree
Hide file tree
Showing 73 changed files with 116 additions and 808 deletions.
24 changes: 10 additions & 14 deletions AK/Assertions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@
# define ERRORLN warnln
#endif

#if !defined(KERNEL)

# if defined(EXECINFO_BACKTRACE)
#if defined(EXECINFO_BACKTRACE)
namespace {
ALWAYS_INLINE void dump_backtrace()
{
Expand Down Expand Up @@ -74,39 +72,37 @@ ALWAYS_INLINE void dump_backtrace()
} else {
error_builder.append(sym);
}
# if !defined(AK_OS_ANDROID)
# if !defined(AK_OS_ANDROID)
error_builder.append('\n');
# endif
# endif
error_builder.append('\0');
PRINT_ERROR(error_builder.string_view().characters_without_null_termination());
}
free(syms);
}
}
# endif
#endif

extern "C" {

void ak_verification_failed(char const* message)
{
# if defined(AK_OS_SERENITY) || defined(AK_OS_ANDROID)
#if defined(AK_OS_SERENITY) || defined(AK_OS_ANDROID)
bool colorize_output = true;
# elif defined(AK_OS_WINDOWS)
#elif defined(AK_OS_WINDOWS)
bool colorize_output = false;
# else
#else
bool colorize_output = isatty(STDERR_FILENO) == 1;
# endif
#endif

if (colorize_output)
ERRORLN("\033[31;1mVERIFICATION FAILED\033[0m: {}", message);
else
ERRORLN("VERIFICATION FAILED: {}", message);

# if defined(EXECINFO_BACKTRACE)
#if defined(EXECINFO_BACKTRACE)
dump_backtrace();
# endif
#endif
__builtin_trap();
}
}

#endif
24 changes: 10 additions & 14 deletions AK/Assertions.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,15 @@

#pragma once

#if defined(KERNEL)
# include <Kernel/Library/Assertions.h>
#else
extern "C" __attribute__((noreturn)) void ak_verification_failed(char const*);
# define __stringify_helper(x) #x
# define __stringify(x) __stringify_helper(x)
# define VERIFY(expr) \
(__builtin_expect(!(expr), 0) \
? ak_verification_failed(#expr " at " __FILE__ ":" __stringify(__LINE__)) \
: (void)0)
# define VERIFY_NOT_REACHED() VERIFY(false) /* NOLINT(cert-dcl03-c,misc-static-assert) No, this can't be static_assert, it's a runtime check */
#define __stringify_helper(x) #x
#define __stringify(x) __stringify_helper(x)
#define VERIFY(expr) \
(__builtin_expect(!(expr), 0) \
? ak_verification_failed(#expr " at " __FILE__ ":" __stringify(__LINE__)) \
: (void)0)
#define VERIFY_NOT_REACHED() VERIFY(false) /* NOLINT(cert-dcl03-c,misc-static-assert) No, this can't be static_assert, it's a runtime check */
static constexpr bool TODO = false;
# define TODO() VERIFY(TODO) /* NOLINT(cert-dcl03-c,misc-static-assert) No, this can't be static_assert, it's a runtime check */
# define TODO_AARCH64() VERIFY(TODO) /* NOLINT(cert-dcl03-c,misc-static-assert) No, this can't be static_assert, it's a runtime check */
# define TODO_RISCV64() VERIFY(TODO) /* NOLINT(cert-dcl03-c,misc-static-assert) No, this can't be static_assert, it's a runtime check */
#endif
#define TODO() VERIFY(TODO) /* NOLINT(cert-dcl03-c,misc-static-assert) No, this can't be static_assert, it's a runtime check */
#define TODO_AARCH64() VERIFY(TODO) /* NOLINT(cert-dcl03-c,misc-static-assert) No, this can't be static_assert, it's a runtime check */
#define TODO_RISCV64() VERIFY(TODO) /* NOLINT(cert-dcl03-c,misc-static-assert) No, this can't be static_assert, it's a runtime check */
12 changes: 4 additions & 8 deletions AK/Demangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@

#pragma once

#ifndef KERNEL

# include <AK/ByteString.h>
# include <AK/StringView.h>
# include <cxxabi.h>
#include <AK/ByteString.h>
#include <AK/StringView.h>
#include <cxxabi.h>

namespace AK {

Expand All @@ -26,8 +24,6 @@ inline ByteString demangle(StringView name)

}

# if USING_AK_GLOBALLY
#if USING_AK_GLOBALLY
using AK::demangle;
# endif

#endif
2 changes: 0 additions & 2 deletions AK/DoublyLinkedList.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ class DoublyLinkedList {
return {};
}

#ifndef KERNEL
template<typename U>
void append(U&& value)
{
Expand All @@ -146,7 +145,6 @@ class DoublyLinkedList {
{
MUST(try_prepend(forward<U>(value)));
}
#endif

[[nodiscard]] bool contains_slow(T const& value) const
{
Expand Down
9 changes: 0 additions & 9 deletions AK/Error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,11 @@

#include <AK/Error.h>

#ifdef KERNEL
# include <AK/Format.h>
#endif

namespace AK {

Error Error::from_string_view_or_print_error_and_return_errno(StringView string_literal, [[maybe_unused]] int code)
{
#ifdef KERNEL
dmesgln("{}", string_literal);
return Error::from_errno(code);
#else
return Error::from_string_view(string_literal);
#endif
}

}
26 changes: 2 additions & 24 deletions AK/Error.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,8 @@
#include <AK/StringView.h>
#include <AK/Try.h>
#include <AK/Variant.h>

#if defined(AK_OS_SERENITY) && defined(KERNEL)
# include <errno_codes.h>
#else
# include <errno.h>
# include <string.h>
#endif
#include <errno.h>
#include <string.h>

namespace AK {

Expand All @@ -36,7 +31,6 @@ class [[nodiscard]] Error {
// the Error::from_string_view method!
static Error from_string_view_or_print_error_and_return_errno(StringView string_literal, int code);

#ifndef KERNEL
static Error from_syscall(StringView syscall_name, int rc)
{
return Error(syscall_name, rc);
Expand All @@ -52,14 +46,11 @@ class [[nodiscard]] Error {
VERIFY_NOT_REACHED();
}

#endif

static Error copy(Error const& error)
{
return Error(error);
}

#ifndef KERNEL
// NOTE: Prefer `from_string_literal` when directly typing out an error message:
//
// return Error::from_string_literal("Class: Some failure");
Expand All @@ -78,23 +69,17 @@ class [[nodiscard]] Error {
{
return from_string_view(string);
}
#endif

bool operator==(Error const& other) const
{
#ifdef KERNEL
return m_code == other.m_code;
#else
return m_code == other.m_code && m_string_literal == other.m_string_literal && m_syscall == other.m_syscall;
#endif
}

int code() const { return m_code; }
bool is_errno() const
{
return m_code != 0;
}
#ifndef KERNEL
bool is_syscall() const
{
return m_syscall;
Expand All @@ -103,7 +88,6 @@ class [[nodiscard]] Error {
{
return m_string_literal;
}
#endif

protected:
Error(int code)
Expand All @@ -112,7 +96,6 @@ class [[nodiscard]] Error {
}

private:
#ifndef KERNEL
Error(StringView string_literal)
: m_string_literal(string_literal)
{
Expand All @@ -124,20 +107,15 @@ class [[nodiscard]] Error {
, m_syscall(true)
{
}
#endif

Error(Error const&) = default;
Error& operator=(Error const&) = default;

#ifndef KERNEL
StringView m_string_literal;
#endif

int m_code { 0 };

#ifndef KERNEL
bool m_syscall { false };
#endif
};

template<typename T, typename E>
Expand Down
8 changes: 1 addition & 7 deletions AK/FixedPoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@
#include <AK/Concepts.h>
#include <AK/Format.h>
#include <AK/IntegralMath.h>
#include <AK/Math.h>
#include <AK/NumericLimits.h>
#include <AK/Types.h>

#ifndef KERNEL
# include <AK/Math.h>
#endif
#ifndef __SIZEOF_INT128__
# include <AK/UFixedBigInt.h>
# include <AK/UFixedBigIntDivision.h>
Expand Down Expand Up @@ -45,27 +43,23 @@ class FixedPoint {
{
}

#ifndef KERNEL
template<FloatingPoint F>
FixedPoint(F value)
: m_value(round_to<Underlying>(value * (static_cast<Underlying>(1) << precision)))
{
}
#endif

template<size_t P, typename U>
explicit constexpr FixedPoint(FixedPoint<P, U> const& other)
: m_value(other.template cast_to<precision, Underlying>().m_value)
{
}

#ifndef KERNEL
template<FloatingPoint F>
explicit ALWAYS_INLINE operator F() const
{
return (F)m_value * pow<F>(0.5, precision);
}
#endif

template<Integral I>
explicit constexpr operator I() const
Expand Down
5 changes: 0 additions & 5 deletions AK/FloatingPointStringConversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@

#pragma once

#ifdef KERNEL
# error This file should not be included in the KERNEL as it deals with doubles \
and there is no guraantee does not do any floating point computations.
#endif

#include <AK/StringView.h>

namespace AK {
Expand Down
Loading

0 comments on commit 5ca2f4d

Please sign in to comment.