Browse Source

Fixed assert macros, and improved error handling.

Бранимир Караџић 4 years ago
parent
commit
51c3264846

+ 1 - 0
include/bx/bx.h

@@ -15,6 +15,7 @@
 #include "platform.h"
 #include "config.h"
 #include "macros.h"
+#include "debug.h"
 
 ///
 #define BX_COUNTOF(_x) sizeof(bx::CountOfRequireArrayArgumentT(_x) )

+ 5 - 3
include/bx/config.h

@@ -6,11 +6,13 @@
 #ifndef BX_CONFIG_H_HEADER_GUARD
 #define BX_CONFIG_H_HEADER_GUARD
 
-#include "bx.h"
+#ifndef BX_CONFIG_DEBUG
+#	error "BX_CONFIG_DEBUG must be defined in build script!"
+#endif // BX_CONFIG_DEBUG
 
 #ifndef BX_CONFIG_ALLOCATOR_DEBUG
-#	define BX_CONFIG_ALLOCATOR_DEBUG 0
-#endif // BX_CONFIG_DEBUG_ALLOC
+#	define BX_CONFIG_ALLOCATOR_DEBUG BX_CONFIG_DEBUG
+#endif // BX_CONFIG_ALLOCATOR_DEBUG
 
 #ifndef BX_CONFIG_SUPPORTS_THREADING
 #	define BX_CONFIG_SUPPORTS_THREADING !(0 \

+ 3 - 1
include/bx/debug.h

@@ -6,10 +6,12 @@
 #ifndef BX_DEBUG_H_HEADER_GUARD
 #define BX_DEBUG_H_HEADER_GUARD
 
-#include "string.h"
+#include "bx.h"
 
 namespace bx
 {
+	class StringView;
+
 	///
 	void debugBreak();
 

+ 30 - 0
include/bx/error.h

@@ -71,6 +71,36 @@ namespace bx
 		uint32_t   m_code;
 	};
 
+	/// Do nothing even if error is set.
+	class ErrorIgnore : public Error
+	{
+	public:
+		///
+		operator Error*();
+	};
+
+	/// In debug build assert if error is set.
+	class ErrorAssert : public Error
+	{
+	public:
+		///
+		~ErrorAssert();
+
+		///
+		operator Error*();
+	};
+
+	/// Exit application if error is set.
+	class ErrorFatal : public Error
+	{
+	public:
+		///
+		~ErrorFatal();
+
+		///
+		operator Error*();
+	};
+
 	///
 	class ErrorScope
 	{

+ 4 - 4
include/bx/file.h

@@ -124,19 +124,19 @@ namespace bx
 
 	/// Creates a directory named `_filePath`.
 	///
-	bool make(const FilePath& _filePath, Error* _err = NULL);
+	bool make(const FilePath& _filePath, Error* _err = bx::ErrorIgnore{});
 
 	/// Creates a directory named `_filePath` along with all necessary parents.
 	///
-	bool makeAll(const FilePath& _filePath, Error* _err = NULL);
+	bool makeAll(const FilePath& _filePath, Error* _err = bx::ErrorIgnore{});
 
 	/// Removes file or directory.
 	///
-	bool remove(const FilePath& _filePath, Error* _err = NULL);
+	bool remove(const FilePath& _filePath, Error* _err = bx::ErrorIgnore{});
 
 	/// Removes file or directory recursivelly.
 	///
-	bool removeAll(const FilePath& _filePath, Error* _err = NULL);
+	bool removeAll(const FilePath& _filePath, Error* _err = bx::ErrorIgnore{});
 
 } // namespace bx
 

+ 43 - 8
include/bx/inline/error.inl

@@ -7,6 +7,8 @@
 #	error "Must be included from bx/error!"
 #endif // BX_ERROR_H_HEADER_GUARD
 
+#include <bx/debug.h>
+
 namespace bx
 {
 	inline Error::Error()
@@ -59,6 +61,42 @@ namespace bx
 		return _rhs.code != m_code;
 	}
 
