Branimir Karadžić 7 年之前
父節點
當前提交
d1c6ff2b1f
共有 10 個文件被更改,包括 45 次插入53 次删除
  1. 5 9
      include/bx/bx.h
  2. 6 1
      include/bx/inline/bx.inl
  3. 1 1
      include/bx/inline/rng.inl
  4. 4 6
      include/bx/os.h
  5. 3 7
      makefile
  6. 2 2
      src/bx.cpp
  7. 1 1
      src/dtoa.cpp
  8. 8 4
      src/filepath.cpp
  9. 13 20
      src/os.cpp
  10. 2 2
      src/sort.cpp

+ 5 - 9
include/bx/bx.h

@@ -17,7 +17,7 @@
 #include "macros.h"
 #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) )
 #define BX_IGNORE_C4127(_x) bx::ignoreC4127(!!(_x) )
@@ -38,12 +38,12 @@ namespace bx
 	template<class Ty>
 	template<class Ty>
 	constexpr bool isTriviallyCopyable();
 	constexpr bool isTriviallyCopyable();
 
 
-	/// Exchange two values.
+	/// Swap two values.
 	template<typename Ty>
 	template<typename Ty>
-	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.
 	/// Returns minimum of two values.
 	template<typename Ty>
 	template<typename Ty>
@@ -73,10 +73,6 @@ namespace bx
 	template<typename Ty>
 	template<typename Ty>
 	constexpr bool isPowerOf2(Ty _a);
 	constexpr bool isPowerOf2(Ty _a);
 
 
-	// http://cnicholson.net/2011/01/stupid-c-tricks-a-better-sizeof_array/
-	template<typename T, size_t N>
-	char (&COUNTOF_REQUIRES_ARRAY_ARGUMENT(const T(&)[N]) )[N];
-
 	///
 	///
 	void memCopy(void* _dst, const void* _src, size_t _numBytes);
 	void memCopy(void* _dst, const void* _src, size_t _numBytes);
 
 

+ 6 - 1
include/bx/inline/bx.inl

@@ -9,6 +9,11 @@
 
 
 namespace bx
 namespace bx
 {
 {
+	// Reference:
+	// https://web.archive.org/web/20181115035420/http://cnicholson.net/2011/01/stupid-c-tricks-a-better-sizeof_array/
+	template<typename Ty, size_t Num>
+	char(&CountOfRequireArrayArgumentT(const Ty(&)[Num]))[Num];
+
 	template<bool>
 	template<bool>
 	inline constexpr bool isEnabled()
 	inline constexpr bool isEnabled()
 	{
 	{
@@ -33,7 +38,7 @@ namespace bx
 	}
 	}
 
 
 	template<typename Ty>
 	template<typename Ty>
-	inline void xchg(Ty& _a, Ty& _b)
+	inline void swap(Ty& _a, Ty& _b)
 	{
 	{
 		Ty tmp = _a; _a = _b; _b = tmp;
 		Ty tmp = _a; _a = _b; _b = tmp;
 	}
 	}

+ 1 - 1
include/bx/inline/rng.inl

@@ -141,7 +141,7 @@ namespace bx
 		for (uint32_t ii = 0, num = _num-1; ii < num; ++ii)
 		for (uint32_t ii = 0, num = _num-1; ii < num; ++ii)
 		{
 		{
 			uint32_t jj = ii + 1 + _rng->gen() % (num - ii);
 			uint32_t jj = ii + 1 + _rng->gen() % (num - ii);
-			bx::xchg(_array[ii], _array[jj]);
+			bx::swap(_array[ii], _array[jj]);
 		}
 		}
 	}
 	}
 
 

+ 4 - 6
include/bx/os.h

@@ -7,6 +7,7 @@
 #define BX_OS_H_HEADER_GUARD
 #define BX_OS_H_HEADER_GUARD
 
 
 #include "debug.h"
 #include "debug.h"
+#include "filepath.h"
 
 
 #if BX_PLATFORM_OSX
 #if BX_PLATFORM_OSX
 #	define BX_DL_EXT "dylib"
 #	define BX_DL_EXT "dylib"
@@ -31,7 +32,7 @@ namespace bx
 	size_t getProcessMemoryUsed();
 	size_t getProcessMemoryUsed();
 
 
 	///
 	///
-	void* dlopen(const char* _filePath);
+	void* dlopen(const FilePath& _filePath);
 
 
 	///
 	///
 	void dlclose(void* _handle);
 	void dlclose(void* _handle);
@@ -40,13 +41,10 @@ namespace bx
 	void* dlsym(void* _handle, const char* _symbol);
 	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);
 	int chdir(const char* _path);

+ 3 - 7
makefile

@@ -6,8 +6,7 @@
 GENIE=../bx/tools/bin/$(OS)/genie
 GENIE=../bx/tools/bin/$(OS)/genie
 
 
 all:
 all:
-	$(GENIE) vs2012
-	$(GENIE) vs2013
+	$(GENIE) vs2017
 	$(GENIE) --gcc=android-arm gmake
 	$(GENIE) --gcc=android-arm gmake
 	$(GENIE) --gcc=android-mips gmake
 	$(GENIE) --gcc=android-mips gmake
 	$(GENIE) --gcc=android-x86 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
 	make -R -C .build/projects/gmake-mingw-clang config=release64
 mingw-clang: mingw-clang-debug32 mingw-clang-release32 mingw-clang-debug64 mingw-clang-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:
 .build/projects/gmake-osx:
 	$(GENIE) --gcc=osx gmake
 	$(GENIE) --gcc=osx gmake

