From ab969f0a1a003a8073121415f3150f67909de918 Mon Sep 17 00:00:00 2001 From: bkaradzic Date: Sun, 22 Sep 2013 21:40:17 -0700 Subject: [PATCH] Enable tinystl by default. --- LICENSE | 2 ++ examples/07-callback/callback.cpp | 11 +++++--- examples/common/font/font_manager.cpp | 15 +---------- makefile | 1 - premake/bgfx.lua | 1 - src/bgfx.cpp | 37 ++++++++++++--------------- src/bgfx_p.h | 15 +++++------ src/config.h | 2 +- 8 files changed, 34 insertions(+), 50 deletions(-) diff --git a/LICENSE b/LICENSE index fd7fbc22..1d7f50be 100644 --- a/LICENSE +++ b/LICENSE @@ -20,3 +20,5 @@ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +https://github.com/bkaradzic/bgfx diff --git a/examples/07-callback/callback.cpp b/examples/07-callback/callback.cpp index 75e94795..2739113d 100644 --- a/examples/07-callback/callback.cpp +++ b/examples/07-callback/callback.cpp @@ -337,10 +337,13 @@ public: virtual void free(void* _ptr, const char* _file, uint32_t _line) BX_OVERRIDE { - dbgPrintf("%s(%d): FREE %p\n", _file, _line, _ptr); - BX_UNUSED(_file, _line); - ::free(_ptr); - --m_numBlocks; + if (NULL != _ptr) + { + dbgPrintf("%s(%d): FREE %p\n", _file, _line, _ptr); + BX_UNUSED(_file, _line); + ::free(_ptr); + --m_numBlocks; + } } virtual void* realloc(void* _ptr, size_t _size, const char* _file, uint32_t _line) BX_OVERRIDE diff --git a/examples/common/font/font_manager.cpp b/examples/common/font/font_manager.cpp index 3156e2ee..cb6c536a 100644 --- a/examples/common/font/font_manager.cpp +++ b/examples/common/font/font_manager.cpp @@ -13,21 +13,8 @@ #include "font_manager.h" #include "../cube_atlas.h" -#if BGFX_CONFIG_USE_TINYSTL -namespace tinystl -{ -} // namespace tinystl -# include +#include namespace stl = tinystl; -#else -# include -namespace std { namespace tr1 {} } -namespace stl -{ - using namespace std; - using namespace std::tr1; -} -#endif // BGFX_CONFIG_USE_TINYSTL struct FTHolder { diff --git a/makefile b/makefile index 3bb471ff..dfc79790 100644 --- a/makefile +++ b/makefile @@ -17,7 +17,6 @@ all: premake4 --file=premake/premake4.lua --gcc=ios-simulator gmake premake4 --file=premake/premake4.lua --gcc=qnx-arm gmake premake4 --file=premake/premake4.lua xcode4 - make -s --no-print-directory -C src android-arm-debug: make -R -C .build/projects/gmake-android-arm config=debug diff --git a/premake/bgfx.lua b/premake/bgfx.lua index 0a009c53..2bd25728 100644 --- a/premake/bgfx.lua +++ b/premake/bgfx.lua @@ -8,7 +8,6 @@ project "bgfx" kind "StaticLib" includedirs { - BGFX_DIR .. "../tinystl/include", BGFX_DIR .. "../bx/include", } diff --git a/src/bgfx.cpp b/src/bgfx.cpp index 5c3fb269..5d88da01 100755 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -5,22 +5,6 @@ #include "bgfx_p.h" -#if BGFX_CONFIG_USE_TINYSTL -namespace tinystl -{ - void* bgfx_allocator::static_allocate(size_t _bytes) - { - return BX_ALLOC(g_allocator, _bytes); - } - - void bgfx_allocator::static_deallocate(void* _ptr, size_t /*_bytes*/) - { - BX_FREE(g_allocator, _ptr); - } - -} // namespace tinystl -#endif // BGFX_CONFIG_USE_TINYSTL - namespace bgfx { #define BGFX_MAIN_THREAD_MAGIC 0x78666762 @@ -62,6 +46,16 @@ namespace bgfx } #endif // BX_PLATFORM_* + void* TinyStlAllocator::static_allocate(size_t _bytes) + { + return BX_ALLOC(bgfx::g_allocator, _bytes); + } + + void TinyStlAllocator::static_deallocate(void* _ptr, size_t /*_bytes*/) + { + BX_FREE(bgfx::g_allocator, _ptr); + } + struct CallbackStub : public CallbackI { virtual ~CallbackStub() @@ -134,12 +128,13 @@ namespace bgfx virtual void free(void* _ptr, const char* _file, uint32_t _line) BX_OVERRIDE { - BX_CHECK(_ptr != NULL, "Freeing NULL! Fix it!"); + if (NULL != _ptr) + { + --m_numBlocks; - --m_numBlocks; - - BX_UNUSED(_file, _line); - ::free(_ptr); + BX_UNUSED(_file, _line); + ::free(_ptr); + } } virtual void* realloc(void* _ptr, size_t _size, const char* _file, uint32_t _line) BX_OVERRIDE diff --git a/src/bgfx_p.h b/src/bgfx_p.h index 7f0ca373..c65ab456 100755 --- a/src/bgfx_p.h +++ b/src/bgfx_p.h @@ -82,19 +82,18 @@ namespace bgfx #include // mingw wants it to be before tr1/unordered_*... #if BGFX_CONFIG_USE_TINYSTL -namespace tinystl +namespace bgfx { - struct bgfx_allocator + struct TinyStlAllocator { static void* static_allocate(size_t _bytes); static void static_deallocate(void* _ptr, size_t /*_bytes*/); }; -} // namespace tinystl -# define TINYSTL_ALLOCATOR tinystl::bgfx_allocator - -# include -# include -# include +} // namespace bgfx +# define TINYSTL_ALLOCATOR bgfx::TinyStlAllocator +# include +# include +# include namespace stl = tinystl; #else # include diff --git a/src/config.h b/src/config.h index c6a88433..35995280 100644 --- a/src/config.h +++ b/src/config.h @@ -212,7 +212,7 @@ #endif // BGFX_CONFIG_MAX_CONSTANT_BUFFER_SIZE #ifndef BGFX_CONFIG_USE_TINYSTL -# define BGFX_CONFIG_USE_TINYSTL 0 +# define BGFX_CONFIG_USE_TINYSTL 1 #endif // BGFX_CONFIG_USE_TINYSTL #ifndef BGFX_CONFIG_MAX_INSTANCE_DATA_COUNT