+	inline ErrorIgnore::operator Error*()
+	{
+		return this;
+	}
+
+	inline ErrorAssert::~ErrorAssert()
+	{
+		BX_ASSERT(isOk(), "Error: 0x%08x `%S`"
+			, get().code
+			, &getMessage()
+			);
+	}
+
+	inline ErrorFatal::operator Error*()
+	{
+		return this;
+	}
+
+	inline ErrorFatal::~ErrorFatal()
+	{
+		if (!isOk() )
+		{
+			printf("Error: 0x%08x `%S`"
+				, get().code
+				, &getMessage()
+				);
+
+			exit(kExitFailure);
+		}
+	}
+
+	inline ErrorAssert::operator Error*()
+	{
+		return this;
+	}
+
 	inline ErrorScope::ErrorScope(Error* _err, const StringView& _name)
 		: m_err(_err)
 		, m_name(_name)
@@ -70,20 +108,17 @@ namespace bx
 	{
 		if (m_name.isEmpty() )
 		{
-			BX_ASSERT(m_err->isOk(), "Error: 0x%08x `%.*s`"
+			BX_ASSERT(m_err->isOk(), "Error: 0x%08x `%S`"
 				, m_err->get().code
-				, m_err->getMessage().getLength()
-				, m_err->getMessage().getPtr()
+				, &m_err->getMessage()
 				);
 		}
 		else
 		{
-			BX_ASSERT(m_err->isOk(), "Error: %.*s - 0x%08x `%.*s`"
-				, m_name.getLength()
-				, m_name.getPtr()
+			BX_ASSERT(m_err->isOk(), "Error: %S - 0x%08x `%S`"
+				, &m_name
 				, m_err->get().code
-				, m_err->getMessage().getLength()
-				, m_err->getMessage().getPtr()
+				, &m_err->getMessage()
 				);
 		}
 	}

+ 37 - 3
include/bx/macros.h

@@ -229,17 +229,51 @@
 #endif // BX_COMPILER_MSVC
 
 #ifndef BX_ASSERT
-#	define BX_ASSERT(_condition, ...) BX_NOOP()
+#	if BX_CONFIG_DEBUG
+#		define BX_ASSERT _BX_ASSERT
+#	else
+#		define BX_ASSERT(_condition, ...) BX_NOOP()
+#	endif // BX_CONFIG_DEBUG
 #endif // BX_ASSERT
 
 #ifndef BX_TRACE
-#	define BX_TRACE(...) BX_NOOP()
+#	if BX_CONFIG_DEBUG
+#		define BX_TRACE _BX_TRACE
+#	else
+#		define BX_TRACE(...) BX_NOOP()
+#	endif // BX_CONFIG_DEBUG
 #endif // BX_TRACE
 
 #ifndef BX_WARN
-#	define BX_WARN(_condition, ...) BX_NOOP()
+#	if BX_CONFIG_DEBUG
+#		define BX_WARN _BX_WARN
+#	else
+#		define BX_WARN(_condition, ...) BX_NOOP()
+#	endif // BX_CONFIG_DEBUG
 #endif // BX_ASSERT
 
+#define _BX_TRACE(_format, ...)                                                                    \
+	BX_MACRO_BLOCK_BEGIN                                                                           \
+		bx::debugPrintf(__FILE__ "(" BX_STRINGIZE(__LINE__) "): BX " _format "\n", ##__VA_ARGS__); \
+	BX_MACRO_BLOCK_END
+
+#define _BX_WARN(_condition, _format, ...)            \
+	BX_MACRO_BLOCK_BEGIN                              \
+		if (!BX_IGNORE_C4127(_condition) )            \
+		{                                             \
+			BX_TRACE("WARN " _format, ##__VA_ARGS__); \
+		}                                             \
+	BX_MACRO_BLOCK_END
+
+#define _BX_ASSERT(_condition, _format, ...)            \
+	BX_MACRO_BLOCK_BEGIN                                \
+		if (!BX_IGNORE_C4127(_condition) )              \
+		{                                               \
+			BX_TRACE("ASSERT " _format, ##__VA_ARGS__); \
+			bx::debugBreak();                           \
+		}                                               \
+	BX_MACRO_BLOCK_END
+
 // static_assert sometimes causes unused-local-typedef...
 BX_PRAGMA_DIAGNOSTIC_IGNORED_CLANG("-Wunused-local-typedef")
 

+ 3 - 1
include/bx/os.h

@@ -6,7 +6,6 @@
 #ifndef BX_OS_H_HEADER_GUARD
 #define BX_OS_H_HEADER_GUARD
 
-#include "debug.h"
 #include "filepath.h"
 
 #if BX_PLATFORM_OSX
@@ -56,6 +55,9 @@ namespace bx
 	///
 	void* exec(const char* const* _argv);
 
+	///
+	BX_NO_RETURN void exit(int32_t _exitCode);
+
 } // namespace bx
 
 #include "inline/os.inl"

+ 20 - 20
include/bx/readerwriter.h

@@ -81,7 +81,7 @@ namespace bx
 		virtual ~ReaderOpenI() = 0;
 
 		///
-		virtual bool open(const FilePath& _filePath, Error* _err) = 0;
+		virtual bool open(const FilePath& _filePath, Error* _err = ErrorIgnore{}) = 0;
 	};
 
 	/// Open for writing interface.
@@ -91,7 +91,7 @@ namespace bx
 		virtual ~WriterOpenI() = 0;
 
 		///
-		virtual bool open(const FilePath& _filePath, bool _append, Error* _err) = 0;
+		virtual bool open(const FilePath& _filePath, bool _append = false, Error* _err = ErrorIgnore{}) = 0;
 	};
 
 	/// Open process interface.
@@ -101,7 +101,7 @@ namespace bx
 		virtual ~ProcessOpenI() = 0;
 
 		///
-		virtual bool open(const FilePath& _filePath, const StringView& _args, Error* _err) = 0;
+		virtual bool open(const FilePath& _filePath, const StringView& _args, Error* _err = ErrorIgnore{}) = 0;
 	};
 
 	/// Closer interface.
@@ -265,25 +265,25 @@ namespace bx
 	};
 
 	/// Read data.
