diff --git a/amxmodx/amx.h b/amxmodx/amx.h index 7ecbf48e..8fbddce9 100755 --- a/amxmodx/amx.h +++ b/amxmodx/amx.h @@ -79,15 +79,6 @@ #endif #endif -#if HAVE_ALLOCA_H - #include -#endif -#if defined __WIN32__ || defined _WIN32 || defined WIN32 /* || defined __MSDOS__ */ - #if !defined alloca - #define alloca(n) _alloca(n) - #endif -#endif - #if !defined arraysize #define arraysize(array) (sizeof(array) / sizeof((array)[0])) #endif diff --git a/amxmodx/debugger.cpp b/amxmodx/debugger.cpp index 90d5729a..95c2355f 100755 --- a/amxmodx/debugger.cpp +++ b/amxmodx/debugger.cpp @@ -450,6 +450,7 @@ int Debugger::FormatError(char *buffer, size_t maxLength) amx_err = AMX_ERR_NOTFOUND;*/ //if (!amx_err) size += _snprintf(buffer, maxLength, "(native \"%s\")", native_name); +#if 0 } else if (error == AMX_ERR_BOUNDS) { tagAMX_DBG *pDbg = m_pAmxDbg; int symbols = pDbg->hdr->symbols; @@ -649,6 +650,7 @@ int Debugger::FormatError(char *buffer, size_t maxLength) _msgbuf[0] = '\0'; size += _snprintf(buffer, maxLength, "%s", _msgbuf); +#endif //0 - NOT USED! } return size; diff --git a/amxmodx/natives.cpp b/amxmodx/natives.cpp index b9bae033..6f81ac6a 100755 --- a/amxmodx/natives.cpp +++ b/amxmodx/natives.cpp @@ -31,6 +31,7 @@ #include "amxmodx.h" #include "sh_stack.h" #include "natives.h" +#include "Debugger.h" #ifdef __linux__ #include @@ -87,18 +88,26 @@ int amxx_DynaCallback(int idx, AMX *amx, cell *params) for (int i=numParams; i>=1; i--) amx_Push(pNative->amx, params[i]); } - if ( (err=amx_Exec(pNative->amx, &ret, pNative->func)) != AMX_ERR_NONE) - { - g_NativeStack.pop(); - LogError(pNative->amx, err, ""); - return 0; - } - if (g_errorNum) + Debugger *pDebugger = (Debugger *)amx->userdata[UD_DEBUGGER]; + if (pDebugger) + pDebugger->BeginExec(); + err=amx_Exec(pNative->amx, &ret, pNative->func); + if (err != AMX_ERR_NONE) { + if (pDebugger && pDebugger->ErrorExists()) + { + //don't care + } else if (err != -1) { + //nothing logged the error + LogError(amx, err, NULL); + } + amx->error = AMX_ERR_NONE; + } else if (g_errorNum) { g_NativeStack.pop(); LogError(amx, g_errorNum, g_errorStr); - return ret; } + if (pDebugger) + pDebugger->EndExec(); g_NativeStack.pop(); return ret; diff --git a/amxmodx/sh_list.h b/amxmodx/sh_list.h index 55d8504d..9b7afb61 100644 --- a/amxmodx/sh_list.h +++ b/amxmodx/sh_list.h @@ -11,311 +11,280 @@ #ifndef _INCLUDE_SMM_LIST_H #define _INCLUDE_SMM_LIST_H -#include "sh_stack.h" +#include +#include //namespace SourceHook //{ -//This class is from CSDM for AMX Mod X -template -class List -{ -public: - class iterator; - friend class iterator; - class ListNode + //This class is from CSDM for AMX Mod X + /* + A circular, doubly-linked list with one sentinel node + + Empty: + m_Head = sentinel + m_Head->next = m_Head; + m_Head->prev = m_Head; + One element: + m_Head = sentinel + m_Head->next = node1 + m_Head->prev = node1 + node1->next = m_Head + node1->prev = m_Head + Two elements: + m_Head = sentinel + m_Head->next = node1 + m_Head->prev = node2 + node1->next = node2 + node1->prev = m_Head + node2->next = m_Head + node2->prev = node1 + */ + template + class List { public: - ListNode(const T & o) : obj(o) { }; - ListNode() { }; - void Set(const T & o) { obj = o; } - ~ListNode() - { + class iterator; + friend class iterator; + class ListNode + { + public: + ListNode(const T & o) : obj(o) { }; + ListNode() { }; + T obj; + ListNode *next; + ListNode *prev; }; - T obj; - ListNode *next; - ListNode *prev; - }; -private: - ListNode *_Initialize() - { - ListNode *n = (ListNode *)malloc(sizeof(ListNode)); - n->next = NULL; - n->prev = NULL; - return n; - } -public: - List() : m_Head(_Initialize()), m_Size(0) - { - } - List(const List &src) : m_Head(_Initialize()), m_Size(0) - { - iterator iter; - for (iter=src.begin(); iter!=src.end(); iter++) - push_back( (*iter) ); - } - ~List() - { - clear(); - if (m_Head) + private: + // Initializes the sentinel node. + // BAIL used malloc instead of new in order to bypass the need for a constructor. + ListNode *_Initialize() { - free(m_Head); - m_Head = NULL; + ListNode *n = (ListNode *)malloc(sizeof(ListNode)); + n->next = n; + n->prev = n; + return n; } - } - void unshift(const T &obj) - { - if (!m_Head->next) + public: + List() : m_Head(_Initialize()), m_Size(0) { - push_back(obj); - return; } - - ListNode *node; - if (m_FreeStack.empty()) + List(const List &src) : m_Head(_Initialize()), m_Size(0) { - node = new ListNode(obj); - } else { - node = m_FreeStack.front(); - m_FreeStack.pop(); - node->Set(obj); + iterator iter; + for (iter=src.begin(); iter!=src.end(); iter++) + push_back( (*iter) ); } - - //is the list one item circular? - /*bool realign = false; - if (m_Head->next == m_Head->prev) + ~List() { - m_Head->next->next = - }*/ - - node->next = m_Head->next; - node->prev = m_Head; - m_Head->next->prev = node; - m_Head->next = node; + clear(); - m_Size++; - } - void push_back(const T &obj) - { - ListNode *node; - if (m_FreeStack.empty()) - { - node = new ListNode(obj); - } else { - node = m_FreeStack.front(); - m_FreeStack.pop(); - node->Set(obj); + // Don't forget to free the sentinel + if (m_Head) + { + free(m_Head); + m_Head = NULL; + } } - - if (!m_Head->prev) + void push_back(const T &obj) { - //link in the node as the first item - node->next = m_Head; - node->prev = m_Head; - m_Head->prev = node; - m_Head->next = node; - } else { + ListNode *node = new ListNode(obj); + node->prev = m_Head->prev; node->next = m_Head; m_Head->prev->next = node; m_Head->prev = node; + + m_Size++; } - m_Size++; - } - size_t size() - { - return m_Size; - } - void clear() - { - ListNode *node = m_Head->next; - ListNode *temp; - m_Head->next = NULL; - m_Head->prev = NULL; - while (node && node != m_Head) + size_t size() { - temp = node->next; - delete node; - node = temp; + return m_Size; } - m_Size = 0; - while (!m_FreeStack.empty()) + + void clear() { - delete m_FreeStack.front(); - m_FreeStack.pop(); + ListNode *node = m_Head->next; + ListNode *temp; + m_Head->next = m_Head; + m_Head->prev = m_Head; + + // Iterate through the nodes until we find g_Head (the sentinel) again + while (node != m_Head) + { + temp = node->next; + delete node; + node = temp; + } + m_Size = 0; } - } - bool empty() - { - return (m_Head->next == NULL); - } - T & back() - { - return m_Head->prev->obj; - } -private: -#if defined __GNUC__ - CStack m_FreeStack; -#else - typename CStack m_FreeStack; -#endif - ListNode *m_Head; - size_t m_Size; -public: - class iterator - { - friend class List; - public: - iterator() + bool empty() { - m_This = NULL; + return (m_Size == 0); } - iterator(const List &src) + T & back() { - m_This = src.m_Head; - } - iterator(ListNode *n) : m_This(n) - { - } - iterator(const iterator &where) - { - m_This = where.m_This; - } - //pre decrement - iterator & operator--() - { - if (m_This) - m_This = m_This->prev; - return *this; - } - //post decrement - iterator operator--(int) - { - iterator old(*this); - if (m_This) - m_This = m_This->prev; - return old; - } - - //pre increment - iterator & operator++() - { - if (m_This) - m_This = m_This->next; - return *this; - } - //post increment - iterator operator++(int) - { - iterator old(*this); - if (m_This) - m_This = m_This->next; - return old; - } - - const T & operator * () const - { - return m_This->obj; - } - T & operator * () - { - return m_This->obj; - } - - T * operator -> () - { - return &(m_This->obj); - } - const T * operator -> () const - { - return &(m_This->obj); - } - - bool operator != (const iterator &where) const - { - return (m_This != where.m_This); - } - bool operator ==(const iterator &where) const - { - return (m_This == where.m_This); + return m_Head->prev->obj; } private: - ListNode *m_This; - }; -public: - iterator begin() const - { - if (m_Size) - return iterator(m_Head->next); - else - return iterator(m_Head); - } - iterator end() const - { - return iterator(m_Head); - } - iterator erase(iterator &where) - { - ListNode *pNode = where.m_This; - iterator iter(where); - iter++; - - //If we are both the head and tail... - if (m_Head->next == pNode && m_Head->prev == pNode) + ListNode *m_Head; + size_t m_Size; + public: + class iterator { - m_Head->next = NULL; - m_Head->prev = NULL; - } else if (m_Head->next == pNode) { - //we are only the first - pNode->next->prev = m_Head; - m_Head->next = pNode->next; - } else if (m_Head->prev == pNode) { - //we are the tail - pNode->prev->next = m_Head; - m_Head->prev = pNode->prev; - } else { - //middle unlink + friend class List; + public: + iterator() + { + m_This = NULL; + } + iterator(const List &src) + { + m_This = src.m_Head; + } + iterator(ListNode *n) : m_This(n) + { + } + iterator(const iterator &where) + { + m_This = where.m_This; + } + //pre decrement + iterator & operator--() + { + if (m_This) + m_This = m_This->prev; + return *this; + } + //post decrement + iterator operator--(int) + { + iterator old(*this); + if (m_This) + m_This = m_This->prev; + return old; + } + + //pre increment + iterator & operator++() + { + if (m_This) + m_This = m_This->next; + return *this; + } + //post increment + iterator operator++(int) + { + iterator old(*this); + if (m_This) + m_This = m_This->next; + return old; + } + + const T & operator * () const + { + return m_This->obj; + } + T & operator * () + { + return m_This->obj; + } + + T * operator -> () + { + return &(m_This->obj); + } + const T * operator -> () const + { + return &(m_This->obj); + } + + bool operator != (const iterator &where) const + { + return (m_This != where.m_This); + } + bool operator ==(const iterator &where) const + { + return (m_This == where.m_This); + } + private: + ListNode *m_This; + }; + public: + iterator begin() const + { + return iterator(m_Head->next); + } + iterator end() const + { + return iterator(m_Head); + } + iterator erase(iterator &where) + { + ListNode *pNode = where.m_This; + iterator iter(where); + iter++; + + + // Works for all cases: empty list, erasing first element, erasing tail, erasing in the middle... pNode->prev->next = pNode->next; pNode->next->prev = pNode->prev; + + delete pNode; + m_Size--; + + return iter; } - m_FreeStack.push(pNode); - m_Size--; - - return iter; - } -public: - void remove(const T & obj) - { - iterator b; - for (b=begin(); b!=end(); b++) + iterator insert(iterator where, const T &obj) { - if ( (*b) == obj ) + // Insert obj right before where + + ListNode *node = new ListNode(obj); + ListNode *pWhereNode = where.m_This; + + pWhereNode->prev->next = node; + node->prev = pWhereNode->prev; + pWhereNode->prev = node; + node->next = pWhereNode; + + m_Size++; + + return iterator(node); + } + + public: + void remove(const T & obj) + { + iterator b; + for (b=begin(); b!=end(); b++) { - erase( b ); - break; + if ( (*b) == obj ) + { + erase( b ); + break; + } } } - } - template - iterator find(const U & equ) - { - iterator iter; - for (iter=begin(); iter!=end(); iter++) + template + iterator find(const U & equ) { - if ( (*iter) == equ ) - return iter; + iterator iter; + for (iter=begin(); iter!=end(); iter++) + { + if ( (*iter) == equ ) + return iter; + } + return end(); } - return end(); - } - List & operator =(List &src) - { - clear(); - iterator iter; - for (iter=src.begin(); iter!=src.end(); iter++) - push_back( (*iter) ); - return *this; - } -}; + List & operator =(const List &src) + { + clear(); + iterator iter; + for (iter=src.begin(); iter!=src.end(); iter++) + push_back( (*iter) ); + return *this; + } + }; //}; //NAMESPACE #endif //_INCLUDE_CSDM_LIST_H