diff --git a/include/bx/bx.h b/include/bx/bx.h index e55c471..7c2d061 100644 --- a/include/bx/bx.h +++ b/include/bx/bx.h @@ -17,7 +17,7 @@ #include "macros.h" /// -#define BX_COUNTOF(_x) sizeof(bx::COUNTOF_REQUIRES_ARRAY_ARGUMENT(_x) ) +#define BX_COUNTOF(_x) sizeof(bx::CountOfRequireArrayArgumentT(_x) ) /// #define BX_IGNORE_C4127(_x) bx::ignoreC4127(!!(_x) ) @@ -38,12 +38,12 @@ namespace bx template constexpr bool isTriviallyCopyable(); - /// Exchange two values. + /// Swap two values. template - void xchg(Ty& _a, Ty& _b); + void swap(Ty& _a, Ty& _b); - /// Exchange memory. - void xchg(void* _a, void* _b, size_t _numBytes); + /// Swap memory. + void swap(void* _a, void* _b, size_t _numBytes); /// Returns minimum of two values. template @@ -73,10 +73,6 @@ namespace bx template constexpr bool isPowerOf2(Ty _a); - // http://cnicholson.net/2011/01/stupid-c-tricks-a-better-sizeof_array/ - template - char (&COUNTOF_REQUIRES_ARRAY_ARGUMENT(const T(&)[N]) )[N]; - /// void memCopy(void* _dst, const void* _src, size_t _numBytes); diff --git a/include/bx/inline/bx.inl b/include/bx/inline/bx.inl index 37a00da..34c8948 100644 --- a/include/bx/inline/bx.inl +++ b/include/bx/inline/bx.inl @@ -9,6 +9,11 @@ namespace bx { + // Reference: + // https://web.archive.org/web/20181115035420/http://cnicholson.net/2011/01/stupid-c-tricks-a-better-sizeof_array/ + template + char(&CountOfRequireArrayArgumentT(const Ty(&)[Num]))[Num]; + template inline constexpr bool isEnabled() { @@ -33,7 +38,7 @@ namespace bx } template - inline void xchg(Ty& _a, Ty& _b) + inline void swap(Ty& _a, Ty& _b) { Ty tmp = _a; _a = _b; _b = tmp; } diff --git a/include/bx/inline/rng.inl b/include/bx/inline/rng.inl index 8261a75..d9796bd 100644 --- a/include/bx/inline/rng.inl +++ b/include/bx/inline/rng.inl @@ -141,7 +141,7 @@ namespace bx for (uint32_t ii = 0, num = _num-1; ii < num; ++ii) { uint32_t jj = ii + 1 + _rng->gen() % (num - ii); - bx::xchg(_array[ii], _array[jj]); + bx::swap(_array[ii], _array[jj]); } } diff --git a/include/bx/os.h b/include/bx/os.h index 09097a1..7258970 100644 --- a/include/bx/os.h +++ b/include/bx/os.h @@ -7,6 +7,7 @@ #define BX_OS_H_HEADER_GUARD #include "debug.h" +#include "filepath.h" #if BX_PLATFORM_OSX # define BX_DL_EXT "dylib" @@ -31,7 +32,7 @@ namespace bx size_t getProcessMemoryUsed(); /// - void* dlopen(const char* _filePath); + void* dlopen(const FilePath& _filePath); /// void dlclose(void* _handle); @@ -40,13 +41,10 @@ namespace bx void* dlsym(void* _handle, const char* _symbol); /// - bool getenv(const char* _name, char* _out, uint32_t* _inOutSize); + bool getEnv(const char* _name, char* _out, uint32_t* _inOutSize); /// - void setenv(const char* _name, const char* _value); - - /// - void unsetenv(const char* _name); + void setEnv(const char* _name, const char* _value); /// int chdir(const char* _path); diff --git a/makefile b/makefile index a22063d..65e55a7 100644 --- a/makefile +++ b/makefile @@ -6,8 +6,7 @@ GENIE=../bx/tools/bin/$(OS)/genie all: - $(GENIE) vs2012 - $(GENIE) vs2013 + $(GENIE) vs2017 $(GENIE) --gcc=android-arm gmake $(GENIE) --gcc=android-mips gmake $(GENIE) --gcc=android-x86 gmake @@ -75,11 +74,8 @@ mingw-clang-release64: .build/projects/gmake-mingw-clang make -R -C .build/projects/gmake-mingw-clang config=release64 mingw-clang: mingw-clang-debug32 mingw-clang-release32 mingw-clang-debug64 mingw-clang-release64 -.build/projects/vs2012: - $(GENIE) vs2012 - -.build/projects/vs2013: - $(GENIE) vs2013 +.build/projects/vs2017: + $(GENIE) vs2017 .build/projects/gmake-osx: $(GENIE) --gcc=osx gmake diff --git a/src/bx.cpp b/src/bx.cpp index 16868df..659cb59 100644 --- a/src/bx.cpp +++ b/src/bx.cpp @@ -13,14 +13,14 @@ namespace bx { - void xchg(void* _a, void* _b, size_t _numBytes) + void swap(void* _a, void* _b, size_t _numBytes) { uint8_t* lhs = (uint8_t*)_a; uint8_t* rhs = (uint8_t*)_b; const uint8_t* end = rhs + _numBytes; while (rhs != end) { - xchg(*lhs++, *rhs++); + swap(*lhs++, *rhs++); } } diff --git a/src/dtoa.cpp b/src/dtoa.cpp index 37d7407..3c23ea5 100644 --- a/src/dtoa.cpp +++ b/src/dtoa.cpp @@ -467,7 +467,7 @@ namespace bx { for (int32_t ii = 0, jj = _len - 1; ii < jj; ++ii, --jj) { - xchg(_dst[ii], _dst[jj]); + swap(_dst[ii], _dst[jj]); } } diff --git a/src/filepath.cpp b/src/filepath.cpp index e09ed59..f3a5431 100644 --- a/src/filepath.cpp +++ b/src/filepath.cpp @@ -158,7 +158,7 @@ namespace bx uint32_t len = *_inOutSize; *_out = '\0'; - if (getenv(_name, _out, &len) ) + if (getEnv(_name, _out, &len) ) { FileInfo fi; if (stat(_out, fi) @@ -190,9 +190,13 @@ namespace bx static bool getCurrentPath(char* _out, uint32_t* _inOutSize) { uint32_t len = *_inOutSize; - pwd(_out, len); - *_inOutSize = strLen(_out); - return true; + if (NULL != pwd(_out, len)) + { + *_inOutSize = strLen(_out); + return true; + } + + return false; } static bool getHomePath(char* _out, uint32_t* _inOutSize) diff --git a/src/os.cpp b/src/os.cpp index b90eae4..9ed078c 100644 --- a/src/os.cpp +++ b/src/os.cpp @@ -171,10 +171,10 @@ namespace bx #endif // BX_PLATFORM_* } - void* dlopen(const char* _filePath) + void* dlopen(const FilePath& _filePath) { #if BX_PLATFORM_WINDOWS - return (void*)::LoadLibraryA(_filePath); + return (void*)::LoadLibraryA(_filePath.get() ); #elif BX_PLATFORM_EMSCRIPTEN \ || BX_PLATFORM_PS4 \ || BX_PLATFORM_XBOXONE \ @@ -183,7 +183,7 @@ namespace bx BX_UNUSED(_filePath); return NULL; #else - return ::dlopen(_filePath, RTLD_LOCAL|RTLD_LAZY); + return ::dlopen(_filePath.get(), RTLD_LOCAL|RTLD_LAZY); #endif // BX_PLATFORM_ } @@ -218,7 +218,7 @@ namespace bx #endif // BX_PLATFORM_ } - bool getenv(const char* _name, char* _out, uint32_t* _inOutSize) + bool getEnv(const char* _name, char* _out, uint32_t* _inOutSize) { #if BX_PLATFORM_WINDOWS DWORD len = ::GetEnvironmentVariableA(_name, _out, *_inOutSize); @@ -251,7 +251,7 @@ namespace bx #endif // BX_PLATFORM_ } - void setenv(const char* _name, const char* _value) + void setEnv(const char* _name, const char* _value) { #if BX_PLATFORM_WINDOWS ::SetEnvironmentVariableA(_name, _value); @@ -261,21 +261,14 @@ namespace bx || BX_CRT_NONE BX_UNUSED(_name, _value); #else - ::setenv(_name, _value, 1); -#endif // BX_PLATFORM_ - } - - void unsetenv(const char* _name) - { -#if BX_PLATFORM_WINDOWS - ::SetEnvironmentVariableA(_name, NULL); -#elif BX_PLATFORM_PS4 \ - || BX_PLATFORM_XBOXONE \ - || BX_PLATFORM_WINRT \ - || BX_CRT_NONE - BX_UNUSED(_name); -#else - ::unsetenv(_name); + if (NULL == _value) + { + ::setenv(_name, _value, 1); + } + else + { + ::unsetenv(_name); + } #endif // BX_PLATFORM_ } diff --git a/src/sort.cpp b/src/sort.cpp index 2dd3fa6..515b33f 100644 --- a/src/sort.cpp +++ b/src/sort.cpp @@ -27,12 +27,12 @@ namespace bx int32_t result = _fn(&data[ii*_stride], _pivot); if (0 > result) { - xchg(&data[ll*_stride], &data[ii*_stride], _stride); + swap(&data[ll*_stride], &data[ii*_stride], _stride); ++ll; } else if (0 == result) { - xchg(&data[gg*_stride], &data[ii*_stride], _stride); + swap(&data[gg*_stride], &data[ii*_stride], _stride); ++gg; ++ii; }