-	int32_t read(ReaderI* _reader, void* _data, int32_t _size, Error* _err = NULL);
+	int32_t read(ReaderI* _reader, void* _data, int32_t _size, Error* _err);
 
 	/// Read value.
 	template<typename Ty>
-	int32_t read(ReaderI* _reader, Ty& _value, Error* _err = NULL);
+	int32_t read(ReaderI* _reader, Ty& _value, Error* _err);
 
 	/// Read value and converts it to host endianess. _fromLittleEndian specifies
 	/// underlying stream endianess.
 	template<typename Ty>
-	int32_t readHE(ReaderI* _reader, Ty& _value, bool _fromLittleEndian, Error* _err = NULL);
+	int32_t readHE(ReaderI* _reader, Ty& _value, bool _fromLittleEndian, Error* _err);
 
 	/// Write data.
-	int32_t write(WriterI* _writer, const void* _data, int32_t _size, Error* _err = NULL);
+	int32_t write(WriterI* _writer, const void* _data, int32_t _size, Error* _err);
 
 	/// Write C string.
-	int32_t write(WriterI* _writer, const char* _str, Error* _err = NULL);
+	int32_t write(WriterI* _writer, const char* _str, Error* _err);
 
 	/// Write string view.
-	int32_t write(WriterI* _writer, const StringView& _str, Error* _err = NULL);
+	int32_t write(WriterI* _writer, const StringView& _str, Error* _err);
 
 	/// Write formatted string.
 	int32_t write(WriterI* _writer, const StringView& _format, va_list _argList, Error* _err);
@@ -295,19 +295,19 @@ namespace bx
 	int32_t write(WriterI* _writer, Error* _err, const char* _format, ...);
 
 	/// Write repeat the same value.
-	int32_t writeRep(WriterI* _writer, uint8_t _byte, int32_t _size, Error* _err = NULL);
+	int32_t writeRep(WriterI* _writer, uint8_t _byte, int32_t _size, Error* _err);
 
 	/// Write value.
 	template<typename Ty>
-	int32_t write(WriterI* _writer, const Ty& _value, Error* _err = NULL);
+	int32_t write(WriterI* _writer, const Ty& _value, Error* _err);
 
 	/// Write value as little endian.
 	template<typename Ty>
-	int32_t writeLE(WriterI* _writer, const Ty& _value, Error* _err = NULL);
+	int32_t writeLE(WriterI* _writer, const Ty& _value, Error* _err);
 
 	/// Write value as big endian.
 	template<typename Ty>