+ 2 - 2
src/bx.cpp

@@ -13,14 +13,14 @@
 
 
 namespace bx
 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* lhs = (uint8_t*)_a;
 		uint8_t* rhs = (uint8_t*)_b;
 		uint8_t* rhs = (uint8_t*)_b;
 		const uint8_t* end = rhs + _numBytes;
 		const uint8_t* end = rhs + _numBytes;
 		while (rhs != end)
 		while (rhs != end)
 		{
 		{
-			xchg(*lhs++, *rhs++);
+			swap(*lhs++, *rhs++);
 		}
 		}
 	}
 	}
 
 

+ 1 - 1
src/dtoa.cpp

@@ -467,7 +467,7 @@ namespace bx
 	{
 	{
 		for (int32_t ii = 0, jj = _len - 1; ii < jj; ++ii, --jj)
 		for (int32_t ii = 0, jj = _len - 1; ii < jj; ++ii, --jj)
 		{
 		{
-			xchg(_dst[ii], _dst[jj]);
+			swap(_dst[ii], _dst[jj]);
 		}
 		}
 	}
 	}
 
 

+ 8 - 4
src/filepath.cpp

@@ -158,7 +158,7 @@ namespace bx
 		uint32_t len = *_inOutSize;
 		uint32_t len = *_inOutSize;
 		*_out = '\0';
 		*_out = '\0';
 
 
-		if (getenv(_name, _out, &len) )
+		if (getEnv(_name, _out, &len) )
 		{
 		{
 			FileInfo fi;
 			FileInfo fi;
 			if (stat(_out, fi)
 			if (stat(_out, fi)
@@ -190,9 +190,13 @@ namespace bx
 	static bool getCurrentPath(char* _out, uint32_t* _inOutSize)
 	static bool getCurrentPath(char* _out, uint32_t* _inOutSize)
 	{
 	{
 		uint32_t len = *_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)
 	static bool getHomePath(char* _out, uint32_t* _inOutSize)

+ 13 - 20
src/os.cpp

@@ -171,10 +171,10 @@ namespace bx
 #endif // BX_PLATFORM_*
 #endif // BX_PLATFORM_*
 	}
 	}
 
 
-	void* dlopen(const char* _filePath)
+	void* dlopen(const FilePath& _filePath)
 	{
 	{
 #if BX_PLATFORM_WINDOWS
 #if BX_PLATFORM_WINDOWS
-		return (void*)::LoadLibraryA(_filePath);
+		return (void*)::LoadLibraryA(_filePath.get() );
 #elif  BX_PLATFORM_EMSCRIPTEN \
 #elif  BX_PLATFORM_EMSCRIPTEN \
 	|| BX_PLATFORM_PS4        \
 	|| BX_PLATFORM_PS4        \
 	|| BX_PLATFORM_XBOXONE    \
 	|| BX_PLATFORM_XBOXONE    \
@@ -183,7 +183,7 @@ namespace bx
 		BX_UNUSED(_filePath);
 		BX_UNUSED(_filePath);
 		return NULL;
 		return NULL;
 #else
 #else
-		return ::dlopen(_filePath, RTLD_LOCAL|RTLD_LAZY);
+		return ::dlopen(_filePath.get(), RTLD_LOCAL|RTLD_LAZY);
 #endif // BX_PLATFORM_
 #endif // BX_PLATFORM_
 	}
 	}
 
 
@@ -218,7 +218,7 @@ namespace bx
 #endif // BX_PLATFORM_
 #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
 #if BX_PLATFORM_WINDOWS
 		DWORD len = ::GetEnvironmentVariableA(_name, _out, *_inOutSize);
 		DWORD len = ::GetEnvironmentVariableA(_name, _out, *_inOutSize);
@@ -251,7 +251,7 @@ namespace bx
 #endif // BX_PLATFORM_
 #endif // BX_PLATFORM_
 	}
 	}
 
 
-	void setenv(const char* _name, const char* _value)
+	void setEnv(const char* _name, const char* _value)
 	{
 	{
 #if BX_PLATFORM_WINDOWS
 #if BX_PLATFORM_WINDOWS
 		::SetEnvironmentVariableA(_name, _value);
 		::SetEnvironmentVariableA(_name, _value);
@@ -261,21 +261,14 @@ namespace bx
 	|| BX_CRT_NONE
 	|| BX_CRT_NONE
 		BX_UNUSED(_name, _value);
 		BX_UNUSED(_name, _value);
 #else
 #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_
 #endif // BX_PLATFORM_
 	}
 	}
 
 

+ 2 - 2
src/sort.cpp

@@ -27,12 +27,12 @@ namespace bx
 			int32_t result = _fn(&data[ii*_stride], _pivot);
 			int32_t result = _fn(&data[ii*_stride], _pivot);
 			if (0 > result)
 			if (0 > result)
 			{
 			{
-				xchg(&data[ll*_stride], &data[ii*_stride], _stride);
+				swap(&data[ll*_stride], &data[ii*_stride], _stride);
 				++ll;
 				++ll;
 			}
 			}
 			else if (0 == result)
 			else if (0 == result)
 			{
 			{
-				xchg(&data[gg*_stride], &data[ii*_stride], _stride);
+				swap(&data[gg*_stride], &data[ii*_stride], _stride);
 				++gg;
 				++gg;
 				++ii;
 				++ii;
 			}
 			}