From 7706db354ee0f5e1c01c49ca18e44bbc93184597 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Mon, 23 Mar 2015 15:14:43 +0000 Subject: [PATCH] fixed building problems with old compilers --- qse/cmd/xli/xli.c | 7 ++++ qse/include/qse/Types.hpp | 56 +++++++++++++++++++++++--- qse/include/qse/cmn/Array.hpp | 36 ++++++++++------- qse/include/qse/cmn/HashList.hpp | 13 +----- qse/include/qse/cmn/HashTable.hpp | 14 ++++++- qse/include/qse/cmn/LinkedList.hpp | 16 ++------ qse/include/qse/cmn/Mmgr.hpp | 7 ++-- qse/include/qse/cmn/Mpool.hpp | 7 ++-- qse/include/qse/cmn/RedBlackTree.hpp | 10 ++--- qse/include/qse/cmn/ScopedPtr.hpp | 8 ++-- qse/include/qse/cmn/SharedPtr.hpp | 19 +++++---- qse/include/qse/cmn/StrBase.hpp | 30 ++++++-------- qse/include/qse/xli/xli.h | 21 ++++++++-- qse/lib/awk/Awk.cpp | 12 ++++-- qse/lib/xli/xli.c | 60 ++++++++++++++++++++++++++-- 15 files changed, 221 insertions(+), 95 deletions(-) diff --git a/qse/cmd/xli/xli.c b/qse/cmd/xli/xli.c index ff557caf..7c1d8181 100644 --- a/qse/cmd/xli/xli.c +++ b/qse/cmd/xli/xli.c @@ -587,6 +587,13 @@ for (i = 0; i < QSE_COUNTOF(defs); i++) qse_xli_definepair (xli, defs[i].name, & qse_printf (QSE_T("#LIST\n")); } } + + /* + if (g_value) + { + TODO: ... set value... + } + */ } diff --git a/qse/include/qse/Types.hpp b/qse/include/qse/Types.hpp index cefc9565..e0cc026e 100644 --- a/qse/include/qse/Types.hpp +++ b/qse/include/qse/Types.hpp @@ -34,12 +34,58 @@ #include #include -/// The QSE_ENABLE_CPP11_MOVE macro enables C++11 move semantics -/// in various classes. -#if (__cplusplus >= 201103L) // C++11 -# define QSE_ENABLE_CPP11_MOVE 1 -#endif +// The QSE_CPP_CALL_DESTRUCTOR() macro calls a destructor explicitly. +// The QSE_CPP_CALL_PLACEMENT_DELETE1() macro calls the global operator delete +// with 1 extra argument given. +#if (__cplusplus >= 201103L) // C++11 + + /// The QSE_ENABLE_CPP11_MOVE macro enables C++11 move semantics + /// in various classes. + #define QSE_ENABLE_CPP11_MOVE 1 + + #define QSE_CPP_CALL_DESTRUCTOR(ptr, class_name) ((ptr)->~class_name()) + #define QSE_CPP_CALL_PLACEMENT_DELETE1(ptr, arg1) (::operator delete ((ptr), (arg1))) + +#elif (__cplusplus >= 199711L) // C++98 + + #define QSE_CPP_CALL_DESTRUCTOR(ptr, class_name) ((ptr)->~class_name()) + #define QSE_CPP_CALL_PLACEMENT_DELETE1(ptr, arg1) (::operator delete ((ptr), (arg1))) + +#else + + #if defined(__BORLANDC__) + + // Explicit destructor call requires a class name depending on the + // C++ standard/compiler. + // + // Node* x; + // x->~Node (); + // + // While x->~Node() is ok with modern compilers, some old compilers + // like BCC55 required the class name in the call as shown below. + // + // x->Node::~Node (); + + #define QSE_CPP_CALL_DESTRUCTOR(ptr, class_name) ((ptr)->class_name::~class_name()) + #define QSE_CPP_CALL_PLACEMENT_DELETE1(ptr, arg1) (::operator delete ((ptr), (arg1))) + + #elif defined(__WATCOMC__) + // WATCOM has a problem with this syntax. + // Node* x; x->Node::~Node(). + // But it doesn't support operator delete overloading. + + #define QSE_CPP_CALL_DESTRUCTOR(ptr, class_name) ((ptr)->~class_name()) + #define QSE_CPP_CALL_PLACEMENT_DELETE1(ptr, arg1) (::operator_delete ((ptr), (arg1))) + + #else + + #define QSE_CPP_CALL_DESTRUCTOR(ptr, class_name) ((ptr)->~class_name()) + #define QSE_CPP_CALL_PLACEMENT_DELETE1(ptr, arg1) (::operator delete ((ptr), (arg1))) + + #endif + +#endif #if defined(QSE_ENABLE_CPP11_MOVE) diff --git a/qse/include/qse/cmn/Array.hpp b/qse/include/qse/cmn/Array.hpp index 35ffc4d9..60da2729 100644 --- a/qse/include/qse/cmn/Array.hpp +++ b/qse/include/qse/cmn/Array.hpp @@ -198,7 +198,8 @@ protected: qse_size_t index; //T* tmp = new T[capa]; - T* tmp = (T*)::operator new (capa * QSE_SIZEOF(*tmp), this->getMmgr()); + //T* tmp = (T*)::operator new (capa * QSE_SIZEOF(*tmp), this->getMmgr()); + T* tmp = (T*)this->getMmgr()->allocate (capa * QSE_SIZEOF(*tmp)); try { @@ -217,9 +218,11 @@ protected: { --index; this->_positioner (tmp[index], INVALID_INDEX); - tmp[index].~T (); + tmp[index].T::~T (); } - ::operator delete (tmp, this->getMmgr()); + + //::operator delete (tmp, this->getMmgr()); + this->getMmgr()->dispose (tmp); throw; } @@ -236,7 +239,8 @@ protected: qse_size_t index; //T* tmp = new T[capa]; - T* tmp = (T*)::operator new (capa * QSE_SIZEOF(*tmp), this->getMmgr()); + //T* tmp = (T*)::operator new (capa * QSE_SIZEOF(*tmp), this->getMmgr()); + T* tmp = (T*)this->getMmgr()->allocate (capa * QSE_SIZEOF(*tmp)); try { @@ -265,9 +269,11 @@ protected: //catch (...) {} this->_positioner (tmp[index], INVALID_INDEX); - tmp[index].~T (); + tmp[index].T::~T (); } - ::operator delete (tmp, this->getMmgr()); + + //::operator delete (tmp, this->getMmgr()); + this->getMmgr()->dispose (tmp); throw; } @@ -320,7 +326,7 @@ protected: { --i; this->_positioner (this->buffer[i], INVALID_INDEX); - this->buffer[i].~T (); + this->buffer[i].T::~T (); } this->count = 0; @@ -587,7 +593,7 @@ public: // 1. destruct followed by copy construct //this->_positioner (this->buffer[j], INVALID_INDEX); - //this->buffer[j].~T(); + //this->buffer[j].T::~T(); //new((QSE::Mmgr*)QSE_NULL, &this->buffer[j]) T(this->buffer[i]); //this->_positioner (this->buffer[j], j); @@ -602,7 +608,7 @@ public: while (j < this->count) { this->_positioner (this->buffer[j], INVALID_INDEX); - this->buffer[j].~T (); + this->buffer[j].T::~T (); j++; } @@ -638,11 +644,10 @@ public: QSE_ASSERT (this->count <= 0); QSE_ASSERT (this->capacity > 0); - ::operator delete (this->buffer, this->getMmgr()); - this->capacity = 0; + //::operator delete (this->buffer, this->getMmgr()); + this->getMmgr()->dispose (this->buffer); this->buffer = QSE_NULL; - - QSE_ASSERT (this->capacity == 0); + this->capacity = 0; } } @@ -654,7 +659,7 @@ public: { // call the destructor of the items this->_positioner (this->buffer[i], INVALID_INDEX); - this->buffer[i].~T (); + this->buffer[i].T::~T (); } this->count = size; @@ -703,7 +708,8 @@ public: QSE_ASSERT (this->capacity <= 0); QSE_ASSERT (this->count <= 0); - this->buffer = (T*)::operator new (capa * QSE_SIZEOF(*this->buffer), this->getMmgr()); + //this->buffer = (T*)::operator new (capa * QSE_SIZEOF(*this->buffer), this->getMmgr()); + this->buffer = (T*)this->getMmgr()->allocate (capa * QSE_SIZEOF(*this->buffer)); this->capacity = capa; } } diff --git a/qse/include/qse/cmn/HashList.hpp b/qse/include/qse/cmn/HashList.hpp index a49521b0..4989259e 100644 --- a/qse/include/qse/cmn/HashList.hpp +++ b/qse/include/qse/cmn/HashList.hpp @@ -763,17 +763,8 @@ private: void free_datum_list () { // destruction in response to 'placement new' - - #if defined(__BORLANDC__) - // BCC55 doesn't support the explicit destructor call. - // instead, call shatter() which is actually called by ~DatumList(). - this->datum_list->shatter (); - #else - // call the destructor for completeness - this->datum_list->~DatumList (); - #endif - // free the memory - ::operator delete (this->datum_list, this->getMmgr()); + QSE_CPP_CALL_DESTRUCTOR (this->datum_list, DatumList); + QSE_CPP_CALL_PLACEMENT_DELETE1 (this->datum_list, this->getMmgr()); } }; diff --git a/qse/include/qse/cmn/HashTable.hpp b/qse/include/qse/cmn/HashTable.hpp index e00087f5..0d4c1cc7 100644 --- a/qse/include/qse/cmn/HashTable.hpp +++ b/qse/include/qse/cmn/HashTable.hpp @@ -248,8 +248,12 @@ public: Pair* search (const K& key) { - //PairNode* node = this->pair_list.update (Pair(key)); + //PairNode* node = this->pair_list.search (Pair(key)); + #if defined(__WATCOMC__) + PairNode* node = this->pair_list.heterofindNode (key); + #else PairNode* node = this->pair_list.template heterofindNode (key); + #endif if (!node) return QSE_NULL; return &node->value; } @@ -257,14 +261,22 @@ public: int remove (const K& key) { //return this->pair_list.remove (Pair(key)); + #if defined(__WATCOMC__) + return this->pair_list.heteroremove (key); + #else return this->pair_list.template heteroremove (key); + #endif } template Pair* heterosearch (const MK& key) { typedef MHeteroEqualer MEqualer; + #if defined(__WATCOMC__) + PairNode* node = this->pair_list.heterosearch (key); + #else PairNode* node = this->pair_list.template heterosearch (key); + #endif if (!node) return QSE_NULL; return &node->value; } diff --git a/qse/include/qse/cmn/LinkedList.hpp b/qse/include/qse/cmn/LinkedList.hpp index 822545ca..a6a6680a 100644 --- a/qse/include/qse/cmn/LinkedList.hpp +++ b/qse/include/qse/cmn/LinkedList.hpp @@ -207,11 +207,6 @@ public: }; ~LinkedList () - { - this->shatter (); - } - - void shatter () { this->clear (true); } @@ -441,11 +436,8 @@ public: void remove (Node* node) { this->yield (node, false); - - //call the destructor - node->~Node (); - // free the memory - ::operator delete (node, &this->mp); + QSE_CPP_CALL_DESTRUCTOR (node, Node); + QSE_CPP_CALL_PLACEMENT_DELETE1 (node, &this->mp); } Node* yieldByValue (const T& value, bool clear_links = true) @@ -659,8 +651,8 @@ public: saved = p->next; // placement new/delete handling - p->~Node (); // call the destructor - ::operator delete (p, &this->mp); // free the memory + QSE_CPP_CALL_DESTRUCTOR (p, Node); + QSE_CPP_CALL_PLACEMENT_DELETE1 (p, &this->mp); this->node_count--; p = saved; diff --git a/qse/include/qse/cmn/Mmgr.hpp b/qse/include/qse/cmn/Mmgr.hpp index 01426b92..096f1eb2 100644 --- a/qse/include/qse/cmn/Mmgr.hpp +++ b/qse/include/qse/cmn/Mmgr.hpp @@ -174,10 +174,11 @@ protected: QSE_END_NAMESPACE(QSE) ///////////////////////////////// -void* operator new (qse_size_t size, QSE::Mmgr* mmgr); -void operator delete (void* ptr, QSE::Mmgr* mmgr); +QSE_EXPORT void* operator new (qse_size_t size, QSE::Mmgr* mmgr); -void* operator new (qse_size_t size, QSE::Mmgr* mmgr, void* existing_ptr); +QSE_EXPORT void operator delete (void* ptr, QSE::Mmgr* mmgr); + +QSE_EXPORT void* operator new (qse_size_t size, QSE::Mmgr* mmgr, void* existing_ptr); #if 0 // i found no way to delete an array allocated with diff --git a/qse/include/qse/cmn/Mpool.hpp b/qse/include/qse/cmn/Mpool.hpp index 7fa21660..c8125a1c 100644 --- a/qse/include/qse/cmn/Mpool.hpp +++ b/qse/include/qse/cmn/Mpool.hpp @@ -124,9 +124,10 @@ protected: QSE_END_NAMESPACE(QSE) //////////////////////////////// -void* operator new (qse_size_t size, QSE::Mpool* mp); -void operator delete (void* ptr, QSE::Mpool* mp); +QSE_EXPORT void* operator new (qse_size_t size, QSE::Mpool* mp); -void* operator new (qse_size_t size, QSE::Mpool* mp, void* existing_ptr); +QSE_EXPORT void operator delete (void* ptr, QSE::Mpool* mp); + +QSE_EXPORT void* operator new (qse_size_t size, QSE::Mpool* mp, void* existing_ptr); #endif diff --git a/qse/include/qse/cmn/RedBlackTree.hpp b/qse/include/qse/cmn/RedBlackTree.hpp index 1ad53f4b..05b2eb47 100644 --- a/qse/include/qse/cmn/RedBlackTree.hpp +++ b/qse/include/qse/cmn/RedBlackTree.hpp @@ -387,8 +387,8 @@ public: #if defined(QSE_REDBLACKTREE_ALLOCATE_NIL) // destroy the nil node. - this->nil->~Node (); - ::operator delete (this->nil, this->getMmgr()); + QSE_CPP_CALL_DESTRUCTOR (this->nil, Node); + QSE_CPP_CALL_PLACEMENT_DELETE1 (this->nil, this->getMmgr()); #else // do nothing #endif @@ -447,10 +447,8 @@ public: protected: void dispose_node (Node* node) { - //call the destructor - node->~Node (); - // free the memory - ::operator delete (node, &this->mp); + QSE_CPP_CALL_DESTRUCTOR (node, Node); + QSE_CPP_CALL_PLACEMENT_DELETE1 (node, &this->mp); } Node* find_node (const T& datum) const diff --git a/qse/include/qse/cmn/ScopedPtr.hpp b/qse/include/qse/cmn/ScopedPtr.hpp index 4d1c002f..4771ba3a 100644 --- a/qse/include/qse/cmn/ScopedPtr.hpp +++ b/qse/include/qse/cmn/ScopedPtr.hpp @@ -60,8 +60,8 @@ struct ScopedPtrMmgrDeleter { void operator() (T* ptr, void* arg) { - ptr->~T (); - ::operator delete (ptr, (QSE::Mmgr*)arg); + QSE_CPP_CALL_DESTRUCTOR (ptr, T); + QSE_CPP_CALL_PLACEMENT_DELETE1 (ptr, (QSE::Mmgr*)arg); } }; @@ -184,8 +184,8 @@ public: } private: - T* _ptr; - void* _darg; + T* _ptr; + void* _darg; DELETER _deleter; }; diff --git a/qse/include/qse/cmn/SharedPtr.hpp b/qse/include/qse/cmn/SharedPtr.hpp index 3db3cb7a..054bdf92 100644 --- a/qse/include/qse/cmn/SharedPtr.hpp +++ b/qse/include/qse/cmn/SharedPtr.hpp @@ -60,8 +60,8 @@ struct SharedPtrMmgrDeleter { void operator() (T* ptr, void* arg) { - ptr->~T (); - ::operator delete (ptr, (QSE::Mmgr*)arg); + QSE_CPP_CALL_DESTRUCTOR (ptr, T); + QSE_CPP_CALL_PLACEMENT_DELETE1 (ptr, (QSE::Mmgr*)arg); } }; @@ -79,7 +79,7 @@ public: SharedPtr (T* ptr = (T*)QSE_NULL, void* darg = (void*)QSE_NULL): Mmged(QSE_NULL) { - this->_item = new (this->getMmgr()) item_t; + this->_item = new(this->getMmgr()) item_t; this->_item->ptr = ptr; this->_item->darg = darg; @@ -88,7 +88,7 @@ public: SharedPtr (Mmgr* mmgr, T* ptr = (T*)QSE_NULL, void* darg = (void*)QSE_NULL): Mmged(mmgr) { - this->_item = new (this->getMmgr()) item_t; + this->_item = new(this->getMmgr()) item_t; this->_item->ptr = ptr; this->_item->darg = darg; @@ -104,9 +104,11 @@ public: { if (this->_item->deref() <= 0) { + // reference count reached 0. if (this->_item->ptr) this->_item->deleter (this->_item->ptr, this->_item->darg); - // no destructor as *this->_ref is a plain type. - ::operator delete (this->_item, this->getMmgr()); + + QSE_CPP_CALL_DESTRUCTOR (this->_item, item_t); + QSE_CPP_CALL_PLACEMENT_DELETE1 (this->_item, this->getMmgr()); } } @@ -117,8 +119,9 @@ public: if (this->_item->deref() <= 0) { if (this->_item->ptr) this->_item->deleter (this->_item->ptr, this->_item->darg); - // no destructor as *this->_ref is a plain type. - ::operator delete (this->_item, this->getMmgr()); + + QSE_CPP_CALL_DESTRUCTOR (this->_item, item_t); + QSE_CPP_CALL_PLACEMENT_DELETE1 (this->_item, this->getMmgr()); } // must copy the memory manager pointer as the item diff --git a/qse/include/qse/cmn/StrBase.hpp b/qse/include/qse/cmn/StrBase.hpp index 79366dd3..cff5ae05 100644 --- a/qse/include/qse/cmn/StrBase.hpp +++ b/qse/include/qse/cmn/StrBase.hpp @@ -53,7 +53,8 @@ protected: if (capacity < size) capacity = size; // I assume that CHAR_TYPE is a plain type. - this->buffer = (CHAR_TYPE*)::operator new ((capacity + 1) * QSE_SIZEOF(CHAR_TYPE), mmgr); + //this->buffer = (CHAR_TYPE*)::operator new ((capacity + 1) * QSE_SIZEOF(CHAR_TYPE), mmgr); + this->buffer = (CHAR_TYPE*)mmgr->allocate((capacity + 1) * QSE_SIZEOF(CHAR_TYPE)); // So no constructor calling is needed. //for (qse_size_t i = 0; i < capacity + 1; i++) //{ @@ -69,7 +70,8 @@ protected: buffer (QSE_NULL) // set buffer to QSE_NULL here in case operator new rasises an exception { if (capacity < size) capacity = size; - this->buffer = (CHAR_TYPE*)::operator new ((capacity + 1) * QSE_SIZEOF(CHAR_TYPE), mmgr); + //this->buffer = (CHAR_TYPE*)::operator new ((capacity + 1) * QSE_SIZEOF(CHAR_TYPE), mmgr); + this->buffer = (CHAR_TYPE*)mmgr->allocate((capacity + 1) * QSE_SIZEOF(CHAR_TYPE)); this->capacity = capacity; this->buffer[size] = NULL_CHAR; @@ -80,7 +82,7 @@ protected: void shatter (Mmgr* mmgr) { QSE_ASSERT (this->buffer != QSE_NULL); - ::operator delete (this->buffer, mmgr); + mmgr->dispose (this->buffer); //::operator_delete (this->buffer, mmgr); this->buffer = QSE_NULL; } @@ -107,13 +109,15 @@ protected: if (inc > 0) { qse_size_t newcapa = this->capacity + inc; - CHAR_TYPE* tmp = ::operator new ((newcapa + 1) * QSE_SIZEOF(CHAR_TYPE), mmgr); + //CHAR_TYPE* tmp = ::operator new ((newcapa + 1) * QSE_SIZEOF(CHAR_TYPE), mmgr); + CHAR_TYPE* tmp = (CHAR_TYPE*)mmgr->allocate((newcapa + 1) * QSE_SIZEOF(CHAR_TYPE)); qse_size_t cursize = this->size; this->size = this->opset.copy (tmp, this->buffer, cursize); QSE_ASSERT (this->size == cursize); - ::operator delete (this->buffer, mmgr); + //::operator_delete (this->buffer, mmgr); + mmgr->dispose (this->buffer); this->buffer = tmp; this->capacity = newcapa; @@ -287,18 +291,10 @@ protected: // destroy the actual contents via the shatter() funtion // call the destructor for completeness only sd->shatter (this->getMmgr()); - #if defined(__BORLANDC__) - // BCC55 doesn't support calling the destructor explicitly. - // anyway, it's safe not to call it for the way i destroy - // the object using the shatter() call above - // - // DO NOTHING - // - #else - // call the destructor - sd->~StringItem (); - #endif - ::operator delete (sd, this->getMmgr()); + + // delete the object allocated using the place new + QSE_CPP_CALL_DESTRUCTOR (sd, StringItem); + QSE_CPP_CALL_PLACEMENT_DELETE1 (sd, this->getMmgr()); } } diff --git a/qse/include/qse/xli/xli.h b/qse/include/qse/xli/xli.h index 506ca1f0..57fd15d0 100644 --- a/qse/include/qse/xli/xli.h +++ b/qse/include/qse/xli/xli.h @@ -42,6 +42,7 @@ * } * key3 = "12345"; * \endcode + * */ #include @@ -145,16 +146,16 @@ enum qse_xli_trait_t }; typedef enum qse_xli_trait_t qse_xli_trait_t; -typedef struct qse_xli_val_t qse_xli_val_t; -typedef struct qse_xli_nil_t qse_xli_nil_t; -typedef struct qse_xli_str_t qse_xli_str_t; +typedef struct qse_xli_val_t qse_xli_val_t; +typedef struct qse_xli_nil_t qse_xli_nil_t; +typedef struct qse_xli_str_t qse_xli_str_t; typedef struct qse_xli_list_t qse_xli_list_t; typedef struct qse_xli_atom_t qse_xli_atom_t; typedef struct qse_xli_pair_t qse_xli_pair_t; typedef struct qse_xli_text_t qse_xli_text_t; typedef struct qse_xli_file_t qse_xli_file_t; -typedef struct qse_xli_eof_t qse_xli_eof_t; +typedef struct qse_xli_eof_t qse_xli_eof_t; enum qse_xli_val_type_t { @@ -581,6 +582,13 @@ QSE_EXPORT qse_xli_pair_t* qse_xli_insertpair ( qse_xli_val_t* val ); +/** + * The qse_xli_insertpairwithemptylist() function inserts a new pair + * with an empty list as a value. You should call this function for adding + * a new pair holding a list. + * + * \return pointer to an inserted pair on success, #QSE_NULL on failure. + */ QSE_EXPORT qse_xli_pair_t* qse_xli_insertpairwithemptylist ( qse_xli_t* xli, qse_xli_list_t* list, @@ -590,6 +598,10 @@ QSE_EXPORT qse_xli_pair_t* qse_xli_insertpairwithemptylist ( const qse_char_t* keytag ); +/** + * The qse_xli_insertpairwithstr() function inserts a new pair with a key + * named \a key with a string value \a value. + */ QSE_EXPORT qse_xli_pair_t* qse_xli_insertpairwithstr ( qse_xli_t* xli, qse_xli_list_t* list, @@ -644,6 +656,7 @@ QSE_EXPORT qse_size_t qse_xli_countpairs ( const qse_char_t* fqpn ); + /** * The qse_xli_addsegtostr() function creates a new string segment made of * the character string pointed to by \a value and chains it to the XLI string diff --git a/qse/lib/awk/Awk.cpp b/qse/lib/awk/Awk.cpp index 19a89f80..0af03af6 100644 --- a/qse/lib/awk/Awk.cpp +++ b/qse/lib/awk/Awk.cpp @@ -1452,7 +1452,11 @@ int Awk::dispatch_function (Run* run, const fnc_info_t* fi) return -1; } #else - try { args = (Value*)::operator new (QSE_SIZEOF(Value) * nargs, this->getMmgr()); } + try + { + //args = (Value*)::operator new (QSE_SIZEOF(Value) * nargs, this->getMmgr()); + args = (Value*)this->getMmgr()->allocate (QSE_SIZEOF(Value) * nargs); + } catch (...) { args = QSE_NULL; } if (args == QSE_NULL) { @@ -1564,9 +1568,11 @@ int Awk::dispatch_function (Run* run, const fnc_info_t* fi) for (i = nargs; i > 0; ) { --i; - args[i].~Value (); + args[i].Value::~Value (); } - ::operator delete (args, this->getMmgr()); + + //::operator delete (args, this->getMmgr()); + this->getMmgr()->dispose (args); #endif } diff --git a/qse/lib/xli/xli.c b/qse/lib/xli/xli.c index e9d577c6..dc140891 100644 --- a/qse/lib/xli/xli.c +++ b/qse/lib/xli/xli.c @@ -490,6 +490,14 @@ static void free_val (qse_xli_root_list_t* root, qse_xli_val_t* val) static void free_atom (qse_xli_root_list_t* root, qse_xli_atom_t* atom) { + /* Among all atom type, QSE_XLI_PAIR has a value to dispose of specially. + * A tag and an alise are inlined to the atom itself. see insert_atom() + * above for details. + * + * for QSE_XLI_TEXT, QSE_XLI_FILE, QSE_XLI_EOF, data are inlined to + * the atom itself as well. + */ + if (atom->type == QSE_XLI_PAIR) free_val (root, ((qse_xli_pair_t*)atom)->val); QSE_MMGR_FREE (root->mmgr, atom); } @@ -947,15 +955,58 @@ void qse_xli_undefinepairs (qse_xli_t* xli) qse_rbt_clear (xli->schema); } - -#if 0 +/* qse_xli_pair_t* qse_xli_getpair (qse_xli_t* xli, const qse_char_t* fqpn) { return qse_xli_findpair (xli, &xli->root->list, fqpn); } +*/ -qse_xli_pair_t* qse_xli_setpair (qse_xli_t* xli, const qse_char_t* fqpn, const qse_xli_val_t* val) -> str, val, nil +#if 0 +/* val is str , list or nil */ +qse_xli_pair_t* qse_xli_updatepair (qse_xli_t* xli, const qse_char_t* fqpn, const qse_xli_val_t* val) { + qse_xli_pair_t* pair; + + pair = qse_xli_findpair (xli, fqpn); + if (pair) + { + /* update the value of an existing pair */ + qse_xli_val_t* old_val; + qse_xli_scm_t* scm; + + if (xli->opt.trait & QSE_XLI_VALIDATE) + { + qse_rbt_pair_t* scm_pair; + + scm_pair = qse_rbt_search (xli->schema, fqpn, qse_strlen(fqpn)); + if (!scm_pair) + { + /*qse_xli_seterror (xli, QSE_XLI_EUDKEY, (const qse_cstr_t*)&key, &kloc);*/ + goto oops; + } + + scm = (qse_xli_scm_t*)QSE_RBT_VPTR(pair); + } + + if (scm->flags & QSE_XLI_SCM_KEYNODUP) key_nodup = 2; + if (scm->flags & QSE_XLI_SCM_KEYALIAS) key_alias = 2; + if (scm->flags & QSE_XLI_SCM_VALIFFY) val_iffy = 1; + +/* TODO: alias, tag?? + * when alias and tags are to changed, it can't just update the value only + * the whole pair may have to get reallocated and update must be made to the rbt data array. + */ + + old_val = pair->val; + pair->val = val; + free_val (old_val); + + } + + return pair; + +#if 0 const qse_char_t* ptr; const qse_xli_list_t* curlist; fqpn_seg_t seg; @@ -1035,7 +1086,10 @@ qse_xli_pair_t* qse_xli_setpair (qse_xli_t* xli, const qse_char_t* fqpn, const q noent: qse_xli_seterrnum (xli, QSE_XLI_ENOENT, &seg.ki); return QSE_NULL; +#endif } + + #endif void* qse_getxlipairxtn (qse_xli_pair_t* pair)