-	int32_t writeBE(WriterI* _writer, const Ty& _value, Error* _err = NULL);
+	int32_t writeBE(WriterI* _writer, const Ty& _value, Error* _err);
 
 	/// Skip _offset bytes forward.
 	int64_t skip(SeekerI* _seeker, int64_t _offset);
@@ -322,26 +322,26 @@ namespace bx
 	int64_t getRemain(SeekerI* _seeker);
 
 	/// Peek data.
-	int32_t peek(ReaderSeekerI* _reader, void* _data, int32_t _size, Error* _err = NULL);
+	int32_t peek(ReaderSeekerI* _reader, void* _data, int32_t _size, Error* _err);
 
 	/// Peek value.
 	template<typename Ty>
-	int32_t peek(ReaderSeekerI* _reader, Ty& _value, Error* _err = NULL);
+	int32_t peek(ReaderSeekerI* _reader, Ty& _value, Error* _err);
 
 	/// Align reader stream.
-	int32_t align(ReaderSeekerI* _reader, uint32_t _alignment, Error* _err = NULL);
+	int32_t align(ReaderSeekerI* _reader, uint32_t _alignment, Error* _err);
 
 	/// Align writer stream (pads stream with zeros).
-	int32_t align(WriterSeekerI* _writer, uint32_t _alignment, Error* _err = NULL);
+	int32_t align(WriterSeekerI* _writer, uint32_t _alignment, Error* _err);
 
 	/// Open for read.
-	bool open(ReaderOpenI* _reader, const FilePath& _filePath, Error* _err = NULL);
+	bool open(ReaderOpenI* _reader, const FilePath& _filePath, Error* _err = ErrorIgnore{});
 
 	/// Open for write.
-	bool open(WriterOpenI* _writer, const FilePath& _filePath, bool _append = false, Error* _err = NULL);
+	bool open(WriterOpenI* _writer, const FilePath& _filePath, bool _append = false, Error* _err = ErrorIgnore{});
 
 	/// Open process.
-	bool open(ProcessOpenI* _process, const FilePath& _filePath, const StringView& _args, Error* _err = NULL);
+	bool open(ProcessOpenI* _process, const FilePath& _filePath, const StringView& _args, Error* _err = ErrorIgnore{});
 
 	/// Close.
 	void close(CloserI* _reader);

+ 2 - 2
include/bx/settings.h

@@ -51,10 +51,10 @@ namespace bx
 	};
 
 	///
-	int32_t read(ReaderSeekerI* _reader, Settings& _settings, Error* _err = NULL);
+	int32_t read(ReaderSeekerI* _reader, Settings& _settings, Error* _err);
 
 	///
-	int32_t write(WriterI* _writer, const Settings& _settings, Error* _err = NULL);
+	int32_t write(WriterI* _writer, const Settings& _settings, Error* _err);
 
 } // namespace bx
 

+ 3 - 3
include/bx/string.h

@@ -372,7 +372,7 @@ namespace bx
 	{
 	public:
 		///
-		LineReader(const bx::StringView& _str);
+		LineReader(const StringView& _str);
 
 		///
 		void reset();
@@ -387,8 +387,8 @@ namespace bx
 		uint32_t getLine() const;
 
 	private:
-		const bx::StringView m_str;
-		bx::StringView m_curr;
+		const StringView m_str;
+		StringView m_curr;
 		uint32_t m_line;
 	};
 

+ 1 - 7
scripts/bin2c.lua

@@ -6,18 +6,12 @@
 project "bin2c"
 	kind "ConsoleApp"
 
-	includedirs {
-		"../include",
-	}
-
 	files {
 		"../tools/bin2c/**.cpp",
 		"../tools/bin2c/**.h",
 	}
 
-	links {
-		"bx",
-	}
+	using_bx()
 
 	configuration { "mingw-*" }
 		targetextension ".exe"

+ 32 - 5
scripts/bx.lua

@@ -15,6 +15,28 @@ local function userdefines()
 	return defines
 end
 
+function using_bx()
+	includedirs {
+		path.join(BX_DIR, "include"),
+	}
+
+	links {
+		"bx",
+	}
+
+	configuration { "Debug" }
+		defines {
+			"BX_CONFIG_DEBUG=1",
+		}
+
+	configuration { "Release" }
+		defines {
+			"BX_CONFIG_DEBUG=0",
+		}
+
+	configuration {}
+end
+
 project "bx"
 	kind "StaticLib"
 
