From 1a102644edda8352086955eb4abcd16ea60ac94a Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sun, 1 Jul 2018 07:59:06 +0000 Subject: [PATCH] prevented HeapMmgr::allocMem() and HeapMmgr::reallocMem() from thrown an exception --- qse/include/qse/cmn/Mmgr.hpp | 2 +- qse/include/qse/si/TcpServer.hpp | 6 +++--- qse/include/qse/si/Thread.hpp | 8 ++++---- qse/lib/cmn/HeapMmgr.cpp | 16 ++++++---------- qse/samples/si/tcpsvr01.cpp | 6 +++--- 5 files changed, 17 insertions(+), 21 deletions(-) diff --git a/qse/include/qse/cmn/Mmgr.hpp b/qse/include/qse/cmn/Mmgr.hpp index 45f5f2e0..481c695d 100644 --- a/qse/include/qse/cmn/Mmgr.hpp +++ b/qse/include/qse/cmn/Mmgr.hpp @@ -109,7 +109,7 @@ public: /// /// The dispose() function calls freeMem() for memory disposal. /// - void dispose (void* ptr) + void dispose (void* ptr) QSE_CPP_NOEXCEPT { this->freeMem (ptr); } diff --git a/qse/include/qse/si/TcpServer.hpp b/qse/include/qse/si/TcpServer.hpp index 45910e44..902258c8 100644 --- a/qse/include/qse/si/TcpServer.hpp +++ b/qse/include/qse/si/TcpServer.hpp @@ -41,7 +41,7 @@ QSE_BEGIN_NAMESPACE(QSE) // The TcpServer class implements a simple block TCP server that start a thread // for each connection accepted. -class TcpServer: public Uncopyable, public Mmged, public Types +class QSE_EXPORT TcpServer: public Uncopyable, public Mmged, public Types { public: TcpServer (Mmgr* mmgr = QSE_NULL) QSE_CPP_NOEXCEPT; @@ -176,7 +176,7 @@ private: // functor as a template parameter template -class TcpServerF: public TcpServer +class QSE_EXPORT TcpServerF: public TcpServer { public: TcpServerF (Mmgr* mmgr = QSE_NULL) QSE_CPP_NOEXCEPT: TcpServer(mmgr) {} @@ -201,7 +201,7 @@ template class TcpServerL; template -class TcpServerL: public TcpServer +class QSE_EXPORT TcpServerL: public TcpServer { public: TcpServerL (Mmgr* mmgr = QSE_NULL) QSE_CPP_NOEXCEPT: TcpServer(mmgr), __lfunc(nullptr) {} diff --git a/qse/include/qse/si/Thread.hpp b/qse/include/qse/si/Thread.hpp index 579d6d18..61942850 100644 --- a/qse/include/qse/si/Thread.hpp +++ b/qse/include/qse/si/Thread.hpp @@ -33,7 +33,7 @@ QSE_BEGIN_NAMESPACE(QSE) -class Thread: public Uncopyable, public Mmged +class QSE_EXPORT Thread: public Uncopyable, public Mmged { public: // native thread handle type @@ -94,7 +94,7 @@ protected: static Handle INVALID_HANDLE; }; -class ThreadR: public Thread +class QSE_EXPORT ThreadR: public Thread { public: ThreadR (Mmgr* mmgr = QSE_NULL) QSE_CPP_NOEXCEPT: Thread(mmgr) {} @@ -109,7 +109,7 @@ protected: }; template -class ThreadF: public Thread +class QSE_EXPORT ThreadF: public Thread { public: ThreadF (Mmgr* mmgr = QSE_NULL) QSE_CPP_NOEXCEPT: Thread(mmgr) {} @@ -163,7 +163,7 @@ template class ThreadL; template -class ThreadL: public Thread +class QSE_EXPORT ThreadL: public Thread { public: ThreadL (Mmgr* mmgr = QSE_NULL) QSE_CPP_NOEXCEPT: Thread(mmgr), __lfunc(nullptr) {} diff --git a/qse/lib/cmn/HeapMmgr.cpp b/qse/lib/cmn/HeapMmgr.cpp index dec1ccba..74521192 100644 --- a/qse/lib/cmn/HeapMmgr.cpp +++ b/qse/lib/cmn/HeapMmgr.cpp @@ -55,32 +55,28 @@ void* HeapMmgr::allocMem (qse_size_t n) QSE_CPP_NOEXCEPT { if (!this->xma) { - this->xma = qse_xma_open (this->getMmgr(), QSE_SIZEOF(xma_xtn_t), heap_size); + this->xma = qse_xma_open(this->getMmgr(), QSE_SIZEOF(xma_xtn_t), heap_size); if (!this->xma) return QSE_NULL; - xma_xtn_t* xtn = (xma_xtn_t*)qse_xma_getxtn (this->xma); + xma_xtn_t* xtn = (xma_xtn_t*)qse_xma_getxtn(this->xma); xtn->heap = this; } - void* xptr = qse_xma_alloc (this->xma, n); - if (!xptr) QSE_THROW (MemoryError); - return xptr; + return qse_xma_alloc(this->xma, n); } void* HeapMmgr::reallocMem (void* ptr, qse_size_t n) QSE_CPP_NOEXCEPT { if (!this->xma) { - this->xma = qse_xma_open (this->getMmgr(), QSE_SIZEOF(xma_xtn_t), heap_size); + this->xma = qse_xma_open(this->getMmgr(), QSE_SIZEOF(xma_xtn_t), heap_size); if (!this->xma) return QSE_NULL; - xma_xtn_t* xtn = (xma_xtn_t*)qse_xma_getxtn (this->xma); + xma_xtn_t* xtn = (xma_xtn_t*)qse_xma_getxtn(this->xma); xtn->heap = this; } - void* xptr = qse_xma_realloc (this->xma, ptr, n); - if (!xptr) QSE_THROW (MemoryError); - return xptr; + return qse_xma_realloc(this->xma, ptr, n); } void HeapMmgr::freeMem (void* ptr) QSE_CPP_NOEXCEPT diff --git a/qse/samples/si/tcpsvr01.cpp b/qse/samples/si/tcpsvr01.cpp index 8ff70ebb..b4946697 100644 --- a/qse/samples/si/tcpsvr01.cpp +++ b/qse/samples/si/tcpsvr01.cpp @@ -29,7 +29,7 @@ public: qse_ssize_t n; cliaddr->toStrBuf(addrbuf, QSE_COUNTOF(addrbuf)); - //qse_printf (QSE_T("hello word..from %s\n"), addrbuf); + qse_printf (QSE_T("hello word..from %s\n"), addrbuf); while (!server->isStopRequested()) { @@ -41,7 +41,7 @@ public: clisock->send (bb, n); } - //qse_printf (QSE_T("byte to %s\n"), addrbuf); + qse_printf (QSE_T("byte to %s\n"), addrbuf); return 0; } }; @@ -74,7 +74,7 @@ static int test1 (void) } clisock->send (bb, n); } - + qse_printf (QSE_T("byte to %s\n"), addrbuf); return 0; }),