prevented HeapMmgr::allocMem() and HeapMmgr::reallocMem() from thrown an exception

This commit is contained in:
hyung-hwan 2018-07-01 07:59:06 +00:00
parent 9ff9cb1d55
commit 1a102644ed
5 changed files with 17 additions and 21 deletions

View File

@ -109,7 +109,7 @@ public:
/// ///
/// The dispose() function calls freeMem() for memory disposal. /// The dispose() function calls freeMem() for memory disposal.
/// ///
void dispose (void* ptr) void dispose (void* ptr) QSE_CPP_NOEXCEPT
{ {
this->freeMem (ptr); this->freeMem (ptr);
} }

View File

@ -41,7 +41,7 @@ QSE_BEGIN_NAMESPACE(QSE)
// The TcpServer class implements a simple block TCP server that start a thread // The TcpServer class implements a simple block TCP server that start a thread
// for each connection accepted. // for each connection accepted.
class TcpServer: public Uncopyable, public Mmged, public Types class QSE_EXPORT TcpServer: public Uncopyable, public Mmged, public Types
{ {
public: public:
TcpServer (Mmgr* mmgr = QSE_NULL) QSE_CPP_NOEXCEPT; TcpServer (Mmgr* mmgr = QSE_NULL) QSE_CPP_NOEXCEPT;
@ -176,7 +176,7 @@ private:
// functor as a template parameter // functor as a template parameter
template <typename F> template <typename F>
class TcpServerF: public TcpServer class QSE_EXPORT TcpServerF: public TcpServer
{ {
public: public:
TcpServerF (Mmgr* mmgr = QSE_NULL) QSE_CPP_NOEXCEPT: TcpServer(mmgr) {} TcpServerF (Mmgr* mmgr = QSE_NULL) QSE_CPP_NOEXCEPT: TcpServer(mmgr) {}
@ -201,7 +201,7 @@ template <typename T>
class TcpServerL; class TcpServerL;
template <typename RT, typename... ARGS> template <typename RT, typename... ARGS>
class TcpServerL<RT(ARGS...)>: public TcpServer class QSE_EXPORT TcpServerL<RT(ARGS...)>: public TcpServer
{ {
public: public:
TcpServerL (Mmgr* mmgr = QSE_NULL) QSE_CPP_NOEXCEPT: TcpServer(mmgr), __lfunc(nullptr) {} TcpServerL (Mmgr* mmgr = QSE_NULL) QSE_CPP_NOEXCEPT: TcpServer(mmgr), __lfunc(nullptr) {}

View File

@ -33,7 +33,7 @@
QSE_BEGIN_NAMESPACE(QSE) QSE_BEGIN_NAMESPACE(QSE)
class Thread: public Uncopyable, public Mmged class QSE_EXPORT Thread: public Uncopyable, public Mmged
{ {
public: public:
// native thread handle type // native thread handle type
@ -94,7 +94,7 @@ protected:
static Handle INVALID_HANDLE; static Handle INVALID_HANDLE;
}; };
class ThreadR: public Thread class QSE_EXPORT ThreadR: public Thread
{ {
public: public:
ThreadR (Mmgr* mmgr = QSE_NULL) QSE_CPP_NOEXCEPT: Thread(mmgr) {} ThreadR (Mmgr* mmgr = QSE_NULL) QSE_CPP_NOEXCEPT: Thread(mmgr) {}
@ -109,7 +109,7 @@ protected:
}; };
template <typename F> template <typename F>
class ThreadF: public Thread class QSE_EXPORT ThreadF: public Thread
{ {
public: public:
ThreadF (Mmgr* mmgr = QSE_NULL) QSE_CPP_NOEXCEPT: Thread(mmgr) {} ThreadF (Mmgr* mmgr = QSE_NULL) QSE_CPP_NOEXCEPT: Thread(mmgr) {}
@ -163,7 +163,7 @@ template <typename T>
class ThreadL; class ThreadL;
template <typename RT, typename... ARGS> template <typename RT, typename... ARGS>
class ThreadL<RT(ARGS...)>: public Thread class QSE_EXPORT ThreadL<RT(ARGS...)>: public Thread
{ {
public: public:
ThreadL (Mmgr* mmgr = QSE_NULL) QSE_CPP_NOEXCEPT: Thread(mmgr), __lfunc(nullptr) {} ThreadL (Mmgr* mmgr = QSE_NULL) QSE_CPP_NOEXCEPT: Thread(mmgr), __lfunc(nullptr) {}

View File

@ -55,32 +55,28 @@ void* HeapMmgr::allocMem (qse_size_t n) QSE_CPP_NOEXCEPT
{ {
if (!this->xma) 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; 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; xtn->heap = this;
} }
void* xptr = qse_xma_alloc (this->xma, n); return qse_xma_alloc(this->xma, n);
if (!xptr) QSE_THROW (MemoryError);
return xptr;
} }
void* HeapMmgr::reallocMem (void* ptr, qse_size_t n) QSE_CPP_NOEXCEPT void* HeapMmgr::reallocMem (void* ptr, qse_size_t n) QSE_CPP_NOEXCEPT
{ {
if (!this->xma) 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; 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; xtn->heap = this;
} }
void* xptr = qse_xma_realloc (this->xma, ptr, n); return qse_xma_realloc(this->xma, ptr, n);
if (!xptr) QSE_THROW (MemoryError);
return xptr;
} }
void HeapMmgr::freeMem (void* ptr) QSE_CPP_NOEXCEPT void HeapMmgr::freeMem (void* ptr) QSE_CPP_NOEXCEPT

View File

@ -29,7 +29,7 @@ public:
qse_ssize_t n; qse_ssize_t n;
cliaddr->toStrBuf(addrbuf, QSE_COUNTOF(addrbuf)); 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()) while (!server->isStopRequested())
{ {
@ -41,7 +41,7 @@ public:
clisock->send (bb, n); clisock->send (bb, n);
} }
//qse_printf (QSE_T("byte to %s\n"), addrbuf); qse_printf (QSE_T("byte to %s\n"), addrbuf);
return 0; return 0;
} }
}; };
@ -74,7 +74,7 @@ static int test1 (void)
} }
clisock->send (bb, n); clisock->send (bb, n);
} }
qse_printf (QSE_T("byte to %s\n"), addrbuf); qse_printf (QSE_T("byte to %s\n"), addrbuf);
return 0; return 0;
}), }),