@@ -32,11 +54,6 @@ project "bx"
 
 	defines (userdefines())
 
-	configuration { "Debug" }
-		defines {
-			"BX_CONFIG_DEBUG=1",
-		}
-
 	configuration { "linux-*" }
 		buildoptions {
 			"-fPIC",
@@ -75,4 +92,14 @@ project "bx"
 		}
 	end
 
+	configuration { "Debug" }
+		defines {
+			"BX_CONFIG_DEBUG=1",
+		}
+
+	configuration { "Release" }
+		defines {
+			"BX_CONFIG_DEBUG=0",
+		}
+
 	configuration {}

+ 11 - 4
scripts/genie.lua

@@ -51,7 +51,6 @@ project "bx.test"
 	}
 
 	includedirs {
-		path.join(BX_DIR, "include"),
 		BX_THIRD_PARTY_DIR,
 	}
 
@@ -61,9 +60,7 @@ project "bx.test"
 		path.join(BX_DIR, "tests/dbg.*"),
 	}
 
-	links {
-		"bx",
-	}
+	using_bx()
 
 	configuration { "vs* or mingw*" }
 		links {
@@ -131,6 +128,16 @@ project "bx.bench"
 			"Cocoa.framework",
 		}
 
+	configuration { "Debug" }
+		defines {
+			"BX_CONFIG_DEBUG=1",
+		}
+
+	configuration { "Release" }
+		defines {
+			"BX_CONFIG_DEBUG=0",
+		}
+
 	configuration {}
 
 	strip()

+ 3 - 4
src/allocator.cpp

@@ -3,7 +3,6 @@
  * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
  */
 
-#include "bx_p.h"
 #include <bx/allocator.h>
 
 #include <malloc.h>
@@ -38,7 +37,7 @@ namespace bx
 				BX_UNUSED(_file, _line);
 				_aligned_free(_ptr);
 #	else
-				bx::alignedFree(this, _ptr, _align, _file, _line);
+				alignedFree(this, _ptr, _align, _file, _line);
 #	endif // BX_
 			}
 
@@ -55,7 +54,7 @@ namespace bx
 			BX_UNUSED(_file, _line);
 			return _aligned_malloc(_size, _align);
 #	else
-			return bx::alignedAlloc(this, _size, _align, _file, _line);
+			return alignedAlloc(this, _size, _align, _file, _line);
 #	endif // BX_
 		}
 
@@ -68,7 +67,7 @@ namespace bx
 		BX_UNUSED(_file, _line);
 		return _aligned_realloc(_ptr, _size, _align);
 #	else
-		return bx::alignedRealloc(this, _ptr, _size, _align, _file, _line);
+		return alignedRealloc(this, _ptr, _size, _align, _file, _line);
 #	endif // BX_
 	}
 

+ 0 - 1
src/bounds.cpp

@@ -3,7 +3,6 @@
  * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
  */
 
-#include "bx_p.h"
 #include <bx/rng.h>
 #include <bx/math.h>
 #include <bx/bounds.h>

+ 0 - 1
src/bx.cpp

@@ -3,7 +3,6 @@
  * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
  */
 
-#include "bx_p.h"
 #include <bx/debug.h>
 #include <bx/readerwriter.h>
 

+ 0 - 45
src/bx_p.h

