mirror of
https://github.com/bkaradzic/bx.git
synced 2026-02-17 20:52:37 +01:00
Fixed assert macros, and improved error handling.
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
#include "platform.h"
|
||||
#include "config.h"
|
||||
#include "macros.h"
|
||||
#include "debug.h"
|
||||
|
||||
///
|
||||
#define BX_COUNTOF(_x) sizeof(bx::CountOfRequireArrayArgumentT(_x) )
|
||||
|
||||
@@ -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 \
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,17 +229,51 @@
|
||||
#endif // BX_COMPILER_MSVC
|
||||
|
||||
#ifndef BX_ASSERT
|
||||
# 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
|
||||
# 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
|
||||
# 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")
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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 {}
|
||||
|
||||
@@ -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,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_
|
||||
}
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
|
||||
45
src/bx_p.h
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
|
||||
@@ -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>
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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,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);
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
* License: https://github.com/bkaradzic/bx#license-bsd-2-clause
|
||||
*/
|
||||
|
||||
#include "bx_p.h"
|
||||
#include <bx/hash.h>
|
||||
|
||||
namespace bx
|
||||
|
||||
@@ -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,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);
|
||||
}
|
||||
|
||||
16
src/os.cpp
16
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
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
* License: https://github.com/bkaradzic/bx#license-bsd-2-clause
|
||||
*/
|
||||
|
||||
#include "bx_p.h"
|
||||
#include <bx/settings.h>
|
||||
|
||||
namespace
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
* License: https://github.com/bkaradzic/bx#license-bsd-2-clause
|
||||
*/
|
||||
|
||||
#include "bx_p.h"
|
||||
#include <bx/sort.h>
|
||||
|
||||
namespace bx
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
* License: https://github.com/bkaradzic/bnet#license-bsd-2-clause
|
||||
*/
|
||||
|
||||
#include "bx_p.h"
|
||||
#include <bx/url.h>
|
||||
|
||||
namespace bx
|
||||
|
||||
@@ -42,7 +42,7 @@ TEST_CASE("easing", "")
|
||||
if (vv >= ys
|
||||
&& vv < ye)
|
||||
{
|
||||
bx::write(writer, "*");
|
||||
bx::write(writer, &err, "*");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,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
|
||||
|
||||
Binary file not shown.
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user