@@ -1,45 +0,0 @@
-/*
- * Copyright 2010-2021 Branimir Karadzic. All rights reserved.
- * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
- */
-
-#ifndef BX_P_H_HEADER_GUARD
-#define BX_P_H_HEADER_GUARD
-
-#ifndef BX_CONFIG_DEBUG
-#	define BX_CONFIG_DEBUG 0
-#endif // BX_CONFIG_DEBUG
-
-#if BX_CONFIG_DEBUG
-#	define BX_TRACE _BX_TRACE
-#	define BX_WARN  _BX_WARN
-#	define BX_ASSERT _BX_ASSERT
-#	define BX_CONFIG_ALLOCATOR_DEBUG 1
-#endif // BX_CONFIG_DEBUG
-
-#define _BX_TRACE(_format, ...)                                                                       \
-				BX_MACRO_BLOCK_BEGIN                                                                  \
-					bx::debugPrintf(__FILE__ "(" BX_STRINGIZE(__LINE__) "): BX " _format "\n", ##__VA_ARGS__); \
-				BX_MACRO_BLOCK_END
-
-#define _BX_WARN(_condition, _format, ...)                        \
-				BX_MACRO_BLOCK_BEGIN                              \
-					if (!BX_IGNORE_C4127(_condition) )            \
-					{                                             \
-						BX_TRACE("WARN " _format, ##__VA_ARGS__); \
-					}                                             \
-				BX_MACRO_BLOCK_END
-
-#define _BX_ASSERT(_condition, _format, ...)                        \
-				BX_MACRO_BLOCK_BEGIN                               \
-					if (!BX_IGNORE_C4127(_condition) )             \
-					{                                              \
-						BX_TRACE("CHECK " _format, ##__VA_ARGS__); \
-						bx::debugBreak();                          \
-					}                                              \
-				BX_MACRO_BLOCK_END
-
-#include <bx/bx.h>
-#include <bx/debug.h>
-
-#endif // BX_P_H_HEADER_GUARD

+ 0 - 1
src/commandline.cpp

@@ -3,7 +3,6 @@
  * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
  */
 
-#include "bx_p.h"
 #include <bx/commandline.h>
 #include <bx/string.h>
 

+ 0 - 1
src/crtnone.cpp

@@ -3,7 +3,6 @@
  * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
  */
 
-#include "bx_p.h"
 #include <bx/debug.h>
 #include <bx/file.h>
 #include <bx/math.h>

+ 0 - 1
src/debug.cpp

@@ -3,7 +3,6 @@
  * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
  */
 
-#include "bx_p.h"
 #include <bx/debug.h>
 #include <bx/string.h>       // isPrint
 #include <bx/readerwriter.h> // WriterI

+ 1 - 2
src/dtoa.cpp

@@ -3,7 +3,6 @@
  * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
  */
 
-#include "bx_p.h"
 #include <bx/cpu.h>
 #include <bx/math.h>
 #include <bx/string.h>
@@ -1120,7 +1119,7 @@ namespace bx
 
 	bool fromString(int32_t* _out, const StringView& _str)
 	{
-		StringView str = bx::strLTrimSpace(_str);
+		StringView str = strLTrimSpace(_str);
 
 		const char* ptr  = str.getPtr();
 		const char* term = str.getTerm();

+ 0 - 1
src/easing.cpp

@@ -3,7 +3,6 @@
  * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
  */
 
-#include "bx_p.h"
 #include <bx/easing.h>
 
 namespace bx

+ 3 - 4
src/file.cpp

@@ -3,7 +3,6 @@
  * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
  */
 
-#include "bx_p.h"
 #include <bx/file.h>
 
 #ifndef BX_CONFIG_CRT_FILE_READER_WRITER
@@ -923,7 +922,7 @@ namespace bx
 		Error err;
 		DirectoryReader dr;
 
-		if (!bx::open(&dr, _filePath) )
+		if (!open(&dr, _filePath, &err) )
 		{
 			BX_ERROR_SET(_err, kErrorNotDirectory, "File already exist, and is not directory.");
 			return false;
@@ -931,7 +930,7 @@ namespace bx
 
 		while (err.isOk() )
 		{
-			bx::read(&dr, fi, &err);
+			read(&dr, fi, &err);
 
 			if (err.isOk() )
 			{
@@ -951,7 +950,7 @@ namespace bx
 			}
 		}
 
-		bx::close(&dr);
+		close(&dr);
 
 		return remove(_filePath, _err);
 	}

+ 0 - 1
src/filepath.cpp

@@ -3,7 +3,6 @@
  * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
  */
 
-#include "bx_p.h"
 #include <bx/file.h>
 #include <bx/os.h>
 #include <bx/readerwriter.h>

+ 0 - 1
src/hash.cpp

@@ -3,7 +3,6 @@
  * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
  */
 
-#include "bx_p.h"
 #include <bx/hash.h>
 
 namespace bx

+ 0 - 1
src/math.cpp

@@ -3,7 +3,6 @@
  * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
  */
 
-#include "bx_p.h"
 #include <bx/math.h>
 #include <bx/uint32_t.h>
 

+ 3 - 4
src/mutex.cpp

@@ -3,7 +3,6 @@
  * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
  */
 
-#include "bx_p.h"
 #include <bx/mutex.h>
 
 #if BX_CONFIG_SUPPORTS_THREADING
@@ -59,12 +58,12 @@ namespace bx
 	{
 		uint32_t* futex = (uint32_t*)m_internal;
 
-		if (State::Unlocked == bx::atomicCompareAndSwap<uint32_t>(futex, State::Unlocked, State::Locked) )
+		if (State::Unlocked == atomicCompareAndSwap<uint32_t>(futex, State::Unlocked, State::Locked) )
 		{
 			return;
 		}
 
-		while (State::Unlocked != bx::atomicCompareAndSwap<uint32_t>(futex, State::Locked, State::Contested) )
+		while (State::Unlocked != atomicCompareAndSwap<uint32_t>(futex, State::Locked, State::Contested) )
 		{
 			crt0::futexWait(futex, State::Contested);
 		}
@@ -74,7 +73,7 @@ namespace bx
 	{
 		uint32_t* futex = (uint32_t*)m_internal;
 
-		if (State::Contested == bx::atomicCompareAndSwap<uint32_t>(futex, State::Locked, State::Unlocked) )
+		if (State::Contested == atomicCompareAndSwap<uint32_t>(futex, State::Locked, State::Unlocked) )
 		{
 			crt0::futexWake(futex, State::Locked);
 		}

+ 10 - 6
src/os.cpp

@@ -3,7 +3,6 @@
  * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
  */
 
-#include "bx_p.h"
 #include <bx/string.h>
 #include <bx/os.h>
 #include <bx/uint32_t.h>
@@ -209,7 +208,7 @@ namespace bx
 	{
 		const int32_t symbolMax = _symbol.getLength()+1;
 		char* symbol = (char*)alloca(symbolMax);
-		bx::strCopy(symbol, symbolMax, _symbol);
+		strCopy(symbol, symbolMax, _symbol);
 
 #if BX_PLATFORM_WINDOWS
 		return (void*)::GetProcAddress( (HMODULE)_handle, symbol);
@@ -229,7 +228,7 @@ namespace bx
 	{
 		const int32_t nameMax = _name.getLength()+1;
 		char* name = (char*)alloca(nameMax);
-		bx::strCopy(name, nameMax, _name);
+		strCopy(name, nameMax, _name);
 
 #if BX_PLATFORM_WINDOWS
 		DWORD len = ::GetEnvironmentVariableA(name, _out, *_inOutSize);
@@ -267,14 +266,14 @@ namespace bx
 	{
 		const int32_t nameMax = _name.getLength()+1;
 		char* name = (char*)alloca(nameMax);
-		bx::strCopy(name, nameMax, _name);
+		strCopy(name, nameMax, _name);
 
 		char* value = NULL;
 		if (!_value.isEmpty() )
 		{
 			int32_t valueMax = _value.getLength()+1;
 			value = (char*)alloca(valueMax);
-			bx::strCopy(value, valueMax, _value);
+			strCopy(value, valueMax, _value);
 		}
 
 #if BX_PLATFORM_WINDOWS
@@ -344,7 +343,7 @@ namespace bx
 		int32_t len = 0;
 		for(uint32_t ii = 0; NULL != _argv[ii]; ++ii)
 		{
-			len += snprintf(&temp[len], bx::uint32_imax(0, total-len)
+			len += snprintf(&temp[len], uint32_imax(0, total-len)
 				, "%s "
 				, _argv[ii]
 				);
@@ -373,4 +372,9 @@ namespace bx
 #endif // BX_PLATFORM_LINUX || BX_PLATFORM_HURD
 	}
 
+	void exit(int32_t _exitCode)
+	{
+		::exit(_exitCode);
+	}
+
 } // namespace bx

+ 0 - 1
src/process.cpp

@@ -3,7 +3,6 @@
  * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
  */
 
-#include "bx_p.h"
 #include <bx/process.h>
 
 #include <stdio.h>

+ 0 - 1
src/semaphore.cpp

@@ -3,7 +3,6 @@
  * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
  */
 
-#include "bx_p.h"
 #include <bx/semaphore.h>
 
 #if BX_CONFIG_SUPPORTS_THREADING

+ 0 - 1
src/settings.cpp

@@ -3,7 +3,6 @@
  * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
  */
 
-#include "bx_p.h"
 #include <bx/settings.h>
 
 namespace

+ 0 - 1
src/sort.cpp

@@ -3,7 +3,6 @@
  * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
  */
 
-#include "bx_p.h"
 #include <bx/sort.h>
 
 namespace bx

+ 0 - 1
src/string.cpp

@@ -3,7 +3,6 @@
  * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
  */
 
-#include "bx_p.h"
 #include <bx/allocator.h>
 #include <bx/file.h>
 #include <bx/hash.h>

+ 1 - 2
src/thread.cpp

@@ -3,7 +3,6 @@
  * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
  */
 
-#include "bx_p.h"
 #include <bx/os.h>
 #include <bx/thread.h>
 
@@ -267,7 +266,7 @@ namespace bx
 
 		if (NULL != SetThreadDescription)
 		{
-			uint32_t length = (uint32_t)bx::strLen(_name)+1;
+			uint32_t length = (uint32_t)strLen(_name)+1;
 			uint32_t size = length*sizeof(wchar_t);
 			wchar_t* name = (wchar_t*)alloca(size);
 			mbstowcs(name, _name, size-2);

+ 0 - 1
src/timer.cpp

@@ -3,7 +3,6 @@
  * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
  */
 
-#include "bx_p.h"
 #include <bx/timer.h>
 
 #if BX_CRT_NONE

+ 0 - 1
src/url.cpp

@@ -3,7 +3,6 @@
  * License: https://github.com/bkaradzic/bnet#license-bsd-2-clause
  */
 
-#include "bx_p.h"
 #include <bx/url.h>
 
 namespace bx

+ 1 - 1
tests/easing_test.cpp

@@ -42,7 +42,7 @@ TEST_CASE("easing", "")
 					if (vv >= ys
 					&&  vv <  ye)
 					{
-						bx::write(writer, "*");
+						bx::write(writer, &err, "*");
 						break;
 					}
 				}

+ 4 - 4
tests/settings_test.cpp

@@ -21,9 +21,9 @@ TEST_CASE("Settings", "")
 	settings.set("test/foo/bar/abvgd", "1389");
 
 	bx::FileWriter writer;
-	if (bx::open(&writer, filePath) )
+	if (bx::open(&writer, filePath, false, bx::ErrorIgnore{}) )
 	{
-		bx::write(&writer, settings);
+		bx::write(&writer, settings, bx::ErrorIgnore{});
 		bx::close(&writer);
 	}
 
@@ -37,9 +37,9 @@ TEST_CASE("Settings", "")
 	settings.clear();
 
 	bx::FileReader reader;
-	if (bx::open(&reader, filePath) )
+	if (bx::open(&reader, filePath, bx::ErrorIgnore{}) )
 	{
-		bx::read(&reader, settings);
+		bx::read(&reader, settings, bx::ErrorIgnore{});
 		bx::close(&reader);
 	}
 

+ 3 - 3
tests/test.h

@@ -3,8 +3,8 @@
  * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
  */
 
-#ifndef __TEST_H__
-#define __TEST_H__
+#ifndef BX_TEST_H_HEADER_GUARD
+#define BX_TEST_H_HEADER_GUARD
 
 #include <bx/bx.h>
 
@@ -18,4 +18,4 @@ BX_PRAGMA_DIAGNOSTIC_POP();
 
 #include "dbg.h"
 
-#endif // __TEST_H__
+#endif // BX_TEST_H_HEADER_GUARD

BIN
tools/bin/linux/bin2c


+ 2 - 2
tools/bin2c/bin2c.cpp

@@ -252,14 +252,14 @@ int main(int _argc, const char* _argv[])
 
 		bx::DefaultAllocator allocator;
 		data = BX_ALLOC(&allocator, size);
-		bx::read(&fr, data, size);
+		bx::read(&fr, data, size, bx::ErrorAssert{});
 		bx::close(&fr);
 
 		bx::FileWriter fw;
 		if (bx::open(&fw, outFilePath) )
 		{
 			Bin2cWriter writer(&allocator, name);
-			bx::write(&writer, data, size);
+			bx::write(&writer, data, size, bx::ErrorAssert{});
 
 			writer.output(&fw);
 			bx::close(&fw);